refactor(temporal): extract this-type-check boilerplate into a macro#5233
Open
Nakshatra480 wants to merge 1 commit intoboa-dev:mainfrom
Open
refactor(temporal): extract this-type-check boilerplate into a macro#5233Nakshatra480 wants to merge 1 commit intoboa-dev:mainfrom
Nakshatra480 wants to merge 1 commit intoboa-dev:mainfrom
Conversation
…oral_object! macro
Replace 163 occurrences of the 5-line this-type-check boilerplate across
8 Temporal builtin files with a single this_temporal_object! macro defined
in temporal/mod.rs.
The macro produces two let-bindings in the caller's scope: one for the
owned JsObject (to keep it alive) and one for the downcast Ref<T>.
Error messages standardized to: 'the this object must be a {Type} object.'
Files changed:
- temporal/mod.rs: macro definition
- zoneddatetime/mod.rs: 47 replacements
- plain_date_time/mod.rs: 37 replacements
- plain_time/mod.rs: 16 replacements
- plain_year_month/mod.rs: 15 replacements
- plain_date/mod.rs: 15 replacements
- duration/mod.rs: 13 replacements
- instant/mod.rs: 12 replacements
- plain_month_day/mod.rs: 8 replacements
Net delta: +188 / -1145 lines
4053092 to
4c42492
Compare
Test262 conformance changes
Tested main commit: |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5233 +/- ##
===========================================
+ Coverage 47.24% 60.44% +13.19%
===========================================
Files 476 582 +106
Lines 46892 62806 +15914
===========================================
+ Hits 22154 37960 +15806
- Misses 24738 24846 +108 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR removes the repetitive
this-type-check boilerplate present in almost every Temporal prototype method.Previously, each method manually called
this.as_object(), downcasted with.as_ref().and_then(JsObject::downcast_ref::<Self>), and threw aTypeErroron failure - 5 lines repeated 158 times across 8 files.I've extracted this into a single
this_temporal_object!macro intemporal/mod.rs. A helper function isn't viable here becausethis.as_object()returns an ownedJsObjectthat the resultingRef<T>borrows from - the owner must live in the caller's scope. The macro solves this by emitting theletbindings directly there.Changes
TypeErrormessages to"the this object must be a {Type} object."- a few types likeDurationpreviously used inconsistent phrasing