Implement run steps after a timeout#39994
Conversation
e0afe9c to
da86cbf
Compare
|
🔨 Triggering try run (#18636760458) for Linux (WPT) |
|
Test results for linux-wpt from try job (#18636760458): Flaky unexpected result (18)
Stable unexpected results that are known to be intermittent (19)
|
|
✨ Try run (#18636760458) succeeded. |
TimvdLippe
left a comment
There was a problem hiding this comment.
Some nits at a glance. The timer implementation looks fine, but it is difficult to judge for me as I am not familiar with that code yet
Since there are no WPT changes, can we add the AbortSignal.timeout implementation as well? I expect that to be minimal and then we also have test coverage for this new code.
components/script/timers.rs
Outdated
| suspended_since: Cell::new(None), | ||
| suspension_offset: Cell::new(Duration::ZERO), | ||
| expected_event_id: Cell::new(TimerEventId(0)), | ||
| runsteps_active: DomRefCell::new(FxHashMap::default()), |
There was a problem hiding this comment.
Nit: Default::default() for the whole expression (same on next line)
components/script/timers.rs
Outdated
| } | ||
|
|
||
| /// <https://html.spec.whatwg.org/multipage/#run-steps-after-a-timeout> | ||
| /// Step 2. Let startTime be the current high resolution time given global. |
There was a problem hiding this comment.
Nit: move spec comment in the method
components/script/timers.rs
Outdated
| type OrderingIdentifier = DOMString; | ||
|
|
||
| // Per-ordering queue entry: (deadline_ms, sequence, handle) | ||
| type OrderingEntry = (u64, u64, OneshotTimerHandle); |
There was a problem hiding this comment.
Nit: make this a struct with named fields, so it is easier to distinguish the two u64
| } | ||
|
|
||
| /// <https://html.spec.whatwg.org/multipage/#run-steps-after-a-timeout> | ||
| pub(crate) fn run_steps_after_a_timeout<F>( |
There was a problem hiding this comment.
I don't see any usages of this method. Why isn't it marked as unused and does Clippy fail on it?
Yeah @gterzian has context and he can review, you don't need to review PR if you don't have full context(we have something about this in PR review guideline), this is incremental work AbortSignal.timeout will be next. |
da86cbf to
5658982
Compare
5658982 to
48a0045
Compare
gterzian
left a comment
There was a problem hiding this comment.
LGTM as a first step with some comments.
components/script/timers.rs
Outdated
| runsteps_queues: DomRefCell<OrderingQueues>, | ||
|
|
||
| /// <https://html.spec.whatwg.org/multipage/#run-steps-after-a-timeout> | ||
| /// Step 1. Let timerKey be a new unique internal value. |
There was a problem hiding this comment.
I think just <html.spec.whatwg.org/multipage/#timers:unique-internal-value-5> is better
components/script/timers.rs
Outdated
| expected_event_id: Cell<TimerEventId>, | ||
| /// <https://html.spec.whatwg.org/multipage/#run-steps-after-a-timeout> | ||
| /// Step 3. Set global's map of active timers[timerKey] to startTime plus milliseconds. | ||
| runsteps_active: DomRefCell<RunStepsActiveMap>, |
There was a problem hiding this comment.
I think the name should be like in the spec, and we should add a todo that this should also be used for the other timers as per html.spec.whatwg.org/multipage/#map-of-settimeout-and-setinterval-ids.
components/script/timers.rs
Outdated
| type OrderingIdentifier = DOMString; | ||
|
|
||
| // Per-ordering queue entry: (deadline_ms, sequence, handle) | ||
| type OrderingEntry = (u64, u64, OneshotTimerHandle); |
| type CompletionStep = Box<dyn FnOnce(&GlobalScope, CanGc) + 'static>; | ||
|
|
||
| // OrderingIdentifier per spec ("orderingIdentifier") | ||
| type OrderingIdentifier = DOMString; |
There was a problem hiding this comment.
here it's worth adding a link to the algo.
components/script/timers.rs
Outdated
| RefreshRedirectDue(RefreshRedirectDue), | ||
| /// <https://html.spec.whatwg.org/multipage/#run-steps-after-a-timeout> | ||
| RunStepsAfterTimeout { | ||
| // Step 1. timerKey |
There was a problem hiding this comment.
I think this should be /// also
components/script/timers.rs
Outdated
| suspended_since: Cell::new(None), | ||
| suspension_offset: Cell::new(Duration::ZERO), | ||
| expected_event_id: Cell::new(TimerEventId(0)), | ||
| runsteps_active: DomRefCell::new(FxHashMap::default()), |
components/script/timers.rs
Outdated
| } | ||
|
|
||
| /// <https://html.spec.whatwg.org/multipage/#run-steps-after-a-timeout> | ||
| /// Step 2. Let startTime be the current high resolution time given global. |
| } | ||
|
|
||
| /// <https://html.spec.whatwg.org/multipage/#run-steps-after-a-timeout> | ||
| pub(crate) fn run_steps_after_a_timeout<F>( |
There was a problem hiding this comment.
This should end-up being used in the other timer mechanism as well, so we should add a todo to integrate as per https://html.spec.whatwg.org/multipage/#timers:run-steps-after-a-timeout
| let callback = timer.callback; | ||
| callback.invoke(global, &self.js_timers, can_gc); | ||
| match &timer.callback { | ||
| OneshotTimerCallback::RunStepsAfterTimeout { ordering_id, .. } => { |
There was a problem hiding this comment.
So this should end-up turned inside out, where the "normal" timers are just using the "run steps after timeout" mechanism and an ordering id of "setTimeout/setInterval". Let's file an issue for that.
The current implementation means that you could actually just use SetTimeOut, but the way the spec works is rather that this is the general mechanism, and SetTimeOut is a specific use of it.
| let is_head = head_handle_opt.is_none_or(|head| head == timer.handle); | ||
|
|
||
| if !is_head { | ||
| let rein = OneshotTimer { |
There was a problem hiding this comment.
Not sure about this re queuing, but this would go away if we revisit timers as I mentioned in my other comments.
Signed-off-by: Taym Haddadi <[email protected]>
826eb29 to
6259646
Compare
Signed-off-by: Taym Haddadi <[email protected]>
6259646 to
4530705
Compare
Implement run steps after a timeout, spec:
https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#run-steps-after-a-timeout
Testing: should pass existing wpt test
Fixes: #36934