Skip to content

Commit 2af6314

Browse files
AtkinsSJawesomekling
authored andcommitted
LibWeb/HTML: Resolve/reject apiMethodTracker before dispatching events
Corresponds to: whatwg/html@93634ae The current live spec has been rearranged since this went in, so that these steps are no longer located here. But that's a much larger change that I don't want to implement right now. See here: whatwg/html@e09d102 While I was at it, I also made use of extract_error_information() to populate the ErrorEvent.
1 parent c1e4024 commit 2af6314

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

Libraries/LibWeb/HTML/Navigation.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,15 +1201,15 @@ bool Navigation::inner_navigate_event_firing_algorithm(
12011201

12021202
// 5. Finish event given true.
12031203
event->finish(true);
1204+
1205+
// 6. If apiMethodTracker is non-null, then resolve the finished promise for apiMethodTracker.
1206+
if (api_method_tracker != nullptr)
1207+
resolve_the_finished_promise(*api_method_tracker);
12041208

12051209
// FIXME: Implement https://dom.spec.whatwg.org/#concept-event-fire somewhere
1206-
// 6. Fire an event named navigatesuccess at navigation.
1210+
// 7. Fire an event named navigatesuccess at navigation.
12071211
dispatch_event(DOM::Event::create(realm, EventNames::navigatesuccess));
12081212

1209-
// 7. If apiMethodTracker is non-null, then resolve the finished promise for apiMethodTracker.
1210-
if (api_method_tracker != nullptr)
1211-
resolve_the_finished_promise(*api_method_tracker);
1212-
12131213
// 8. If navigation's transition is not null, then resolve navigation's transition's finished promise with undefined.
12141214
if (m_transition != nullptr)
12151215
WebIDL::resolve_promise(realm, m_transition->finished(), JS::js_undefined());
@@ -1238,21 +1238,23 @@ bool Navigation::inner_navigate_event_firing_algorithm(
12381238
event->finish(false);
12391239

12401240
// 6. Let errorInfo be the result of extracting error information from rejectionReason.
1241-
ErrorEventInit event_init = {};
1242-
event_init.error = rejection_reason;
1243-
// FIXME: Extract information from the exception and the JS context in the wishy-washy way the spec says here.
1244-
event_init.filename = String {};
1245-
event_init.colno = 0;
1246-
event_init.lineno = 0;
1247-
event_init.message = String {};
1248-
1249-
// 7. Fire an event named navigateerror at navigation using ErrorEvent,with additional attributes initialized according to errorInfo.
1250-
dispatch_event(ErrorEvent::create(realm, EventNames::navigateerror, event_init));
1241+
auto error_info = extract_error_information(vm(), rejection_reason);
12511242

1252-
// 8. If apiMethodTracker is non-null, then reject the finished promise for apiMethodTracker with rejectionReason.
1243+
// 7. If apiMethodTracker is non-null, then reject the finished promise for apiMethodTracker with rejectionReason.
12531244
if (api_method_tracker != nullptr)
12541245
reject_the_finished_promise(*api_method_tracker, rejection_reason);
12551246

1247+
// 8. Fire an event named navigateerror at navigation using ErrorEvent,with additional attributes
1248+
// initialized according to errorInfo.
1249+
ErrorEventInit event_init = {};
1250+
event_init.message = error_info.message;
1251+
event_init.filename = error_info.filename;
1252+
event_init.lineno = error_info.lineno;
1253+
event_init.colno = error_info.colno;
1254+
event_init.error = error_info.error;
1255+
1256+
dispatch_event(ErrorEvent::create(realm, EventNames::navigateerror, event_init));
1257+
12561258
// 9. If navigation's transition is not null, then reject navigation's transition's finished promise with rejectionReason.
12571259
if (m_transition)
12581260
WebIDL::reject_promise(realm, m_transition->finished(), rejection_reason);

0 commit comments

Comments
 (0)