From cc1e8a4e9fa9629604c8478bd29deb4fc6ccc277 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 5 Mar 2023 21:22:34 +0000 Subject: [PATCH] LibWeb/HTML: Propagate errors from Window::initialize_web_interfaces() --- .../Scripting/WindowEnvironmentSettingsObject.cpp | 2 +- Userland/Libraries/LibWeb/HTML/Window.cpp | 15 ++++++++------- Userland/Libraries/LibWeb/HTML/Window.h | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp index e180e4f59c..b0533e1953 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.cpp @@ -77,7 +77,7 @@ WebIDL::ExceptionOr WindowEnvironmentSettingsObject::setup(AK::URL const& // Non-Standard: We cannot fully initialize window object until *after* the we set up // the realm's [[HostDefined]] internal slot as the internal slot contains the web platform intrinsics - window.initialize_web_interfaces({}); + TRY(window.initialize_web_interfaces({})); return {}; } diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index c073cdf0c9..6d3b44fd3b 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -1111,14 +1111,16 @@ Vector> Window::pdf_viewer_mime_type_objects() return m_pdf_viewer_mime_type_objects; } -void Window::initialize_web_interfaces(Badge) +WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge) { auto& realm = this->realm(); add_window_exposed_interfaces(*this); Object::set_prototype(&Bindings::ensure_web_prototype(realm, "Window")); - m_crypto = Crypto::Crypto::create(realm).release_value_but_fixme_should_propagate_errors(); + m_crypto = MUST_OR_THROW_OOM(heap().allocate(realm, realm)); + m_location = MUST_OR_THROW_OOM(heap().allocate(realm, realm)); + m_navigator = MUST_OR_THROW_OOM(heap().allocate(realm, realm)); // FIXME: These should be native accessors, not properties define_native_accessor(realm, "top", top_getter, nullptr, JS::Attribute::Enumerable); @@ -1184,7 +1186,7 @@ void Window::initialize_web_interfaces(Badge) define_native_accessor(realm, "outerWidth", outer_width_getter, {}, attr); define_native_accessor(realm, "outerHeight", outer_height_getter, {}, attr); - define_direct_property("CSS", heap().allocate(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(), 0); + define_direct_property("CSS", MUST_OR_THROW_OOM(heap().allocate(realm, realm)), 0); define_native_accessor(realm, "localStorage", local_storage_getter, {}, attr); define_native_accessor(realm, "sessionStorage", session_storage_getter, {}, attr); @@ -1194,9 +1196,6 @@ void Window::initialize_web_interfaces(Badge) // Legacy define_native_accessor(realm, "event", event_getter, event_setter, JS::Attribute::Enumerable); - m_location = heap().allocate(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); - - m_navigator = heap().allocate(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(); define_native_accessor(realm, "navigator", navigator_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable); define_native_accessor(realm, "clientInformation", navigator_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable); @@ -1204,7 +1203,7 @@ void Window::initialize_web_interfaces(Badge) define_native_accessor(realm, "location", location_getter, location_setter, JS::Attribute::Enumerable); // WebAssembly "namespace" - define_direct_property("WebAssembly", heap().allocate(realm, realm).release_allocated_value_but_fixme_should_propagate_errors(), JS::Attribute::Enumerable | JS::Attribute::Configurable); + define_direct_property("WebAssembly", MUST_OR_THROW_OOM(heap().allocate(realm, realm)), JS::Attribute::Enumerable | JS::Attribute::Configurable); // HTML::GlobalEventHandlers and HTML::WindowEventHandlers #define __ENUMERATE(attribute, event_name) \ @@ -1212,6 +1211,8 @@ void Window::initialize_web_interfaces(Badge) ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE); ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE); #undef __ENUMERATE + + return {}; } HTML::Origin Window::origin() const diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 29ec3f2498..a78a6a009f 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -137,7 +137,7 @@ public: // https://html.spec.whatwg.org/multipage/interaction.html#transient-activation bool has_transient_activation() const; - void initialize_web_interfaces(Badge); + WebIDL::ExceptionOr initialize_web_interfaces(Badge); Vector> pdf_viewer_plugin_objects(); Vector> pdf_viewer_mime_type_objects();