1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 06:47:40 +00:00

LibWeb: Remove unecessary dependence on Window from assorted classes

These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
This commit is contained in:
Andrew Kaster 2022-09-25 18:11:21 -06:00 committed by Linus Groh
parent 4878a18ee7
commit 4bb6345b2f
30 changed files with 125 additions and 126 deletions

View file

@ -8,21 +8,21 @@
#include <AK/Random.h> #include <AK/Random.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <LibJS/Runtime/TypedArray.h> #include <LibJS/Runtime/TypedArray.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Crypto/Crypto.h> #include <LibWeb/Crypto/Crypto.h>
#include <LibWeb/Crypto/SubtleCrypto.h> #include <LibWeb/Crypto/SubtleCrypto.h>
#include <LibWeb/HTML/Window.h>
namespace Web::Crypto { namespace Web::Crypto {
JS::NonnullGCPtr<Crypto> Crypto::create(HTML::Window& window) JS::NonnullGCPtr<Crypto> Crypto::create(JS::Realm& realm)
{ {
return *window.heap().allocate<Crypto>(window.realm(), window); return *realm.heap().allocate<Crypto>(realm, realm);
} }
Crypto::Crypto(HTML::Window& window) Crypto::Crypto(JS::Realm& realm)
: PlatformObject(window.realm()) : PlatformObject(realm)
{ {
set_prototype(&window.cached_web_prototype("Crypto")); set_prototype(&Bindings::cached_web_prototype(realm, "Crypto"));
} }
Crypto::~Crypto() = default; Crypto::~Crypto() = default;
@ -30,7 +30,7 @@ Crypto::~Crypto() = default;
void Crypto::initialize(JS::Realm& realm) void Crypto::initialize(JS::Realm& realm)
{ {
Base::initialize(realm); Base::initialize(realm);
m_subtle = SubtleCrypto::create(global_object()); m_subtle = SubtleCrypto::create(realm);
} }
JS::NonnullGCPtr<SubtleCrypto> Crypto::subtle() const JS::NonnullGCPtr<SubtleCrypto> Crypto::subtle() const
@ -43,16 +43,16 @@ WebIDL::ExceptionOr<JS::Value> 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. // 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<JS::Int8Array>(array.as_object()) || is<JS::Uint8Array>(array.as_object()) || is<JS::Uint8ClampedArray>(array.as_object()) || is<JS::Int16Array>(array.as_object()) || is<JS::Uint16Array>(array.as_object()) || is<JS::Int32Array>(array.as_object()) || is<JS::Uint32Array>(array.as_object()) || is<JS::BigInt64Array>(array.as_object()) || is<JS::BigUint64Array>(array.as_object()))) if (!array.is_object() || !(is<JS::Int8Array>(array.as_object()) || is<JS::Uint8Array>(array.as_object()) || is<JS::Uint8ClampedArray>(array.as_object()) || is<JS::Int16Array>(array.as_object()) || is<JS::Uint16Array>(array.as_object()) || is<JS::Int32Array>(array.as_object()) || is<JS::Uint32Array>(array.as_object()) || is<JS::BigInt64Array>(array.as_object()) || is<JS::BigUint64Array>(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<JS::TypedArrayBase&>(array.as_object()); auto& typed_array = static_cast<JS::TypedArrayBase&>(array.as_object());
// 2. If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm. // 2. If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
if (typed_array.byte_length() > 65536) 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. // IMPLEMENTATION DEFINED: If the viewed array buffer is detached, throw a InvalidStateError and terminate the algorithm.
if (typed_array.viewed_array_buffer()->is_detached()) 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 // FIXME: Handle SharedArrayBuffers
// 3. Overwrite all elements of array with cryptographically strong random values of the appropriate type. // 3. Overwrite all elements of array with cryptographically strong random values of the appropriate type.

View file

@ -16,7 +16,7 @@ class Crypto : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(Crypto, Bindings::PlatformObject); WEB_PLATFORM_OBJECT(Crypto, Bindings::PlatformObject);
public: public:
static JS::NonnullGCPtr<Crypto> create(HTML::Window&); static JS::NonnullGCPtr<Crypto> create(JS::Realm&);
virtual ~Crypto() override; virtual ~Crypto() override;
@ -29,7 +29,7 @@ protected:
virtual void visit_edges(Cell::Visitor&) override; virtual void visit_edges(Cell::Visitor&) override;
private: private:
explicit Crypto(HTML::Window&); explicit Crypto(JS::Realm&);
virtual void initialize(JS::Realm&) override; virtual void initialize(JS::Realm&) override;
JS::GCPtr<SubtleCrypto> m_subtle; JS::GCPtr<SubtleCrypto> m_subtle;

View file

@ -7,37 +7,37 @@
#include <LibCrypto/Hash/HashManager.h> #include <LibCrypto/Hash/HashManager.h>
#include <LibJS/Runtime/ArrayBuffer.h> #include <LibJS/Runtime/ArrayBuffer.h>
#include <LibJS/Runtime/Promise.h> #include <LibJS/Runtime/Promise.h>
#include <LibWeb/Bindings/MainThreadVM.h> #include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Crypto/SubtleCrypto.h> #include <LibWeb/Crypto/SubtleCrypto.h>
#include <LibWeb/WebIDL/AbstractOperations.h> #include <LibWeb/WebIDL/AbstractOperations.h>
#include <LibWeb/WebIDL/DOMException.h> #include <LibWeb/WebIDL/DOMException.h>
namespace Web::Crypto { namespace Web::Crypto {
JS::NonnullGCPtr<SubtleCrypto> SubtleCrypto::create(HTML::Window& window) JS::NonnullGCPtr<SubtleCrypto> SubtleCrypto::create(JS::Realm& realm)
{ {
return *window.heap().allocate<SubtleCrypto>(window.realm(), window); return *realm.heap().allocate<SubtleCrypto>(realm, realm);
} }
SubtleCrypto::SubtleCrypto(HTML::Window& window) SubtleCrypto::SubtleCrypto(JS::Realm& realm)
: PlatformObject(window.realm()) : PlatformObject(realm)
{ {
set_prototype(&window.cached_web_prototype("SubtleCrypto")); set_prototype(&Bindings::cached_web_prototype(realm, "SubtleCrypto"));
} }
SubtleCrypto::~SubtleCrypto() = default; SubtleCrypto::~SubtleCrypto() = default;
// https://w3c.github.io/webcrypto/#dfn-SubtleCrypto-method-digest
JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object> const& data) JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object> const& data)
{ {
auto& vm = Bindings::main_thread_vm(); auto& realm = this->realm();
auto& realm = *vm.current_realm();
// 1. Let algorithm be the algorithm parameter passed to the digest() method. // 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. // 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()); auto data_buffer_or_error = WebIDL::get_buffer_source_copy(*data.cell());
if (data_buffer_or_error.is_error()) { 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); auto* promise = JS::Promise::create(realm);
promise->reject(error.ptr()); promise->reject(error.ptr());
return promise; return promise;
@ -58,7 +58,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
} }
// 4. If an error occurred, return a Promise rejected with normalizedAlgorithm. // 4. If an error occurred, return a Promise rejected with normalizedAlgorithm.
else { else {
auto error = WebIDL::NotSupportedError::create(global_object(), String::formatted("Invalid hash function '{}'", algorithm)); auto error = WebIDL::NotSupportedError::create(realm, String::formatted("Invalid hash function '{}'", algorithm));
auto* promise = JS::Promise::create(realm); auto* promise = JS::Promise::create(realm);
promise->reject(error.ptr()); promise->reject(error.ptr());
return promise; return promise;
@ -79,7 +79,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
auto digest = hash.digest(); auto digest = hash.digest();
auto result_buffer = ByteBuffer::copy(digest.immutable_data(), hash.digest_size()); auto result_buffer = ByteBuffer::copy(digest.immutable_data(), hash.digest_size());
if (result_buffer.is_error()) { if (result_buffer.is_error()) {
auto error = WebIDL::OperationError::create(global_object(), "Failed to create result buffer"); auto error = WebIDL::OperationError::create(realm, "Failed to create result buffer");
promise->reject(error.ptr()); promise->reject(error.ptr());
return promise; return promise;
} }

View file

@ -15,14 +15,14 @@ class SubtleCrypto final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(SubtleCrypto, Bindings::PlatformObject); WEB_PLATFORM_OBJECT(SubtleCrypto, Bindings::PlatformObject);
public: public:
static JS::NonnullGCPtr<SubtleCrypto> create(HTML::Window&); static JS::NonnullGCPtr<SubtleCrypto> create(JS::Realm&);
virtual ~SubtleCrypto() override; virtual ~SubtleCrypto() override;
JS::Promise* digest(String const& algorithm, JS::Handle<JS::Object> const& data); JS::Promise* digest(String const& algorithm, JS::Handle<JS::Object> const& data);
private: private:
explicit SubtleCrypto(HTML::Window&); explicit SubtleCrypto(JS::Realm&);
}; };
} }

