mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 05:17:34 +00:00
LibJS: Replace GlobalObject with VM in common AOs [Part 18/19]
This commit is contained in:
parent
7856886ed5
commit
25849f8a6d
95 changed files with 536 additions and 677 deletions
|
@ -128,8 +128,8 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
|
|||
// 2. If IsCallable(value) is true, then set value to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the IDL operation P on object O.
|
||||
if (value->is_function()) {
|
||||
value = JS::NativeFunction::create(
|
||||
realm, [function = JS::make_handle(*value)](auto&, auto& global_object) {
|
||||
return JS::call(global_object, function.value(), JS::js_undefined());
|
||||
realm, [function = JS::make_handle(*value)](auto& vm, auto&) {
|
||||
return JS::call(vm, function.value(), JS::js_undefined());
|
||||
},
|
||||
0, "");
|
||||
}
|
||||
|
@ -145,8 +145,8 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
|
|||
// 2. If e.[[NeedsGet]] is true, then set crossOriginGet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the getter of the IDL attribute P on object O.
|
||||
if (*entry.needs_get) {
|
||||
cross_origin_get = JS::NativeFunction::create(
|
||||
realm, [object_ptr, getter = JS::make_handle(*original_descriptor->get)](auto&, auto& global_object) {
|
||||
return JS::call(global_object, getter.cell(), object_ptr);
|
||||
realm, [object_ptr, getter = JS::make_handle(*original_descriptor->get)](auto& vm, auto&) {
|
||||
return JS::call(vm, getter.cell(), object_ptr);
|
||||
},
|
||||
0, "");
|
||||
}
|
||||
|
@ -157,8 +157,8 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo
|
|||
// If e.[[NeedsSet]] is true, then set crossOriginSet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the setter of the IDL attribute P on object O.
|
||||
if (*entry.needs_set) {
|
||||
cross_origin_set = JS::NativeFunction::create(
|
||||
realm, [object_ptr, setter = JS::make_handle(*original_descriptor->set)](auto&, auto& global_object) {
|
||||
return JS::call(global_object, setter.cell(), object_ptr);
|
||||
realm, [object_ptr, setter = JS::make_handle(*original_descriptor->set)](auto& vm, auto&) {
|
||||
return JS::call(vm, setter.cell(), object_ptr);
|
||||
},
|
||||
0, "");
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ JS::ThrowCompletionOr<JS::Value> cross_origin_get(JS::GlobalObject& global_objec
|
|||
return vm.throw_completion<DOMExceptionWrapper>(DOM::SecurityError::create(String::formatted("Can't get property '{}' on cross-origin object", property_key)));
|
||||
|
||||
// 7. Return ? Call(getter, Receiver).
|
||||
return JS::call(global_object, *getter, receiver);
|
||||
return JS::call(vm, *getter, receiver);
|
||||
}
|
||||
|
||||
// 7.2.3.6 CrossOriginSet ( O, P, V, Receiver ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginset-(-o,-p,-v,-receiver-)
|
||||
|
@ -222,7 +222,7 @@ JS::ThrowCompletionOr<bool> cross_origin_set(JS::GlobalObject& global_object, JS
|
|||
if (descriptor->set.has_value() && *descriptor->set) {
|
||||
// FIXME: Spec issue, `setter` isn't being defined.
|
||||
// 1. Perform ? Call(setter, Receiver, «V»).
|
||||
TRY(JS::call(global_object, *descriptor->set, receiver, value));
|
||||
TRY(JS::call(vm, *descriptor->set, receiver, value));
|
||||
|
||||
// 2. Return true.
|
||||
return true;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -106,8 +106,7 @@ JS::Completion invoke_callback(Bindings::CallbackType& callback, Optional<JS::Va
|
|||
|
||||
// 5. Let realm be F’s associated Realm.
|
||||
// See the comment about associated realm on step 4 of call_user_object_operation.
|
||||
auto& global_object = function_object->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = function_object->shape().realm();
|
||||
|
||||
// 6. Let relevant settings be realm’s settings object.
|
||||
auto& relevant_settings = verify_cast<HTML::EnvironmentSettingsObject>(*realm.host_defined());
|
||||
|
@ -125,7 +124,8 @@ JS::Completion invoke_callback(Bindings::CallbackType& callback, Optional<JS::Va
|
|||
// For simplicity, we currently make the caller do this. However, this means we can't throw exceptions at this point like the spec wants us to.
|
||||
|
||||
// 11. Let callResult be Call(F, thisArg, esArgs).
|
||||
auto call_result = JS::call(global_object, verify_cast<JS::FunctionObject>(*function_object), this_argument.value(), move(args));
|
||||
auto& vm = function_object->vm();
|
||||
auto call_result = JS::call(vm, verify_cast<JS::FunctionObject>(*function_object), this_argument.value(), move(args));
|
||||
|
||||
// 12. If callResult is an abrupt completion, set completion to callResult and jump to the step labeled return.
|
||||
if (call_result.is_throw_completion()) {
|
||||
|
|
|
@ -57,8 +57,7 @@ JS::Completion call_user_object_operation(Bindings::CallbackType& callback, Stri
|
|||
auto& object = *callback.callback.cell();
|
||||
|
||||
// 4. Let realm be O’s associated Realm.
|
||||
auto& global_object = object.global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& realm = object.shape().realm();
|
||||
|
||||
// 5. Let relevant settings be realm’s settings object.
|
||||
auto& relevant_settings = verify_cast<HTML::EnvironmentSettingsObject>(*realm.host_defined());
|
||||
|
@ -105,7 +104,8 @@ JS::Completion call_user_object_operation(Bindings::CallbackType& callback, Stri
|
|||
|
||||
// 12. Let callResult be Call(X, thisArg, esArgs).
|
||||
VERIFY(actual_function_object);
|
||||
auto call_result = JS::call(global_object, verify_cast<JS::FunctionObject>(*actual_function_object), this_argument.value(), forward<Args>(args)...);
|
||||
auto& vm = object.vm();
|
||||
auto call_result = JS::call(vm, verify_cast<JS::FunctionObject>(*actual_function_object), this_argument.value(), forward<Args>(args)...);
|
||||
|
||||
// 13. If callResult is an abrupt completion, set completion to callResult and jump to the step labeled return.
|
||||
if (call_result.is_throw_completion()) {
|
||||
|
|
|
@ -129,8 +129,6 @@ JS::VM& main_thread_vm()
|
|||
|
||||
// 8.1.5.3.1 HostCallJobCallback(callback, V, argumentsList), https://html.spec.whatwg.org/multipage/webappapis.html#hostcalljobcallback
|
||||
vm->host_call_job_callback = [](JS::JobCallback& callback, JS::Value this_value, JS::MarkedVector<JS::Value> arguments_list) {
|
||||
auto& realm = *vm->current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
auto& callback_host_defined = verify_cast<WebEngineCustomJobCallbackData>(*callback.custom_data);
|
||||
|
||||
// 1. Let incumbent settings be callback.[[HostDefined]].[[IncumbentSettings]]. (NOTE: Not necessary)
|
||||
|
@ -144,7 +142,7 @@ JS::VM& main_thread_vm()
|
|||
vm->push_execution_context(*callback_host_defined.active_script_context);
|
||||
|
||||
// 5. Let result be Call(callback.[[Callback]], V, argumentsList).
|
||||
auto result = JS::call(global_object, *callback.callback.cell(), this_value, move(arguments_list));
|
||||
auto result = JS::call(*vm, *callback.callback.cell(), this_value, move(arguments_list));
|
||||
|
||||
// 6. If script execution context is not null, then pop script execution context from the JavaScript execution context stack.
|
||||
if (callback_host_defined.active_script_context) {
|
||||
|
|
|
@ -216,7 +216,7 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(Wasm::Module
|
|||
for (auto& entry : arguments)
|
||||
argument_values.append(to_js_value(global_object, entry));
|
||||
|
||||
auto result_or_error = JS::call(global_object, function, JS::js_undefined(), move(argument_values));
|
||||
auto result_or_error = JS::call(vm, function, JS::js_undefined(), move(argument_values));
|
||||
if (result_or_error.is_error()) {
|
||||
return Wasm::Trap();
|
||||
}
|
||||
|
|
|
@ -83,16 +83,17 @@ DOM::ExceptionOr<String> XMLHttpRequest::response_text() const
|
|||
DOM::ExceptionOr<JS::Value> XMLHttpRequest::response()
|
||||
{
|
||||
auto& global_object = wrapper()->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
auto& vm = wrapper()->vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 1. If this’s response type is the empty string or "text", then:
|
||||
if (m_response_type == Bindings::XMLHttpRequestResponseType::Empty || m_response_type == Bindings::XMLHttpRequestResponseType::Text) {
|
||||
// 1. If this’s state is not loading or done, then return the empty string.
|
||||
if (m_ready_state != ReadyState::Loading && m_ready_state != ReadyState::Done)
|
||||
return JS::Value(JS::js_string(global_object.heap(), ""));
|
||||
return JS::Value(JS::js_string(vm, ""));
|
||||
|
||||
// 2. Return the result of getting a text response for this.
|
||||
return JS::Value(JS::js_string(global_object.heap(), get_text_response()));
|
||||
return JS::Value(JS::js_string(vm, get_text_response()));
|
||||
}
|
||||
// 2. If this’s state is not done, then return null.
|
||||
if (m_ready_state != ReadyState::Done)
|
||||
|
@ -143,7 +144,7 @@ DOM::ExceptionOr<JS::Value> XMLHttpRequest::response()
|
|||
// 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.
|
||||
TextCodec::UTF8Decoder decoder;
|
||||
|
||||
auto json_object_result = JS::call(global_object, global_object.json_parse_function(), JS::js_undefined(), JS::js_string(global_object.heap(), decoder.to_utf8({ m_received_bytes.data(), m_received_bytes.size() })));
|
||||
auto json_object_result = JS::call(vm, global_object.json_parse_function(), JS::js_undefined(), JS::js_string(global_object.heap(), decoder.to_utf8({ m_received_bytes.data(), m_received_bytes.size() })));
|
||||
if (json_object_result.is_error())
|
||||
return JS::Value(JS::js_null());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue