Skip to content

fix: Make StdClock monotonic using std::time::Instant#4841

Merged
jedel1043 merged 6 commits intoboa-dev:mainfrom
abhinavs1920:JSInstant
Mar 15, 2026
Merged

fix: Make StdClock monotonic using std::time::Instant#4841
jedel1043 merged 6 commits intoboa-dev:mainfrom
abhinavs1920:JSInstant

Conversation

@abhinavs1920
Copy link
Contributor

This Pull Request fixes/closes #4330 .

Previously, StdClock used SystemTime which isn't monotonic—it can jump backward when the system clock adjusts. This broke the guarantees that JsInstant is supposed to provide for engine timing.

Now StdClock uses std::time::Instant with a base instant, measuring elapsed time from that point. This makes JsInstant truly monotonic like std::time::Instant, so time never goes backward for setTimeout, setInterval, and job scheduling.

For Date objects that need actual wall-clock time, I added a separate system_time_millis() method to the Clock trait. Clean separation of concerns.

Added tests to verify the monotonic behavior works as expected.

@abhinavs1920 abhinavs1920 requested a review from a team as a code owner March 3, 2026 18:33
@abhinavs1920
Copy link
Contributor Author

Heyy @jedel1043 , I have refactored the API design as we discussed. Please take a look when ever you are available :)

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 49,935 49,935 0
Ignored 2,207 2,207 0
Failed 821 821 0
Panics 0 0 0
Conformance 94.28% 94.28% 0.00%

Tested main commit: 79e6549e0e82187e207883e9215535cb63ef343b
Tested PR commit: 9943af25e2721cac7df217ec1d09df7462e6f0f4
Compare commits: 79e6549...9943af2

@abhinavs1920
Copy link
Contributor Author

Heyy I have put pushed my latest commit, but it doesn't seem to be pushed here due to some github issue. 🥲

Copy link
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.

Yep, pretty much what I expected. Thanks!

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.97%. Comparing base (6ddc2b4) to head (9943af2).
⚠️ Report is 854 commits behind head on main.

Files with missing lines Patch % Lines
core/engine/src/context/time.rs 60.00% 4 Missing ⚠️
core/engine/src/builtins/temporal/now.rs 0.00% 3 Missing ⚠️
core/engine/src/builtins/date/mod.rs 66.66% 1 Missing ⚠️
...e/engine/src/builtins/intl/date_time_format/mod.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #4841       +/-   ##
===========================================
+ Coverage   47.24%   58.97%   +11.72%     
===========================================
  Files         476      563       +87     
  Lines       46892    62584    +15692     
===========================================
+ Hits        22154    36908    +14754     
- Misses      24738    25676      +938     

☔ 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.

@abhinavs1920 abhinavs1920 requested a review from jedel1043 March 7, 2026 18:26
static_assertions.workspace = true
futures-channel.workspace = true
aligned-vec.workspace = true
instant.workspace = true
Copy link
Member

Choose a reason for hiding this comment

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

Need to remove this dependency

Cargo.toml Outdated
wasm-bindgen = { version = "0.2.97", default-features = false }
getrandom = { version = "0.4.1", default-features = false }
console_error_panic_hook = "0.1.7"
instant = { version = "0.1", features = ["wasm-bindgen"] }
Copy link
Member

Choose a reason for hiding this comment

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

Also here, needs to be removed

@jedel1043 jedel1043 added A-Bug Something isn't working A-API Changes related to public APIs Waiting On Author Waiting on PR changes from the author labels Mar 13, 2026
Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
@github-actions github-actions bot added C-Dependencies Pull requests that update a dependency file C-Builtins PRs and Issues related to builtins/intrinsics C-Intl Changes related to the `Intl` implementation Waiting On Review Waiting on reviews from the maintainers labels Mar 14, 2026
Copy link
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.

Thank you! Looks good

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

Labels

A-API Changes related to public APIs A-Bug Something isn't working C-Builtins PRs and Issues related to builtins/intrinsics C-Dependencies Pull requests that update a dependency file C-Intl Changes related to the `Intl` implementation Waiting On Author Waiting on PR changes from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implementation of StdClock is not monotonic.

2 participants