View file

@ -6,30 +6,30 @@
#include <AK/FlyString.h> #include <AK/FlyString.h>
#include <LibJS/Runtime/TypedArray.h> #include <LibJS/Runtime/TypedArray.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Encoding/TextDecoder.h> #include <LibWeb/Encoding/TextDecoder.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/WebIDL/AbstractOperations.h> #include <LibWeb/WebIDL/AbstractOperations.h>
namespace Web::Encoding { namespace Web::Encoding {
WebIDL::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> TextDecoder::create_with_global_object(HTML::Window& window, FlyString encoding) WebIDL::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> TextDecoder::construct_impl(JS::Realm& realm, FlyString encoding)
{ {
auto decoder = TextCodec::decoder_for(encoding); auto decoder = TextCodec::decoder_for(encoding);
if (!decoder) if (!decoder)
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Invalid encoding {}", encoding) }; return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Invalid encoding {}", encoding) };
return JS::NonnullGCPtr(*window.heap().allocate<TextDecoder>(window.realm(), window, *decoder, move(encoding), false, false)); return JS::NonnullGCPtr(*realm.heap().allocate<TextDecoder>(realm, realm, *decoder, move(encoding), false, false));
} }
// https://encoding.spec.whatwg.org/#dom-textdecoder // https://encoding.spec.whatwg.org/#dom-textdecoder
TextDecoder::TextDecoder(HTML::Window& window, TextCodec::Decoder& decoder, FlyString encoding, bool fatal, bool ignore_bom) TextDecoder::TextDecoder(JS::Realm& realm, TextCodec::Decoder& decoder, FlyString encoding, bool fatal, bool ignore_bom)
: PlatformObject(window.realm()) : PlatformObject(realm)
, m_decoder(decoder) , m_decoder(decoder)
, m_encoding(move(encoding)) , m_encoding(move(encoding))
, m_fatal(fatal) , m_fatal(fatal)
, m_ignore_bom(ignore_bom) , m_ignore_bom(ignore_bom)
{ {
set_prototype(&window.cached_web_prototype("TextDecoder")); set_prototype(&Bindings::cached_web_prototype(realm, "TextDecoder"));
} }
TextDecoder::~TextDecoder() = default; TextDecoder::~TextDecoder() = default;
@ -41,7 +41,7 @@ WebIDL::ExceptionOr<String> TextDecoder::decode(JS::Handle<JS::Object> const& in
auto data_buffer_or_error = WebIDL::get_buffer_source_copy(*input.cell()); auto data_buffer_or_error = WebIDL::get_buffer_source_copy(*input.cell());
if (data_buffer_or_error.is_error()) 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(); auto& data_buffer = data_buffer_or_error.value();
return m_decoder.to_utf8({ data_buffer.data(), data_buffer.size() }); return m_decoder.to_utf8({ data_buffer.data(), data_buffer.size() });
} }

