From f0c5f77f99801441db1d8e99c14dae2ab1357b47 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sun, 25 Sep 2022 16:38:21 -0600 Subject: LibWeb: Remove unecessary dependence on Window from HTML classes These classes only needed Window to get at its realm. Pass a realm directly to construct HTML classes. --- .../Libraries/LibWeb/Bindings/MainThreadVM.cpp | 2 +- Userland/Libraries/LibWeb/DOM/Document.cpp | 4 ++-- Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp | 6 +++--- .../LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h | 12 +++++------ .../Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp | 7 +++---- Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp | 24 +++++++++++----------- Userland/Libraries/LibWeb/HTML/CanvasGradient.h | 8 ++++---- .../LibWeb/HTML/CanvasRenderingContext2D.cpp | 24 +++++++++++----------- .../LibWeb/HTML/CanvasRenderingContext2D.h | 4 ++-- Userland/Libraries/LibWeb/HTML/CloseEvent.cpp | 20 +++++++++++------- Userland/Libraries/LibWeb/HTML/CloseEvent.h | 7 ++++--- .../LibWeb/HTML/CrossOrigin/AbstractOperations.cpp | 6 +++--- Userland/Libraries/LibWeb/HTML/DOMParser.cpp | 12 +++++------ Userland/Libraries/LibWeb/HTML/DOMParser.h | 5 +++-- Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp | 8 ++++---- Userland/Libraries/LibWeb/HTML/ErrorEvent.cpp | 16 +++++++-------- Userland/Libraries/LibWeb/HTML/ErrorEvent.h | 8 ++++---- Userland/Libraries/LibWeb/HTML/EventHandler.cpp | 1 - .../Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp | 6 ++++-- .../Libraries/LibWeb/HTML/HTMLAnchorElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLAudioElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLBRElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLButtonElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLCanvasElement.cpp | 4 ++-- .../Libraries/LibWeb/HTML/HTMLDListElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLDataElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLDataListElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLDetailsElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLDialogElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLDirectoryElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLDivElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLElement.cpp | 6 +++--- .../Libraries/LibWeb/HTML/HTMLEmbedElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp | 4 ++-- .../Libraries/LibWeb/HTML/HTMLFrameElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLFrameSetElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLHRElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLHeadElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLHeadingElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLHtmlElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLIFrameElement.cpp | 4 ++-- .../Libraries/LibWeb/HTML/HTMLImageElement.cpp | 6 +++--- .../Libraries/LibWeb/HTML/HTMLInputElement.cpp | 12 +++++------ Userland/Libraries/LibWeb/HTML/HTMLLIElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLLabelElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLLegendElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLMapElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLMediaElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLMenuElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLMetaElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLMeterElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLModElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLOListElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLObjectElement.cpp | 8 ++++---- .../Libraries/LibWeb/HTML/HTMLOptGroupElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLOptionElement.cpp | 2 +- .../LibWeb/HTML/HTMLOptionsCollection.cpp | 8 ++++---- .../Libraries/LibWeb/HTML/HTMLOutputElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLParagraphElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLParamElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLPictureElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLPreElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLProgressElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLQuoteElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLScriptElement.cpp | 10 ++++----- .../Libraries/LibWeb/HTML/HTMLSelectElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLSlotElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLSourceElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLSpanElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLStyleElement.cpp | 2 +- .../LibWeb/HTML/HTMLTableCaptionElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLTableCellElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLTableColElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLTableElement.cpp | 10 ++++----- .../Libraries/LibWeb/HTML/HTMLTableRowElement.cpp | 2 +- .../LibWeb/HTML/HTMLTableSectionElement.cpp | 6 +++--- .../Libraries/LibWeb/HTML/HTMLTemplateElement.cpp | 4 ++-- .../Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLTimeElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLTitleElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLTrackElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLUListElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLUnknownElement.cpp | 2 +- .../Libraries/LibWeb/HTML/HTMLVideoElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/History.cpp | 13 ++++++------ Userland/Libraries/LibWeb/HTML/History.h | 5 ++--- Userland/Libraries/LibWeb/HTML/ImageData.cpp | 13 ++++++------ Userland/Libraries/LibWeb/HTML/ImageData.h | 4 ++-- Userland/Libraries/LibWeb/HTML/MessageChannel.cpp | 16 +++++++-------- Userland/Libraries/LibWeb/HTML/MessageChannel.h | 4 ++-- Userland/Libraries/LibWeb/HTML/MessageEvent.cpp | 20 +++++++++++------- Userland/Libraries/LibWeb/HTML/MessageEvent.h | 5 +++-- Userland/Libraries/LibWeb/HTML/MessagePort.cpp | 14 ++++++------- Userland/Libraries/LibWeb/HTML/MessagePort.h | 4 ++-- .../Libraries/LibWeb/HTML/PageTransitionEvent.cpp | 16 +++++++-------- .../Libraries/LibWeb/HTML/PageTransitionEvent.h | 6 +++--- .../Libraries/LibWeb/HTML/Parser/HTMLParser.cpp | 6 +++--- Userland/Libraries/LibWeb/HTML/Path2D.cpp | 12 +++++------ Userland/Libraries/LibWeb/HTML/Path2D.h | 4 ++-- .../LibWeb/HTML/PromiseRejectionEvent.cpp | 16 +++++++-------- .../Libraries/LibWeb/HTML/PromiseRejectionEvent.h | 9 ++++---- .../LibWeb/HTML/Scripting/ClassicScript.cpp | 2 +- .../LibWeb/HTML/Scripting/Environments.cpp | 2 +- Userland/Libraries/LibWeb/HTML/Storage.cpp | 12 +++++------ Userland/Libraries/LibWeb/HTML/Storage.h | 4 ++-- Userland/Libraries/LibWeb/HTML/SubmitEvent.cpp | 16 +++++++-------- Userland/Libraries/LibWeb/HTML/SubmitEvent.h | 8 ++++---- Userland/Libraries/LibWeb/HTML/TextMetrics.cpp | 12 +++++------ Userland/Libraries/LibWeb/HTML/TextMetrics.h | 4 ++-- Userland/Libraries/LibWeb/HTML/Window.cpp | 12 +++++------ Userland/Libraries/LibWeb/HTML/WindowProxy.cpp | 6 +++--- Userland/Libraries/LibWeb/HTML/Worker.cpp | 14 ++++++------- Userland/Libraries/LibWeb/HTML/Worker.h | 5 +++-- .../Libraries/LibWeb/HTML/WorkerGlobalScope.cpp | 4 ++-- Userland/Libraries/LibWeb/HTML/WorkerNavigator.cpp | 1 + 122 files changed, 334 insertions(+), 317 deletions(-) diff --git a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp index 8e90f654ae..6f8f02219a 100644 --- a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -134,7 +134,7 @@ JS::VM& main_thread_vm() /* .promise = */ promise, /* .reason = */ promise.result(), }; - auto promise_rejection_event = HTML::PromiseRejectionEvent::create(window, HTML::EventNames::rejectionhandled, event_init); + auto promise_rejection_event = HTML::PromiseRejectionEvent::create(HTML::relevant_realm(global), HTML::EventNames::rejectionhandled, event_init); window.dispatch_event(*promise_rejection_event); }); break; diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 7cedd45bf8..5c0e711187 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1210,7 +1210,7 @@ WebIDL::ExceptionOr> Document::create_event(String const } else if (interface_lowercase == "keyboardevent") { event = UIEvents::KeyboardEvent::create(window, ""); } else if (interface_lowercase == "messageevent") { - event = HTML::MessageEvent::create(window, ""); + event = HTML::MessageEvent::create(realm, ""); } else if (interface_lowercase.is_one_of("mouseevent", "mouseevents")) { event = UIEvents::MouseEvent::create(window, ""); } else if (interface_lowercase == "storageevent") { @@ -1967,7 +1967,7 @@ CSS::StyleSheetList const& Document::style_sheets() const JS::NonnullGCPtr Document::history() { if (!m_history) - m_history = HTML::History::create(window(), *this); + m_history = HTML::History::create(realm(), *this); return *m_history; } diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index 674dca3d5a..72e347dfdd 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -187,7 +187,7 @@ NonnullRefPtr BrowsingContext::create_a_new_browsing_context(Pa // load timing info is loadTimingInfo, // FIXME: navigation id is null, // and which is ready for post-load tasks. - auto document = DOM::Document::create(*window); + auto document = DOM::Document::create(window->realm()); // Non-standard document->set_window({}, *window); @@ -885,7 +885,7 @@ WebIDL::ExceptionOr BrowsingContext::navigate( // 1. If exceptionsEnabled is given and is true, then throw a "SecurityError" DOMException. if (exceptions_enabled) { VERIFY(source_browsing_context.active_document()); - return WebIDL::SecurityError::create(source_browsing_context.active_document()->global_object(), "Source browsing context not allowed to navigate"sv); + return WebIDL::SecurityError::create(source_browsing_context.active_document()->realm(), "Source browsing context not allowed to navigate"sv); } // FIXME: 2. Otherwise, the user agent may instead offer to open resource in a new top-level browsing context @@ -1184,7 +1184,7 @@ WebIDL::ExceptionOr BrowsingContext::traverse_the_history(size_t entry_ind // and the newURL attribute initialized to newURL. // FIXME: Implement a proper HashChangeEvent class. - auto event = DOM::Event::create(verify_cast(relevant_global_object(*new_document)), HTML::EventNames::hashchange); + auto event = DOM::Event::create(verify_cast(relevant_global_object(*new_document)).realm(), HTML::EventNames::hashchange); new_document->dispatch_event(event); }); } diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h index 9e9b3e6eba..bfbfc16c13 100644 --- a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h +++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h @@ -44,20 +44,20 @@ public: JS::NonnullGCPtr create_radial_gradient(double x0, double y0, double r0, double x1, double y1, double r1) { - auto& window = static_cast(*this).global_object(); - return CanvasGradient::create_radial(window, x0, y0, r0, x1, y1, r1); + auto& realm = static_cast(*this).realm(); + return CanvasGradient::create_radial(realm, x0, y0, r0, x1, y1, r1); } JS::NonnullGCPtr create_linear_gradient(double x0, double y0, double x1, double y1) { - auto& window = static_cast(*this).global_object(); - return CanvasGradient::create_linear(window, x0, y0, x1, y1); + auto& realm = static_cast(*this).realm(); + return CanvasGradient::create_linear(realm, x0, y0, x1, y1); } JS::NonnullGCPtr create_conic_gradient(double start_angle, double x, double y) { - auto& window = static_cast(*this).global_object(); - return CanvasGradient::create_conic(window, start_angle, x, y); + auto& realm = static_cast(*this).realm(); + return CanvasGradient::create_conic(realm, start_angle, x, y); } protected: diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp index 7964d954c2..75bf523af9 100644 --- a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp +++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp @@ -7,7 +7,6 @@ #include #include -#include namespace Web::HTML { @@ -39,17 +38,17 @@ void CanvasPath::bezier_curve_to(double cp1x, double cp1y, double cp2x, double c WebIDL::ExceptionOr CanvasPath::arc(float x, float y, float radius, float start_angle, float end_angle, bool counter_clockwise) { if (radius < 0) - return WebIDL::IndexSizeError::create(m_self.global_object(), String::formatted("The radius provided ({}) is negative.", radius)); + return WebIDL::IndexSizeError::create(m_self.realm(), String::formatted("The radius provided ({}) is negative.", radius)); return ellipse(x, y, radius, radius, 0, start_angle, end_angle, counter_clockwise); } WebIDL::ExceptionOr CanvasPath::ellipse(float x, float y, float radius_x, float radius_y, float rotation, float start_angle, float end_angle, bool counter_clockwise) { if (radius_x < 0) - return WebIDL::IndexSizeError::create(m_self.global_object(), String::formatted("The major-axis radius provided ({}) is negative.", radius_x)); + return WebIDL::IndexSizeError::create(m_self.realm(), String::formatted("The major-axis radius provided ({}) is negative.", radius_x)); if (radius_y < 0) - return WebIDL::IndexSizeError::create(m_self.global_object(), String::formatted("The minor-axis radius provided ({}) is negative.", radius_y)); + return WebIDL::IndexSizeError::create(m_self.realm(), String::formatted("The minor-axis radius provided ({}) is negative.", radius_y)); if (constexpr float tau = M_TAU; (!counter_clockwise && (end_angle - start_angle) >= tau) || (counter_clockwise && (start_angle - end_angle) >= tau)) { diff --git a/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp b/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp index 49f80af456..2e969860ec 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp +++ b/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp @@ -5,13 +5,13 @@ */ #include +#include #include -#include #include namespace Web::HTML { -JS::NonnullGCPtr CanvasGradient::create_radial(HTML::Window& window, double x0, double y0, double r0, double x1, double y1, double r1) +JS::NonnullGCPtr CanvasGradient::create_radial(JS::Realm& realm, double x0, double y0, double r0, double x1, double y1, double r1) { (void)x0; (void)y0; @@ -19,31 +19,31 @@ JS::NonnullGCPtr CanvasGradient::create_radial(HTML::Window& win (void)x1; (void)y1; (void)r1; - return *window.heap().allocate(window.realm(), window, Type::Radial); + return *realm.heap().allocate(realm, realm, Type::Radial); } -JS::NonnullGCPtr CanvasGradient::create_linear(HTML::Window& window, double x0, double y0, double x1, double y1) +JS::NonnullGCPtr CanvasGradient::create_linear(JS::Realm& realm, double x0, double y0, double x1, double y1) { (void)x0; (void)y0; (void)x1; (void)y1; - return *window.heap().allocate(window.realm(), window, Type::Linear); + return *realm.heap().allocate(realm, realm, Type::Linear); } -JS::NonnullGCPtr CanvasGradient::create_conic(HTML::Window& window, double start_angle, double x, double y) +JS::NonnullGCPtr CanvasGradient::create_conic(JS::Realm& realm, double start_angle, double x, double y) { (void)start_angle; (void)x; (void)y; - return *window.heap().allocate(window.realm(), window, Type::Conic); + return *realm.heap().allocate(realm, realm, Type::Conic); } -CanvasGradient::CanvasGradient(HTML::Window& window, Type type) - : PlatformObject(window.realm()) +CanvasGradient::CanvasGradient(JS::Realm& realm, Type type) + : PlatformObject(realm) , m_type(type) { - set_prototype(&window.cached_web_prototype("CanvasGradient")); + set_prototype(&Bindings::cached_web_prototype(realm, "CanvasGradient")); } CanvasGradient::~CanvasGradient() = default; @@ -53,14 +53,14 @@ WebIDL::ExceptionOr CanvasGradient::add_color_stop(double offset, String c { // 1. If the offset is less than 0 or greater than 1, then throw an "IndexSizeError" DOMException. if (offset < 0 || offset > 1) - return WebIDL::IndexSizeError::create(global_object(), "CanvasGradient color stop offset out of bounds"); + return WebIDL::IndexSizeError::create(realm(), "CanvasGradient color stop offset out of bounds"); // 2. Let parsed color be the result of parsing color. auto parsed_color = Color::from_string(color); // 3. If parsed color is failure, throw a "SyntaxError" DOMException. if (!parsed_color.has_value()) - return WebIDL::SyntaxError::create(global_object(), "Could not parse color for CanvasGradient"); + return WebIDL::SyntaxError::create(realm(), "Could not parse color for CanvasGradient"); // 4. Place a new stop on the gradient, at offset offset relative to the whole gradient, and with the color parsed color. m_color_stops.append(ColorStop { offset, parsed_color.value() }); diff --git a/Userland/Libraries/LibWeb/HTML/CanvasGradient.h b/Userland/Libraries/LibWeb/HTML/CanvasGradient.h index 422222c1e3..944357b718 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasGradient.h +++ b/Userland/Libraries/LibWeb/HTML/CanvasGradient.h @@ -21,16 +21,16 @@ public: Conic, }; - static JS::NonnullGCPtr create_radial(HTML::Window&, double x0, double y0, double r0, double x1, double y1, double r1); - static JS::NonnullGCPtr create_linear(HTML::Window&, double x0, double y0, double x1, double y1); - static JS::NonnullGCPtr create_conic(HTML::Window&, double start_angle, double x, double y); + static JS::NonnullGCPtr create_radial(JS::Realm&, double x0, double y0, double r0, double x1, double y1, double r1); + static JS::NonnullGCPtr create_linear(JS::Realm&, double x0, double y0, double x1, double y1); + static JS::NonnullGCPtr create_conic(JS::Realm&, double start_angle, double x, double y); WebIDL::ExceptionOr add_color_stop(double offset, String const& color); ~CanvasGradient(); private: - CanvasGradient(HTML::Window&, Type); + CanvasGradient(JS::Realm&, Type); Type m_type {}; diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp index d7381dab17..8e716b708e 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp +++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp @@ -10,30 +10,30 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #include #include namespace Web::HTML { -JS::NonnullGCPtr CanvasRenderingContext2D::create(HTML::Window& window, HTMLCanvasElement& element) +JS::NonnullGCPtr CanvasRenderingContext2D::create(JS::Realm& realm, HTMLCanvasElement& element) { - return *window.heap().allocate(window.realm(), window, element); + return *realm.heap().allocate(realm, realm, element); } -CanvasRenderingContext2D::CanvasRenderingContext2D(HTML::Window& window, HTMLCanvasElement& element) - : PlatformObject(window.realm()) +CanvasRenderingContext2D::CanvasRenderingContext2D(JS::Realm& realm, HTMLCanvasElement& element) + : PlatformObject(realm) , CanvasPath(static_cast(*this)) , m_element(element) { - set_prototype(&window.cached_web_prototype("CanvasRenderingContext2D")); + set_prototype(&Bindings::cached_web_prototype(realm, "CanvasRenderingContext2D")); } CanvasRenderingContext2D::~CanvasRenderingContext2D() = default; @@ -267,7 +267,7 @@ void CanvasRenderingContext2D::fill(Path2D& path, String const& fill_rule) JS::GCPtr CanvasRenderingContext2D::create_image_data(int width, int height) const { - return ImageData::create_with_size(global_object(), width, height); + return ImageData::create_with_size(realm(), width, height); } // https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-getimagedata @@ -275,15 +275,15 @@ WebIDL::ExceptionOr> CanvasRenderingContext2D::get_image_da { // 1. If either the sw or sh arguments are zero, then throw an "IndexSizeError" DOMException. if (width == 0 || height == 0) - return WebIDL::IndexSizeError::create(global_object(), "Width and height must not be zero"); + return WebIDL::IndexSizeError::create(realm(), "Width and height must not be zero"); // 2. If the CanvasRenderingContext2D's origin-clean flag is set to false, then throw a "SecurityError" DOMException. if (!m_origin_clean) - return WebIDL::SecurityError::create(global_object(), "CanvasRenderingContext2D is not origin-clean"); + return WebIDL::SecurityError::create(realm(), "CanvasRenderingContext2D is not origin-clean"); // 3. Let imageData be a new ImageData object. // 4. Initialize imageData given sw, sh, settings set to settings, and defaultColorSpace set to this's color space. - auto image_data = ImageData::create_with_size(global_object(), width, height); + auto image_data = ImageData::create_with_size(realm(), width, height); // NOTE: We don't attempt to create the underlying bitmap here; if it doesn't exist, it's like copying only transparent black pixels (which is a no-op). if (!canvas_element().bitmap()) @@ -352,7 +352,7 @@ JS::NonnullGCPtr CanvasRenderingContext2D::measure_text(String cons // TextMetrics object with members behaving as described in the following // list: auto prepared_text = prepare_text(text); - auto metrics = TextMetrics::create(global_object()); + auto metrics = TextMetrics::create(realm()); // FIXME: Use the font that was used to create the glyphs in prepared_text. auto& font = Platform::FontPlugin::the().default_font(); @@ -497,7 +497,7 @@ WebIDL::ExceptionOr check_usability_of_image(CanvasI [](JS::Handle const& canvas_element) -> WebIDL::ExceptionOr> { // If image has either a horizontal dimension or a vertical dimension equal to zero, then throw an "InvalidStateError" DOMException. if (canvas_element->width() == 0 || canvas_element->height() == 0) - return WebIDL::InvalidStateError::create(canvas_element->global_object(), "Canvas width or height is zero"); + return WebIDL::InvalidStateError::create(canvas_element->realm(), "Canvas width or height is zero"); return Optional {}; })); if (usability.has_value()) diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h index caaae49815..3c0b63d2e0 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h +++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h @@ -51,7 +51,7 @@ class CanvasRenderingContext2D WEB_PLATFORM_OBJECT(CanvasRenderingContext2D, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create(HTML::Window&, HTMLCanvasElement&); + static JS::NonnullGCPtr create(JS::Realm&, HTMLCanvasElement&); virtual ~CanvasRenderingContext2D() override; virtual void fill_rect(float x, float y, float width, float height) override; @@ -83,7 +83,7 @@ public: virtual void clip() override; private: - explicit CanvasRenderingContext2D(HTML::Window&, HTMLCanvasElement&); + explicit CanvasRenderingContext2D(JS::Realm&, HTMLCanvasElement&); virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/HTML/CloseEvent.cpp b/Userland/Libraries/LibWeb/HTML/CloseEvent.cpp index 4fc7808ef8..1c6b8d7de8 100644 --- a/Userland/Libraries/LibWeb/HTML/CloseEvent.cpp +++ b/Userland/Libraries/LibWeb/HTML/CloseEvent.cpp @@ -4,28 +4,34 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include namespace Web::HTML { -CloseEvent* CloseEvent::create(HTML::Window& window_object, FlyString const& event_name, CloseEventInit const& event_init) +CloseEvent* CloseEvent::create(JS::Realm& realm, FlyString const& event_name, CloseEventInit const& event_init) { - return window_object.heap().allocate(window_object.realm(), window_object, event_name, event_init); + return realm.heap().allocate(realm, realm, event_name, event_init); } -CloseEvent* CloseEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, CloseEventInit const& event_init) +CloseEvent* CloseEvent::create(HTML::Window& window, FlyString const& event_name, CloseEventInit const& event_init) { - return create(window_object, event_name, event_init); + return create(window.realm(), event_name, event_init); } -CloseEvent::CloseEvent(HTML::Window& window_object, FlyString const& event_name, CloseEventInit const& event_init) - : DOM::Event(window_object, event_name, event_init) +CloseEvent* CloseEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, CloseEventInit const& event_init) +{ + return create(realm, event_name, event_init); +} + +CloseEvent::CloseEvent(JS::Realm& realm, FlyString const& event_name, CloseEventInit const& event_init) + : DOM::Event(realm, event_name, event_init) , m_was_clean(event_init.was_clean) , m_code(event_init.code) , m_reason(event_init.reason) { - set_prototype(&window_object.cached_web_prototype("CloseEvent")); + set_prototype(&Bindings::cached_web_prototype(realm, "CloseEvent")); } CloseEvent::~CloseEvent() = default; diff --git a/Userland/Libraries/LibWeb/HTML/CloseEvent.h b/Userland/Libraries/LibWeb/HTML/CloseEvent.h index 365e1e9964..2fa5701117 100644 --- a/Userland/Libraries/LibWeb/HTML/CloseEvent.h +++ b/Userland/Libraries/LibWeb/HTML/CloseEvent.h @@ -21,10 +21,9 @@ class CloseEvent : public DOM::Event { WEB_PLATFORM_OBJECT(CloseEvent, DOM::Event); public: + static CloseEvent* create(JS::Realm&, FlyString const& event_name, CloseEventInit const& event_init = {}); static CloseEvent* create(HTML::Window&, FlyString const& event_name, CloseEventInit const& event_init = {}); - static CloseEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, CloseEventInit const& event_init); - - CloseEvent(HTML::Window&, FlyString const& event_name, CloseEventInit const& event_init); + static CloseEvent* construct_impl(JS::Realm&, FlyString const& event_name, CloseEventInit const& event_init); virtual ~CloseEvent() override; @@ -33,6 +32,8 @@ public: String reason() const { return m_reason; } private: + CloseEvent(JS::Realm&, FlyString const& event_name, CloseEventInit const& event_init); + bool m_was_clean { false }; u16 m_code { 0 }; String m_reason; diff --git a/Userland/Libraries/LibWeb/HTML/CrossOrigin/AbstractOperations.cpp b/Userland/Libraries/LibWeb/HTML/CrossOrigin/AbstractOperations.cpp index 738c348b1c..e0dce226c3 100644 --- a/Userland/Libraries/LibWeb/HTML/CrossOrigin/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/HTML/CrossOrigin/AbstractOperations.cpp @@ -78,7 +78,7 @@ JS::ThrowCompletionOr cross_origin_property_fallback(JS: return JS::PropertyDescriptor { .value = JS::js_undefined(), .writable = false, .enumerable = false, .configurable = true }; // 2. Throw a "SecurityError" DOMException. - return throw_completion(WebIDL::SecurityError::create(vm.current_realm()->global_object(), String::formatted("Can't access property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(*vm.current_realm(), String::formatted("Can't access property '{}' on cross-origin object", property_key))); } // 7.2.3.3 IsPlatformObjectSameOrigin ( O ), https://html.spec.whatwg.org/multipage/browsers.html#isplatformobjectsameorigin-(-o-) @@ -196,7 +196,7 @@ JS::ThrowCompletionOr cross_origin_get(JS::VM& vm, JS::Object const& // 6. If getter is undefined, then throw a "SecurityError" DOMException. if (!getter.has_value()) - return throw_completion(WebIDL::SecurityError::create(vm.current_realm()->global_object(), String::formatted("Can't get property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(*vm.current_realm(), String::formatted("Can't get property '{}' on cross-origin object", property_key))); // 7. Return ? Call(getter, Receiver). return JS::call(vm, *getter, receiver); @@ -222,7 +222,7 @@ JS::ThrowCompletionOr cross_origin_set(JS::VM& vm, JS::Object& object, JS: } // 4. Throw a "SecurityError" DOMException. - return throw_completion(WebIDL::SecurityError::create(vm.current_realm()->global_object(), String::formatted("Can't set property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(*vm.current_realm(), String::formatted("Can't set property '{}' on cross-origin object", property_key))); } // 7.2.3.7 CrossOriginOwnPropertyKeys ( O ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginownpropertykeys-(-o-) diff --git a/Userland/Libraries/LibWeb/HTML/DOMParser.cpp b/Userland/Libraries/LibWeb/HTML/DOMParser.cpp index bd4db0052f..9083241248 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/DOMParser.cpp @@ -13,15 +13,15 @@ namespace Web::HTML { -WebIDL::ExceptionOr> DOMParser::create_with_global_object(HTML::Window& window) +WebIDL::ExceptionOr> DOMParser::construct_impl(JS::Realm& realm) { - return JS::NonnullGCPtr(*window.heap().allocate(window.realm(), window)); + return JS::NonnullGCPtr(*realm.heap().allocate(realm, realm)); } -DOMParser::DOMParser(HTML::Window& window) - : PlatformObject(window.realm()) +DOMParser::DOMParser(JS::Realm& realm) + : PlatformObject(realm) { - set_prototype(&window.cached_web_prototype("DOMParser")); + set_prototype(&Bindings::cached_web_prototype(realm, "DOMParser")); } DOMParser::~DOMParser() = default; @@ -30,7 +30,7 @@ DOMParser::~DOMParser() = default; JS::NonnullGCPtr DOMParser::parse_from_string(String const& string, Bindings::DOMParserSupportedType type) { // 1. Let document be a new Document, whose content type is type and url is this's relevant global object's associated Document's URL. - auto document = DOM::Document::create(Bindings::main_thread_internal_window_object(), verify_cast(relevant_global_object(*this)).associated_document().url()); + auto document = DOM::Document::create(realm(), verify_cast(relevant_global_object(*this)).associated_document().url()); document->set_content_type(Bindings::idl_enum_to_string(type)); // 2. Switch on type: diff --git a/Userland/Libraries/LibWeb/HTML/DOMParser.h b/Userland/Libraries/LibWeb/HTML/DOMParser.h index 8ae6f70f6d..44f5942fa9 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMParser.h +++ b/Userland/Libraries/LibWeb/HTML/DOMParser.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -18,14 +19,14 @@ class DOMParser final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(DOMParser, Bindings::PlatformObject); public: - static WebIDL::ExceptionOr> create_with_global_object(HTML::Window&); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&); virtual ~DOMParser() override; JS::NonnullGCPtr parse_from_string(String const&, Bindings::DOMParserSupportedType type); private: - explicit DOMParser(HTML::Window&); + explicit DOMParser(JS::Realm&); }; } diff --git a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp index 71fee91ac4..900538a466 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp +++ b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp @@ -5,21 +5,21 @@ */ #include +#include #include #include #include -#include namespace Web::HTML { JS::NonnullGCPtr DOMStringMap::create(DOM::Element& element) { - auto& realm = element.document().window().realm(); + auto& realm = element.realm(); return *realm.heap().allocate(realm, element); } DOMStringMap::DOMStringMap(DOM::Element& element) - : PlatformObject(element.window().cached_web_prototype("DOMStringMap")) + : PlatformObject(Bindings::cached_web_prototype(element.realm(), "DOMStringMap")) , m_associated_element(element) { } @@ -126,7 +126,7 @@ WebIDL::ExceptionOr DOMStringMap::set_value_of_new_named_property(String c if (current_character == '-' && character_index + 1 < name.length()) { auto next_character = name[character_index + 1]; if (is_ascii_lower_alpha(next_character)) - return WebIDL::SyntaxError::create(global_object(), "Name cannot contain a '-' followed by a lowercase character."); + return WebIDL::SyntaxError::create(realm(), "Name cannot contain a '-' followed by a lowercase character."); } // 2. For each ASCII upper alpha in name, insert a U+002D HYPHEN-MINUS character (-) before the character and replace the character with the same character converted to ASCII lowercase. diff --git a/Userland/Libraries/LibWeb/HTML/ErrorEvent.cpp b/Userland/Libraries/LibWeb/HTML/ErrorEvent.cpp index 4a2fe17b6d..55b0620ba2 100644 --- a/Userland/Libraries/LibWeb/HTML/ErrorEvent.cpp +++ b/Userland/Libraries/LibWeb/HTML/ErrorEvent.cpp @@ -4,30 +4,30 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include namespace Web::HTML { -ErrorEvent* ErrorEvent::create(HTML::Window& window_object, FlyString const& event_name, ErrorEventInit const& event_init) +ErrorEvent* ErrorEvent::create(JS::Realm& realm, FlyString const& event_name, ErrorEventInit const& event_init) { - return window_object.heap().allocate(window_object.realm(), window_object, event_name, event_init); + return realm.heap().allocate(realm, realm, event_name, event_init); } -ErrorEvent* ErrorEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, ErrorEventInit const& event_init) +ErrorEvent* ErrorEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, ErrorEventInit const& event_init) { - return create(window_object, event_name, event_init); + return create(realm, event_name, event_init); } -ErrorEvent::ErrorEvent(HTML::Window& window_object, FlyString const& event_name, ErrorEventInit const& event_init) - : DOM::Event(window_object, event_name) +ErrorEvent::ErrorEvent(JS::Realm& realm, FlyString const& event_name, ErrorEventInit const& event_init) + : DOM::Event(realm, event_name) , m_message(event_init.message) , m_filename(event_init.filename) , m_lineno(event_init.lineno) , m_colno(event_init.colno) , m_error(event_init.error) { - set_prototype(&window_object.cached_web_prototype("ErrorEvent")); + set_prototype(&Bindings::cached_web_prototype(realm, "ErrorEvent")); } ErrorEvent::~ErrorEvent() = default; diff --git a/Userland/Libraries/LibWeb/HTML/ErrorEvent.h b/Userland/Libraries/LibWeb/HTML/ErrorEvent.h index 6cdf2fbdd6..ea4429bd35 100644 --- a/Userland/Libraries/LibWeb/HTML/ErrorEvent.h +++ b/Userland/Libraries/LibWeb/HTML/ErrorEvent.h @@ -24,10 +24,8 @@ class ErrorEvent final : public DOM::Event { WEB_PLATFORM_OBJECT(ErrorEvent, DOM::Event); public: - static ErrorEvent* create(HTML::Window&, FlyString const& event_name, ErrorEventInit const& event_init = {}); - static ErrorEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, ErrorEventInit const& event_init); - - ErrorEvent(HTML::Window&, FlyString const& event_name, ErrorEventInit const& event_init); + static ErrorEvent* create(JS::Realm&, FlyString const& event_name, ErrorEventInit const& event_init = {}); + static ErrorEvent* construct_impl(JS::Realm&, FlyString const& event_name, ErrorEventInit const& event_init); virtual ~ErrorEvent() override; @@ -47,6 +45,8 @@ public: JS::Value error() const { return m_error; } private: + ErrorEvent(JS::Realm&, FlyString const& event_name, ErrorEventInit const& event_init); + virtual void visit_edges(Cell::Visitor&) override; String m_message { "" }; diff --git a/Userland/Libraries/LibWeb/HTML/EventHandler.cpp b/Userland/Libraries/LibWeb/HTML/EventHandler.cpp index 230d94e1d2..f733fe4fc4 100644 --- a/Userland/Libraries/LibWeb/HTML/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventHandler.cpp @@ -6,7 +6,6 @@ #include #include -#include namespace Web::HTML { diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp index 08e8932c69..74edfdb56b 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp @@ -368,8 +368,10 @@ void EventLoop::unregister_environment_settings_object(Badge> EventLoop::same_loop_windows() const { Vector> windows; - for (auto& document : documents_in_this_event_loop()) - windows.append(JS::make_handle(document->window())); + for (auto& document : documents_in_this_event_loop()) { + if (document->is_fully_active()) + windows.append(JS::make_handle(document->window())); + } return windows; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp index 0ac6ec956d..6517fba4ca 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLAnchorElement::HTMLAnchorElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLAnchorElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLAnchorElement")); activation_behavior = [this](auto const& event) { run_activation_behavior(event); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp index 74026bf2e4..99bc7b563d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLAreaElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLAreaElement::HTMLAreaElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLAreaElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLAreaElement")); } HTMLAreaElement::~HTMLAreaElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAudioElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLAudioElement.cpp index 19e6645e13..86bd83230d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAudioElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLAudioElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLAudioElement::HTMLAudioElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLMediaElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLAudioElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLAudioElement")); } HTMLAudioElement::~HTMLAudioElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBRElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLBRElement.cpp index bde4a474ea..cd9f46b889 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBRElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLBRElement.cpp @@ -13,7 +13,7 @@ namespace Web::HTML { HTMLBRElement::HTMLBRElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLBRElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLBRElement")); } HTMLBRElement::~HTMLBRElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp index 090bd75a4d..37e780d1ec 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLBaseElement::HTMLBaseElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLBaseElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLBaseElement")); } HTMLBaseElement::~HTMLBaseElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp index 38165dddbb..85aa75e484 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp @@ -15,7 +15,7 @@ namespace Web::HTML { HTMLBodyElement::HTMLBodyElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLBodyElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLBodyElement")); } HTMLBodyElement::~HTMLBodyElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp index 7aea6bf993..0474691b09 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp @@ -13,7 +13,7 @@ namespace Web::HTML { HTMLButtonElement::HTMLButtonElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLButtonElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLButtonElement")); // https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element:activation-behaviour activation_behavior = [this](auto&) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index fb9324f82f..2d836095fd 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -21,7 +21,7 @@ static constexpr auto max_canvas_area = 16384 * 16384; HTMLCanvasElement::HTMLCanvasElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&document.window().cached_web_prototype("HTMLCanvasElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLCanvasElement")); } HTMLCanvasElement::~HTMLCanvasElement() = default; @@ -88,7 +88,7 @@ HTMLCanvasElement::HasOrCreatedContext HTMLCanvasElement::create_2d_context() if (!m_context.has()) return m_context.has>() ? HasOrCreatedContext::Yes : HasOrCreatedContext::No; - m_context = CanvasRenderingContext2D::create(window(), *this); + m_context = CanvasRenderingContext2D::create(realm(), *this); return HasOrCreatedContext::Yes; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDListElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLDListElement.cpp index a9b1451419..384407b89c 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDListElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLDListElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLDListElement::HTMLDListElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLDListElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDListElement")); } HTMLDListElement::~HTMLDListElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDataElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLDataElement.cpp index 9270655d7f..46c22f721f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDataElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLDataElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLDataElement::HTMLDataElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLDataElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDataElement")); } HTMLDataElement::~HTMLDataElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDataListElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLDataListElement.cpp index 9f0db05519..474a1af4c2 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDataListElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLDataListElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLDataListElement::HTMLDataListElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLDataListElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDataListElement")); } HTMLDataListElement::~HTMLDataListElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp index b0b8312c63..1801e692ba 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLDetailsElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLDetailsElement::HTMLDetailsElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLDetailsElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDetailsElement")); } HTMLDetailsElement::~HTMLDetailsElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.cpp index d6960cbe0b..f6ccac670f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLDialogElement::HTMLDialogElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLDialogElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDialogElement")); } HTMLDialogElement::~HTMLDialogElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDirectoryElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLDirectoryElement.cpp index 576c588d69..3f44578d1f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDirectoryElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLDirectoryElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLDirectoryElement::HTMLDirectoryElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLDirectoryElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDirectoryElement")); } HTMLDirectoryElement::~HTMLDirectoryElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDivElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLDivElement.cpp index 28ba8e5498..3f1ecd1b4c 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDivElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLDivElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLDivElement::HTMLDivElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLDivElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLDivElement")); } HTMLDivElement::~HTMLDivElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index a7192f08f5..52389e18dd 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -31,7 +31,7 @@ namespace Web::HTML { HTMLElement::HTMLElement(DOM::Document& document, DOM::QualifiedName qualified_name) : Element(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLElement")); } HTMLElement::~HTMLElement() = default; @@ -104,7 +104,7 @@ WebIDL::ExceptionOr HTMLElement::set_content_editable(String const& conten set_attribute(HTML::AttributeNames::contenteditable, "false"); return {}; } - return WebIDL::SyntaxError::create(global_object(), "Invalid contentEditable value, must be 'true', 'false', or 'inherit'"); + return WebIDL::SyntaxError::create(realm(), "Invalid contentEditable value, must be 'true', 'false', or 'inherit'"); } void HTMLElement::set_inner_text(StringView text) @@ -436,7 +436,7 @@ bool HTMLElement::fire_a_synthetic_pointer_event(FlyString const& type, DOM::Ele // 1. Let event be the result of creating an event using PointerEvent. // 2. Initialize event's type attribute to e. // FIXME: Actually create a PointerEvent! - auto event = UIEvents::MouseEvent::create(document().window(), type); + auto event = UIEvents::MouseEvent::create(window(), type); // 3. Initialize event's bubbles and cancelable attributes to true. event->set_bubbles(true); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLEmbedElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLEmbedElement.cpp index c62afdd6cb..4585da81ed 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLEmbedElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLEmbedElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLEmbedElement::HTMLEmbedElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLEmbedElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLEmbedElement")); } HTMLEmbedElement::~HTMLEmbedElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp index ece4176a8d..ba4ae3da67 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp @@ -13,7 +13,7 @@ namespace Web::HTML { HTMLFieldSetElement::HTMLFieldSetElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLFieldSetElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLFieldSetElement")); } HTMLFieldSetElement::~HTMLFieldSetElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp index dd104088cb..45266b57d4 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp @@ -14,7 +14,7 @@ namespace Web::HTML { HTMLFontElement::HTMLFontElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLFontElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLFontElement")); } HTMLFontElement::~HTMLFontElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index 3a16a49cae..ba1014d821 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -25,7 +25,7 @@ namespace Web::HTML { HTMLFormElement::HTMLFormElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLFormElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLFormElement")); } HTMLFormElement::~HTMLFormElement() = default; @@ -73,7 +73,7 @@ void HTMLFormElement::submit_form(JS::GCPtr submitter, bool from_su SubmitEventInit event_init {}; event_init.submitter = submitter_button; - auto submit_event = SubmitEvent::create(document().window(), EventNames::submit, event_init); + auto submit_event = SubmitEvent::create(realm(), EventNames::submit, event_init); submit_event->set_bubbles(true); submit_event->set_cancelable(true); bool continue_ = dispatch_event(*submit_event); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFrameElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFrameElement.cpp index 9e0b3653b7..707e69f44e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFrameElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFrameElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLFrameElement::HTMLFrameElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLFrameElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLFrameElement")); } HTMLFrameElement::~HTMLFrameElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFrameSetElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFrameSetElement.cpp index 33054ee584..a9cd0b0a90 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFrameSetElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFrameSetElement.cpp @@ -13,7 +13,7 @@ namespace Web::HTML { HTMLFrameSetElement::HTMLFrameSetElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLFrameSetElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLFrameSetElement")); } HTMLFrameSetElement::~HTMLFrameSetElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHRElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLHRElement.cpp index 00a89cab77..3f9196485a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHRElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLHRElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLHRElement::HTMLHRElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLHRElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLHRElement")); } HTMLHRElement::~HTMLHRElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHeadElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLHeadElement.cpp index 0740228b11..74cbec9612 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHeadElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLHeadElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLHeadElement::HTMLHeadElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLHeadElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLHeadElement")); } HTMLHeadElement::~HTMLHeadElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHeadingElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLHeadingElement.cpp index 165fd4832a..46b5efa5d2 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHeadingElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLHeadingElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLHeadingElement::HTMLHeadingElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLHeadingElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLHeadingElement")); } HTMLHeadingElement::~HTMLHeadingElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHtmlElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLHtmlElement.cpp index 22eab1230c..842055d99e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHtmlElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLHtmlElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLHtmlElement::HTMLHtmlElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLHtmlElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLHtmlElement")); } HTMLHtmlElement::~HTMLHtmlElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp index 93ce002b9a..399e1f9676 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp @@ -16,7 +16,7 @@ namespace Web::HTML { HTMLIFrameElement::HTMLIFrameElement(DOM::Document& document, DOM::QualifiedName qualified_name) : BrowsingContextContainer(document, move(qualified_name)) { - set_prototype(&document.window().cached_web_prototype("HTMLIFrameElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLIFrameElement")); } HTMLIFrameElement::~HTMLIFrameElement() = default; @@ -144,7 +144,7 @@ void run_iframe_load_event_steps(HTML::HTMLIFrameElement& element) // FIXME: 4. Set childDocument's iframe load in progress flag. // 5. Fire an event named load at element. - element.dispatch_event(*DOM::Event::create(element.document().window(), HTML::EventNames::load)); + element.dispatch_event(*DOM::Event::create(element.realm(), HTML::EventNames::load)); // FIXME: 6. Unset childDocument's iframe load in progress flag. } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp index 9e4a0507a4..1ca65c3b3d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -22,13 +22,13 @@ HTMLImageElement::HTMLImageElement(DOM::Document& document, DOM::QualifiedName q : HTMLElement(document, move(qualified_name)) , m_image_loader(*this) { - set_prototype(&window().cached_web_prototype("HTMLImageElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLImageElement")); m_image_loader.on_load = [this] { set_needs_style_update(true); this->document().set_needs_layout(); queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] { - dispatch_event(*DOM::Event::create(this->document().window(), EventNames::load)); + dispatch_event(*DOM::Event::create(this->realm(), EventNames::load)); }); }; @@ -37,7 +37,7 @@ HTMLImageElement::HTMLImageElement(DOM::Document& document, DOM::QualifiedName q set_needs_style_update(true); this->document().set_needs_layout(); queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] { - dispatch_event(*DOM::Event::create(this->document().window(), EventNames::error)); + dispatch_event(*DOM::Event::create(this->realm(), EventNames::error)); }); }; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 1d3f4eb77f..d6b11b1124 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -24,7 +24,7 @@ HTMLInputElement::HTMLInputElement(DOM::Document& document, DOM::QualifiedName q : HTMLElement(document, move(qualified_name)) , m_value(String::empty()) { - set_prototype(&window().cached_web_prototype("HTMLInputElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLInputElement")); activation_behavior = [this](auto&) { // The activation behavior for input elements are these steps: @@ -99,13 +99,13 @@ void HTMLInputElement::run_input_activation_behavior() return; // 2. Fire an event named input at the element with the bubbles and composed attributes initialized to true. - auto input_event = DOM::Event::create(document().window(), HTML::EventNames::input); + auto input_event = DOM::Event::create(realm(), HTML::EventNames::input); input_event->set_bubbles(true); input_event->set_composed(true); dispatch_event(*input_event); // 3. Fire an event named change at the element with the bubbles attribute initialized to true. - auto change_event = DOM::Event::create(document().window(), HTML::EventNames::change); + auto change_event = DOM::Event::create(realm(), HTML::EventNames::change); change_event->set_bubbles(true); dispatch_event(*change_event); } else if (type_state() == TypeAttributeState::SubmitButton) { @@ -121,7 +121,7 @@ void HTMLInputElement::run_input_activation_behavior() // 3. Submit the form owner from the element. form->submit_form(this); } else { - dispatch_event(*DOM::Event::create(document().window(), EventNames::change)); + dispatch_event(*DOM::Event::create(realm(), EventNames::change)); } } @@ -134,13 +134,13 @@ void HTMLInputElement::did_edit_text_node(Badge) // NOTE: This is a bit ad-hoc, but basically implements part of "4.10.5.5 Common event behaviors" // https://html.spec.whatwg.org/multipage/input.html#common-input-element-events queue_an_element_task(HTML::Task::Source::UserInteraction, [this] { - auto input_event = DOM::Event::create(document().window(), HTML::EventNames::input); + auto input_event = DOM::Event::create(realm(), HTML::EventNames::input); input_event->set_bubbles(true); input_event->set_composed(true); dispatch_event(*input_event); // FIXME: This should only fire when the input is "committed", whatever that means. - auto change_event = DOM::Event::create(document().window(), HTML::EventNames::change); + auto change_event = DOM::Event::create(realm(), HTML::EventNames::change); change_event->set_bubbles(true); dispatch_event(*change_event); }); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLIElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLIElement.cpp index c7f99a2614..307461215f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLIElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLLIElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLLIElement::HTMLLIElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLLIElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLLIElement")); } HTMLLIElement::~HTMLLIElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLabelElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLabelElement.cpp index b3c6b7ab9a..7f23ab89c3 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLabelElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLLabelElement.cpp @@ -13,7 +13,7 @@ namespace Web::HTML { HTMLLabelElement::HTMLLabelElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLLabelElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLLabelElement")); } HTMLLabelElement::~HTMLLabelElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.cpp index c4781885b4..48ee6eaf00 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLLegendElement.cpp @@ -13,7 +13,7 @@ namespace Web::HTML { HTMLLegendElement::HTMLLegendElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLLegendElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLLegendElement")); } HTMLLegendElement::~HTMLLegendElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index 5b4d4158df..f813ccc593 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -21,7 +21,7 @@ namespace Web::HTML { HTMLLinkElement::HTMLLinkElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLLinkElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLLinkElement")); } HTMLLinkElement::~HTMLLinkElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMapElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMapElement.cpp index 5f8ef1f9e1..a112424d68 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMapElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMapElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLMapElement::HTMLMapElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLMapElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLMapElement")); } HTMLMapElement::~HTMLMapElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp index 496e591205..798f4d3bba 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLMarqueeElement::HTMLMarqueeElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLMarqueeElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLMarqueeElement")); } HTMLMarqueeElement::~HTMLMarqueeElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index 793510c5d4..fbf1f6c64b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp @@ -13,7 +13,7 @@ namespace Web::HTML { HTMLMediaElement::HTMLMediaElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLMediaElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLMediaElement")); } HTMLMediaElement::~HTMLMediaElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMenuElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMenuElement.cpp index 01aa6c3c7a..7035eac2bd 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMenuElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMenuElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLMenuElement::HTMLMenuElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLMenuElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLMenuElement")); } HTMLMenuElement::~HTMLMenuElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMetaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMetaElement.cpp index b263fd28d9..e57088c8a9 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMetaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMetaElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLMetaElement::HTMLMetaElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLMetaElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLMetaElement")); } HTMLMetaElement::~HTMLMetaElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMeterElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMeterElement.cpp index 7938a3e798..9cc97e7615 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMeterElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMeterElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLMeterElement::HTMLMeterElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLMeterElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLMeterElement")); } HTMLMeterElement::~HTMLMeterElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLModElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLModElement.cpp index e510e47e32..8bf0d43361 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLModElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLModElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLModElement::HTMLModElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLModElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLModElement")); } HTMLModElement::~HTMLModElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOListElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOListElement.cpp index 7a02c49ead..2f613b3a6c 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOListElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLOListElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLOListElement::HTMLOListElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLOListElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLOListElement")); } HTMLOListElement::~HTMLOListElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp index d791560daf..b90a79ff08 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp @@ -19,7 +19,7 @@ namespace Web::HTML { HTMLObjectElement::HTMLObjectElement(DOM::Document& document, DOM::QualifiedName qualified_name) : BrowsingContextContainer(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLObjectElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLObjectElement")); } HTMLObjectElement::~HTMLObjectElement() = default; @@ -97,7 +97,7 @@ void HTMLObjectElement::queue_element_task_to_run_object_representation_steps() // 3. If that failed, fire an event named error at the element, then jump to the step below labeled fallback. if (!url.is_valid()) { - dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::error)); + dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); return run_object_representation_fallback_steps(); } @@ -124,7 +124,7 @@ void HTMLObjectElement::queue_element_task_to_run_object_representation_steps() void HTMLObjectElement::resource_did_fail() { // 4.7. If the load failed (e.g. there was an HTTP 404 error, there was a DNS error), fire an event named error at the element, then jump to the step below labeled fallback. - dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::error)); + dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); run_object_representation_fallback_steps(); } @@ -262,7 +262,7 @@ void HTMLObjectElement::run_object_representation_completed_steps(Representation // 4.11. If the object element does not represent its nested browsing context, then once the resource is completely loaded, queue an element task on the DOM manipulation task source given the object element to fire an event named load at the element. if (representation != Representation::NestedBrowsingContext) { queue_an_element_task(HTML::Task::Source::DOMManipulation, [&]() { - dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::load)); + dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::load)); }); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptGroupElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOptGroupElement.cpp index 97a61dd588..72eb7f8fa4 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOptGroupElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLOptGroupElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLOptGroupElement::HTMLOptGroupElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLOptGroupElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLOptGroupElement")); } HTMLOptGroupElement::~HTMLOptGroupElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp index 56555d0cdb..de27226c66 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp @@ -20,7 +20,7 @@ namespace Web::HTML { HTMLOptionElement::HTMLOptionElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLOptionElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLOptionElement")); } HTMLOptionElement::~HTMLOptionElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp index 22ff334903..49b46ff6ed 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp @@ -4,11 +4,11 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include #include -#include #include namespace Web::HTML { @@ -21,7 +21,7 @@ JS::NonnullGCPtr HTMLOptionsCollection::create(DOM::Paren HTMLOptionsCollection::HTMLOptionsCollection(DOM::ParentNode& root, Function filter) : DOM::HTMLCollection(root, move(filter)) { - set_prototype(&root.window().cached_web_prototype("HTMLOptionsCollection")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLOptionsCollection")); } HTMLOptionsCollection::~HTMLOptionsCollection() = default; @@ -40,11 +40,11 @@ WebIDL::ExceptionOr HTMLOptionsCollection::add(HTMLOptionOrOptGroupElement // 1. If element is an ancestor of the select element on which the HTMLOptionsCollection is rooted, then throw a "HierarchyRequestError" DOMException. if (resolved_element->is_ancestor_of(root())) - return WebIDL::HierarchyRequestError::create(global_object(), "The provided element is an ancestor of the root select element."); + return WebIDL::HierarchyRequestError::create(realm(), "The provided element is an ancestor of the root select element."); // 2. If before is an element, but that element isn't a descendant of the select element on which the HTMLOptionsCollection is rooted, then throw a "NotFoundError" DOMException. if (before_element && !before_element->is_descendant_of(root())) - return WebIDL::NotFoundError::create(global_object(), "The 'before' element is not a descendant of the root select element."); + return WebIDL::NotFoundError::create(realm(), "The 'before' element is not a descendant of the root select element."); // 3. If element and before are the same element, then return. if (before_element && (resolved_element.ptr() == before_element.ptr())) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOutputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOutputElement.cpp index 08b9fbedee..a469069590 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOutputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLOutputElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLOutputElement::HTMLOutputElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLOutputElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLOutputElement")); } HTMLOutputElement::~HTMLOutputElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLParagraphElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLParagraphElement.cpp index 0311b98bfd..1acfdbb3f6 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLParagraphElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLParagraphElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLParagraphElement::HTMLParagraphElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLParagraphElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLParagraphElement")); } HTMLParagraphElement::~HTMLParagraphElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLParamElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLParamElement.cpp index 1698471a13..390764ad60 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLParamElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLParamElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLParamElement::HTMLParamElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLParamElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLParamElement")); } HTMLParamElement::~HTMLParamElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLPictureElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLPictureElement.cpp index 0f21efb14a..3dd888e721 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLPictureElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLPictureElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLPictureElement::HTMLPictureElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLPictureElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLPictureElement")); } HTMLPictureElement::~HTMLPictureElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLPreElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLPreElement.cpp index 8461ebeea8..76cd022d26 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLPreElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLPreElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLPreElement::HTMLPreElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLPreElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLPreElement")); } HTMLPreElement::~HTMLPreElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp index cc31d8e0d5..27a4dd681e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLProgressElement.cpp @@ -18,7 +18,7 @@ namespace Web::HTML { HTMLProgressElement::HTMLProgressElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLProgressElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLProgressElement")); } HTMLProgressElement::~HTMLProgressElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLQuoteElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLQuoteElement.cpp index fdeae0a18e..09d207a0c1 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLQuoteElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLQuoteElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLQuoteElement::HTMLQuoteElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLQuoteElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLQuoteElement")); } HTMLQuoteElement::~HTMLQuoteElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp index 3e5f5e8237..384f034776 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp @@ -22,7 +22,7 @@ namespace Web::HTML { HTMLScriptElement::HTMLScriptElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLScriptElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLScriptElement")); } HTMLScriptElement::~HTMLScriptElement() = default; @@ -57,7 +57,7 @@ void HTMLScriptElement::execute_script() // 3. If the script's script is null for scriptElement, then fire an event named error at scriptElement, and return. if (!m_script) { dbgln("HTMLScriptElement: Refusing to run script because the script's script is null."); - dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::error)); + dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); return; } @@ -104,7 +104,7 @@ void HTMLScriptElement::execute_script() // 7. If scriptElement is from an external file, then fire an event named load at scriptElement. if (m_from_an_external_file) - dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::load)); + dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::load)); } // https://mimesniff.spec.whatwg.org/#javascript-mime-type-essence-match @@ -268,7 +268,7 @@ void HTMLScriptElement::prepare_script() if (src.is_empty()) { dbgln("HTMLScriptElement: Refusing to run script because the src attribute is empty."); queue_an_element_task(HTML::Task::Source::Unspecified, [this] { - dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::error)); + dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); }); return; } @@ -281,7 +281,7 @@ void HTMLScriptElement::prepare_script() if (!url.is_valid()) { dbgln("HTMLScriptElement: Refusing to run script because the src URL '{}' is invalid.", url); queue_an_element_task(HTML::Task::Source::Unspecified, [this] { - dispatch_event(*DOM::Event::create(document().window(), HTML::EventNames::error)); + dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); }); return; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index 6671dd26b6..c1994c6ad3 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -16,7 +16,7 @@ namespace Web::HTML { HTMLSelectElement::HTMLSelectElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLSelectElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLSelectElement")); } HTMLSelectElement::~HTMLSelectElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSlotElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSlotElement.cpp index 5964546ddf..c46cd74158 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSlotElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSlotElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLSlotElement::HTMLSlotElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLSlotElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLSlotElement")); } HTMLSlotElement::~HTMLSlotElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSourceElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSourceElement.cpp index 4e22808d5f..5a470f3187 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSourceElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSourceElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLSourceElement::HTMLSourceElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLSourceElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLSourceElement")); } HTMLSourceElement::~HTMLSourceElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSpanElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSpanElement.cpp index 31881bb054..6e22b262e3 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSpanElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSpanElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLSpanElement::HTMLSpanElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLSpanElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLSpanElement")); } HTMLSpanElement::~HTMLSpanElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp index f59055aa3f..92f55b552a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp @@ -14,7 +14,7 @@ namespace Web::HTML { HTMLStyleElement::HTMLStyleElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLStyleElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLStyleElement")); } HTMLStyleElement::~HTMLStyleElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableCaptionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableCaptionElement.cpp index ef1bf755fb..c1f31d3f3b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableCaptionElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableCaptionElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLTableCaptionElement::HTMLTableCaptionElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLTableCaptionElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTableCaptionElement")); } HTMLTableCaptionElement::~HTMLTableCaptionElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp index 845496c96d..6eda4d7726 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp @@ -14,7 +14,7 @@ namespace Web::HTML { HTMLTableCellElement::HTMLTableCellElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLTableCellElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTableCellElement")); } HTMLTableCellElement::~HTMLTableCellElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableColElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableColElement.cpp index b1d5c8585d..1a9773473d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableColElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableColElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLTableColElement::HTMLTableColElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLTableColElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTableColElement")); } HTMLTableColElement::~HTMLTableColElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp index 2cd7ff8138..1e20b470d1 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -20,7 +20,7 @@ namespace Web::HTML { HTMLTableElement::HTMLTableElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLTableElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTableElement")); } HTMLTableElement::~HTMLTableElement() = default; @@ -103,7 +103,7 @@ WebIDL::ExceptionOr HTMLTableElement::set_t_head(HTMLTableSectionElement* VERIFY(thead); if (thead->local_name() != TagNames::thead) - return WebIDL::HierarchyRequestError::create(global_object(), "Element is not thead"); + return WebIDL::HierarchyRequestError::create(realm(), "Element is not thead"); // FIXME: The spec requires deleting the current thead if thead is null // Currently the wrapper generator doesn't send us a nullable value @@ -190,7 +190,7 @@ WebIDL::ExceptionOr HTMLTableElement::set_t_foot(HTMLTableSectionElement* VERIFY(tfoot); if (tfoot->local_name() != TagNames::tfoot) - return WebIDL::HierarchyRequestError::create(global_object(), "Element is not tfoot"); + return WebIDL::HierarchyRequestError::create(realm(), "Element is not tfoot"); // FIXME: The spec requires deleting the current tfoot if tfoot is null // Currently the wrapper generator doesn't send us a nullable value @@ -286,7 +286,7 @@ WebIDL::ExceptionOr> HTMLTableElement::ins auto rows_length = rows->length(); if (index < -1 || index > (long)rows_length) { - return WebIDL::IndexSizeError::create(global_object(), "Index is negative or greater than the number of rows"); + return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than the number of rows"); } auto& tr = static_cast(*DOM::create_element(document(), TagNames::tr, Namespace::HTML)); if (rows_length == 0 && !has_child_of_type()) { @@ -313,7 +313,7 @@ WebIDL::ExceptionOr HTMLTableElement::delete_row(long index) // 1. If index is less than −1 or greater than or equal to the number of elements in the rows collection, then throw an "IndexSizeError" DOMException. if (index < -1 || index >= (long)rows_length) - return WebIDL::IndexSizeError::create(global_object(), "Index is negative or greater than or equal to the number of rows"); + return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than or equal to the number of rows"); // 2. If index is −1, then remove the last element in the rows collection from its parent, or do nothing if the rows collection is empty. if (index == -1) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp index c26307bbaf..c0d129efed 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp @@ -16,7 +16,7 @@ namespace Web::HTML { HTMLTableRowElement::HTMLTableRowElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLTableRowElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTableRowElement")); } HTMLTableRowElement::~HTMLTableRowElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp index c2e2ff598d..9baefaf7d3 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp @@ -17,7 +17,7 @@ namespace Web::HTML { HTMLTableSectionElement::HTMLTableSectionElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLTableSectionElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTableSectionElement")); } HTMLTableSectionElement::~HTMLTableSectionElement() = default; @@ -43,7 +43,7 @@ WebIDL::ExceptionOr> HTMLTableSectionEleme // 1. If index is less than −1 or greater than the number of elements in the rows collection, throw an "IndexSizeError" DOMException. if (index < -1 || index > rows_collection_size) - return WebIDL::IndexSizeError::create(global_object(), "Index is negative or greater than the number of rows"); + return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than the number of rows"); // 2. Let table row be the result of creating an element given this element's node document, tr, and the HTML namespace. auto& table_row = static_cast(*DOM::create_element(document(), TagNames::tr, Namespace::HTML)); @@ -67,7 +67,7 @@ WebIDL::ExceptionOr HTMLTableSectionElement::delete_row(long index) // 1. If index is less than −1 or greater than or equal to the number of elements in the rows collection, then throw an "IndexSizeError" DOMException. if (index < -1 || index >= rows_collection_size) - return WebIDL::IndexSizeError::create(global_object(), "Index is negative or greater than or equal to the number of rows"); + return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than or equal to the number of rows"); // 2. If index is −1, then remove the last element in the rows collection from this element, or do nothing if the rows collection is empty. if (index == -1) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp index 9dd5b927e0..834e3d85c5 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp @@ -13,7 +13,7 @@ namespace Web::HTML { HTMLTemplateElement::HTMLTemplateElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLTemplateElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTemplateElement")); m_content = heap().allocate(realm(), appropriate_template_contents_owner_document(document)); m_content->set_host(this); @@ -31,7 +31,7 @@ DOM::Document& HTMLTemplateElement::appropriate_template_contents_owner_document { if (!document.created_for_appropriate_template_contents()) { if (!document.associated_inert_template_document()) { - auto new_document = DOM::Document::create(Bindings::main_thread_internal_window_object()); + auto new_document = DOM::Document::create(realm()); new_document->set_created_for_appropriate_template_contents(true); new_document->set_document_type(document.document_type()); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp index 6988607f00..9379192665 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLTextAreaElement::HTMLTextAreaElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLTextAreaElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTextAreaElement")); } HTMLTextAreaElement::~HTMLTextAreaElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTimeElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTimeElement.cpp index 9c6061be89..10283d07a1 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTimeElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTimeElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLTimeElement::HTMLTimeElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLTimeElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTimeElement")); } HTMLTimeElement::~HTMLTimeElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTitleElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTitleElement.cpp index f6c75ec1fb..27bcb0a15e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTitleElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTitleElement.cpp @@ -13,7 +13,7 @@ namespace Web::HTML { HTMLTitleElement::HTMLTitleElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLTitleElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTitleElement")); } HTMLTitleElement::~HTMLTitleElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTrackElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTrackElement.cpp index 78e3394c51..01b2607a87 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTrackElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTrackElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLTrackElement::HTMLTrackElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLTrackElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLTrackElement")); } HTMLTrackElement::~HTMLTrackElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLUListElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLUListElement.cpp index 89164939ed..54d5c0f0e8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLUListElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLUListElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLUListElement::HTMLUListElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLUListElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLUListElement")); } HTMLUListElement::~HTMLUListElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLUnknownElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLUnknownElement.cpp index 1f07432f31..9aa404dfa1 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLUnknownElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLUnknownElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLUnknownElement::HTMLUnknownElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLUnknownElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLUnknownElement")); } HTMLUnknownElement::~HTMLUnknownElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.cpp index beb9feb413..0a6486cfa4 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.cpp @@ -12,7 +12,7 @@ namespace Web::HTML { HTMLVideoElement::HTMLVideoElement(DOM::Document& document, DOM::QualifiedName qualified_name) : HTMLMediaElement(document, move(qualified_name)) { - set_prototype(&window().cached_web_prototype("HTMLVideoElement")); + set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLVideoElement")); } HTMLVideoElement::~HTMLVideoElement() = default; diff --git a/Userland/Libraries/LibWeb/HTML/History.cpp b/Userland/Libraries/LibWeb/HTML/History.cpp index 706e6e209a..f1ecf6a98d 100644 --- a/Userland/Libraries/LibWeb/HTML/History.cpp +++ b/Userland/Libraries/LibWeb/HTML/History.cpp @@ -4,21 +4,22 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include namespace Web::HTML { -JS::NonnullGCPtr History::create(HTML::Window& window, DOM::Document& document) +JS::NonnullGCPtr History::create(JS::Realm& realm, DOM::Document& document) { - return *window.heap().allocate(window.realm(), window, document); + return *realm.heap().allocate(realm, realm, document); } -History::History(HTML::Window& window, DOM::Document& document) - : PlatformObject(window.realm()) +History::History(JS::Realm& realm, DOM::Document& document) + : PlatformObject(realm) , m_associated_document(document) { - set_prototype(&window.cached_web_prototype("History")); + set_prototype(&Bindings::cached_web_prototype(realm, "History")); } History::~History() = default; @@ -50,7 +51,7 @@ WebIDL::ExceptionOr History::shared_history_push_replace_state(JS::Value, // 2. If document is not fully active, then throw a "SecurityError" DOMException. if (!m_associated_document->is_fully_active()) - return WebIDL::SecurityError::create(global_object(), "Cannot perform pushState or replaceState on a document that isn't fully active."); + return WebIDL::SecurityError::create(realm(), "Cannot perform pushState or replaceState on a document that isn't fully active."); // 3. Optionally, return. (For example, the user agent might disallow calls to these methods that are invoked on a timer, // or from event listeners that are not triggered in response to a clear user action, or that are invoked in rapid succession.) diff --git a/Userland/Libraries/LibWeb/HTML/History.h b/Userland/Libraries/LibWeb/HTML/History.h index b7d22ef12c..23fe7001e6 100644 --- a/Userland/Libraries/LibWeb/HTML/History.h +++ b/Userland/Libraries/LibWeb/HTML/History.h @@ -7,7 +7,6 @@ #pragma once -#include #include #include @@ -17,7 +16,7 @@ class History final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(History, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create(HTML::Window&, DOM::Document&); + static JS::NonnullGCPtr create(JS::Realm&, DOM::Document&); virtual ~History() override; @@ -25,7 +24,7 @@ public: WebIDL::ExceptionOr replace_state(JS::Value data, String const& unused, String const& url); private: - explicit History(HTML::Window&, DOM::Document&); + History(JS::Realm&, DOM::Document&); virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/HTML/ImageData.cpp b/Userland/Libraries/LibWeb/HTML/ImageData.cpp index 4cff7f5813..8f16de3eac 100644 --- a/Userland/Libraries/LibWeb/HTML/ImageData.cpp +++ b/Userland/Libraries/LibWeb/HTML/ImageData.cpp @@ -6,14 +6,13 @@ #include #include +#include #include -#include namespace Web::HTML { -JS::GCPtr ImageData::create_with_size(HTML::Window& window, int width, int height) +JS::GCPtr ImageData::create_with_size(JS::Realm& realm, int width, int height) { - auto& realm = window.realm(); if (width <= 0 || height <= 0) return nullptr; @@ -29,15 +28,15 @@ JS::GCPtr ImageData::create_with_size(HTML::Window& window, int width auto bitmap_or_error = Gfx::Bitmap::try_create_wrapper(Gfx::BitmapFormat::RGBA8888, Gfx::IntSize(width, height), 1, width * sizeof(u32), data->data().data()); if (bitmap_or_error.is_error()) return nullptr; - return realm.heap().allocate(realm, window, bitmap_or_error.release_value(), move(data)); + return realm.heap().allocate(realm, realm, bitmap_or_error.release_value(), move(data)); } -ImageData::ImageData(HTML::Window& window, NonnullRefPtr bitmap, JS::NonnullGCPtr data) - : PlatformObject(window.realm()) +ImageData::ImageData(JS::Realm& realm, NonnullRefPtr bitmap, JS::NonnullGCPtr data) + : PlatformObject(realm) , m_bitmap(move(bitmap)) , m_data(move(data)) { - set_prototype(&window.cached_web_prototype("ImageData")); + set_prototype(&Bindings::cached_web_prototype(realm, "ImageData")); } ImageData::~ImageData() = default; diff --git a/Userland/Libraries/LibWeb/HTML/ImageData.h b/Userland/Libraries/LibWeb/HTML/ImageData.h index 2f588dd257..e56f026c1b 100644 --- a/Userland/Libraries/LibWeb/HTML/ImageData.h +++ b/Userland/Libraries/LibWeb/HTML/ImageData.h @@ -15,7 +15,7 @@ class ImageData final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(ImageData, Bindings::PlatformObject); public: - static JS::GCPtr create_with_size(HTML::Window&, int width, int height); + static JS::GCPtr create_with_size(JS::Realm&, int width, int height); virtual ~ImageData() override; @@ -29,7 +29,7 @@ public: const JS::Uint8ClampedArray* data() const; private: - explicit ImageData(HTML::Window&, NonnullRefPtr, JS::NonnullGCPtr); + ImageData(JS::Realm&, NonnullRefPtr, JS::NonnullGCPtr); virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/HTML/MessageChannel.cpp b/Userland/Libraries/LibWeb/HTML/MessageChannel.cpp index 767c515b45..8e71b7504b 100644 --- a/Userland/Libraries/LibWeb/HTML/MessageChannel.cpp +++ b/Userland/Libraries/LibWeb/HTML/MessageChannel.cpp @@ -4,28 +4,28 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include -#include namespace Web::HTML { -JS::NonnullGCPtr MessageChannel::create_with_global_object(HTML::Window& window) +JS::NonnullGCPtr MessageChannel::construct_impl(JS::Realm& realm) { - return *window.heap().allocate(window.realm(), window); + return *realm.heap().allocate(realm, realm); } -MessageChannel::MessageChannel(HTML::Window& window) - : PlatformObject(window.realm()) +MessageChannel::MessageChannel(JS::Realm& realm) + : PlatformObject(realm) { - set_prototype(&window.cached_web_prototype("MessageChannel")); + set_prototype(&Bindings::cached_web_prototype(realm, "MessageChannel")); // 1. Set this's port 1 to a new MessagePort in this's relevant Realm. - m_port1 = MessagePort::create(window); + m_port1 = MessagePort::create(realm); // 2. Set this's port 2 to a new MessagePort in this's relevant Realm. - m_port2 = MessagePort::create(window); + m_port2 = MessagePort::create(realm); // 3. Entangle this's port 1 and this's port 2. m_port1->entangle_with(*m_port2); diff --git a/Userland/Libraries/LibWeb/HTML/MessageChannel.h b/Userland/Libraries/LibWeb/HTML/MessageChannel.h index d4d4683c5b..4fc9c2c2e4 100644 --- a/Userland/Libraries/LibWeb/HTML/MessageChannel.h +++ b/Userland/Libraries/LibWeb/HTML/MessageChannel.h @@ -16,7 +16,7 @@ class MessageChannel final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(MessageChannel, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create_with_global_object(HTML::Window&); + static JS::NonnullGCPtr construct_impl(JS::Realm&); virtual ~MessageChannel() override; MessagePort* port1(); @@ -26,7 +26,7 @@ public: MessagePort const* port2() const; private: - explicit MessageChannel(HTML::Window&); + explicit MessageChannel(JS::Realm&); virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/HTML/MessageEvent.cpp b/Userland/Libraries/LibWeb/HTML/MessageEvent.cpp index 98eb672e82..9bb6f9a67f 100644 --- a/Userland/Libraries/LibWeb/HTML/MessageEvent.cpp +++ b/Userland/Libraries/LibWeb/HTML/MessageEvent.cpp @@ -4,28 +4,34 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include namespace Web::HTML { -MessageEvent* MessageEvent::create(HTML::Window& window_object, FlyString const& event_name, MessageEventInit const& event_init) +MessageEvent* MessageEvent::create(JS::Realm& realm, FlyString const& event_name, MessageEventInit const& event_init) { - return window_object.heap().allocate(window_object.realm(), window_object, event_name, event_init); + return realm.heap().allocate(realm, realm, event_name, event_init); } -MessageEvent* MessageEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, MessageEventInit const& event_init) +MessageEvent* MessageEvent::create(HTML::Window& window, FlyString const& event_name, MessageEventInit const& event_init) { - return create(window_object, event_name, event_init); + return create(window.realm(), event_name, event_init); } -MessageEvent::MessageEvent(HTML::Window& window_object, FlyString const& event_name, MessageEventInit const& event_init) - : DOM::Event(window_object, event_name, event_init) +MessageEvent* MessageEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, MessageEventInit const& event_init) +{ + return create(realm, event_name, event_init); +} + +MessageEvent::MessageEvent(JS::Realm& realm, FlyString const& event_name, MessageEventInit const& event_init) + : DOM::Event(realm, event_name, event_init) , m_data(event_init.data) , m_origin(event_init.origin) , m_last_event_id(event_init.last_event_id) { - set_prototype(&window_object.cached_web_prototype("MessageEvent")); + set_prototype(&Bindings::cached_web_prototype(realm, "MessageEvent")); } MessageEvent::~MessageEvent() = default; diff --git a/Userland/Libraries/LibWeb/HTML/MessageEvent.h b/Userland/Libraries/LibWeb/HTML/MessageEvent.h index af35f4155c..282a76b93d 100644 --- a/Userland/Libraries/LibWeb/HTML/MessageEvent.h +++ b/Userland/Libraries/LibWeb/HTML/MessageEvent.h @@ -21,10 +21,11 @@ class MessageEvent : public DOM::Event { WEB_PLATFORM_OBJECT(MessageEvent, DOM::Event); public: + static MessageEvent* create(JS::Realm&, FlyString const& event_name, MessageEventInit const& event_init = {}); static MessageEvent* create(HTML::Window&, FlyString const& event_name, MessageEventInit const& event_init = {}); - static MessageEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, MessageEventInit const& event_init); + static MessageEvent* construct_impl(JS::Realm&, FlyString const& event_name, MessageEventInit const& event_init); - MessageEvent(HTML::Window&, FlyString const& event_name, MessageEventInit const& event_init); + MessageEvent(JS::Realm&, FlyString const& event_name, MessageEventInit const& event_init); virtual ~MessageEvent() override; JS::Value data() const { return m_data; } diff --git a/Userland/Libraries/LibWeb/HTML/MessagePort.cpp b/Userland/Libraries/LibWeb/HTML/MessagePort.cpp index 437a382ff7..c3d5dc1c7f 100644 --- a/Userland/Libraries/LibWeb/HTML/MessagePort.cpp +++ b/Userland/Libraries/LibWeb/HTML/MessagePort.cpp @@ -4,25 +4,25 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include #include #include #include -#include namespace Web::HTML { -JS::NonnullGCPtr MessagePort::create(HTML::Window& window) +JS::NonnullGCPtr MessagePort::create(JS::Realm& realm) { - return *window.heap().allocate(window.realm(), window); + return *realm.heap().allocate(realm, realm); } -MessagePort::MessagePort(HTML::Window& window) - : DOM::EventTarget(window.realm()) +MessagePort::MessagePort(JS::Realm& realm) + : DOM::EventTarget(realm) { - set_prototype(&window.cached_web_prototype("MessagePort")); + set_prototype(&Bindings::cached_web_prototype(realm, "MessagePort")); } MessagePort::~MessagePort() = default; @@ -92,7 +92,7 @@ void MessagePort::post_message(JS::Value message) MessageEventInit event_init {}; event_init.data = message; event_init.origin = ""; - target_port->dispatch_event(*MessageEvent::create(verify_cast(target_port->realm().global_object()), HTML::EventNames::message, event_init)); + target_port->dispatch_event(*MessageEvent::create(target_port->realm(), HTML::EventNames::message, event_init)); })); } diff --git a/Userland/Libraries/LibWeb/HTML/MessagePort.h b/Userland/Libraries/LibWeb/HTML/MessagePort.h index 6a6b1334fc..6dba0493ee 100644 --- a/Userland/Libraries/LibWeb/HTML/MessagePort.h +++ b/Userland/Libraries/LibWeb/HTML/MessagePort.h @@ -22,7 +22,7 @@ class MessagePort final : public DOM::EventTarget { WEB_PLATFORM_OBJECT(MessagePort, DOM::EventTarget); public: - static JS::NonnullGCPtr create(HTML::Window&); + static JS::NonnullGCPtr create(JS::Realm&); virtual ~MessagePort() override; @@ -44,7 +44,7 @@ public: #undef __ENUMERATE private: - explicit MessagePort(HTML::Window&); + explicit MessagePort(JS::Realm&); virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.cpp b/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.cpp index d2d6227035..bf577ea81a 100644 --- a/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.cpp +++ b/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.cpp @@ -4,26 +4,26 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include namespace Web::HTML { -PageTransitionEvent* PageTransitionEvent::create(HTML::Window& window_object, FlyString const& event_name, PageTransitionEventInit const& event_init) +PageTransitionEvent* PageTransitionEvent::create(JS::Realm& realm, FlyString const& event_name, PageTransitionEventInit const& event_init) { - return window_object.heap().allocate(window_object.realm(), window_object, event_name, event_init); + return realm.heap().allocate(realm, realm, event_name, event_init); } -PageTransitionEvent* PageTransitionEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, PageTransitionEventInit const& event_init) +PageTransitionEvent* PageTransitionEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, PageTransitionEventInit const& event_init) { - return create(window_object, event_name, event_init); + return create(realm, event_name, event_init); } -PageTransitionEvent::PageTransitionEvent(HTML::Window& window_object, FlyString const& event_name, PageTransitionEventInit const& event_init) - : DOM::Event(window_object, event_name, event_init) +PageTransitionEvent::PageTransitionEvent(JS::Realm& realm, FlyString const& event_name, PageTransitionEventInit const& event_init) + : DOM::Event(realm, event_name, event_init) , m_persisted(event_init.persisted) { - set_prototype(&window_object.cached_web_prototype("PageTransitionEvent")); + set_prototype(&Bindings::cached_web_prototype(realm, "PageTransitionEvent")); } PageTransitionEvent::~PageTransitionEvent() = default; diff --git a/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.h b/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.h index 159b3baa8b..172df453c0 100644 --- a/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.h +++ b/Userland/Libraries/LibWeb/HTML/PageTransitionEvent.h @@ -18,10 +18,10 @@ class PageTransitionEvent final : public DOM::Event { WEB_PLATFORM_OBJECT(PageTransitionEvent, DOM::Event); public: - static PageTransitionEvent* create(HTML::Window&, FlyString const& event_name, PageTransitionEventInit const& event_init); - static PageTransitionEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, PageTransitionEventInit const& event_init); + static PageTransitionEvent* create(JS::Realm&, FlyString const& event_name, PageTransitionEventInit const& event_init); + static PageTransitionEvent* construct_impl(JS::Realm&, FlyString const& event_name, PageTransitionEventInit const& event_init); - PageTransitionEvent(HTML::Window&, FlyString const& event_name, PageTransitionEventInit const& event_init); + PageTransitionEvent(JS::Realm&, FlyString const& event_name, PageTransitionEventInit const& event_init); virtual ~PageTransitionEvent() override; diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 1ae6320ce8..325dfd1b96 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -240,7 +240,7 @@ void HTMLParser::the_end() document->load_timing_info().dom_content_loaded_event_start_time = main_thread_event_loop().unsafe_shared_current_time(); // 2. Fire an event named DOMContentLoaded at the Document object, with its bubbles attribute initialized to true. - auto content_loaded_event = DOM::Event::create(document->window(), HTML::EventNames::DOMContentLoaded); + auto content_loaded_event = DOM::Event::create(document->realm(), HTML::EventNames::DOMContentLoaded); content_loaded_event->set_bubbles(true); document->dispatch_event(*content_loaded_event); @@ -281,7 +281,7 @@ void HTMLParser::the_end() // 5. Fire an event named load at window, with legacy target override flag set. // FIXME: The legacy target override flag is currently set by a virtual override of dispatch_event() // We should reorganize this so that the flag appears explicitly here instead. - window->dispatch_event(*DOM::Event::create(document->window(), HTML::EventNames::load)); + window->dispatch_event(*DOM::Event::create(document->realm(), HTML::EventNames::load)); // FIXME: 6. Invoke WebDriver BiDi load complete with the Document's browsing context, and a new WebDriver BiDi navigation status whose id is the Document object's navigation id, status is "complete", and url is the Document object's URL. @@ -3375,7 +3375,7 @@ DOM::Document& HTMLParser::document() Vector> HTMLParser::parse_html_fragment(DOM::Element& context_element, StringView markup) { - auto temp_document = DOM::Document::create(context_element.window()); + auto temp_document = DOM::Document::create(context_element.realm()); auto parser = HTMLParser::create(*temp_document, markup, "utf-8"); parser->m_context_element = JS::make_handle(context_element); parser->m_parsing_fragment = true; diff --git a/Userland/Libraries/LibWeb/HTML/Path2D.cpp b/Userland/Libraries/LibWeb/HTML/Path2D.cpp index 54e140dbb2..c569e899f3 100644 --- a/Userland/Libraries/LibWeb/HTML/Path2D.cpp +++ b/Userland/Libraries/LibWeb/HTML/Path2D.cpp @@ -4,22 +4,22 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include namespace Web::HTML { -JS::NonnullGCPtr Path2D::create_with_global_object(HTML::Window& window, Optional, String>> const& path) +JS::NonnullGCPtr Path2D::construct_impl(JS::Realm& realm, Optional, String>> const& path) { - return *window.heap().allocate(window.realm(), window, path); + return *realm.heap().allocate(realm, realm, path); } // https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d -Path2D::Path2D(HTML::Window& window, Optional, String>> const& path) - : PlatformObject(window.realm()) +Path2D::Path2D(JS::Realm& realm, Optional, String>> const& path) + : PlatformObject(realm) , CanvasPath(static_cast(*this)) { - set_prototype(&window.cached_web_prototype("Path2D")); + set_prototype(&Bindings::cached_web_prototype(realm, "Path2D")); // 1. Let output be a new Path2D object. // 2. If path is not given, then return output. diff --git a/Userland/Libraries/LibWeb/HTML/Path2D.h b/Userland/Libraries/LibWeb/HTML/Path2D.h index 19c0442108..5f9aaeff2b 100644 --- a/Userland/Libraries/LibWeb/HTML/Path2D.h +++ b/Userland/Libraries/LibWeb/HTML/Path2D.h @@ -21,12 +21,12 @@ class Path2D final WEB_PLATFORM_OBJECT(Path2D, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create_with_global_object(HTML::Window&, Optional, String>> const& path); + static JS::NonnullGCPtr construct_impl(JS::Realm&, Optional, String>> const& path); virtual ~Path2D() override; private: - Path2D(HTML::Window&, Optional, String>> const&); + Path2D(JS::Realm&, Optional, String>> const&); }; } diff --git a/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.cpp b/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.cpp index e4654a0fc1..075f7b351c 100644 --- a/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.cpp +++ b/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.cpp @@ -4,27 +4,27 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include namespace Web::HTML { -PromiseRejectionEvent* PromiseRejectionEvent::create(HTML::Window& window_object, FlyString const& event_name, PromiseRejectionEventInit const& event_init) +PromiseRejectionEvent* PromiseRejectionEvent::create(JS::Realm& realm, FlyString const& event_name, PromiseRejectionEventInit const& event_init) { - return window_object.heap().allocate(window_object.realm(), window_object, event_name, event_init); + return realm.heap().allocate(realm, realm, event_name, event_init); } -PromiseRejectionEvent* PromiseRejectionEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, PromiseRejectionEventInit const& event_init) +PromiseRejectionEvent* PromiseRejectionEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, PromiseRejectionEventInit const& event_init) { - return create(window_object, event_name, event_init); + return create(realm, event_name, event_init); } -PromiseRejectionEvent::PromiseRejectionEvent(HTML::Window& window_object, FlyString const& event_name, PromiseRejectionEventInit const& event_init) - : DOM::Event(window_object, event_name, event_init) +PromiseRejectionEvent::PromiseRejectionEvent(JS::Realm& realm, FlyString const& event_name, PromiseRejectionEventInit const& event_init) + : DOM::Event(realm, event_name, event_init) , m_promise(const_cast(event_init.promise.cell())) , m_reason(event_init.reason) { - set_prototype(&window_object.cached_web_prototype("PromiseRejectionEvent")); + set_prototype(&Bindings::cached_web_prototype(realm, "PromiseRejectionEvent")); } PromiseRejectionEvent::~PromiseRejectionEvent() = default; diff --git a/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.h b/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.h index 708244c1e7..43029d70a0 100644 --- a/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.h +++ b/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include @@ -22,10 +23,8 @@ class PromiseRejectionEvent final : public DOM::Event { WEB_PLATFORM_OBJECT(PromiseRejectionEvent, DOM::Event); public: - static PromiseRejectionEvent* create(HTML::Window&, FlyString const& event_name, PromiseRejectionEventInit const& event_init = {}); - static PromiseRejectionEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, PromiseRejectionEventInit const& event_init); - - PromiseRejectionEvent(HTML::Window&, FlyString const& event_name, PromiseRejectionEventInit const& event_init); + static PromiseRejectionEvent* create(JS::Realm&, FlyString const& event_name, PromiseRejectionEventInit const& event_init = {}); + static PromiseRejectionEvent* construct_impl(JS::Realm&, FlyString const& event_name, PromiseRejectionEventInit const& event_init); virtual ~PromiseRejectionEvent() override; @@ -34,6 +33,8 @@ public: JS::Value reason() const { return m_reason; } private: + PromiseRejectionEvent(JS::Realm&, FlyString const& event_name, PromiseRejectionEventInit const& event_init); + virtual void visit_edges(Cell::Visitor&) override; JS::Promise* m_promise { nullptr }; diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp index 59f896f58a..7aef833c9e 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp @@ -124,7 +124,7 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors) dbgln("network error"); // 2. Throw a "NetworkError" DOMException. - return throw_completion(WebIDL::NetworkError::create(settings.global_object(), "Script error.")); + return throw_completion(WebIDL::NetworkError::create(settings.realm(), "Script error.")); } // 3. Otherwise, rethrow errors is false. Perform the following steps: diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp index e28b49922d..06f5d4c490 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp @@ -219,7 +219,7 @@ void EnvironmentSettingsObject::notify_about_rejected_promises(Badge) // FIXME: This currently assumes that global is a WindowObject. auto& window = verify_cast(global); - auto promise_rejection_event = PromiseRejectionEvent::create(window, HTML::EventNames::unhandledrejection, event_init); + auto promise_rejection_event = PromiseRejectionEvent::create(window.realm(), HTML::EventNames::unhandledrejection, event_init); bool not_handled = window.dispatch_event(*promise_rejection_event); diff --git a/Userland/Libraries/LibWeb/HTML/Storage.cpp b/Userland/Libraries/LibWeb/HTML/Storage.cpp index 7db1d4a554..5641331365 100644 --- a/Userland/Libraries/LibWeb/HTML/Storage.cpp +++ b/Userland/Libraries/LibWeb/HTML/Storage.cpp @@ -5,20 +5,20 @@ */ #include +#include #include -#include namespace Web::HTML { -JS::NonnullGCPtr Storage::create(HTML::Window& window) +JS::NonnullGCPtr Storage::create(JS::Realm& realm) { - return *window.heap().allocate(window.realm(), window); + return *realm.heap().allocate(realm, realm); } -Storage::Storage(HTML::Window& window) - : PlatformObject(window.realm()) +Storage::Storage(JS::Realm& realm) + : PlatformObject(realm) { - set_prototype(&window.cached_web_prototype("Storage")); + set_prototype(&Bindings::cached_web_prototype(realm, "Storage")); } Storage::~Storage() = default; diff --git a/Userland/Libraries/LibWeb/HTML/Storage.h b/Userland/Libraries/LibWeb/HTML/Storage.h index 409d511949..3651deff07 100644 --- a/Userland/Libraries/LibWeb/HTML/Storage.h +++ b/Userland/Libraries/LibWeb/HTML/Storage.h @@ -16,7 +16,7 @@ class Storage : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(Storage, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create(HTML::Window&); + static JS::NonnullGCPtr create(JS::Realm&); ~Storage(); size_t length() const; @@ -33,7 +33,7 @@ public: void dump() const; private: - explicit Storage(HTML::Window&); + explicit Storage(JS::Realm&); void reorder(); void broadcast(String const& key, String const& old_value, String const& new_value); diff --git a/Userland/Libraries/LibWeb/HTML/SubmitEvent.cpp b/Userland/Libraries/LibWeb/HTML/SubmitEvent.cpp index 684e476341..d1470fdace 100644 --- a/Userland/Libraries/LibWeb/HTML/SubmitEvent.cpp +++ b/Userland/Libraries/LibWeb/HTML/SubmitEvent.cpp @@ -4,26 +4,26 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include namespace Web::HTML { -SubmitEvent* SubmitEvent::create(HTML::Window& window_object, FlyString const& event_name, SubmitEventInit const& event_init) +SubmitEvent* SubmitEvent::create(JS::Realm& realm, FlyString const& event_name, SubmitEventInit const& event_init) { - return window_object.heap().allocate(window_object.realm(), window_object, event_name, event_init); + return realm.heap().allocate(realm, realm, event_name, event_init); } -SubmitEvent* SubmitEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, SubmitEventInit const& event_init) +SubmitEvent* SubmitEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, SubmitEventInit const& event_init) { - return create(window_object, event_name, event_init); + return create(realm, event_name, event_init); } -SubmitEvent::SubmitEvent(HTML::Window& window_object, FlyString const& event_name, SubmitEventInit const& event_init) - : DOM::Event(window_object, event_name, event_init) +SubmitEvent::SubmitEvent(JS::Realm& realm, FlyString const& event_name, SubmitEventInit const& event_init) + : DOM::Event(realm, event_name, event_init) , m_submitter(event_init.submitter) { - set_prototype(&window_object.cached_web_prototype("SubmitEvent")); + set_prototype(&Bindings::cached_web_prototype(realm, "SubmitEvent")); } SubmitEvent::~SubmitEvent() = default; diff --git a/Userland/Libraries/LibWeb/HTML/SubmitEvent.h b/Userland/Libraries/LibWeb/HTML/SubmitEvent.h index 9e484d54ce..7159faa211 100644 --- a/Userland/Libraries/LibWeb/HTML/SubmitEvent.h +++ b/Userland/Libraries/LibWeb/HTML/SubmitEvent.h @@ -19,16 +19,16 @@ class SubmitEvent final : public DOM::Event { WEB_PLATFORM_OBJECT(SubmitEvent, DOM::Event); public: - static SubmitEvent* create(HTML::Window&, FlyString const& event_name, SubmitEventInit const& event_init); - static SubmitEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, SubmitEventInit const& event_init); + static SubmitEvent* create(JS::Realm&, FlyString const& event_name, SubmitEventInit const& event_init); + static SubmitEvent* construct_impl(JS::Realm&, FlyString const& event_name, SubmitEventInit const& event_init); virtual ~SubmitEvent() override; - SubmitEvent(HTML::Window&, FlyString const& event_name, SubmitEventInit const& event_init); - JS::GCPtr submitter() const { return m_submitter; } private: + SubmitEvent(JS::Realm&, FlyString const& event_name, SubmitEventInit const& event_init); + virtual void visit_edges(Cell::Visitor&) override; JS::GCPtr m_submitter; diff --git a/Userland/Libraries/LibWeb/HTML/TextMetrics.cpp b/Userland/Libraries/LibWeb/HTML/TextMetrics.cpp index 16327dfc3f..1ea23bbd8a 100644 --- a/Userland/Libraries/LibWeb/HTML/TextMetrics.cpp +++ b/Userland/Libraries/LibWeb/HTML/TextMetrics.cpp @@ -4,20 +4,20 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include namespace Web::HTML { -JS::NonnullGCPtr TextMetrics::create(HTML::Window& window) +JS::NonnullGCPtr TextMetrics::create(JS::Realm& realm) { - return *window.heap().allocate(window.realm(), window); + return *realm.heap().allocate(realm, realm); } -TextMetrics::TextMetrics(HTML::Window& window) - : PlatformObject(window.realm()) +TextMetrics::TextMetrics(JS::Realm& realm) + : PlatformObject(realm) { - set_prototype(&window.cached_web_prototype("TextMetrics")); + set_prototype(&Bindings::cached_web_prototype(realm, "TextMetrics")); } TextMetrics::~TextMetrics() = default; diff --git a/Userland/Libraries/LibWeb/HTML/TextMetrics.h b/Userland/Libraries/LibWeb/HTML/TextMetrics.h index b764e02ce2..54bdfd29b1 100644 --- a/Userland/Libraries/LibWeb/HTML/TextMetrics.h +++ b/Userland/Libraries/LibWeb/HTML/TextMetrics.h @@ -14,7 +14,7 @@ class TextMetrics : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(TextMetrics, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create(HTML::Window&); + static JS::NonnullGCPtr create(JS::Realm&); virtual ~TextMetrics() override; @@ -45,7 +45,7 @@ public: void set_ideographic_baseline(double baseline) { m_ideographic_baseline = baseline; } private: - explicit TextMetrics(HTML::Window&); + explicit TextMetrics(JS::Realm&); double m_width { 0 }; double m_actual_bounding_box_left { 0 }; diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 22a5c0cfaa..82b9360de3 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -479,7 +479,7 @@ void Window::fire_a_page_transition_event(FlyString const& event_name, bool pers // with the persisted attribute initialized to persisted, HTML::PageTransitionEventInit event_init {}; event_init.persisted = persisted; - auto event = HTML::PageTransitionEvent::create(associated_document().window(), event_name, event_init); + auto event = HTML::PageTransitionEvent::create(associated_document().realm(), event_name, event_init); // ...the cancelable attribute initialized to true, event->set_cancelable(true); @@ -539,7 +539,7 @@ JS::NonnullGCPtr Window::local_storage() static HashMap> local_storage_per_origin; auto storage = local_storage_per_origin.ensure(associated_document().origin(), [this]() -> JS::Handle { - return *HTML::Storage::create(*this); + return *HTML::Storage::create(realm()); }); return *storage; } @@ -551,7 +551,7 @@ JS::NonnullGCPtr Window::session_storage() static HashMap> session_storage_per_origin; auto storage = session_storage_per_origin.ensure(associated_document().origin(), [this]() -> JS::Handle { - return *HTML::Storage::create(*this); + return *HTML::Storage::create(realm()); }); return *storage; } @@ -590,7 +590,7 @@ WebIDL::ExceptionOr Window::post_message_impl(JS::Value message, String co HTML::MessageEventInit event_init {}; event_init.data = message; event_init.origin = ""; - dispatch_event(*HTML::MessageEvent::create(*this, HTML::EventNames::message, event_init)); + dispatch_event(*HTML::MessageEvent::create(realm(), HTML::EventNames::message, event_init)); }); return {}; } @@ -742,7 +742,7 @@ void Window::initialize_web_interfaces(Badge) { ADD_WINDOW_OBJECT_INTERFACES; - Object::set_prototype(&ensure_web_prototype("Window")); + Object::set_prototype(&Bindings::ensure_web_prototype(realm, "Window")); m_crypto = Crypto::Crypto::create(*this); @@ -1064,7 +1064,7 @@ JS_DEFINE_NATIVE_FUNCTION(Window::btoa) byte_string.ensure_capacity(string.length()); for (u32 code_point : Utf8View(string)) { if (code_point > 0xff) - return throw_completion(WebIDL::InvalidCharacterError::create(vm.current_realm()->global_object(), "Data contains characters outside the range U+0000 and U+00FF")); + return throw_completion(WebIDL::InvalidCharacterError::create(*vm.current_realm(), "Data contains characters outside the range U+0000 and U+00FF")); byte_string.append(code_point); } diff --git a/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp b/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp index 5f1764f3f8..1a0947b555 100644 --- a/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp +++ b/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp @@ -90,7 +90,7 @@ JS::ThrowCompletionOr> WindowProxy::internal_ge return Optional {}; // 2. Throw a "SecurityError" DOMException. - return throw_completion(WebIDL::SecurityError::create(window(), String::formatted("Can't access property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(m_window->realm(), String::formatted("Can't access property '{}' on cross-origin object", property_key))); } // 6. Return PropertyDescriptor{ [[Value]]: value, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: true }. @@ -140,7 +140,7 @@ JS::ThrowCompletionOr WindowProxy::internal_define_own_property(JS::Proper } // 3. Throw a "SecurityError" DOMException. - return throw_completion(WebIDL::SecurityError::create(window(), String::formatted("Can't define property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(m_window->realm(), String::formatted("Can't define property '{}' on cross-origin object", property_key))); } // 7.4.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-get @@ -213,7 +213,7 @@ JS::ThrowCompletionOr WindowProxy::internal_delete(JS::PropertyKey const& } // 3. Throw a "SecurityError" DOMException. - return throw_completion(WebIDL::SecurityError::create(window(), String::formatted("Can't delete property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(m_window->realm(), String::formatted("Can't delete property '{}' on cross-origin object", property_key))); } // 7.4.10 [[OwnPropertyKeys]] ( ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-ownpropertykeys diff --git a/Userland/Libraries/LibWeb/HTML/Worker.cpp b/Userland/Libraries/LibWeb/HTML/Worker.cpp index 6e64ec20bc..942ec5d655 100644 --- a/Userland/Libraries/LibWeb/HTML/Worker.cpp +++ b/Userland/Libraries/LibWeb/HTML/Worker.cpp @@ -25,9 +25,9 @@ Worker::Worker(FlyString const& script_url, WorkerOptions const options, DOM::Do , m_worker_vm(JS::VM::create(adopt_own(m_custom_data))) , m_interpreter(JS::Interpreter::create(m_worker_vm)) , m_interpreter_scope(*m_interpreter) - , m_implicit_port(MessagePort::create(document.window())) + , m_implicit_port(MessagePort::create(document.realm())) { - set_prototype(&document.window().cached_web_prototype("Worker")); + set_prototype(&Bindings::cached_web_prototype(document.realm(), "Worker")); } void Worker::visit_edges(Cell::Visitor& visitor) @@ -63,7 +63,7 @@ WebIDL::ExceptionOr> Worker::create(FlyString const& sc // 4. If this fails, throw a "SyntaxError" DOMException. if (!url.is_valid()) { dbgln_if(WEB_WORKER_DEBUG, "WebWorker: Invalid URL loaded '{}'.", script_url); - return WebIDL::SyntaxError::create(document.global_object(), "url is not valid"); + return WebIDL::SyntaxError::create(document.realm(), "url is not valid"); } // 5. Let worker URL be the resulting URL record. @@ -72,7 +72,7 @@ WebIDL::ExceptionOr> Worker::create(FlyString const& sc auto worker = document.heap().allocate(document.realm(), script_url, options, document); // 7. Let outside port be a new MessagePort in outside settings's Realm. - auto outside_port = MessagePort::create(verify_cast(outside_settings.realm().global_object())); + auto outside_port = MessagePort::create(outside_settings.realm()); // 8. Associate the outside port with worker worker->m_outside_port = outside_port; @@ -86,7 +86,7 @@ WebIDL::ExceptionOr> Worker::create(FlyString const& sc } // https://html.spec.whatwg.org/multipage/workers.html#run-a-worker -void Worker::run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_settings, MessagePort& outside_port, WorkerOptions const options) +void Worker::run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_settings, MessagePort& outside_port, WorkerOptions const& options) { // 1. Let is shared be true if worker is a SharedWorker object, and false otherwise. // FIXME: SharedWorker support @@ -162,7 +162,7 @@ void Worker::run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_setti MessageEventInit event_init {}; event_init.data = message; event_init.origin = ""; - dispatch_event(*MessageEvent::create(*m_worker_window, HTML::EventNames::message, event_init)); + dispatch_event(*MessageEvent::create(*m_worker_realm, HTML::EventNames::message, event_init)); })); return JS::js_undefined(); @@ -259,7 +259,7 @@ void Worker::run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_setti // FIXME: Global scope association // 16. Let inside port be a new MessagePort object in inside settings's Realm. - auto inside_port = MessagePort::create(*m_worker_window); + auto inside_port = MessagePort::create(m_inner_settings->realm()); // 17. Associate inside port with worker global scope. // FIXME: Global scope association diff --git a/Userland/Libraries/LibWeb/HTML/Worker.h b/Userland/Libraries/LibWeb/HTML/Worker.h index f24dbe64bc..17bde2e1cc 100644 --- a/Userland/Libraries/LibWeb/HTML/Worker.h +++ b/Userland/Libraries/LibWeb/HTML/Worker.h @@ -37,8 +37,9 @@ class Worker : public DOM::EventTarget { public: static WebIDL::ExceptionOr> create(FlyString const& script_url, WorkerOptions const options, DOM::Document& document); - static WebIDL::ExceptionOr> create_with_global_object(HTML::Window& window, FlyString const& script_url, WorkerOptions const options) + static WebIDL::ExceptionOr> construct_impl(JS::Realm& realm, FlyString const& script_url, WorkerOptions const options) { + auto& window = verify_cast(realm.global_object()); return Worker::create(script_url, options, window.associated_document()); } @@ -92,7 +93,7 @@ private: // There should be *no* Window object in a Worker context. JS::GCPtr m_worker_window; - void run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_settings, MessagePort& outside_port, WorkerOptions const options); + void run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_settings, MessagePort& outside_port, WorkerOptions const& options); }; } diff --git a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp index d45fad5491..fade543580 100644 --- a/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp +++ b/Userland/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp @@ -131,7 +131,7 @@ WebIDL::ExceptionOr WorkerGlobalScope::btoa(String const& data) const byte_string.ensure_capacity(data.length()); for (u32 code_point : Utf8View(data)) { if (code_point > 0xff) - return WebIDL::InvalidCharacterError::create(global_object(), "Data contains characters outside the range U+0000 and U+00FF"); + return WebIDL::InvalidCharacterError::create(realm(), "Data contains characters outside the range U+0000 and U+00FF"); byte_string.append(code_point); } @@ -151,7 +151,7 @@ WebIDL::ExceptionOr WorkerGlobalScope::atob(String const& data) const // 2. If decodedData is failure, then throw an "InvalidCharacterError" DOMException. if (decoded_data.is_error()) - return WebIDL::InvalidCharacterError::create(global_object(), "Input string is not valid base64 data"); + return WebIDL::InvalidCharacterError::create(realm(), "Input string is not valid base64 data"); // 3. Return decodedData. // decode_base64() returns a byte string. LibJS uses UTF-8 for strings. Use Latin1Decoder to convert bytes 128-255 to UTF-8. diff --git a/Userland/Libraries/LibWeb/HTML/WorkerNavigator.cpp b/Userland/Libraries/LibWeb/HTML/WorkerNavigator.cpp index 09898a3805..25915fa413 100644 --- a/Userland/Libraries/LibWeb/HTML/WorkerNavigator.cpp +++ b/Userland/Libraries/LibWeb/HTML/WorkerNavigator.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include -- cgit v1.2.3