mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 16:57:34 +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:
parent
4878a18ee7
commit
4bb6345b2f
30 changed files with 125 additions and 126 deletions
|
@ -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() });
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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&);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue