script: Queue a microtask in wait_for_all of promise type (#39108)

In the wait-for-all algorithm of the IDL promise type, we need to queue
a microtask to perform successSteps given « » if total is 0.

This step was previously implemented in a workaround, which perform
successSteps immediately.

This patch properly queue the microtask, and remove the workaround.

Testing: Refactoring only. Existing tests are enough.
Fixes: #37259

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
This commit is contained in:
Kingsley Yung 2025-09-04 21:50:41 +08:00 committed by GitHub
parent ae2d9674e8
commit 925b7c5dad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 56 additions and 27 deletions

View file

@ -23,6 +23,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::html::htmlimageelement::ImageElementMicrotask;
use crate::dom::html::htmlmediaelement::MediaElementMicrotask;
use crate::dom::mutationobserver::MutationObserver;
use crate::dom::promise::WaitForAllSuccessStepsMicrotask;
use crate::realms::enter_realm;
use crate::script_runtime::{CanGc, JSContext, notify_about_rejected_promises};
use crate::script_thread::ScriptThread;
@ -43,6 +44,7 @@ pub(crate) enum Microtask {
MediaElement(MediaElementMicrotask),
ImageElement(ImageElementMicrotask),
ReadableStreamTeeReadRequest(DefaultTeeReadRequestMicrotask),
WaitForAllSuccessSteps(WaitForAllSuccessStepsMicrotask),
CustomElementReaction,
NotifyMutationObservers,
}
@ -141,16 +143,20 @@ impl MicrotaskQueue {
let _realm = task.enter_realm();
task.handler(can_gc);
},
Microtask::ReadableStreamTeeReadRequest(ref task) => {
let _realm = task.enter_realm();
task.handler(can_gc);
},
Microtask::WaitForAllSuccessSteps(ref task) => {
let _realm = task.enter_realm();
task.handler(can_gc);
},
Microtask::CustomElementReaction => {
ScriptThread::invoke_backup_element_queue(can_gc);
},
Microtask::NotifyMutationObservers => {
MutationObserver::notify_mutation_observers(can_gc);
},
Microtask::ReadableStreamTeeReadRequest(ref task) => {
let _realm = task.enter_realm();
task.handler(can_gc);
},
}
}
}