View file

@ -21,7 +21,7 @@ class TextDecoder : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(TextDecoder, Bindings::PlatformObject); WEB_PLATFORM_OBJECT(TextDecoder, Bindings::PlatformObject);
public: public:
static WebIDL::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> create_with_global_object(HTML::Window&, FlyString encoding); static WebIDL::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> construct_impl(JS::Realm&, FlyString encoding);
virtual ~TextDecoder() override; virtual ~TextDecoder() override;
@ -33,7 +33,7 @@ public:
private: private:
// https://encoding.spec.whatwg.org/#dom-textdecoder // 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; TextCodec::Decoder& m_decoder;
FlyString m_encoding; FlyString m_encoding;

View file

@ -6,20 +6,20 @@
#include <AK/FlyString.h> #include <AK/FlyString.h>
#include <LibJS/Runtime/TypedArray.h> #include <LibJS/Runtime/TypedArray.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Encoding/TextEncoder.h> #include <LibWeb/Encoding/TextEncoder.h>
#include <LibWeb/HTML/Window.h>
namespace Web::Encoding { namespace Web::Encoding {
JS::NonnullGCPtr<TextEncoder> TextEncoder::create_with_global_object(HTML::Window& window) JS::NonnullGCPtr<TextEncoder> TextEncoder::construct_impl(JS::Realm& realm)
{ {
return *window.heap().allocate<TextEncoder>(window.realm(), window); return *realm.heap().allocate<TextEncoder>(realm, realm);
} }
TextEncoder::TextEncoder(HTML::Window& window) TextEncoder::TextEncoder(JS::Realm& realm)
: PlatformObject(window.realm()) : PlatformObject(realm)
{ {
set_prototype(&window.cached_web_prototype("TextEncoder")); set_prototype(&Bindings::cached_web_prototype(realm, "TextEncoder"));
} }
TextEncoder::~TextEncoder() = default; TextEncoder::~TextEncoder() = default;

View file

@ -20,7 +20,7 @@ class TextEncoder final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(TextEncoder, Bindings::PlatformObject); WEB_PLATFORM_OBJECT(TextEncoder, Bindings::PlatformObject);
public: public:
static JS::NonnullGCPtr<TextEncoder> create_with_global_object(HTML::Window&); static JS::NonnullGCPtr<TextEncoder> construct_impl(JS::Realm&);
virtual ~TextEncoder() override; virtual ~TextEncoder() override;
@ -30,7 +30,7 @@ public:
protected: protected:
// https://encoding.spec.whatwg.org/#dom-textencoder // https://encoding.spec.whatwg.org/#dom-textencoder
explicit TextEncoder(HTML::Window&); explicit TextEncoder(JS::Realm&);
}; };
} }

View file

