Skip to content

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

Open
abhinavs1920 wants to merge 5 commits intoboa-dev:mainfrom
abhinavs1920:JSInstant
Open

fix: Make StdClock monotonic using std::time::Instant#4841
abhinavs1920 wants to merge 5 commits intoboa-dev:mainfrom
abhinavs1920:JSInstant

Conversation

@abhinavs1920
Copy link

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
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,687 49,687 0
Ignored 2,262 2,262 0
Failed 1,014 1,014 0
Panics 0 0 0
Conformance 93.81% 93.81% 0.00%

Tested main commit: 34ca7f1f404c2712d6897c3e39e5f5e981ce9ed6
Tested PR commit: 48fb1f8f4d14099a1af82adfc6c1af2608ce5220
Compare commits: 34ca7f1...48fb1f8

@abhinavs1920
Copy link
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 57.89%. Comparing base (6ddc2b4) to head (48fb1f8).
⚠️ Report is 779 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%   57.89%   +10.65%     
===========================================
  Files         476      557       +81     
  Lines       46892    60968    +14076     
===========================================
+ Hits        22154    35300    +13146     
- Misses      24738    25668      +930     

☔ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implementation of StdClock is not monotonic.

2 participants