refactor(temporal): remove unnecessary clone in roundTo option parsing#5290
Merged
jedel1043 merged 2 commits intoboa-dev:mainfrom Apr 1, 2026
Merged
Conversation
Refactored the `round` method across 5 Temporal builtins (Duration, Instant, PlainDateTime, PlainTime, ZonedDateTime) to avoid an unnecessary JsVariant-to-JsValue conversion when calling `get_options_object`. Instead of matching on `JsValue::variant()` and reconstructing a JsValue in the fallback arm, the code now works directly with `&JsValue` via `args.get_or_undefined(0)`. This resolves the TODO comments requesting removal of the clone.
Test262 conformance changes
Tested main commit: |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5290 +/- ##
===========================================
+ Coverage 47.24% 59.80% +12.56%
===========================================
Files 476 589 +113
Lines 46892 63477 +16585
===========================================
+ Hits 22154 37963 +15809
- Misses 24738 25514 +776 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
zhuzhu81998
approved these changes
Apr 1, 2026
Contributor
zhuzhu81998
left a comment
There was a problem hiding this comment.
looks correct to me 👀
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.
PR: refactor(temporal): remove unnecessary clone in roundTo option parsing
Summary
The
roundmethod in 5 Temporal builtins (Duration,Instant,PlainDateTime,PlainTime,ZonedDateTime) previously matched onargs.first().map(JsValue::variant)to inspect theroundToargument. In the fallback arm, the extractedJsVariantwas converted back into aJsValueviaJsValue::from(round_to)just to pass it toget_options_object(&JsValue)— an unnecessary round-trip that cloned the inner value.This PR refactors all 5 call sites to work directly with
&JsValueviaargs.get_or_undefined(0), usingis_undefined()andas_string()checks instead of variant pattern matching. This eliminates the clone while preserving identical semantics.Changes
duration/mod.rs— ReplacedmatchonJsVariantwithif/elseon&JsValueinstant/mod.rs— Same refactor + removed unusedJsVariantimportplain_date_time/mod.rs— Same refactor + removed unusedJsVariantimportplain_time/mod.rs— Same refactorzoneddatetime/mod.rs— Same refactorResolves the
TODO: remove this clonecomments in the affected files.Test plan
cargo fmt -- --checkpassescargo clippy --all-features --all-targetspassescargo clippy --no-default-featurespassescargo test -p boa_engine -- temporalpasses