@ -7,7 +7,6 @@
#include <LibWeb/Fetch/BodyInit.h> #include <LibWeb/Fetch/BodyInit.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h> #include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/URL/URLSearchParams.h> #include <LibWeb/URL/URLSearchParams.h>
#include <LibWeb/WebIDL/AbstractOperations.h> #include <LibWeb/WebIDL/AbstractOperations.h>
#include <LibWeb/WebIDL/ExceptionOr.h> #include <LibWeb/WebIDL/ExceptionOr.h>
@ -22,7 +21,7 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
if (auto const* handle = object.get_pointer<JS::Handle<Streams::ReadableStream>>()) { if (auto const* handle = object.get_pointer<JS::Handle<Streams::ReadableStream>>()) {
stream = const_cast<Streams::ReadableStream*>(handle->cell()); stream = const_cast<Streams::ReadableStream*>(handle->cell());
} else { } else {
stream = realm.heap().allocate<Streams::ReadableStream>(realm, verify_cast<HTML::Window>(realm.global_object())); stream = realm.heap().allocate<Streams::ReadableStream>(realm, realm);
} }
// FIXME: 2. Let action be null. // FIXME: 2. Let action be null.

View file

@ -30,11 +30,10 @@ WebIDL::ExceptionOr<Body> Body::clone() const
auto& vm = Bindings::main_thread_vm(); auto& vm = Bindings::main_thread_vm();
auto& realm = *vm.current_realm(); auto& realm = *vm.current_realm();
auto& window = verify_cast<HTML::Window>(realm.global_object());
// FIXME: 1. Let « out1, out2 » be the result of teeing bodys stream. // FIXME: 1. Let « out1, out2 » be the result of teeing bodys stream.
// FIXME: 2. Set bodys stream to out1. // FIXME: 2. Set bodys stream to out1.
auto* out2 = vm.heap().allocate<Streams::ReadableStream>(realm, window); auto* out2 = vm.heap().allocate<Streams::ReadableStream>(realm, realm);
// 3. Return a body whose stream is out2 and other members are copied from body. // 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 }; return Body { JS::make_handle(out2), m_source, m_length };

View file

@ -658,7 +658,7 @@ void Window::invoke_idle_callbacks()
// 1. Pop the top callback from window's list of runnable idle callbacks. // 1. Pop the top callback from window's list of runnable idle callbacks.
auto callback = m_runnable_idle_callbacks.take_first(); auto callback = m_runnable_idle_callbacks.take_first();
// 2. Let deadlineArg be a new IdleDeadline whose [get deadline time algorithm] is getDeadline. // 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. // 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); auto result = callback->invoke(deadline_arg);
if (result.is_error()) if (result.is_error())
@ -744,7 +744,7 @@ void Window::initialize_web_interfaces(Badge<WindowEnvironmentSettingsObject>)
Object::set_prototype(&Bindings::ensure_web_prototype<Bindings::WindowPrototype>(realm, "Window")); Object::set_prototype(&Bindings::ensure_web_prototype<Bindings::WindowPrototype>(realm, "Window"));
m_crypto = Crypto::Crypto::create(*this); m_crypto = Crypto::Crypto::create(realm);
// FIXME: These should be native accessors, not properties // FIXME: These should be native accessors, not properties
define_direct_property("window", this, JS::Attribute::Enumerable); define_direct_property("window", this, JS::Attribute::Enumerable);

View file

@ -17,7 +17,7 @@ Performance::Performance(HTML::Window& window)
: DOM::EventTarget(window.realm()) : DOM::EventTarget(window.realm())
, m_window(window) , m_window(window)
{ {
set_prototype(&window.cached_web_prototype("Performance")); set_prototype(&Bindings::cached_web_prototype(realm(), "Performance"));
m_timer.start(); m_timer.start();
} }

View file

@ -4,26 +4,26 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/Element.h> #include <LibWeb/DOM/Element.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/IntersectionObserver/IntersectionObserver.h> #include <LibWeb/IntersectionObserver/IntersectionObserver.h>
namespace Web::IntersectionObserver { namespace Web::IntersectionObserver {
// https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-intersectionobserver // https://w3c.github.io/IntersectionObserver/#dom-intersectionobserver-intersectionobserver
JS::NonnullGCPtr<IntersectionObserver> IntersectionObserver::create_with_global_object(HTML::Window& window, WebIDL::CallbackType* callback, IntersectionObserverInit const& options) JS::NonnullGCPtr<IntersectionObserver> IntersectionObserver::construct_impl(JS::Realm& realm, WebIDL::CallbackType* callback, IntersectionObserverInit const& options)
{ {
// FIXME: Implement // FIXME: Implement
(void)callback; (void)callback;
(void)options; (void)options;
return *window.heap().allocate<IntersectionObserver>(window.realm(), window); return *realm.heap().allocate<IntersectionObserver>(realm, realm);
} }
IntersectionObserver::IntersectionObserver(HTML::Window& window) IntersectionObserver::IntersectionObserver(JS::Realm& realm)
: PlatformObject(window.realm()) : PlatformObject(realm)
{ {
set_prototype(&window.cached_web_prototype("IntersectionObserver")); set_prototype(&Bindings::cached_web_prototype(realm, "IntersectionObserver"));
} }
IntersectionObserver::~IntersectionObserver() = default; IntersectionObserver::~IntersectionObserver() = default;

View file

@ -22,7 +22,7 @@ class IntersectionObserver : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(IntersectionObserver, Bindings::PlatformObject); WEB_PLATFORM_OBJECT(IntersectionObserver, Bindings::PlatformObject);
public: public:
static JS::NonnullGCPtr<IntersectionObserver> create_with_global_object(HTML::Window&, WebIDL::CallbackType* callback, IntersectionObserverInit const& options = {}); static JS::NonnullGCPtr<IntersectionObserver> construct_impl(JS::Realm&, WebIDL::CallbackType* callback, IntersectionObserverInit const& options = {});
virtual ~IntersectionObserver() override; virtual ~IntersectionObserver() override;
@ -31,7 +31,7 @@ public:
void disconnect(); void disconnect();
private: private:
explicit IntersectionObserver(HTML::Window&); explicit IntersectionObserver(JS::Realm&);
}; };
} }

