commit dd7b3ee4d8ab226115de9cc9a10e9868d7d1c376 parent 61644fd71fac3987ed3b45ab55a5ef54ecfa4d5e Author: Andreas Farre <farre@mozilla.com> Date: Wed, 26 Nov 2025 14:48:48 +0000 Bug 2001985 - Mark all resulting promises from NavigateEvent handlers. r=dom-core,smaug Differential Revision: https://phabricator.services.mozilla.com/D273832 Diffstat:
4 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/dom/navigation/Navigation.cpp b/dom/navigation/Navigation.cpp @@ -1415,6 +1415,13 @@ struct NavigationWaitForAllScope final : public nsISupports, }; if (mAPIMethodTracker && !StaticPrefs::dom_navigation_api_internal_method_tracker()) { + // Promise::WaitForAll marks all promises as handled, but since we're + // delaying wait for all one microtask, we need to manually mark them + // here. + for (auto& promise : promiseList) { + (void)promise->SetAnyPromiseIsHandled(); + } + LOG_FMTD("Waiting for committed"); mAPIMethodTracker->CommittedPromise() ->AddCallbacksWithCycleCollectedArgs( diff --git a/dom/promise/Promise.cpp b/dom/promise/Promise.cpp @@ -322,9 +322,19 @@ void Promise::WaitForAll(nsIGlobalObject* aGlobal, return nullptr; }; // Step 9.4 (and actually also step 4 and step 9.3) - (void)promise->ThenCatchWithCycleCollectedArgs( + Result resultPromise = promise->ThenCatchWithCycleCollectedArgs( fulfillmentHandlerSteps, rejectionHandlerSteps, result, arg); + // https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-performpromisethen + // Step 12 + // Promise;:ThenCatchWithCycleCollectedArgs is fairly similar to, but not + // exactly the same as PerformPromiseThen, in particular the step that marks + // the promise as handled is missing. It's performed here to not change the + // existing behavior of ThenCatchWithCycleCollectedArgs. + if (resultPromise.isOk()) { + (void)resultPromise.unwrap()->SetAnyPromiseIsHandled(); + } + // Step 9.5 index++; } diff --git a/testing/web-platform/meta/navigation-api/ordering-and-transition/back-same-document-intercept-reject.html.ini b/testing/web-platform/meta/navigation-api/ordering-and-transition/back-same-document-intercept-reject.html.ini @@ -1,10 +1,8 @@ [back-same-document-intercept-reject.html?no-currententrychange] - expected: ERROR [event and promise ordering for same-document navigation.back() intercepted by passing a rejected promise to intercept()] expected: FAIL [back-same-document-intercept-reject.html?currententrychange] - expected: ERROR [event and promise ordering for same-document navigation.back() intercepted by passing a rejected promise to intercept()] expected: FAIL diff --git a/testing/web-platform/meta/navigation-api/precommit-handler/precommitHandler-traverse.html.ini b/testing/web-platform/meta/navigation-api/precommit-handler/precommitHandler-traverse.html.ini @@ -1,5 +1,4 @@ [precommitHandler-traverse.html] - expected: ERROR [precommitHandler for a traverse navigation, reject after commit] expected: FAIL