diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp index a5c0dc17c2..672bfe6bc2 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp @@ -8,21 +8,21 @@ #include #include #include +#include #include #include -#include namespace Web::Crypto { -JS::NonnullGCPtr Crypto::create(HTML::Window& window) +JS::NonnullGCPtr Crypto::create(JS::Realm& realm) { - return *window.heap().allocate(window.realm(), window); + return *realm.heap().allocate(realm, realm); } -Crypto::Crypto(HTML::Window& window) - : PlatformObject(window.realm()) +Crypto::Crypto(JS::Realm& realm) + : PlatformObject(realm) { - set_prototype(&window.cached_web_prototype("Crypto")); + set_prototype(&Bindings::cached_web_prototype(realm, "Crypto")); } Crypto::~Crypto() = default; @@ -30,7 +30,7 @@ Crypto::~Crypto() = default; void Crypto::initialize(JS::Realm& realm) { Base::initialize(realm); - m_subtle = SubtleCrypto::create(global_object()); + m_subtle = SubtleCrypto::create(realm); } JS::NonnullGCPtr Crypto::subtle() const @@ -43,16 +43,16 @@ WebIDL::ExceptionOr Crypto::get_random_values(JS::Value array) const { // 1. If array is not an Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array, then throw a TypeMismatchError and terminate the algorithm. if (!array.is_object() || !(is(array.as_object()) || is(array.as_object()) || is(array.as_object()) || is(array.as_object()) || is(array.as_object()) || is(array.as_object()) || is(array.as_object()) || is(array.as_object()) || is(array.as_object()))) - return WebIDL::TypeMismatchError::create(global_object(), "array must be one of Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array"); + return WebIDL::TypeMismatchError::create(realm(), "array must be one of Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array"); auto& typed_array = static_cast(array.as_object()); // 2. If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm. if (typed_array.byte_length() > 65536) - return WebIDL::QuotaExceededError::create(global_object(), "array's byteLength may not be greater than 65536"); + return WebIDL::QuotaExceededError::create(realm(), "array's byteLength may not be greater than 65536"); // IMPLEMENTATION DEFINED: If the viewed array buffer is detached, throw a InvalidStateError and terminate the algorithm. if (typed_array.viewed_array_buffer()->is_detached()) - return WebIDL::InvalidStateError::create(global_object(), "array is detached"); + return WebIDL::InvalidStateError::create(realm(), "array is detached"); // FIXME: Handle SharedArrayBuffers // 3. Overwrite all elements of array with cryptographically strong random values of the appropriate type. diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.h b/Userland/Libraries/LibWeb/Crypto/Crypto.h index dececef8b5..40fba4f071 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.h +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.h @@ -16,7 +16,7 @@ class Crypto : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(Crypto, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create(HTML::Window&); + static JS::NonnullGCPtr create(JS::Realm&); virtual ~Crypto() override; @@ -29,7 +29,7 @@ protected: virtual void visit_edges(Cell::Visitor&) override; private: - explicit Crypto(HTML::Window&); + explicit Crypto(JS::Realm&); virtual void initialize(JS::Realm&) override; JS::GCPtr m_subtle; diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp index 0c67a0bc40..4fd53936d8 100644 --- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp @@ -7,37 +7,37 @@ #include #include #include -#include +#include #include #include #include namespace Web::Crypto { -JS::NonnullGCPtr SubtleCrypto::create(HTML::Window& window) +JS::NonnullGCPtr SubtleCrypto::create(JS::Realm& realm) { - return *window.heap().allocate(window.realm(), window); + return *realm.heap().allocate(realm, realm); } -SubtleCrypto::SubtleCrypto(HTML::Window& window) - : PlatformObject(window.realm()) +SubtleCrypto::SubtleCrypto(JS::Realm& realm) + : PlatformObject(realm) { - set_prototype(&window.cached_web_prototype("SubtleCrypto")); + set_prototype(&Bindings::cached_web_prototype(realm, "SubtleCrypto")); } SubtleCrypto::~SubtleCrypto() = default; +// https://w3c.github.io/webcrypto/#dfn-SubtleCrypto-method-digest JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle const& data) { - auto& vm = Bindings::main_thread_vm(); - auto& realm = *vm.current_realm(); + auto& realm = this->realm(); // 1. Let algorithm be the algorithm parameter passed to the digest() method. // 2. Let data be the result of getting a copy of the bytes held by the data parameter passed to the digest() method. auto data_buffer_or_error = WebIDL::get_buffer_source_copy(*data.cell()); if (data_buffer_or_error.is_error()) { - auto error = WebIDL::OperationError::create(global_object(), "Failed to copy bytes from ArrayBuffer"); + auto error = WebIDL::OperationError::create(realm, "Failed to copy bytes from ArrayBuffer"); auto* promise = JS::Promise::create(realm); promise->reject(error.ptr()); return promise; @@ -58,7 +58,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handlereject(error.ptr()); return promise; @@ -79,7 +79,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handlereject(error.ptr()); return promise; } diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h index 8ac7df8c27..9099500eb6 100644 --- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h +++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h @@ -15,14 +15,14 @@ class SubtleCrypto final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(SubtleCrypto, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create(HTML::Window&); + static JS::NonnullGCPtr create(JS::Realm&); virtual ~SubtleCrypto() override; JS::Promise* digest(String const& algorithm, JS::Handle const& data); private: - explicit SubtleCrypto(HTML::Window&); + explicit SubtleCrypto(JS::Realm&); }; } diff --git a/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp b/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp index 5301470c46..3a23c32f9f 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp +++ b/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp @@ -6,30 +6,30 @@ #include #include +#include #include -#include #include namespace Web::Encoding { -WebIDL::ExceptionOr> TextDecoder::create_with_global_object(HTML::Window& window, FlyString encoding) +WebIDL::ExceptionOr> TextDecoder::construct_impl(JS::Realm& realm, FlyString encoding) { auto decoder = TextCodec::decoder_for(encoding); if (!decoder) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Invalid encoding {}", encoding) }; - return JS::NonnullGCPtr(*window.heap().allocate(window.realm(), window, *decoder, move(encoding), false, false)); + return JS::NonnullGCPtr(*realm.heap().allocate(realm, realm, *decoder, move(encoding), false, false)); } // https://encoding.spec.whatwg.org/#dom-textdecoder -TextDecoder::TextDecoder(HTML::Window& window, TextCodec::Decoder& decoder, FlyString encoding, bool fatal, bool ignore_bom) - : PlatformObject(window.realm()) +TextDecoder::TextDecoder(JS::Realm& realm, TextCodec::Decoder& decoder, FlyString encoding, bool fatal, bool ignore_bom) + : PlatformObject(realm) , m_decoder(decoder) , m_encoding(move(encoding)) , m_fatal(fatal) , m_ignore_bom(ignore_bom) { - set_prototype(&window.cached_web_prototype("TextDecoder")); + set_prototype(&Bindings::cached_web_prototype(realm, "TextDecoder")); } TextDecoder::~TextDecoder() = default; @@ -41,7 +41,7 @@ WebIDL::ExceptionOr TextDecoder::decode(JS::Handle const& in auto data_buffer_or_error = WebIDL::get_buffer_source_copy(*input.cell()); if (data_buffer_or_error.is_error()) - return WebIDL::OperationError::create(global_object(), "Failed to copy bytes from ArrayBuffer"); + return WebIDL::OperationError::create(realm(), "Failed to copy bytes from ArrayBuffer"); auto& data_buffer = data_buffer_or_error.value(); return m_decoder.to_utf8({ data_buffer.data(), data_buffer.size() }); } diff --git a/Userland/Libraries/LibWeb/Encoding/TextDecoder.h b/Userland/Libraries/LibWeb/Encoding/TextDecoder.h index fe37ccec45..b5b32fea0b 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextDecoder.h +++ b/Userland/Libraries/LibWeb/Encoding/TextDecoder.h @@ -21,7 +21,7 @@ class TextDecoder : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(TextDecoder, Bindings::PlatformObject); public: - static WebIDL::ExceptionOr> create_with_global_object(HTML::Window&, FlyString encoding); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, FlyString encoding); virtual ~TextDecoder() override; @@ -33,7 +33,7 @@ public: private: // https://encoding.spec.whatwg.org/#dom-textdecoder - TextDecoder(HTML::Window&, TextCodec::Decoder&, FlyString encoding, bool fatal, bool ignore_bom); + TextDecoder(JS::Realm&, TextCodec::Decoder&, FlyString encoding, bool fatal, bool ignore_bom); TextCodec::Decoder& m_decoder; FlyString m_encoding; diff --git a/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp b/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp index 8889d0b34f..5f0c1ebda5 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp +++ b/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp @@ -6,20 +6,20 @@ #include #include +#include #include -#include namespace Web::Encoding { -JS::NonnullGCPtr TextEncoder::create_with_global_object(HTML::Window& window) +JS::NonnullGCPtr TextEncoder::construct_impl(JS::Realm& realm) { - return *window.heap().allocate(window.realm(), window); + return *realm.heap().allocate(realm, realm); } -TextEncoder::TextEncoder(HTML::Window& window) - : PlatformObject(window.realm()) +TextEncoder::TextEncoder(JS::Realm& realm) + : PlatformObject(realm) { - set_prototype(&window.cached_web_prototype("TextEncoder")); + set_prototype(&Bindings::cached_web_prototype(realm, "TextEncoder")); } TextEncoder::~TextEncoder() = default; diff --git a/Userland/Libraries/LibWeb/Encoding/TextEncoder.h b/Userland/Libraries/LibWeb/Encoding/TextEncoder.h index d3cf0fb425..e27f96b368 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextEncoder.h +++ b/Userland/Libraries/LibWeb/Encoding/TextEncoder.h @@ -20,7 +20,7 @@ class TextEncoder final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(TextEncoder, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create_with_global_object(HTML::Window&); + static JS::NonnullGCPtr construct_impl(JS::Realm&); virtual ~TextEncoder() override; @@ -30,7 +30,7 @@ public: protected: // https://encoding.spec.whatwg.org/#dom-textencoder - explicit TextEncoder(HTML::Window&); + explicit TextEncoder(JS::Realm&); }; } diff --git a/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp b/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp index 163b0ddafb..5f5964d972 100644 --- a/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp +++ b/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -22,7 +21,7 @@ WebIDL::ExceptionOr extract_body(JS::Realm& realm, if (auto const* handle = object.get_pointer>()) { stream = const_cast(handle->cell()); } else { - stream = realm.heap().allocate(realm, verify_cast(realm.global_object())); + stream = realm.heap().allocate(realm, realm); } // FIXME: 2. Let action be null. diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp index 6de71b696f..eb4e74858e 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp @@ -30,11 +30,10 @@ WebIDL::ExceptionOr Body::clone() const auto& vm = Bindings::main_thread_vm(); auto& realm = *vm.current_realm(); - auto& window = verify_cast(realm.global_object()); // FIXME: 1. Let « out1, out2 » be the result of teeing body’s stream. // FIXME: 2. Set body’s stream to out1. - auto* out2 = vm.heap().allocate(realm, window); + auto* out2 = vm.heap().allocate(realm, realm); // 3. Return a body whose stream is out2 and other members are copied from body. return Body { JS::make_handle(out2), m_source, m_length }; diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 82b9360de3..cfeafd2ab8 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -658,7 +658,7 @@ void Window::invoke_idle_callbacks() // 1. Pop the top callback from window's list of runnable idle callbacks. auto callback = m_runnable_idle_callbacks.take_first(); // 2. Let deadlineArg be a new IdleDeadline whose [get deadline time algorithm] is getDeadline. - auto deadline_arg = RequestIdleCallback::IdleDeadline::create(*this); + auto deadline_arg = RequestIdleCallback::IdleDeadline::create(realm()); // 3. Call callback with deadlineArg as its argument. If an uncaught runtime script error occurs, then report the exception. auto result = callback->invoke(deadline_arg); if (result.is_error()) @@ -744,7 +744,7 @@ void Window::initialize_web_interfaces(Badge) Object::set_prototype(&Bindings::ensure_web_prototype(realm, "Window")); - m_crypto = Crypto::Crypto::create(*this); + m_crypto = Crypto::Crypto::create(realm); // FIXME: These should be native accessors, not properties define_direct_property("window", this, JS::Attribute::Enumerable); diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp index 84c8ac48e3..d73c1321e2 100644 --- a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp +++ b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp @@ -17,7 +17,7 @@ Performance::Performance(HTML::Window& window) : DOM::EventTarget(window.realm()) , m_window(window) { - set_prototype(&window.cached_web_prototype("Performance")); + set_prototype(&Bindings::cached_web_prototype(realm(), "Performance")); m_timer.start(); } diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp index 9b6917880e..19b58562b2 100644 --- a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp +++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp @@ -4,26 +4,26 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include #include namespace Web::IntersectionObserver { // https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-intersectionobserver -JS::NonnullGCPtr IntersectionObserver::create_with_global_object(HTML::Window& window, WebIDL::CallbackType* callback, IntersectionObserverInit const& options) +JS::NonnullGCPtr IntersectionObserver::construct_impl(JS::Realm& realm, WebIDL::CallbackType* callback, IntersectionObserverInit const& options) { // FIXME: Implement (void)callback; (void)options; - return *window.heap().allocate(window.realm(), window); + return *realm.heap().allocate(realm, realm); } -IntersectionObserver::IntersectionObserver(HTML::Window& window) - : PlatformObject(window.realm()) +IntersectionObserver::IntersectionObserver(JS::Realm& realm) + : PlatformObject(realm) { - set_prototype(&window.cached_web_prototype("IntersectionObserver")); + set_prototype(&Bindings::cached_web_prototype(realm, "IntersectionObserver")); } IntersectionObserver::~IntersectionObserver() = default; diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h index 266e885887..418cce0cc8 100644 --- a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h +++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h @@ -22,7 +22,7 @@ class IntersectionObserver : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(IntersectionObserver, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create_with_global_object(HTML::Window&, WebIDL::CallbackType* callback, IntersectionObserverInit const& options = {}); + static JS::NonnullGCPtr construct_impl(JS::Realm&, WebIDL::CallbackType* callback, IntersectionObserverInit const& options = {}); virtual ~IntersectionObserver() override; @@ -31,7 +31,7 @@ public: void disconnect(); private: - explicit IntersectionObserver(HTML::Window&); + explicit IntersectionObserver(JS::Realm&); }; } diff --git a/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp index 552b8899ca..cc5f507d00 100644 --- a/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp +++ b/Userland/Libraries/LibWeb/NavigationTiming/PerformanceTiming.cpp @@ -12,7 +12,7 @@ PerformanceTiming::PerformanceTiming(HTML::Window& window) : PlatformObject(window.realm()) , m_window(window) { - set_prototype(&window.cached_web_prototype("PerformanceTiming")); + set_prototype(&Bindings::cached_web_prototype(realm(), "PerformanceTiming")); } PerformanceTiming::~PerformanceTiming() = default; diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 63279afdf6..593636a231 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -203,12 +203,12 @@ bool EventHandler::handle_mouseup(Gfx::IntPoint const& position, unsigned button } auto offset = compute_mouse_event_offset(position, *layout_node); - node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->document().window(), UIEvents::EventNames::mouseup, offset.x(), offset.y(), position.x(), position.y(), button)); + node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mouseup, offset.x(), offset.y(), position.x(), position.y(), button)); handled_event = true; bool run_activation_behavior = true; if (node.ptr() == m_mousedown_target && button == GUI::MouseButton::Primary) { - run_activation_behavior = node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->document().window(), UIEvents::EventNames::click, offset.x(), offset.y(), position.x(), position.y(), button)); + run_activation_behavior = node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::click, offset.x(), offset.y(), position.x(), position.y(), button)); } if (run_activation_behavior) { @@ -332,7 +332,7 @@ bool EventHandler::handle_mousedown(Gfx::IntPoint const& position, unsigned butt m_mousedown_target = node.ptr(); auto offset = compute_mouse_event_offset(position, *layout_node); - node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->document().window(), UIEvents::EventNames::mousedown, offset.x(), offset.y(), position.x(), position.y(), button)); + node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mousedown, offset.x(), offset.y(), position.x(), position.y(), button)); } // NOTE: Dispatching an event may have disturbed the world. @@ -453,7 +453,7 @@ bool EventHandler::handle_mousemove(Gfx::IntPoint const& position, unsigned butt } auto offset = compute_mouse_event_offset(position, *layout_node); - node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->document().window(), UIEvents::EventNames::mousemove, offset.x(), offset.y(), position.x(), position.y())); + node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mousemove, offset.x(), offset.y(), position.x(), position.y())); // NOTE: Dispatching an event may have disturbed the world. if (!paint_root() || paint_root() != node->document().paint_box()) return true; @@ -542,7 +542,7 @@ bool EventHandler::handle_doubleclick(Gfx::IntPoint const& position, unsigned bu return false; auto offset = compute_mouse_event_offset(position, *layout_node); - node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->document().window(), UIEvents::EventNames::dblclick, offset.x(), offset.y(), position.x(), position.y(), button)); + node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::dblclick, offset.x(), offset.y(), position.x(), position.y(), button)); // NOTE: Dispatching an event may have disturbed the world. if (!paint_root() || paint_root() != node->document().paint_box()) @@ -721,7 +721,7 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin return true; } - auto event = UIEvents::KeyboardEvent::create_from_platform_event(document->window(), UIEvents::EventNames::keydown, key, modifiers, code_point); + auto event = UIEvents::KeyboardEvent::create_from_platform_event(document->realm(), UIEvents::EventNames::keydown, key, modifiers, code_point); if (JS::GCPtr focused_element = document->focused_element()) return focused_element->dispatch_event(*event); @@ -738,7 +738,7 @@ bool EventHandler::handle_keyup(KeyCode key, unsigned modifiers, u32 code_point) if (!document) return false; - auto event = UIEvents::KeyboardEvent::create_from_platform_event(document->window(), UIEvents::EventNames::keyup, key, modifiers, code_point); + auto event = UIEvents::KeyboardEvent::create_from_platform_event(document->realm(), UIEvents::EventNames::keyup, key, modifiers, code_point); if (JS::GCPtr focused_element = document->focused_element()) return document->focused_element()->dispatch_event(*event); diff --git a/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp index 2012c50ac6..e854ba9944 100644 --- a/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp +++ b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.cpp @@ -11,16 +11,16 @@ namespace Web::RequestIdleCallback { -JS::NonnullGCPtr IdleDeadline::create(HTML::Window& window, bool did_timeout) +JS::NonnullGCPtr IdleDeadline::create(JS::Realm& realm, bool did_timeout) { - return *window.heap().allocate(window.realm(), window, did_timeout); + return *realm.heap().allocate(realm, realm, did_timeout); } -IdleDeadline::IdleDeadline(HTML::Window& window, bool did_timeout) - : PlatformObject(window.realm()) +IdleDeadline::IdleDeadline(JS::Realm& realm, bool did_timeout) + : PlatformObject(realm) , m_did_timeout(did_timeout) { - set_prototype(&window.cached_web_prototype("IdleDeadline")); + set_prototype(&Bindings::cached_web_prototype(realm, "IdleDeadline")); } IdleDeadline::~IdleDeadline() = default; diff --git a/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.h b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.h index aad75d2152..8e08ca0747 100644 --- a/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.h +++ b/Userland/Libraries/LibWeb/RequestIdleCallback/IdleDeadline.h @@ -16,14 +16,14 @@ class IdleDeadline final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(IdleDeadline, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create(HTML::Window&, bool did_timeout = false); + static JS::NonnullGCPtr create(JS::Realm&, bool did_timeout = false); virtual ~IdleDeadline() override; double time_remaining() const; bool did_timeout() const { return m_did_timeout; } private: - IdleDeadline(HTML::Window&, bool did_timeout); + IdleDeadline(JS::Realm&, bool did_timeout); bool m_did_timeout { false }; }; diff --git a/Userland/Libraries/LibWeb/ResizeObserver/ResizeObserver.cpp b/Userland/Libraries/LibWeb/ResizeObserver/ResizeObserver.cpp index e4a6f74a63..98d340a175 100644 --- a/Userland/Libraries/LibWeb/ResizeObserver/ResizeObserver.cpp +++ b/Userland/Libraries/LibWeb/ResizeObserver/ResizeObserver.cpp @@ -4,24 +4,24 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include #include namespace Web::ResizeObserver { // https://drafts.csswg.org/resize-observer/#dom-resizeobserver-resizeobserver -JS::NonnullGCPtr ResizeObserver::create_with_global_object(HTML::Window& window, WebIDL::CallbackType* callback) +JS::NonnullGCPtr ResizeObserver::construct_impl(JS::Realm& realm, WebIDL::CallbackType* callback) { // FIXME: Implement (void)callback; - return *window.heap().allocate(window.realm(), window); + return *realm.heap().allocate(realm, realm); } -ResizeObserver::ResizeObserver(HTML::Window& window) - : PlatformObject(window.realm()) +ResizeObserver::ResizeObserver(JS::Realm& realm) + : PlatformObject(realm) { - set_prototype(&window.cached_web_prototype("ResizeObserver")); + set_prototype(&Bindings::cached_web_prototype(realm, "ResizeObserver")); } ResizeObserver::~ResizeObserver() = default; diff --git a/Userland/Libraries/LibWeb/ResizeObserver/ResizeObserver.h b/Userland/Libraries/LibWeb/ResizeObserver/ResizeObserver.h index dee26b65e5..591ed454cd 100644 --- a/Userland/Libraries/LibWeb/ResizeObserver/ResizeObserver.h +++ b/Userland/Libraries/LibWeb/ResizeObserver/ResizeObserver.h @@ -19,7 +19,7 @@ class ResizeObserver : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(ResizeObserver, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create_with_global_object(HTML::Window&, WebIDL::CallbackType* callback); + static JS::NonnullGCPtr construct_impl(JS::Realm&, WebIDL::CallbackType* callback); virtual ~ResizeObserver() override; @@ -28,7 +28,7 @@ public: void disconnect(); private: - explicit ResizeObserver(HTML::Window&); + explicit ResizeObserver(JS::Realm&); }; } diff --git a/Userland/Libraries/LibWeb/Selection/Selection.cpp b/Userland/Libraries/LibWeb/Selection/Selection.cpp index d90894e6d4..250bcb48b8 100644 --- a/Userland/Libraries/LibWeb/Selection/Selection.cpp +++ b/Userland/Libraries/LibWeb/Selection/Selection.cpp @@ -4,20 +4,20 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include namespace Web::Selection { -JS::NonnullGCPtr Selection::create(HTML::Window& window) +JS::NonnullGCPtr Selection::create(JS::Realm& realm) { - return *window.heap().allocate(window.realm(), window); + return *realm.heap().allocate(realm, realm); } -Selection::Selection(HTML::Window& window) - : PlatformObject(window.realm()) +Selection::Selection(JS::Realm& realm) + : PlatformObject(realm) { - set_prototype(&window.cached_web_prototype("Selection")); + set_prototype(&Bindings::cached_web_prototype(realm, "Selection")); } Selection::~Selection() = default; diff --git a/Userland/Libraries/LibWeb/Selection/Selection.h b/Userland/Libraries/LibWeb/Selection/Selection.h index 05faf1d56f..fc4949cc57 100644 --- a/Userland/Libraries/LibWeb/Selection/Selection.h +++ b/Userland/Libraries/LibWeb/Selection/Selection.h @@ -14,7 +14,7 @@ class Selection final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(Selection, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create(HTML::Window&); + static JS::NonnullGCPtr create(JS::Realm&); virtual ~Selection() override; @@ -43,7 +43,7 @@ public: String to_string() const; private: - explicit Selection(HTML::Window&); + explicit Selection(JS::Realm&); }; } diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp b/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp index eeaa7efaa5..bbd1b21af8 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp +++ b/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp @@ -4,24 +4,25 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include +#include namespace Web::Streams { // https://streams.spec.whatwg.org/#rs-constructor -WebIDL::ExceptionOr> ReadableStream::create_with_global_object(HTML::Window& window) +WebIDL::ExceptionOr> ReadableStream::construct_impl(JS::Realm& realm) { - auto* readable_stream = window.heap().allocate(window.realm(), window); + auto* readable_stream = realm.heap().allocate(realm, realm); return JS::NonnullGCPtr { *readable_stream }; } -ReadableStream::ReadableStream(HTML::Window& window) - : PlatformObject(window.realm()) +ReadableStream::ReadableStream(JS::Realm& realm) + : PlatformObject(realm) { - set_prototype(&window.cached_web_prototype("ReadableStream")); + set_prototype(&Bindings::cached_web_prototype(realm, "ReadableStream")); } ReadableStream::~ReadableStream() = default; diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStream.h b/Userland/Libraries/LibWeb/Streams/ReadableStream.h index 94f89096f2..ec18af5397 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStream.h +++ b/Userland/Libraries/LibWeb/Streams/ReadableStream.h @@ -24,7 +24,7 @@ public: Errored, }; - static WebIDL::ExceptionOr> create_with_global_object(HTML::Window&); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&); virtual ~ReadableStream() override; @@ -39,7 +39,7 @@ public: bool is_disturbed() const; private: - explicit ReadableStream(HTML::Window&); + explicit ReadableStream(JS::Realm&); virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/URL/URL.cpp b/Userland/Libraries/LibWeb/URL/URL.cpp index 9302c0f818..8f742edb63 100644 --- a/Userland/Libraries/LibWeb/URL/URL.cpp +++ b/Userland/Libraries/LibWeb/URL/URL.cpp @@ -6,17 +6,17 @@ */ #include -#include +#include #include namespace Web::URL { -JS::NonnullGCPtr URL::create(HTML::Window& window, AK::URL url, JS::NonnullGCPtr query) +JS::NonnullGCPtr URL::create(JS::Realm& realm, AK::URL url, JS::NonnullGCPtr query) { - return *window.heap().allocate(window.realm(), window, move(url), move(query)); + return *realm.heap().allocate(realm, realm, move(url), move(query)); } -WebIDL::ExceptionOr> URL::create_with_global_object(HTML::Window& window, String const& url, String const& base) +WebIDL::ExceptionOr> URL::construct_impl(JS::Realm& realm, String const& url, String const& base) { // 1. Let parsedBase be null. Optional parsed_base; @@ -41,21 +41,21 @@ WebIDL::ExceptionOr> URL::create_with_global_object(HTML:: auto& query = parsed_url.query().is_null() ? String::empty() : parsed_url.query(); // 6. Set this’s URL to parsedURL. // 7. Set this’s query object to a new URLSearchParams object. - auto query_object = MUST(URLSearchParams::create_with_global_object(window, query)); + auto query_object = MUST(URLSearchParams::construct_impl(realm, query)); // 8. Initialize this’s query object with query. - auto result_url = URL::create(window, move(parsed_url), move(query_object)); + auto result_url = URL::create(realm, move(parsed_url), move(query_object)); // 9. Set this’s query object’s URL object to this. result_url->m_query->m_url = result_url; return result_url; } -URL::URL(HTML::Window& window, AK::URL url, JS::NonnullGCPtr query) - : PlatformObject(window.realm()) +URL::URL(JS::Realm& realm, AK::URL url, JS::NonnullGCPtr query) + : PlatformObject(realm) , m_url(move(url)) , m_query(move(query)) { - set_prototype(&window.cached_web_prototype("URL")); + set_prototype(&Bindings::cached_web_prototype(realm, "URL")); } URL::~URL() = default; diff --git a/Userland/Libraries/LibWeb/URL/URL.h b/Userland/Libraries/LibWeb/URL/URL.h index 849a51871b..015480d841 100644 --- a/Userland/Libraries/LibWeb/URL/URL.h +++ b/Userland/Libraries/LibWeb/URL/URL.h @@ -19,8 +19,8 @@ class URL : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(URL, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create(HTML::Window&, AK::URL url, JS::NonnullGCPtr query); - static WebIDL::ExceptionOr> create_with_global_object(HTML::Window&, String const& url, String const& base); + static JS::NonnullGCPtr create(JS::Realm&, AK::URL url, JS::NonnullGCPtr query); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, String const& url, String const& base); virtual ~URL() override; @@ -63,7 +63,7 @@ public: void set_query(Badge, String query) { m_url.set_query(move(query)); } private: - URL(HTML::Window&, AK::URL, JS::NonnullGCPtr query); + URL(JS::Realm&, AK::URL, JS::NonnullGCPtr query); virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/URL/URLSearchParams.cpp b/Userland/Libraries/LibWeb/URL/URLSearchParams.cpp index ef12b26927..f928b64e5f 100644 --- a/Userland/Libraries/LibWeb/URL/URLSearchParams.cpp +++ b/Userland/Libraries/LibWeb/URL/URLSearchParams.cpp @@ -7,17 +7,17 @@ #include #include #include -#include +#include #include #include namespace Web::URL { -URLSearchParams::URLSearchParams(HTML::Window& window, Vector list) - : PlatformObject(window.realm()) +URLSearchParams::URLSearchParams(JS::Realm& realm, Vector list) + : PlatformObject(realm) , m_list(move(list)) { - set_prototype(&window.cached_web_prototype("URLSearchParams")); + set_prototype(&Bindings::cached_web_prototype(realm, "URLSearchParams")); } URLSearchParams::~URLSearchParams() = default; @@ -82,14 +82,14 @@ Vector url_decode(StringView input) return output; } -JS::NonnullGCPtr URLSearchParams::create(HTML::Window& window, Vector list) +JS::NonnullGCPtr URLSearchParams::create(JS::Realm& realm, Vector list) { - return *window.heap().allocate(window.realm(), window, move(list)); + return *realm.heap().allocate(realm, realm, move(list)); } // https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams // https://url.spec.whatwg.org/#urlsearchparams-initialize -WebIDL::ExceptionOr> URLSearchParams::create_with_global_object(HTML::Window& window, Variant>, OrderedHashMap, String> const& init) +WebIDL::ExceptionOr> URLSearchParams::construct_impl(JS::Realm& realm, Variant>, OrderedHashMap, String> const& init) { // 1. If init is a string and starts with U+003F (?), then remove the first code point from init. // NOTE: We do this when we know that it's a string on step 3 of initialization. @@ -114,7 +114,7 @@ WebIDL::ExceptionOr> URLSearchParams::create_w list.append(QueryParam { .name = pair[0], .value = pair[1] }); } - return URLSearchParams::create(window, move(list)); + return URLSearchParams::create(realm, move(list)); } // 2. Otherwise, if init is a record, then for each name → value of init, append a new name-value pair whose name is name and value is value, to query’s list. @@ -127,7 +127,7 @@ WebIDL::ExceptionOr> URLSearchParams::create_w for (auto const& pair : init_record) list.append(QueryParam { .name = pair.key, .value = pair.value }); - return URLSearchParams::create(window, move(list)); + return URLSearchParams::create(realm, move(list)); } // 3. Otherwise: @@ -139,7 +139,7 @@ WebIDL::ExceptionOr> URLSearchParams::create_w StringView stripped_init = init_string.substring_view(init_string.starts_with('?')); // b. Set query’s list to the result of parsing init. - return URLSearchParams::create(window, url_decode(stripped_init)); + return URLSearchParams::create(realm, url_decode(stripped_init)); } void URLSearchParams::append(String const& name, String const& value) diff --git a/Userland/Libraries/LibWeb/URL/URLSearchParams.h b/Userland/Libraries/LibWeb/URL/URLSearchParams.h index 97413dcb6b..38e9331c44 100644 --- a/Userland/Libraries/LibWeb/URL/URLSearchParams.h +++ b/Userland/Libraries/LibWeb/URL/URLSearchParams.h @@ -23,8 +23,8 @@ class URLSearchParams : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(URLSearchParams, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create(HTML::Window&, Vector list); - static WebIDL::ExceptionOr> create_with_global_object(HTML::Window&, Variant>, OrderedHashMap, String> const& init); + static JS::NonnullGCPtr create(JS::Realm&, Vector list); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, Variant>, OrderedHashMap, String> const& init); virtual ~URLSearchParams() override; @@ -46,7 +46,7 @@ private: friend class URL; friend class URLSearchParamsIterator; - URLSearchParams(HTML::Window&, Vector list); + URLSearchParams(JS::Realm&, Vector list); virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp b/Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp index e70a40f946..9d1cb1a3da 100644 --- a/Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp +++ b/Userland/Libraries/LibWeb/URL/URLSearchParamsIterator.cpp @@ -6,8 +6,8 @@ #include #include +#include #include -#include #include namespace Web::URL { @@ -22,7 +22,7 @@ URLSearchParamsIterator::URLSearchParamsIterator(URLSearchParams const& url_sear , m_url_search_params(url_search_params) , m_iteration_kind(iteration_kind) { - set_prototype(&url_search_params.global_object().ensure_web_prototype("URLSearchParamsIterator")); + set_prototype(&Bindings::ensure_web_prototype(url_search_params.realm(), "URLSearchParamsIterator")); } URLSearchParamsIterator::~URLSearchParamsIterator() = default; diff --git a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp index d23574b212..64105d6b23 100644 --- a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp +++ b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp @@ -177,7 +177,7 @@ void XMLDocumentBuilder::document_end() document->load_timing_info().dom_content_loaded_event_start_time = HTML::main_thread_event_loop().unsafe_shared_current_time(); // 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); @@ -209,7 +209,7 @@ void XMLDocumentBuilder::document_end() return; // Let window be the Document's relevant global object. - JS::NonnullGCPtr window = document->window(); + JS::NonnullGCPtr window = verify_cast(relevant_global_object(*document)); // Set the Document's load timing info's load event start time to the current high resolution time given window. document->load_timing_info().load_event_start_time = HTML::main_thread_event_loop().unsafe_shared_current_time(); @@ -217,7 +217,7 @@ void XMLDocumentBuilder::document_end() // 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: 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.