diff --git a/Userland/Libraries/LibWeb/Fetch/Body.cpp b/Userland/Libraries/LibWeb/Fetch/Body.cpp index 95d95b82be..db33872859 100644 --- a/Userland/Libraries/LibWeb/Fetch/Body.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Body.cpp @@ -132,7 +132,7 @@ WebIDL::ExceptionOr package_data(JS::Realm& realm, ByteBuffer bytes, } case PackageDataType::JSON: // Return the result of running parse JSON from bytes on bytes. - return Infra::parse_json_bytes_to_javascript_value(vm, bytes); + return Infra::parse_json_bytes_to_javascript_value(realm, bytes); case PackageDataType::Text: // Return the result of running UTF-8 decode on bytes. return JS::PrimitiveString::create(vm, TRY_OR_THROW_OOM(vm, String::from_utf8(bytes))); diff --git a/Userland/Libraries/LibWeb/Fetch/FetchMethod.cpp b/Userland/Libraries/LibWeb/Fetch/FetchMethod.cpp index ed4fa016ae..1743c9715f 100644 --- a/Userland/Libraries/LibWeb/Fetch/FetchMethod.cpp +++ b/Userland/Libraries/LibWeb/Fetch/FetchMethod.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,7 @@ JS::NonnullGCPtr fetch_impl(JS::VM& vm, RequestInfo const& input, R if (exception_or_request_object.is_exception()) { // FIXME: We should probably make this a public API? auto throw_completion = Bindings::Detail::dom_exception_to_throw_completion(vm, exception_or_request_object.release_error()); - WebIDL::reject_promise(vm, promise_capability, *throw_completion.value()); + WebIDL::reject_promise(realm, promise_capability, *throw_completion.value()); return verify_cast(*promise_capability->promise().ptr()); } auto request_object = exception_or_request_object.release_value(); @@ -47,7 +48,7 @@ JS::NonnullGCPtr fetch_impl(JS::VM& vm, RequestInfo const& input, R // 4. If requestObject’s signal is aborted, then: if (request_object->signal()->aborted()) { // 1. Abort the fetch() call with p, request, null, and requestObject’s signal’s abort reason. - abort_fetch(vm, promise_capability, request, nullptr, request_object->signal()->reason()); + abort_fetch(realm, promise_capability, request, nullptr, request_object->signal()->reason()); // 2. Return p. return verify_cast(*promise_capability->promise().ptr()); @@ -79,11 +80,21 @@ JS::NonnullGCPtr fetch_impl(JS::VM& vm, RequestInfo const& input, R // 12. Set controller to the result of calling fetch given request and processResponse given response being these // steps: - auto process_response = [&vm, locally_aborted, promise_capability, request, response_object_handle, &relevant_realm](JS::NonnullGCPtr response) mutable { + auto process_response = [locally_aborted, promise_capability, request, response_object_handle, &relevant_realm](JS::NonnullGCPtr response) mutable { // 1. If locallyAborted is true, then abort these steps. if (locally_aborted->value()) return; + // NOTE: Not part of the spec, but we need to have an execution context on the stack to call native functions. + // (In this case, Promise functions) + auto& environment_settings_object = Bindings::host_defined_environment_settings_object(relevant_realm); + environment_settings_object.prepare_to_run_script(); + + ScopeGuard guard = [&]() { + // See above NOTE. + environment_settings_object.clean_up_after_running_script(); + }; + // 2. If response’s aborted flag is set, then: if (response->aborted()) { // FIXME: 1. Let deserializedError be the result of deserialize a serialized abort reason given controller’s @@ -91,7 +102,7 @@ JS::NonnullGCPtr fetch_impl(JS::VM& vm, RequestInfo const& input, R auto deserialized_error = JS::js_undefined(); // 2. Abort the fetch() call with p, request, responseObject, and deserializedError. - abort_fetch(vm, promise_capability, request, response_object_handle.cell(), deserialized_error); + abort_fetch(relevant_realm, promise_capability, request, response_object_handle.cell(), deserialized_error); // 3. Abort these steps. return; @@ -100,7 +111,7 @@ JS::NonnullGCPtr fetch_impl(JS::VM& vm, RequestInfo const& input, R // 3. If response is a network error, then reject p with a TypeError and abort these steps. if (response->is_network_error()) { auto message = response->network_error_message().value_or("Response is a network error"sv); - WebIDL::reject_promise(vm, promise_capability, JS::TypeError::create(relevant_realm, message).release_allocated_value_but_fixme_should_propagate_errors()); + WebIDL::reject_promise(relevant_realm, promise_capability, JS::TypeError::create(relevant_realm, message).release_allocated_value_but_fixme_should_propagate_errors()); return; } @@ -110,7 +121,7 @@ JS::NonnullGCPtr fetch_impl(JS::VM& vm, RequestInfo const& input, R response_object_handle = JS::make_handle(response_object); // 5. Resolve p with responseObject. - WebIDL::resolve_promise(vm, promise_capability, response_object); + WebIDL::resolve_promise(relevant_realm, promise_capability, response_object); }; controller = MUST(Fetching::fetch( realm, @@ -126,7 +137,7 @@ JS::NonnullGCPtr fetch_impl(JS::VM& vm, RequestInfo const& input, R }))); // 11. Add the following abort steps to requestObject’s signal: - request_object->signal()->add_abort_algorithm([&vm, locally_aborted, request, controller, promise_capability_handle = JS::make_handle(*promise_capability), request_object_handle = JS::make_handle(*request_object), response_object_handle] { + request_object->signal()->add_abort_algorithm([locally_aborted, request, controller, promise_capability_handle = JS::make_handle(*promise_capability), request_object_handle = JS::make_handle(*request_object), response_object_handle, &relevant_realm] { dbgln_if(WEB_FETCH_DEBUG, "Fetch: Request object signal's abort algorithm called"); auto& promise_capability = *promise_capability_handle; @@ -140,10 +151,10 @@ JS::NonnullGCPtr fetch_impl(JS::VM& vm, RequestInfo const& input, R VERIFY(controller); // 3. Abort controller with requestObject’s signal’s abort reason. - controller->abort(vm, request_object.signal()->reason()); + controller->abort(relevant_realm, request_object.signal()->reason()); // 4. Abort the fetch() call with p, request, responseObject, and requestObject’s signal’s abort reason. - abort_fetch(vm, promise_capability, request, response_object, request_object.signal()->reason()); + abort_fetch(relevant_realm, promise_capability, request, response_object, request_object.signal()->reason()); }); // 13. Return p. @@ -151,13 +162,13 @@ JS::NonnullGCPtr fetch_impl(JS::VM& vm, RequestInfo const& input, R } // https://fetch.spec.whatwg.org/#abort-fetch -void abort_fetch(JS::VM& vm, WebIDL::Promise const& promise, JS::NonnullGCPtr request, JS::GCPtr response_object, JS::Value error) +void abort_fetch(JS::Realm& realm, WebIDL::Promise const& promise, JS::NonnullGCPtr request, JS::GCPtr response_object, JS::Value error) { dbgln_if(WEB_FETCH_DEBUG, "Fetch: Aborting fetch with: request @ {}, error = {}", request.ptr(), error); // 1. Reject promise with error. // NOTE: This is a no-op if promise has already fulfilled. - WebIDL::reject_promise(vm, promise, error); + WebIDL::reject_promise(realm, promise, error); // 2. If request’s body is non-null and is readable, then cancel request’s body with error. if (auto* body = request->body().get_pointer(); body != nullptr && body->stream()->is_readable()) { diff --git a/Userland/Libraries/LibWeb/Fetch/FetchMethod.h b/Userland/Libraries/LibWeb/Fetch/FetchMethod.h index 7f0b31e306..b722850a1c 100644 --- a/Userland/Libraries/LibWeb/Fetch/FetchMethod.h +++ b/Userland/Libraries/LibWeb/Fetch/FetchMethod.h @@ -15,6 +15,6 @@ namespace Web::Fetch { JS::NonnullGCPtr fetch_impl(JS::VM&, RequestInfo const& input, RequestInit const& init = {}); -void abort_fetch(JS::VM&, WebIDL::Promise const&, JS::NonnullGCPtr, JS::GCPtr, JS::Value error); +void abort_fetch(JS::Realm&, WebIDL::Promise const&, JS::NonnullGCPtr, JS::GCPtr, JS::Value error); } diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index f7a5480b3a..094642dd5d 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -759,7 +759,7 @@ WebIDL::ExceptionOr> http_fetch(JS::Realm& rea // 4. If request’s service-workers mode is "all", then: if (request->service_workers_mode() == Infrastructure::Request::ServiceWorkersMode::All) { // 1. Let requestForServiceWorker be a clone of request. - auto request_for_service_worker = TRY(request->clone(vm)); + auto request_for_service_worker = TRY(request->clone(realm)); // 2. If requestForServiceWorker’s body is non-null, then: if (!request_for_service_worker->body().has()) { @@ -1147,7 +1147,7 @@ WebIDL::ExceptionOr> http_network_or_cache_fet // NOTE: Implementations are encouraged to avoid teeing request’s body’s stream when request’s body’s // source is null as only a single body is needed in that case. E.g., when request’s body’s source // is null, redirects and authentication will end up failing the fetch. - http_request = TRY(request->clone(vm)); + http_request = TRY(request->clone(realm)); // 2. Set httpFetchParams to a copy of fetchParams. // 3. Set httpFetchParams’s request to httpRequest. diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp index b26a01d80f..db80400e20 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp @@ -55,10 +55,8 @@ JS::NonnullGCPtr FetchController::extract_full_timing_info() co } // https://fetch.spec.whatwg.org/#fetch-controller-abort -void FetchController::abort(JS::VM& vm, Optional error) +void FetchController::abort(JS::Realm& realm, Optional error) { - auto& realm = *vm.current_realm(); - // 1. Set controller’s state to "aborted". m_state = State::Aborted; diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h index fd9341c519..fafd294563 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h @@ -36,7 +36,7 @@ public: void report_timing(JS::Object const&) const; void process_next_manual_redirect() const; [[nodiscard]] JS::NonnullGCPtr extract_full_timing_info() const; - void abort(JS::VM&, Optional); + void abort(JS::Realm&, Optional); void terminate(); private: diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp index 019f3be8ca..c10f4af16e 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp @@ -25,16 +25,12 @@ Body::Body(JS::Handle stream, SourceType source, Option } // https://fetch.spec.whatwg.org/#concept-body-clone -WebIDL::ExceptionOr Body::clone() const +WebIDL::ExceptionOr Body::clone(JS::Realm& realm) const { // To clone a body body, run these steps: - - auto& vm = Bindings::main_thread_vm(); - auto& realm = *vm.current_realm(); - // FIXME: 1. Let « out1, out2 » be the result of teeing body’s stream. // FIXME: 2. Set body’s stream to out1. - auto out2 = MUST_OR_THROW_OOM(vm.heap().allocate(realm, realm)); + auto out2 = MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm)); // 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 }; diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h index 616993ba5b..c88c8f5833 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h @@ -31,7 +31,7 @@ public: [[nodiscard]] SourceType const& source() const { return m_source; } [[nodiscard]] Optional const& length() const { return m_length; } - WebIDL::ExceptionOr clone() const; + WebIDL::ExceptionOr clone(JS::Realm&) const; WebIDL::ExceptionOr> fully_read_as_promise() const; diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp index 2dd6983a7e..74d39fc689 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp @@ -195,9 +195,10 @@ ErrorOr Request::byte_serialize_origin() const } // https://fetch.spec.whatwg.org/#concept-request-clone -WebIDL::ExceptionOr> Request::clone(JS::VM& vm) const +WebIDL::ExceptionOr> Request::clone(JS::Realm& realm) const { // To clone a request request, run these steps: + auto& vm = realm.vm(); // 1. Let newRequest be a copy of request, except for its body. auto new_request = Infrastructure::Request::create(vm); @@ -242,7 +243,7 @@ WebIDL::ExceptionOr> Request::clone(JS::VM& vm) const // 2. If request’s body is non-null, set newRequest’s body to the result of cloning request’s body. if (auto const* body = m_body.get_pointer()) - new_request->set_body(TRY(body->clone())); + new_request->set_body(TRY(body->clone(realm))); // 3. Return newRequest. return new_request; diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h index 22db8d7fe3..b3237ba135 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h @@ -297,7 +297,7 @@ public: [[nodiscard]] ErrorOr serialize_origin() const; [[nodiscard]] ErrorOr byte_serialize_origin() const; - [[nodiscard]] WebIDL::ExceptionOr> clone(JS::VM&) const; + [[nodiscard]] WebIDL::ExceptionOr> clone(JS::Realm&) const; [[nodiscard]] ErrorOr add_range_header(u64 first, Optional const& last); [[nodiscard]] ErrorOr add_origin_header(); diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp index f7511be576..891518a74a 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp @@ -127,13 +127,14 @@ ErrorOr> Response::location_url(Optional const& reques } // https://fetch.spec.whatwg.org/#concept-response-clone -WebIDL::ExceptionOr> Response::clone(JS::VM& vm) const +WebIDL::ExceptionOr> Response::clone(JS::Realm& realm) const { // To clone a response response, run these steps: + auto& vm = realm.vm(); // 1. If response is a filtered response, then return a new identical filtered response whose internal response is a clone of response’s internal response. if (is(*this)) { - auto internal_response = TRY(static_cast(*this).internal_response()->clone(vm)); + auto internal_response = TRY(static_cast(*this).internal_response()->clone(realm)); if (is(*this)) return TRY_OR_THROW_OOM(vm, BasicFilteredResponse::create(vm, internal_response)); if (is(*this)) @@ -164,7 +165,7 @@ WebIDL::ExceptionOr> Response::clone(JS::VM& vm) cons // 3. If response’s body is non-null, then set newResponse’s body to the result of cloning response’s body. if (m_body.has_value()) - new_response->set_body(TRY(m_body->clone())); + new_response->set_body(TRY(m_body->clone(realm))); // 4. Return newResponse. return new_response; diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h index 1738b2ed55..da9bfa5961 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h @@ -106,7 +106,7 @@ public: [[nodiscard]] Optional url() const; [[nodiscard]] ErrorOr> location_url(Optional const& request_fragment) const; - [[nodiscard]] WebIDL::ExceptionOr> clone(JS::VM&) const; + [[nodiscard]] WebIDL::ExceptionOr> clone(JS::Realm&) const; // Non-standard [[nodiscard]] Optional network_error_message() const; diff --git a/Userland/Libraries/LibWeb/Fetch/Request.cpp b/Userland/Libraries/LibWeb/Fetch/Request.cpp index 07a090f0e1..154a65514a 100644 --- a/Userland/Libraries/LibWeb/Fetch/Request.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Request.cpp @@ -634,14 +634,14 @@ Bindings::RequestDuplex Request::duplex() const // https://fetch.spec.whatwg.org/#dom-request-clone WebIDL::ExceptionOr> Request::clone() const { - auto& vm = this->vm(); + auto& realm = this->realm(); // 1. If this is unusable, then throw a TypeError. if (is_unusable()) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Request is unusable"sv }; // 2. Let clonedRequest be the result of cloning this’s request. - auto cloned_request = TRY(m_request->clone(vm)); + auto cloned_request = TRY(m_request->clone(realm)); // 3. Let clonedRequestObject be the result of creating a Request object, given clonedRequest, this’s headers’s guard, and this’s relevant Realm. auto cloned_request_object = TRY(Request::create(HTML::relevant_realm(*this), cloned_request, m_headers->guard())); diff --git a/Userland/Libraries/LibWeb/Fetch/Response.cpp b/Userland/Libraries/LibWeb/Fetch/Response.cpp index 0173679bdb..c0973cc363 100644 --- a/Userland/Libraries/LibWeb/Fetch/Response.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Response.cpp @@ -286,14 +286,14 @@ JS::NonnullGCPtr Response::headers() const // https://fetch.spec.whatwg.org/#dom-response-clone WebIDL::ExceptionOr> Response::clone() const { - auto& vm = this->vm(); + auto& realm = this->realm(); // 1. If this is unusable, then throw a TypeError. if (is_unusable()) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Response is unusable"sv }; // 2. Let clonedResponse be the result of cloning this’s response. - auto cloned_response = TRY(m_response->clone(vm)); + auto cloned_response = TRY(m_response->clone(realm)); // 3. Return the result of creating a Response object, given clonedResponse, this’s headers’s guard, and this’s relevant Realm. return TRY(Response::create(HTML::relevant_realm(*this), cloned_response, m_headers->guard())); diff --git a/Userland/Libraries/LibWeb/Infra/JSON.cpp b/Userland/Libraries/LibWeb/Infra/JSON.cpp index bf00474d73..472688925e 100644 --- a/Userland/Libraries/LibWeb/Infra/JSON.cpp +++ b/Userland/Libraries/LibWeb/Infra/JSON.cpp @@ -15,23 +15,25 @@ namespace Web::Infra { // https://infra.spec.whatwg.org/#parse-a-json-string-to-a-javascript-value -WebIDL::ExceptionOr parse_json_string_to_javascript_value(JS::VM& vm, StringView string) +WebIDL::ExceptionOr parse_json_string_to_javascript_value(JS::Realm& realm, StringView string) { - auto& realm = *vm.current_realm(); + auto& vm = realm.vm(); // 1. Return ? Call(%JSON.parse%, undefined, « string »). return TRY(JS::call(vm, realm.intrinsics().json_parse_function(), JS::js_undefined(), MUST_OR_THROW_OOM(JS::PrimitiveString::create(vm, string)))); } // https://infra.spec.whatwg.org/#parse-json-bytes-to-a-javascript-value -WebIDL::ExceptionOr parse_json_bytes_to_javascript_value(JS::VM& vm, ReadonlyBytes bytes) +WebIDL::ExceptionOr parse_json_bytes_to_javascript_value(JS::Realm& realm, ReadonlyBytes bytes) { + auto& vm = realm.vm(); + // 1. Let string be the result of running UTF-8 decode on bytes. TextCodec::UTF8Decoder decoder; auto string = TRY_OR_THROW_OOM(vm, decoder.to_utf8(bytes)); // 2. Return the result of parsing a JSON string to an Infra value given string. - return parse_json_string_to_javascript_value(vm, string); + return parse_json_string_to_javascript_value(realm, string); } // https://infra.spec.whatwg.org/#serialize-a-javascript-value-to-a-json-string diff --git a/Userland/Libraries/LibWeb/Infra/JSON.h b/Userland/Libraries/LibWeb/Infra/JSON.h index 8777679b53..e359cd4180 100644 --- a/Userland/Libraries/LibWeb/Infra/JSON.h +++ b/Userland/Libraries/LibWeb/Infra/JSON.h @@ -12,8 +12,8 @@ namespace Web::Infra { -WebIDL::ExceptionOr parse_json_string_to_javascript_value(JS::VM&, StringView); -WebIDL::ExceptionOr parse_json_bytes_to_javascript_value(JS::VM&, ReadonlyBytes); +WebIDL::ExceptionOr parse_json_string_to_javascript_value(JS::Realm&, StringView); +WebIDL::ExceptionOr parse_json_bytes_to_javascript_value(JS::Realm&, ReadonlyBytes); WebIDL::ExceptionOr serialize_javascript_value_to_json_string(JS::VM&, JS::Value); WebIDL::ExceptionOr serialize_javascript_value_to_json_bytes(JS::VM&, JS::Value); diff --git a/Userland/Libraries/LibWeb/WebIDL/Promise.cpp b/Userland/Libraries/LibWeb/WebIDL/Promise.cpp index 436c03cfbe..69ba18800b 100644 --- a/Userland/Libraries/LibWeb/WebIDL/Promise.cpp +++ b/Userland/Libraries/LibWeb/WebIDL/Promise.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -69,20 +70,23 @@ JS::NonnullGCPtr create_rejected_promise(JS::Realm& realm, JS::Value re } // https://webidl.spec.whatwg.org/#resolve -void resolve_promise(JS::VM& vm, Promise const& promise, JS::Value value) +void resolve_promise(JS::Realm& realm, Promise const& promise, JS::Value value) { + auto& vm = realm.vm(); + // 1. If x is not given, then let it be the undefined value. // NOTE: This is done via the default argument. // 2. Let value be the result of converting x to an ECMAScript value. - // 3. Perform ! Call(p.[[Resolve]], undefined, « value »). MUST(JS::call(vm, *promise.resolve(), JS::js_undefined(), value)); } // https://webidl.spec.whatwg.org/#reject -void reject_promise(JS::VM& vm, Promise const& promise, JS::Value reason) +void reject_promise(JS::Realm& realm, Promise const& promise, JS::Value reason) { + auto& vm = realm.vm(); + // 1. Perform ! Call(p.[[Reject]], undefined, « r »). MUST(JS::call(vm, *promise.reject(), JS::js_undefined(), reason)); } diff --git a/Userland/Libraries/LibWeb/WebIDL/Promise.h b/Userland/Libraries/LibWeb/WebIDL/Promise.h index 6292807928..37c8f1e14c 100644 --- a/Userland/Libraries/LibWeb/WebIDL/Promise.h +++ b/Userland/Libraries/LibWeb/WebIDL/Promise.h @@ -22,8 +22,8 @@ using Promise = JS::PromiseCapability; JS::NonnullGCPtr create_promise(JS::Realm&); JS::NonnullGCPtr create_resolved_promise(JS::Realm&, JS::Value); JS::NonnullGCPtr create_rejected_promise(JS::Realm&, JS::Value); -void resolve_promise(JS::VM&, Promise const&, JS::Value = JS::js_undefined()); -void reject_promise(JS::VM&, Promise const&, JS::Value); +void resolve_promise(JS::Realm&, Promise const&, JS::Value = JS::js_undefined()); +void reject_promise(JS::Realm&, Promise const&, JS::Value); JS::NonnullGCPtr react_to_promise(Promise const&, Optional on_fulfilled_callback, Optional on_rejected_callback); JS::NonnullGCPtr upon_fulfillment(Promise const&, ReactionSteps); JS::NonnullGCPtr upon_rejection(Promise const&, ReactionSteps); diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 86c6e1de8f..9b18be22eb 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -182,7 +182,7 @@ WebIDL::ExceptionOr XMLHttpRequest::response() return JS::js_null(); // 3. Let jsonObject be the result of running parse JSON from bytes on this’s received bytes. If that threw an exception, then return null. - auto json_object_result = Infra::parse_json_bytes_to_javascript_value(vm, m_received_bytes); + auto json_object_result = Infra::parse_json_bytes_to_javascript_value(realm(), m_received_bytes); if (json_object_result.is_error()) return JS::js_null();