diff --git a/Userland/Libraries/LibWeb/HTML/NavigateEvent.cpp b/Userland/Libraries/LibWeb/HTML/NavigateEvent.cpp
index 47ca4c5732..211d888c1d 100644
--- a/Userland/Libraries/LibWeb/HTML/NavigateEvent.cpp
+++ b/Userland/Libraries/LibWeb/HTML/NavigateEvent.cpp
@@ -35,7 +35,7 @@ NavigateEvent::NavigateEvent(JS::Realm& realm, FlyString const& event_name, Navi
, m_signal(*event_init.signal)
, m_form_data(event_init.form_data)
, m_download_request(event_init.download_request)
- , m_info(event_init.info)
+ , m_info(event_init.info.value_or(JS::js_undefined()))
, m_has_ua_visual_transition(event_init.has_ua_visual_transition)
{
}
@@ -61,7 +61,7 @@ void NavigateEvent::visit_edges(JS::Cell::Visitor& visitor)
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigateevent-intercept
-WebIDL::ExceptionOr NavigateEvent::intercept(Optional const& options)
+WebIDL::ExceptionOr NavigateEvent::intercept(NavigationInterceptOptions const& options)
{
auto& realm = this->realm();
auto& vm = this->vm();
@@ -84,38 +84,40 @@ WebIDL::ExceptionOr NavigateEvent::intercept(Optionalhandler)));
+ // 6. If options["handler"] exists, then append it to this's navigation handler list.
+ if (options.handler != nullptr)
+ TRY_OR_THROW_OOM(vm, m_navigation_handler_list.try_append(*options.handler));
- // 7. If options["focusReset"] exists, then:
- // 1. If this's focus reset behavior is not null, and it is not equal to options["focusReset"],
- // then the user agent may report a warning to the console indicating that the focusReset option
- // for a previous call to intercept() was overridden by this new value, and the previous value
- // will be ignored.
- if (m_focus_reset_behavior.has_value() && m_focus_reset_behavior.value() != options->focus_reset) {
+ // 7. If options["focusReset"] exists, then:
+ if (options.focus_reset.has_value()) {
+ // 1. If this's focus reset behavior is not null, and it is not equal to options["focusReset"],
+ // then the user agent may report a warning to the console indicating that the focusReset option
+ // for a previous call to intercept() was overridden by this new value, and the previous value
+ // will be ignored.
+ if (m_focus_reset_behavior.has_value() && *m_focus_reset_behavior != *options.focus_reset) {
auto& console = realm.intrinsics().console_object()->console();
console.output_debug_message(JS::Console::LogLevel::Warn,
- TRY_OR_THROW_OOM(vm, String::formatted("focusReset behavior on NavigationEvent overriden (was: {}, now: {})", *m_focus_reset_behavior, options->focus_reset)));
+ TRY_OR_THROW_OOM(vm, String::formatted("focusReset behavior on NavigationEvent overriden (was: {}, now: {})", *m_focus_reset_behavior, *options.focus_reset)));
}
- // 2. Set this's focus reset behavior to options["focusReset"].
- m_focus_reset_behavior = options->focus_reset;
-
- // 8. If options["scroll"] exists, then:
- // 1. If this's scroll behavior is not null, and it is not equal to options["scroll"], then the user
- // agent may report a warning to the console indicating that the scroll option for a previous call
- // to intercept() was overridden by this new value, and the previous value will be ignored.
- if (m_scroll_behavior.has_value() && m_scroll_behavior.value() != options->scroll) {
- auto& console = realm.intrinsics().console_object()->console();
- console.output_debug_message(JS::Console::LogLevel::Warn,
- TRY_OR_THROW_OOM(vm, String::formatted("scroll option on NavigationEvent overriden (was: {}, now: {})", *m_scroll_behavior, options->scroll)));
- }
-
- // 2. Set this's scroll behavior to options["scroll"].
- m_scroll_behavior = options->scroll;
+ // 2. Set this's focus reset behavior to options["focusReset"].
+ m_focus_reset_behavior = options.focus_reset;
}
+ // 8. If options["scroll"] exists, then:
+ if (options.scroll.has_value()) {
+ // 1. If this's scroll behavior is not null, and it is not equal to options["scroll"], then the user
+ // agent may report a warning to the console indicating that the scroll option for a previous call
+ // to intercept() was overridden by this new value, and the previous value will be ignored.
+ if (m_scroll_behavior.has_value() && *m_scroll_behavior != *options.scroll) {
+ auto& console = realm.intrinsics().console_object()->console();
+ console.output_debug_message(JS::Console::LogLevel::Warn,
+ TRY_OR_THROW_OOM(vm, String::formatted("scroll option on NavigationEvent overriden (was: {}, now: {})", *m_scroll_behavior, *options.scroll)));
+ }
+
+ // 2. Set this's scroll behavior to options["scroll"].
+ m_scroll_behavior = options.scroll;
+ }
return {};
}
diff --git a/Userland/Libraries/LibWeb/HTML/NavigateEvent.h b/Userland/Libraries/LibWeb/HTML/NavigateEvent.h
index bf35198712..4fea44ae51 100644
--- a/Userland/Libraries/LibWeb/HTML/NavigateEvent.h
+++ b/Userland/Libraries/LibWeb/HTML/NavigateEvent.h
@@ -23,7 +23,7 @@ struct NavigateEventInit : public DOM::EventInit {
JS::GCPtr signal;
JS::GCPtr form_data = nullptr;
Optional download_request = {};
- JS::Value info;
+ Optional info;
bool has_ua_visual_transition = false;
};
@@ -33,8 +33,8 @@ using NavigationInterceptHandler = JS::NonnullGCPtr;
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigationinterceptoptions
struct NavigationInterceptOptions {
JS::GCPtr handler;
- Bindings::NavigationFocusReset focus_reset;
- Bindings::NavigationScrollBehavior scroll;
+ Optional focus_reset;
+ Optional scroll;
};
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigateevent
@@ -57,7 +57,7 @@ public:
JS::Value info() const { return m_info; }
bool has_ua_visual_transition() const { return m_has_ua_visual_transition; }
- WebIDL::ExceptionOr intercept(Optional const& = {});
+ WebIDL::ExceptionOr intercept(NavigationInterceptOptions const&);
WebIDL::ExceptionOr scroll();
virtual ~NavigateEvent() override;