View file

@ -12,7 +12,7 @@ PerformanceTiming::PerformanceTiming(HTML::Window& window)
: PlatformObject(window.realm()) : PlatformObject(window.realm())
, m_window(window) , m_window(window)
{ {
set_prototype(&window.cached_web_prototype("PerformanceTiming")); set_prototype(&Bindings::cached_web_prototype(realm(), "PerformanceTiming"));
} }
PerformanceTiming::~PerformanceTiming() = default; PerformanceTiming::~PerformanceTiming() = default;

View file

@ -203,12 +203,12 @@ bool EventHandler::handle_mouseup(Gfx::IntPoint const& position, unsigned button
} }
auto offset = compute_mouse_event_offset(position, *layout_node); 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; handled_event = true;
bool run_activation_behavior = true; bool run_activation_behavior = true;
if (node.ptr() == m_mousedown_target && button == GUI::MouseButton::Primary) { 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) { if (run_activation_behavior) {
@ -332,7 +332,7 @@ bool EventHandler::handle_mousedown(Gfx::IntPoint const& position, unsigned butt
m_mousedown_target = node.ptr(); m_mousedown_target = node.ptr();
auto offset = compute_mouse_event_offset(position, *layout_node); 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. // 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); 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. // NOTE: Dispatching an event may have disturbed the world.
if (!paint_root() || paint_root() != node->document().paint_box()) if (!paint_root() || paint_root() != node->document().paint_box())
return true; return true;
@ -542,7 +542,7 @@ bool EventHandler::handle_doubleclick(Gfx::IntPoint const& position, unsigned bu
return false; return false;
auto offset = compute_mouse_event_offset(position, *layout_node); 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. // NOTE: Dispatching an event may have disturbed the world.
if (!paint_root() || paint_root() != node->document().paint_box()) 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; 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<DOM::Element> focused_element = document->focused_element()) if (JS::GCPtr<DOM::Element> focused_element = document->focused_element())
return focused_element->dispatch_event(*event); return focused_element->dispatch_event(*event);
@ -738,7 +738,7 @@ bool EventHandler::handle_keyup(KeyCode key, unsigned modifiers, u32 code_point)
if (!document) if (!document)
return false; 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<DOM::Element> focused_element = document->focused_element()) if (JS::GCPtr<DOM::Element> focused_element = document->focused_element())
return document->focused_element()->dispatch_event(*event); return document->focused_element()->dispatch_event(*event);

View file

@ -11,16 +11,16 @@
namespace Web::RequestIdleCallback { namespace Web::RequestIdleCallback {
JS::NonnullGCPtr<IdleDeadline> IdleDeadline::create(HTML::Window& window, bool did_timeout) JS::NonnullGCPtr<IdleDeadline> IdleDeadline::create(JS::Realm& realm, bool did_timeout)
{ {
return *window.heap().allocate<IdleDeadline>(window.realm(), window, did_timeout); return *realm.heap().allocate<IdleDeadline>(realm, realm, did_timeout);
} }
IdleDeadline::IdleDeadline(HTML::Window& window, bool did_timeout) IdleDeadline::IdleDeadline(JS::Realm& realm, bool did_timeout)
: PlatformObject(window.realm()) : PlatformObject(realm)
, m_did_timeout(did_timeout) , m_did_timeout(did_timeout)
{ {
set_prototype(&window.cached_web_prototype("IdleDeadline")); set_prototype(&Bindings::cached_web_prototype(realm, "IdleDeadline"));
} }
IdleDeadline::~IdleDeadline() = default; IdleDeadline::~IdleDeadline() = default;

View file

@ -16,14 +16,14 @@ class IdleDeadline final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(IdleDeadline, Bindings::PlatformObject); WEB_PLATFORM_OBJECT(IdleDeadline, Bindings::PlatformObject);
public: public:
static JS::NonnullGCPtr<IdleDeadline> create(HTML::Window&, bool did_timeout = false); static JS::NonnullGCPtr<IdleDeadline> create(JS::Realm&, bool did_timeout = false);
virtual ~IdleDeadline() override; virtual ~IdleDeadline() override;
double time_remaining() const; double time_remaining() const;
bool did_timeout() const { return m_did_timeout; } bool did_timeout() const { return m_did_timeout; }
private: private:
IdleDeadline(HTML::Window&, bool did_timeout); IdleDeadline(JS::Realm&, bool did_timeout);
bool m_did_timeout { false }; bool m_did_timeout { false };
}; };

View file

@ -4,24 +4,24 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/Element.h> #include <LibWeb/DOM/Element.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/ResizeObserver/ResizeObserver.h> #include <LibWeb/ResizeObserver/ResizeObserver.h>
namespace Web::ResizeObserver { namespace Web::ResizeObserver {
// https://drafts.csswg.org/resize-observer/#dom-resizeobserver-resizeobserver // https://drafts.csswg.org/resize-observer/#dom-resizeobserver-resizeobserver
JS::NonnullGCPtr<ResizeObserver> ResizeObserver::create_with_global_object(HTML::Window& window, WebIDL::CallbackType* callback) JS::NonnullGCPtr<ResizeObserver> ResizeObserver::construct_impl(JS::Realm& realm, WebIDL::CallbackType* callback)
{ {
// FIXME: Implement // FIXME: Implement
(void)callback; (void)callback;
return *window.heap().allocate<ResizeObserver>(window.realm(), window); return *realm.heap().allocate<ResizeObserver>(realm, realm);
} }
ResizeObserver::ResizeObserver(HTML::Window& window) ResizeObserver::ResizeObserver(JS::Realm& realm)
: PlatformObject(window.realm()) : PlatformObject(realm)
{ {
set_prototype(&window.cached_web_prototype("ResizeObserver")); set_prototype(&Bindings::cached_web_prototype(realm, "ResizeObserver"));
} }
ResizeObserver::~ResizeObserver() = default; ResizeObserver::~ResizeObserver() = default;

View file

@ -19,7 +19,7 @@ class ResizeObserver : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(ResizeObserver, Bindings::PlatformObject); WEB_PLATFORM_OBJECT(ResizeObserver, Bindings::PlatformObject);
public: public:
static JS::NonnullGCPtr<ResizeObserver> create_with_global_object(HTML::Window&, WebIDL::CallbackType* callback); static JS::NonnullGCPtr<ResizeObserver> construct_impl(JS::Realm&, WebIDL::CallbackType* callback);
virtual ~ResizeObserver() override; virtual ~ResizeObserver() override;
@ -28,7 +28,7 @@ public:
void disconnect(); void disconnect();
private: private:
explicit ResizeObserver(HTML::Window&); explicit ResizeObserver(JS::Realm&);
}; };
} }

View file

@ -4,20 +4,20 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibWeb/HTML/Window.h> #include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Selection/Selection.h> #include <LibWeb/Selection/Selection.h>
namespace Web::Selection { namespace Web::Selection {
JS::NonnullGCPtr<Selection> Selection::create(HTML::Window& window) JS::NonnullGCPtr<Selection> Selection::create(JS::Realm& realm)
{ {
return *window.heap().allocate<Selection>(window.realm(), window); return *realm.heap().allocate<Selection>(realm, realm);
} }
Selection::Selection(HTML::Window& window) Selection::Selection(JS::Realm& realm)
: PlatformObject(window.realm()) : PlatformObject(realm)
{ {
set_prototype(&window.cached_web_prototype("Selection")); set_prototype(&Bindings::cached_web_prototype(realm, "Selection"));
} }
Selection::~Selection() = default; Selection::~Selection() = default;

View file

@ -14,7 +14,7 @@ class Selection final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(Selection, Bindings::PlatformObject); WEB_PLATFORM_OBJECT(Selection, Bindings::PlatformObject);
public: public:
static JS::NonnullGCPtr<Selection> create(HTML::Window&); static JS::NonnullGCPtr<Selection> create(JS::Realm&);
virtual ~Selection() override; virtual ~Selection() override;
@ -43,7 +43,7 @@ public:
String to_string() const; String to_string() const;
private: private:
explicit Selection(HTML::Window&); explicit Selection(JS::Realm&);
}; };
} }

View file

@ -4,24 +4,25 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibWeb/HTML/Window.h> #include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Streams/AbstractOperations.h> #include <LibWeb/Streams/AbstractOperations.h>
#include <LibWeb/Streams/ReadableStream.h> #include <LibWeb/Streams/ReadableStream.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::Streams { namespace Web::Streams {
// https://streams.spec.whatwg.org/#rs-constructor // https://streams.spec.whatwg.org/#rs-constructor
WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStream>> ReadableStream::create_with_global_object(HTML::Window& window) WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStream>> ReadableStream::construct_impl(JS::Realm& realm)
{ {
auto* readable_stream = window.heap().allocate<ReadableStream>(window.realm(), window); auto* readable_stream = realm.heap().allocate<ReadableStream>(realm, realm);
return JS::NonnullGCPtr { *readable_stream }; return JS::NonnullGCPtr { *readable_stream };
} }
ReadableStream::ReadableStream(HTML::Window& window) ReadableStream::ReadableStream(JS::Realm& realm)
: PlatformObject(window.realm()) : PlatformObject(realm)
{ {
set_prototype(&window.cached_web_prototype("ReadableStream")); set_prototype(&Bindings::cached_web_prototype(realm, "ReadableStream"));
} }
ReadableStream::~ReadableStream() = default; ReadableStream::~ReadableStream() = default;

View file

@ -24,7 +24,7 @@ public:
Errored, Errored,
}; };
static WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStream>> create_with_global_object(HTML::Window&); static WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStream>> construct_impl(JS::Realm&);
virtual ~ReadableStream() override; virtual ~ReadableStream() override;
@ -39,7 +39,7 @@ public:
bool is_disturbed() const; bool is_disturbed() const;
private: private:
explicit ReadableStream(HTML::Window&); explicit ReadableStream(JS::Realm&);
virtual void visit_edges(Cell::Visitor&) override; virtual void visit_edges(Cell::Visitor&) override;

View file

@ -6,17 +6,17 @@
*/ */
#include <AK/URLParser.h> #include <AK/URLParser.h>
#include <LibWeb/HTML/Window.h> #include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/URL/URL.h> #include <LibWeb/URL/URL.h>
namespace Web::URL { namespace Web::URL {
JS::NonnullGCPtr<URL> URL::create(HTML::Window& window, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query) JS::NonnullGCPtr<URL> URL::create(JS::Realm& realm, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query)
{ {
return *window.heap().allocate<URL>(window.realm(), window, move(url), move(query)); return *realm.heap().allocate<URL>(realm, realm, move(url), move(query));
} }
WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> URL::create_with_global_object(HTML::Window& window, String const& url, String const& base) WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> URL::construct_impl(JS::Realm& realm, String const& url, String const& base)
{ {
// 1. Let parsedBase be null. // 1. Let parsedBase be null.
Optional<AK::URL> parsed_base; Optional<AK::URL> parsed_base;
@ -41,21 +41,21 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> URL::create_with_global_object(HTML::
auto& query = parsed_url.query().is_null() ? String::empty() : parsed_url.query(); auto& query = parsed_url.query().is_null() ? String::empty() : parsed_url.query();
// 6. Set thiss URL to parsedURL. // 6. Set thiss URL to parsedURL.
// 7. Set thiss query object to a new URLSearchParams object. // 7. Set thiss 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 thiss query object with query. // 8. Initialize thiss 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 thiss query objects URL object to this. // 9. Set thiss query objects URL object to this.
result_url->m_query->m_url = result_url; result_url->m_query->m_url = result_url;
return result_url; return result_url;
} }
URL::URL(HTML::Window& window, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query) URL::URL(JS::Realm& realm, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query)
: PlatformObject(window.realm()) : PlatformObject(realm)
, m_url(move(url)) , m_url(move(url))
, m_query(move(query)) , m_query(move(query))
{ {
set_prototype(&window.cached_web_prototype("URL")); set_prototype(&Bindings::cached_web_prototype(realm, "URL"));
} }
URL::~URL() = default; URL::~URL() = default;

View file

@ -19,8 +19,8 @@ class URL : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(URL, Bindings::PlatformObject); WEB_PLATFORM_OBJECT(URL, Bindings::PlatformObject);
public: public:
static JS::NonnullGCPtr<URL> create(HTML::Window&, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query); static JS::NonnullGCPtr<URL> create(JS::Realm&, AK::URL url, JS::NonnullGCPtr<URLSearchParams> query);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> create_with_global_object(HTML::Window&, String const& url, String const& base); static WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> construct_impl(JS::Realm&, String const& url, String const& base);
virtual ~URL() override; virtual ~URL() override;
@ -63,7 +63,7 @@ public:
void set_query(Badge<URLSearchParams>, String query) { m_url.set_query(move(query)); } void set_query(Badge<URLSearchParams>, String query) { m_url.set_query(move(query)); }
private: private:
URL(HTML::Window&, AK::URL, JS::NonnullGCPtr<URLSearchParams> query); URL(JS::Realm&, AK::URL, JS::NonnullGCPtr<URLSearchParams> query);
virtual void visit_edges(Cell::Visitor&) override; virtual void visit_edges(Cell::Visitor&) override;

View file

@ -7,17 +7,17 @@
#include <AK/QuickSort.h> #include <AK/QuickSort.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/Utf8View.h> #include <AK/Utf8View.h>
#include <LibWeb/HTML/Window.h> #include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/URL/URL.h> #include <LibWeb/URL/URL.h>
#include <LibWeb/URL/URLSearchParams.h> #include <LibWeb/URL/URLSearchParams.h>
namespace Web::URL { namespace Web::URL {
URLSearchParams::URLSearchParams(HTML::Window& window, Vector<QueryParam> list) URLSearchParams::URLSearchParams(JS::Realm& realm, Vector<QueryParam> list)
: PlatformObject(window.realm()) : PlatformObject(realm)
, m_list(move(list)) , m_list(move(list))
{ {
set_prototype(&window.cached_web_prototype("URLSearchParams")); set_prototype(&Bindings::cached_web_prototype(realm, "URLSearchParams"));
} }
URLSearchParams::~URLSearchParams() = default; URLSearchParams::~URLSearchParams() = default;
@ -82,14 +82,14 @@ Vector<QueryParam> url_decode(StringView input)
return output; return output;
} }
JS::NonnullGCPtr<URLSearchParams> URLSearchParams::create(HTML::Window& window, Vector<QueryParam> list) JS::NonnullGCPtr<URLSearchParams> URLSearchParams::create(JS::Realm& realm, Vector<QueryParam> list)
{ {
return *window.heap().allocate<URLSearchParams>(window.realm(), window, move(list)); return *realm.heap().allocate<URLSearchParams>(realm, realm, move(list));
} }
// https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams // https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams
// https://url.spec.whatwg.org/#urlsearchparams-initialize // https://url.spec.whatwg.org/#urlsearchparams-initialize
WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::create_with_global_object(HTML::Window& window, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init) WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::construct_impl(JS::Realm& realm, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init)
{ {
// 1. If init is a string and starts with U+003F (?), then remove the first code point from 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. // NOTE: We do this when we know that it's a string on step 3 of initialization.
@ -114,7 +114,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::create_w
list.append(QueryParam { .name = pair[0], .value = pair[1] }); 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 querys 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 querys list.
@ -127,7 +127,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::create_w
for (auto const& pair : init_record) for (auto const& pair : init_record)
list.append(QueryParam { .name = pair.key, .value = pair.value }); list.append(QueryParam { .name = pair.key, .value = pair.value });
return URLSearchParams::create(window, move(list)); return URLSearchParams::create(realm, move(list));
} }
// 3. Otherwise: // 3. Otherwise:
@ -139,7 +139,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> URLSearchParams::create_w
StringView stripped_init = init_string.substring_view(init_string.starts_with('?')); StringView stripped_init = init_string.substring_view(init_string.starts_with('?'));
// b. Set querys list to the result of parsing init. // b. Set querys 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) void URLSearchParams::append(String const& name, String const& value)

View file

@ -23,8 +23,8 @@ class URLSearchParams : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(URLSearchParams, Bindings::PlatformObject); WEB_PLATFORM_OBJECT(URLSearchParams, Bindings::PlatformObject);
public: public:
static JS::NonnullGCPtr<URLSearchParams> create(HTML::Window&, Vector<QueryParam> list); static JS::NonnullGCPtr<URLSearchParams> create(JS::Realm&, Vector<QueryParam> list);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> create_with_global_object(HTML::Window&, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init); static WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> construct_impl(JS::Realm&, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init);
virtual ~URLSearchParams() override; virtual ~URLSearchParams() override;
@ -46,7 +46,7 @@ private:
friend class URL; friend class URL;
friend class URLSearchParamsIterator; friend class URLSearchParamsIterator;
URLSearchParams(HTML::Window&, Vector<QueryParam> list); URLSearchParams(JS::Realm&, Vector<QueryParam> list);
virtual void visit_edges(Cell::Visitor&) override; virtual void visit_edges(Cell::Visitor&) override;

View file

@ -6,8 +6,8 @@
#include <LibJS/Runtime/Array.h> #include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/IteratorOperations.h> #include <LibJS/Runtime/IteratorOperations.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/URLSearchParamsIteratorPrototype.h> #include <LibWeb/Bindings/URLSearchParamsIteratorPrototype.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/URL/URLSearchParamsIterator.h> #include <LibWeb/URL/URLSearchParamsIterator.h>
namespace Web::URL { namespace Web::URL {
@ -22,7 +22,7 @@ URLSearchParamsIterator::URLSearchParamsIterator(URLSearchParams const& url_sear
, m_url_search_params(url_search_params) , m_url_search_params(url_search_params)
, m_iteration_kind(iteration_kind) , m_iteration_kind(iteration_kind)
{ {
set_prototype(&url_search_params.global_object().ensure_web_prototype<Bindings::URLSearchParamsIteratorPrototype>("URLSearchParamsIterator")); set_prototype(&Bindings::ensure_web_prototype<Bindings::URLSearchParamsIteratorPrototype>(url_search_params.realm(), "URLSearchParamsIterator"));
} }
URLSearchParamsIterator::~URLSearchParamsIterator() = default; URLSearchParamsIterator::~URLSearchParamsIterator() = default;

View file

@ -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(); 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. // 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); content_loaded_event->set_bubbles(true);
document->dispatch_event(*content_loaded_event); document->dispatch_event(*content_loaded_event);
@ -209,7 +209,7 @@ void XMLDocumentBuilder::document_end()
return; return;
// Let window be the Document's relevant global object. // Let window be the Document's relevant global object.
JS::NonnullGCPtr<HTML::Window> window = document->window(); JS::NonnullGCPtr<HTML::Window> window = verify_cast<HTML::Window>(relevant_global_object(*document));
// Set the Document's load timing info's load event start time to the current high resolution time given window. // 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(); 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. // 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() // 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. // 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. // 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.