From eb731dde5524d3ea88010b980a09c579575395b8 Mon Sep 17 00:00:00 2001 From: gterzian <2792687+gterzian@users.noreply.github.com> Date: Fri, 6 Jun 2025 21:19:17 +0700 Subject: [PATCH] handle empty list of promise Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com> --- components/script/dom/promise.rs | 33 ++++++++++++++++--------- components/script/dom/readablestream.rs | 2 +- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/components/script/dom/promise.rs b/components/script/dom/promise.rs index 31219c1091c..ed7b538b969 100644 --- a/components/script/dom/promise.rs +++ b/components/script/dom/promise.rs @@ -526,7 +526,8 @@ pub(crate) fn wait_for_all( // Note: done using the len of result. // If total is 0, then: - // TODO: Queue a microtask to perform successSteps given « ». + // Queue a microtask to perform successSteps given « ». + // TODO: #37259 // Let index be 0. // Note: done with `enumerate` below. @@ -600,16 +601,26 @@ pub(crate) fn wait_for_all_promise( failure_promise.reject_native(&reason, can_gc); }); - // Wait for all with promises, given successSteps and failureSteps. - wait_for_all( - cx, - global, - promises, - success_steps, - failure_steps, - realm, - can_gc, - ); + if promises.is_empty() { + // Note: part of `wait_for_all`. + // Done here by using `resolve_native`. + // TODO: #37259 + // If total is 0, then: + // Queue a microtask to perform successSteps given « ». + let empty_list: Vec = vec![]; + promise.resolve_native(&empty_list, can_gc); + } else { + // Wait for all with promises, given successSteps and failureSteps. + wait_for_all( + cx, + global, + promises, + success_steps, + failure_steps, + realm, + can_gc, + ); + } // Return promise. promise diff --git a/components/script/dom/readablestream.rs b/components/script/dom/readablestream.rs index c9e34cc3505..f2e0eec88b4 100644 --- a/components/script/dom/readablestream.rs +++ b/components/script/dom/readablestream.rs @@ -349,7 +349,7 @@ impl Callback for PipeTo { get_dictionary_property( *cx, object.handle(), - "0", + "push", done.handle_mut(), can_gc, )