mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:08:10 +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() });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue