refactor(temporal): extract this-type-check boilerplate into a macro#5233
Draft
Nakshatra480 wants to merge 1 commit intoboa-dev:mainfrom
Draft
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
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.39% +13.15%
===========================================
Files 476 589 +113
Lines 46892 62753 +15861
===========================================
+ Hits 22154 37902 +15748
- Misses 24738 24851 +113 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
nekevss
reviewed
Mar 25, 2026
Member
nekevss
left a comment
There was a problem hiding this comment.
I do sort of like the change for how succinct it is, and it's potential for making the code more readable.
One question: why change just the temporal objects and not the built-ins in general? Had you looked at other built-ins?
4c42492 to
56ac6f3
Compare
56ac6f3 to
4fee1fe
Compare
…lot! macro Replace the repeated as_object/downcast_ref/ok_or_else boilerplate with a single require_internal_slot! macro defined in builtins/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>. Uses the js_error! macro internally for error construction. Temporal modules (163 replacements): - zoneddatetime, plain_date_time, plain_time, plain_year_month, plain_date, duration, instant, plain_month_day Other builtins (32 replacements): - date (9), dataview (5), typed_array (4), array_buffer (4), shared_array_buffer (3), weak_map (2), intl/segmenter (2), intl/collator (1), weak_set (1), weak_ref (1)
4fee1fe to
2fdc570
Compare
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