fix(runtime): make timer IDs 1-based to avoid sentinel collision#5379
Conversation
Test262 conformance changes
Tested main commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5379 +/- ##
===========================================
+ Coverage 47.24% 60.12% +12.87%
===========================================
Files 476 566 +90
Lines 46892 63031 +16139
===========================================
+ Hits 22154 37895 +15741
- Misses 24738 25136 +398 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c5c9a90 to
ea51866
Compare
|
hello @hansl @jedel1043, updated the pr.
also had to fix a windows WPT path issue, add If needed i can split the last part. |
hansl
left a comment
There was a problem hiding this comment.
I'm not convinced we need clear_jobs. We shouldn't need to clear jobs and should fail if jobs are not completed by the end of the run. Let me think a bit more about it.
|
hi @hansl. i went with this because without for now i used |
|
@iammdzaidalam Hey Zaid. Sorry for the late reply I was out on a trip last weekend, and thinking about how to approach this. What you actually want to do is not cancel jobs (there are jobs in there that aren't timers/intervals). You want to clear timers themselves and let the engine exit gracefully. Am I right? In that case, what you could do is add a What do you think? |
|
Hey @hansl, hope the trip was good 😊. tried a repro with a Also confirmed the hang directly. Also i am keeping the 10 second deadline in the harness so we notice if something else holds the loop open later. seems like the right direction, thanks! |
Signed-off-by: iammdzaidalam <161572905+iammdzaidalam@users.noreply.github.com>
…sues Signed-off-by: iammdzaidalam <161572905+iammdzaidalam@users.noreply.github.com>
2881319 to
6389f83
Compare
hansl
left a comment
There was a problem hiding this comment.
Nothing major, but I'm curious why the rustls dependency was added.
…plicate WPT path Signed-off-by: iammdzaidalam <161572905+iammdzaidalam@users.noreply.github.com>
6389f83 to
bd0bd90
Compare
Signed-off-by: iammdzaidalam <161572905+iammdzaidalam@users.noreply.github.com>
|
added a test coverage for the clear_all function... missed it in last commit |
|
Waiting for #5389 to go in then I'll merge main and re-run CI. |
|
@jedel1043 need your approval, PTAL |
Closes #5378
Problem
IntervalInnerState::next_id()returns the internal counter before incrementing it. Since the counter starts at0viaDefault, the first valid timer gets handle0:At the same time, both
set_timeoutandset_intervalreturnOk(0)when no callback is provided. That makes the first real timer and the "nothing was scheduled" sentinel indistinguishable. It also violates WHATWG HTML timer semantics, which require positive timer handles, and breaks common JavaScript code that treats a returned timer ID as truthy.Fix
Update
next_id()to increment the counter before returning it, so valid timer IDs become 1-based again. This preserves0for the no-callback sentinel and restores the pre-#5289 behavior.Tests
timer_ids_are_positive_and_uniqueasserts that timer IDs returned bysetTimeoutandsetIntervalare greater than0and unique.no_callback_returns_zero_sentinelasserts thatsetTimeout()with no callback still returns0and does not collide with a valid timer ID.Verification
cargo test -p boa_runtimecargo run -p boa_cli -- -e "console.log(setTimeout(() => {}, 10)); console.log(setTimeout(() => {}, 10)); console.log(setTimeout())"Before the fix, the first valid timer returned
0. After the fix, the output is1,2,0.