commit b0296789057e7ad52db22847bbc44719cc7313cd
parent 90f6b6e09518af53a63514b80485d3e7edc9e517
Author: Jan-Niklas Jaeschke <jjaschke@mozilla.com>
Date: Tue, 28 Oct 2025 17:18:26 +0000
Bug 1970123, part 5 - Navigation API: Implement #abort-a-navigateevent. r=dom-core,smaug
Differential Revision: https://phabricator.services.mozilla.com/D270182
Diffstat:
2 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/dom/navigation/Navigation.cpp b/dom/navigation/Navigation.cpp
@@ -1726,31 +1726,47 @@ void Navigation::AbortOngoingNavigation(JSContext* aCx,
}
// Step 7
- event->AbortController()->Abort(aCx, error);
+ AbortNavigateEvent(aCx, event, error);
+}
- // Step 8
- mOngoingNavigateEvent = nullptr;
+// https://html.spec.whatwg.org/#abort-a-navigateevent
+void Navigation::AbortNavigateEvent(JSContext* aCx, NavigateEvent* aEvent,
+ JS::Handle<JS::Value> aReason) {
+ // 1. Let navigation be event's relevant global object's navigation API.
+ // Omitted since this is called from a Navigation object.
- // Step 9
+ // 2. Signal abort on event's abort controller given reason.
+ aEvent->AbortController()->Abort(aCx, aReason);
+
+ // 3. Let errorInfo be the result of extracting error information from reason.
RootedDictionary<ErrorEventInit> init(aCx);
- ExtractErrorInformation(aCx, error, init);
+ ExtractErrorInformation(aCx, aReason, init);
+
+ // 4. Set navigation's ongoing navigate event to null.
+ mOngoingNavigateEvent = nullptr;
- // Step 10
+ // 5. If navigation's ongoing API method tracker is non-null, then reject the
+ // finished promise for apiMethodTracker with error.
if (mOngoingAPIMethodTracker) {
- mOngoingAPIMethodTracker->RejectFinishedPromise(error);
+ mOngoingAPIMethodTracker->RejectFinishedPromise(aReason);
}
- // Step 11
+ // 6. Fire an event named navigateerror at navigation using ErrorEvent, with
+ // additional attributes initialized according to errorInfo.
FireErrorEvent(u"navigateerror"_ns, init);
- // Step 12
- if (mTransition) {
- // Step 12.1
- mTransition->Finished()->MaybeReject(error);
-
- // Step 12.2
- mTransition = nullptr;
+ // 7. If navigation's transition is null, then return.
+ if (!mTransition) {
+ return;
}
+
+ // 8. Reject navigation's transition's committed promise with error.
+ mTransition->Committed()->MaybeReject(aReason);
+ // 9. Reject navigation's transition's finished promise with error.
+ mTransition->Finished()->MaybeReject(aReason);
+
+ // 10. Set navigation's transition to null.
+ mTransition = nullptr;
}
// https://html.spec.whatwg.org/#inform-the-navigation-api-about-child-navigable-destruction
diff --git a/dom/navigation/Navigation.h b/dom/navigation/Navigation.h
@@ -185,6 +185,10 @@ class Navigation final : public DOMEventTargetHelper {
JSContext* aCx, JS::Handle<JS::Value> aError = JS::UndefinedHandleValue);
MOZ_CAN_RUN_SCRIPT
+ void AbortNavigateEvent(JSContext* aCx, NavigateEvent* aEvent,
+ JS::Handle<JS::Value> aReason);
+
+ MOZ_CAN_RUN_SCRIPT
void InformAboutChildNavigableDestruction(JSContext* aCx);
void CreateNavigationActivationFrom(