mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +00:00
LibWeb: Remove unecessary dependence on Window from Fetch, XHR, FileAPI
These classes only needed Window to get at its realm. Pass a realm directly to construct Fetch, XMLHttpRequest and FileAPI classes.
This commit is contained in:
parent
6a10352712
commit
4878a18ee7
17 changed files with 144 additions and 169 deletions
|
@ -17,14 +17,12 @@ namespace Web::Fetch {
|
|||
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
|
||||
WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm, BodyInitOrReadbleBytes const& object, bool keepalive)
|
||||
{
|
||||
auto& window = verify_cast<HTML::Window>(realm.global_object());
|
||||
|
||||
// 1. Let stream be object if object is a ReadableStream object. Otherwise, let stream be a new ReadableStream, and set up stream.
|
||||
Streams::ReadableStream* stream;
|
||||
if (auto const* handle = object.get_pointer<JS::Handle<Streams::ReadableStream>>()) {
|
||||
stream = const_cast<Streams::ReadableStream*>(handle->cell());
|
||||
} else {
|
||||
stream = realm.heap().allocate<Streams::ReadableStream>(realm, window);
|
||||
stream = realm.heap().allocate<Streams::ReadableStream>(realm, verify_cast<HTML::Window>(realm.global_object()));
|
||||
}
|
||||
|
||||
// FIXME: 2. Let action be null.
|
||||
|
@ -51,19 +49,19 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
|
|||
},
|
||||
[&](ReadonlyBytes bytes) -> WebIDL::ExceptionOr<void> {
|
||||
// Set source to object.
|
||||
source = TRY_OR_RETURN_OOM(window, ByteBuffer::copy(bytes));
|
||||
source = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(bytes));
|
||||
return {};
|
||||
},
|
||||
[&](JS::Handle<JS::Object> const& buffer_source) -> WebIDL::ExceptionOr<void> {
|
||||
// Set source to a copy of the bytes held by object.
|
||||
source = TRY_OR_RETURN_OOM(window, WebIDL::get_buffer_source_copy(*buffer_source.cell()));
|
||||
source = TRY_OR_RETURN_OOM(realm, WebIDL::get_buffer_source_copy(*buffer_source.cell()));
|
||||
return {};
|
||||
},
|
||||
[&](JS::Handle<URL::URLSearchParams> const& url_search_params) -> WebIDL::ExceptionOr<void> {
|
||||
// Set source to the result of running the application/x-www-form-urlencoded serializer with object’s list.
|
||||
source = url_search_params->to_string().to_byte_buffer();
|
||||
// Set type to `application/x-www-form-urlencoded;charset=UTF-8`.
|
||||
type = TRY_OR_RETURN_OOM(window, ByteBuffer::copy("application/x-www-form-urlencoded;charset=UTF-8"sv.bytes()));
|
||||
type = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy("application/x-www-form-urlencoded;charset=UTF-8"sv.bytes()));
|
||||
return {};
|
||||
},
|
||||
[&](String const& scalar_value_string) -> WebIDL::ExceptionOr<void> {
|
||||
|
@ -71,7 +69,7 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
|
|||
// Set source to the UTF-8 encoding of object.
|
||||
source = scalar_value_string.to_byte_buffer();
|
||||
// Set type to `text/plain;charset=UTF-8`.
|
||||
type = TRY_OR_RETURN_OOM(window, ByteBuffer::copy("text/plain;charset=UTF-8"sv.bytes()));
|
||||
type = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy("text/plain;charset=UTF-8"sv.bytes()));
|
||||
return {};
|
||||
},
|
||||
[&](JS::Handle<Streams::ReadableStream> const& stream) -> WebIDL::ExceptionOr<void> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue