Skip to content

refactor(temporal): remove unnecessary clone in roundTo option parsing#5290

Merged
jedel1043 merged 2 commits intoboa-dev:mainfrom
tkshsbcue:refactor/temporal-remove-roundto-clone
Apr 1, 2026
Merged

refactor(temporal): remove unnecessary clone in roundTo option parsing#5290
jedel1043 merged 2 commits intoboa-dev:mainfrom
tkshsbcue:refactor/temporal-remove-roundto-clone

Conversation

@tkshsbcue
Copy link
Copy Markdown
Contributor

PR: refactor(temporal): remove unnecessary clone in roundTo option parsing

Summary

The round method in 5 Temporal builtins (Duration, Instant, PlainDateTime, PlainTime, ZonedDateTime) previously matched on args.first().map(JsValue::variant) to inspect the roundTo argument. In the fallback arm, the extracted JsVariant was converted back into a JsValue via JsValue::from(round_to) just to pass it to get_options_object(&JsValue) — an unnecessary round-trip that cloned the inner value.

This PR refactors all 5 call sites to work directly with &JsValue via args.get_or_undefined(0), using is_undefined() and as_string() checks instead of variant pattern matching. This eliminates the clone while preserving identical semantics.

Changes

  • duration/mod.rs — Replaced match on JsVariant with if/else on &JsValue
  • instant/mod.rs — Same refactor + removed unused JsVariant import
  • plain_date_time/mod.rs — Same refactor + removed unused JsVariant import
  • plain_time/mod.rs — Same refactor
  • zoneddatetime/mod.rs — Same refactor

Resolves the TODO: remove this clone comments in the affected files.

Test plan

  • cargo fmt -- --check passes
  • cargo clippy --all-features --all-targets passes
  • cargo clippy --no-default-features passes
  • cargo test -p boa_engine -- temporal passes

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.
@github-actions github-actions bot added Waiting On Review Waiting on reviews from the maintainers C-Builtins PRs and Issues related to builtins/intrinsics and removed Waiting On Review Waiting on reviews from the maintainers labels Apr 1, 2026
@github-actions github-actions bot added this to the v1.0.0 milestone Apr 1, 2026
@github-actions github-actions bot added the Waiting On Review Waiting on reviews from the maintainers label Apr 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 50,735 50,735 0
Ignored 1,426 1,426 0
Failed 802 802 0
Panics 0 0 0
Conformance 95.79% 95.79% 0.00%

Tested main commit: f5e88de558e038f0ae675a012d59917a098f44b6
Tested PR commit: 15af09d080ca2b918c092104aee32bf86fe6eb31
Compare commits: f5e88de...15af09d

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 0% with 70 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.80%. Comparing base (6ddc2b4) to head (15af09d).
⚠️ Report is 927 commits behind head on main.

Files with missing lines Patch % Lines
core/engine/src/builtins/temporal/duration/mod.rs 0.00% 14 Missing ⚠️
core/engine/src/builtins/temporal/instant/mod.rs 0.00% 14 Missing ⚠️
...ngine/src/builtins/temporal/plain_date_time/mod.rs 0.00% 14 Missing ⚠️
...ore/engine/src/builtins/temporal/plain_time/mod.rs 0.00% 14 Missing ⚠️
.../engine/src/builtins/temporal/zoneddatetime/mod.rs 0.00% 14 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@zhuzhu81998 zhuzhu81998 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks correct to me 👀

Copy link
Copy Markdown
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jedel1043 jedel1043 added this pull request to the merge queue Apr 1, 2026
Merged via the queue into boa-dev:main with commit fab099a Apr 1, 2026
22 checks passed
@github-actions github-actions bot removed the Waiting On Review Waiting on reviews from the maintainers label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Builtins PRs and Issues related to builtins/intrinsics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants