diff options
author | Andrew Kaster <akaster@serenityos.org> | 2022-09-25 18:11:21 -0600 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-01 21:05:32 +0100 |
commit | 4bb6345b2ff348bd604b17c7dd4e81e61d52b658 (patch) | |
tree | 0f6c0a111e022358921f6c8912972aae3975e32f /Userland/Libraries/LibWeb/Encoding | |
parent | 4878a18ee7ebe0c9d50880f804bd2dc22b1c751c (diff) | |
download | serenity-4bb6345b2ff348bd604b17c7dd4e81e61d52b658.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/Encoding')
-rw-r--r-- | Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp | 14 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Encoding/TextDecoder.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Encoding/TextEncoder.h | 4 |
4 files changed, 17 insertions, 17 deletions
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 <AK/FlyString.h> #include <LibJS/Runtime/TypedArray.h> +#include <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/Encoding/TextDecoder.h> -#include <LibWeb/HTML/Window.h> #include <LibWeb/WebIDL/AbstractOperations.h> 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); if (!decoder) 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 -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<String> TextDecoder::decode(JS::Handle<JS::Object> 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<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; @@ -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 <AK/FlyString.h> #include <LibJS/Runtime/TypedArray.h> +#include <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/Encoding/TextEncoder.h> -#include <LibWeb/HTML/Window.h> 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) - : 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<TextEncoder> create_with_global_object(HTML::Window&); + static JS::NonnullGCPtr<TextEncoder> 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&); }; } |