summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormjz19910 <matthias291999@gmail.com>2022-01-23 02:12:26 -0700
committerLinus Groh <mail@linusgroh.de>2022-01-23 15:24:45 +0000
commit1ef633472b730ac173a9108226f8ebd7a73dbacf (patch)
tree90f60e5eb1fe8e4eb70b0a906bdd697bf508d32b
parentd436746c952fa904e53413279134266ce965a30e (diff)
downloadserenity-1ef633472b730ac173a9108226f8ebd7a73dbacf.zip
Everywhere: Convert VM::call() to JS::call()
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp2
-rw-r--r--Tests/LibWeb/test-web.cpp8
-rw-r--r--Userland/Applications/Spreadsheet/Spreadsheet.cpp5
-rw-r--r--Userland/Libraries/LibJS/AST.cpp2
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp32
-rw-r--r--Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp26
-rw-r--r--Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/JSONObject.cpp7
-rw-r--r--Userland/Libraries/LibJS/Runtime/MapConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/MapPrototype.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.cpp15
-rw-r--r--Userland/Libraries/LibJS/Runtime/Promise.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp40
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseJobs.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseReaction.h32
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/ProxyObject.cpp22
-rw-r--r--Userland/Libraries/LibJS/Runtime/ReflectObject.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetPrototype.cpp3
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringPrototype.cpp16
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp14
-rw-r--r--Userland/Libraries/LibJS/Runtime/VM.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp7
-rw-r--r--Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp2
-rw-r--r--Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp3
-rw-r--r--Userland/Libraries/LibWeb/DOM/Window.cpp7
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp2
37 files changed, 160 insertions, 157 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
index 78b4bf42d1..6390a86039 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp
@@ -3237,7 +3237,7 @@ JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::for_each)
generate_variable_statement(iterator_generator, "wrapped_key", interface.pair_iterator_types->get<0>(), "key");
generate_variable_statement(iterator_generator, "wrapped_value", interface.pair_iterator_types->get<1>(), "value");
iterator_generator.append(R"~~~(
- TRY(vm.call(callback.as_function(), vm.argument(1), wrapped_value, wrapped_key, this_value));
+ TRY(call(global_object, callback.as_function(), vm.argument(1), wrapped_value, wrapped_key, this_value));
return {};
}));
diff --git a/Tests/LibWeb/test-web.cpp b/Tests/LibWeb/test-web.cpp
index 0bd22a29ed..fd21598bbb 100644
--- a/Tests/LibWeb/test-web.cpp
+++ b/Tests/LibWeb/test-web.cpp
@@ -62,8 +62,8 @@ TESTJS_GLOBAL_FUNCTION(after_initial_page_load, afterInitialPageLoad)
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "Function");
}
- after_initial_load_hooks.append([fn = JS::make_handle(&function.as_function()), &vm](auto& page_object) {
- [[maybe_unused]] auto unused = vm.call(const_cast<JS::FunctionObject&>(*fn.cell()), JS::js_undefined(), &page_object);
+ after_initial_load_hooks.append([fn = JS::make_handle(&function.as_function()), &global_object](auto& page_object) {
+ [[maybe_unused]] auto unused = JS::call(global_object, const_cast<JS::FunctionObject&>(*fn.cell()), JS::js_undefined(), &page_object);
});
return JS::js_undefined();
}
@@ -76,8 +76,8 @@ TESTJS_GLOBAL_FUNCTION(before_initial_page_load, beforeInitialPageLoad)
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "Function");
}
- before_initial_load_hooks.append([fn = JS::make_handle(&function.as_function()), &vm](auto& page_object) {
- [[maybe_unused]] auto unused = vm.call(const_cast<JS::FunctionObject&>(*fn.cell()), JS::js_undefined(), &page_object);
+ before_initial_load_hooks.append([fn = JS::make_handle(&function.as_function()), &global_object](auto& page_object) {
+ [[maybe_unused]] auto unused = JS::call(global_object, const_cast<JS::FunctionObject&>(*fn.cell()), JS::js_undefined(), &page_object);
});
return JS::js_undefined();
}
diff --git a/Userland/Applications/Spreadsheet/Spreadsheet.cpp b/Userland/Applications/Spreadsheet/Spreadsheet.cpp
index a514921805..cc0a3721b8 100644
--- a/Userland/Applications/Spreadsheet/Spreadsheet.cpp
+++ b/Userland/Applications/Spreadsheet/Spreadsheet.cpp
@@ -19,6 +19,7 @@
#include <LibCore/File.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Parser.h>
+#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <ctype.h>
#include <unistd.h>
@@ -400,7 +401,7 @@ RefPtr<Sheet> Sheet::from_json(const JsonObject& object, Workbook& workbook)
break;
case Cell::Formula: {
auto& interpreter = sheet->interpreter();
- auto value_or_error = interpreter.vm().call(parse_function, json, JS::js_string(interpreter.heap(), obj.get("value").as_string()));
+ auto value_or_error = JS::call(interpreter.global_object(), parse_function, json, JS::js_string(interpreter.heap(), obj.get("value").as_string()));
VERIFY(!value_or_error.is_error());
cell = make<Cell>(obj.get("source").to_string(), value_or_error.release_value(), position, *sheet);
break;
@@ -530,7 +531,7 @@ JsonObject Sheet::to_json() const
if (it.value->kind() == Cell::Formula) {
data.set("source", it.value->data());
auto json = interpreter().global_object().get_without_side_effects("JSON");
- auto stringified_or_error = interpreter().vm().call(json.as_object().get_without_side_effects("stringify").as_function(), json, it.value->evaluated_data());
+ auto stringified_or_error = JS::call(interpreter().global_object(), json.as_object().get_without_side_effects("stringify").as_function(), json, it.value->evaluated_data());
VERIFY(!stringified_or_error.is_error());
data.set("value", stringified_or_error.release_value().to_string_without_side_effects());
} else {
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp
index a1ef0cc523..41ab8ca398 100644
--- a/Userland/Libraries/LibJS/AST.cpp
+++ b/Userland/Libraries/LibJS/AST.cpp
@@ -426,7 +426,7 @@ Completion CallExpression::execute(Interpreter& interpreter, GlobalObject& globa
return perform_eval(script_value, global_object, vm.in_strict_mode() ? CallerMode::Strict : CallerMode::NonStrict, EvalMode::Direct);
}
- return vm.call(function, this_value, move(arg_list));
+ return call(global_object, function, this_value, move(arg_list));
}
// 13.3.7.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp
index 1e2ec7e88f..aeb51288d4 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp
@@ -399,7 +399,7 @@ void Call::execute_impl(Bytecode::Interpreter& interpreter) const
Value return_value;
if (m_argument_count == 0 && m_type == CallType::Call) {
- auto return_value_or_error = interpreter.vm().call(function, this_value);
+ auto return_value_or_error = call(interpreter.global_object(), function, this_value);
if (!return_value_or_error.is_error())
return_value = return_value_or_error.release_value();
} else {
@@ -408,7 +408,7 @@ void Call::execute_impl(Bytecode::Interpreter& interpreter) const
argument_values.append(interpreter.reg(m_arguments[i]));
}
if (m_type == CallType::Call) {
- auto return_value_or_error = interpreter.vm().call(function, this_value, move(argument_values));
+ auto return_value_or_error = call(interpreter.global_object(), function, this_value, move(argument_values));
if (return_value_or_error.is_error())
return;
return_value = return_value_or_error.release_value();
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp
index a1590a0ed9..0f457e4c04 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp
@@ -127,7 +127,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
Value mapped_value;
if (map_fn) {
- auto mapped_value_or_error = vm.call(*map_fn, this_arg, next_value, Value(k));
+ auto mapped_value_or_error = JS::call(global_object, *map_fn, this_arg, next_value, Value(k));
if (mapped_value_or_error.is_error())
return TRY(iterator_close(global_object, iterator, mapped_value_or_error.release_error()));
mapped_value = mapped_value_or_error.release_value();
@@ -160,7 +160,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
auto k_value = TRY(array_like->get(k));
Value mapped_value;
if (map_fn)
- mapped_value = TRY(vm.call(*map_fn, this_arg, k_value, Value(k)));
+ mapped_value = TRY(JS::call(global_object, *map_fn, this_arg, k_value, Value(k)));
else
mapped_value = k_value;
TRY(array->create_data_property_or_throw(k, mapped_value));
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
index 1a0f730684..f914c88834 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
@@ -186,7 +186,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::filter)
auto k_value = TRY(object->get(k));
// ii. Let selected be ! ToBoolean(? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »)).
- auto selected = TRY(vm.call(callback_function.as_function(), this_arg, k_value, Value(k), object)).to_boolean();
+ auto selected = TRY(call(global_object, callback_function.as_function(), this_arg, k_value, Value(k), object)).to_boolean();
// iii. If selected is true, then
if (selected) {
@@ -236,7 +236,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::for_each)
auto k_value = TRY(object->get(property_name));
// ii. Perform ? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »).
- TRY(vm.call(callback_function.as_function(), this_arg, k_value, Value(k), object));
+ TRY(call(global_object, callback_function.as_function(), this_arg, k_value, Value(k), object));
}
// d. Set k to k + 1.
@@ -280,7 +280,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::map)
auto k_value = TRY(object->get(property_name));
// ii. Let mappedValue be ? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »).
- auto mapped_value = TRY(vm.call(callback_function.as_function(), this_arg, k_value, Value(k), object));
+ auto mapped_value = TRY(call(global_object, callback_function.as_function(), this_arg, k_value, Value(k), object));
// iii. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue).
TRY(array->create_data_property_or_throw(property_name, mapped_value));
@@ -391,7 +391,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_string)
auto join_function = TRY(this_object->get(vm.names.join));
if (!join_function.is_function())
return ObjectPrototype::to_string(vm, global_object);
- return TRY(vm.call(join_function.as_function(), this_object));
+ return TRY(call(global_object, join_function.as_function(), this_object));
}
// 18.5.1 Array.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sup-array.prototype.tolocalestring
@@ -739,7 +739,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce)
auto k_value = TRY(object->get(property_name));
// ii. Set accumulator to ? Call(callbackfn, undefined, « accumulator, kValue, 𝔽(k), O »).
- accumulator = TRY(vm.call(callback_function.as_function(), js_undefined(), accumulator, k_value, Value(k), object));
+ accumulator = TRY(call(global_object, callback_function.as_function(), js_undefined(), accumulator, k_value, Value(k), object));
}
// d. Set k to k + 1.
@@ -821,7 +821,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce_right)
auto k_value = TRY(object->get(property_name));
// ii. Set accumulator to ? Call(callbackfn, undefined, « accumulator, kValue, 𝔽(k), O »).
- accumulator = TRY(vm.call(callback_function.as_function(), js_undefined(), accumulator, k_value, Value((size_t)k), object));
+ accumulator = TRY(call(global_object, callback_function.as_function(), js_undefined(), accumulator, k_value, Value((size_t)k), object));
}
// d. Set k to k - 1.
@@ -907,7 +907,7 @@ static ThrowCompletionOr<void> array_merge_sort(VM& vm, GlobalObject& global_obj
} else if (y.is_undefined()) {
comparison_result = -1;
} else if (compare_func) {
- auto call_result = TRY(vm.call(*compare_func, js_undefined(), left[left_index], right[right_index]));
+ auto call_result = TRY(call(global_object, *compare_func, js_undefined(), left[left_index], right[right_index]));
auto number = TRY(call_result.to_number(global_object));
if (number.is_nan())
comparison_result = 0;
@@ -1128,7 +1128,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find)
auto k_value = TRY(object->get(property_name));
// c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
- auto test_result = TRY(vm.call(predicate.as_function(), this_arg, k_value, Value(k), object)).to_boolean();
+ auto test_result = TRY(call(global_object, predicate.as_function(), this_arg, k_value, Value(k), object)).to_boolean();
// d. If testResult is true, return kValue.
if (test_result)
@@ -1167,7 +1167,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_index)
auto k_value = TRY(object->get(property_name));
// c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
- auto test_result = TRY(vm.call(predicate.as_function(), this_arg, k_value, Value(k), object)).to_boolean();
+ auto test_result = TRY(call(global_object, predicate.as_function(), this_arg, k_value, Value(k), object)).to_boolean();
// d. If testResult is true, return 𝔽(k).
if (test_result)
@@ -1206,7 +1206,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_last)
auto k_value = TRY(object->get(property_name));
// c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
- auto test_result = TRY(vm.call(predicate.as_function(), this_arg, k_value, Value((double)k), object)).to_boolean();
+ auto test_result = TRY(call(global_object, predicate.as_function(), this_arg, k_value, Value((double)k), object)).to_boolean();
// d. If testResult is true, return kValue.
if (test_result)
@@ -1245,7 +1245,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_last_index)
auto k_value = TRY(object->get(property_name));
// c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)).
- auto test_result = TRY(vm.call(predicate.as_function(), this_arg, k_value, Value((double)k), object)).to_boolean();
+ auto test_result = TRY(call(global_object, predicate.as_function(), this_arg, k_value, Value((double)k), object)).to_boolean();
// d. If testResult is true, return 𝔽(k).
if (test_result)
@@ -1289,7 +1289,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::some)
auto k_value = TRY(object->get(property_name));
// ii. Let testResult be ! ToBoolean(? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »)).
- auto test_result = TRY(vm.call(callback_function.as_function(), this_arg, k_value, Value(k), object)).to_boolean();
+ auto test_result = TRY(call(global_object, callback_function.as_function(), this_arg, k_value, Value(k), object)).to_boolean();
// iii. If testResult is true, return true.
if (test_result)
@@ -1334,7 +1334,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::every)
auto k_value = TRY(object->get(property_name));
// ii. Let testResult be ! ToBoolean(? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »)).
- auto test_result = TRY(vm.call(callback_function.as_function(), this_arg, k_value, Value(k), object)).to_boolean();
+ auto test_result = TRY(call(global_object, callback_function.as_function(), this_arg, k_value, Value(k), object)).to_boolean();
// iii. If testResult is false, return false.
if (!test_result)
@@ -1519,7 +1519,7 @@ static ThrowCompletionOr<size_t> flatten_into_array(GlobalObject& global_object,
auto value = TRY(array.get(j));
if (mapper_func)
- value = TRY(vm.call(*mapper_func, this_arg, value, Value(j), &array));
+ value = TRY(call(global_object, *mapper_func, this_arg, value, Value(j), &array));
if (depth > 0 && TRY(value.is_array(global_object))) {
if (vm.did_reach_stack_space_limit())
@@ -1728,7 +1728,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group_by)
auto k_value = TRY(this_object->get(index_property));
// c. Let propertyKey be ? ToPropertyKey(? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »)).
- auto property_key_value = TRY(vm.call(callback_function.as_function(), this_arg, k_value, Value(index), this_object));
+ auto property_key_value = TRY(call(global_object, callback_function.as_function(), this_arg, k_value, Value(index), this_object));
auto property_key = TRY(property_key_value.to_property_key(global_object));
// d. Perform ! AddValueToKeyedGroup(groups, propertyKey, kValue).
@@ -1795,7 +1795,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::group_by_to_map)
auto k_value = TRY(this_object->get(index_property));
// c. Let key be ? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »).
- auto key = TRY(vm.call(callback_function.as_function(), this_arg, k_value, Value(index), this_object));
+ auto key = TRY(call(global_object, callback_function.as_function(), this_arg, k_value, Value(index), this_object));
// d. If key is -0𝔽, set key to +0𝔽.
if (key.is_negative_zero())
diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp
index 1de9586b85..37ff916fe4 100644
--- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp
@@ -33,19 +33,17 @@ void AsyncFromSyncIteratorPrototype::initialize(GlobalObject& global_object)
// 27.1.4.4 AsyncFromSyncIteratorContinuation ( result, promiseCapability ), https://tc39.es/ecma262/#sec-asyncfromsynciteratorcontinuation
static ThrowCompletionOr<Object*> async_from_sync_iterator_continuation(GlobalObject& global_object, Object& result, PromiseCapability& promise_capability)
{
- auto& vm = global_object.vm();
-
// 1. Let done be IteratorComplete(result).
// 2. IfAbruptRejectPromise(done, promiseCapability).
- auto done = TRY_OR_REJECT(vm, promise_capability, iterator_complete(global_object, result));
+ auto done = TRY_OR_REJECT(global_object, promise_capability, iterator_complete(global_object, result));
// 3. Let value be IteratorValue(result).
// 4. IfAbruptRejectPromise(value, promiseCapability).
- auto value = TRY_OR_REJECT(vm, promise_capability, iterator_value(global_object, result));
+ auto value = TRY_OR_REJECT(global_object, promise_capability, iterator_value(global_object, result));
// 5. Let valueWrapper be PromiseResolve(%Promise%, value).
// 6. IfAbruptRejectPromise(valueWrapper, promiseCapability).
- auto value_wrapper = TRY_OR_REJECT(vm, promise_capability, promise_resolve(global_object, *global_object.promise_constructor(), value));
+ auto value_wrapper = TRY_OR_REJECT(global_object, promise_capability, promise_resolve(global_object, *global_object.promise_constructor(), value));
// 7. Let unwrap be a new Abstract Closure with parameters (value) that captures done and performs the following steps when called:
auto unwrap = [done](VM& vm, GlobalObject& global_object) -> ThrowCompletionOr<Value> {
@@ -84,7 +82,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::next)
// 6. Else,
// a. Let result be IteratorNext(syncIteratorRecord).
// 7. IfAbruptRejectPromise(result, promiseCapability).
- auto* result = TRY_OR_REJECT(vm, promise_capability,
+ auto* result = TRY_OR_REJECT(global_object, promise_capability,
(vm.argument_count() > 0 ? iterator_next(global_object, sync_iterator_record, vm.argument(0))
: iterator_next(global_object, sync_iterator_record)));
@@ -107,7 +105,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
// 5. Let return be GetMethod(syncIterator, "return").
// 6. IfAbruptRejectPromise(return, promiseCapability).
- auto* return_method = TRY_OR_REJECT(vm, promise_capability, Value(sync_iterator).get_method(global_object, vm.names.return_));
+ auto* return_method = TRY_OR_REJECT(global_object, promise_capability, Value(sync_iterator).get_method(global_object, vm.names.return_));
// 7. If return is undefined, then
if (return_method == nullptr) {
@@ -115,7 +113,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
auto* iter_result = create_iterator_result_object(global_object, vm.argument(0), true);
// b. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iterResult »).
- MUST(vm.call(*promise_capability.reject, js_undefined(), iter_result));
+ MUST(call(global_object, *promise_capability.reject, js_undefined(), iter_result));
// c. Return promiseCapability.[[Promise]].
return promise_capability.promise;
@@ -126,7 +124,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
// 9. Else,
// a. Let result be Call(return, syncIterator).
// 10. IfAbruptRejectPromise(result, promiseCapability).
- auto result = TRY_OR_REJECT(vm, promise_capability,
+ auto result = TRY_OR_REJECT(global_object, promise_capability,
(vm.argument_count() > 0 ? call(global_object, return_method, sync_iterator, vm.argument(0))
: call(global_object, return_method, sync_iterator)));
@@ -134,7 +132,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
if (!result.is_object()) {
auto* error = TypeError::create(global_object, String::formatted(ErrorType::NotAnObject.message(), "SyncIteratorReturnResult"));
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
- MUST(vm.call(*promise_capability.reject, js_undefined(), error));
+ MUST(call(global_object, *promise_capability.reject, js_undefined(), error));
// b. Return promiseCapability.[[Promise]].
return promise_capability.promise;
}
@@ -158,12 +156,12 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
// 5. Let throw be GetMethod(syncIterator, "throw").
// 6. IfAbruptRejectPromise(throw, promiseCapability).
- auto* throw_method = TRY_OR_REJECT(vm, promise_capability, Value(sync_iterator).get_method(global_object, vm.names.throw_));
+ auto* throw_method = TRY_OR_REJECT(global_object, promise_capability, Value(sync_iterator).get_method(global_object, vm.names.throw_));
// 7. If throw is undefined, then
if (throw_method == nullptr) {
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « value »).
- MUST(vm.call(*promise_capability.reject, js_undefined(), vm.argument(0)));
+ MUST(call(global_object, *promise_capability.reject, js_undefined(), vm.argument(0)));
// b. Return promiseCapability.[[Promise]].
return promise_capability.promise;
}
@@ -172,7 +170,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
// 9. Else,
// a. Let result be Call(throw, syncIterator).
// 10. IfAbruptRejectPromise(result, promiseCapability).
- auto result = TRY_OR_REJECT(vm, promise_capability,
+ auto result = TRY_OR_REJECT(global_object, promise_capability,
(vm.argument_count() > 0 ? call(global_object, throw_method, sync_iterator, vm.argument(0))
: call(global_object, throw_method, sync_iterator)));
@@ -180,7 +178,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::throw_)
if (!result.is_object()) {
auto* error = TypeError::create(global_object, String::formatted(ErrorType::NotAnObject.message(), "SyncIteratorThrowResult"));
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
- MUST(vm.call(*promise_capability.reject, js_undefined(), error));
+ MUST(call(global_object, *promise_capability.reject, js_undefined(), error));
// b. Return promiseCapability.[[Promise]].
return promise_capability.promise;
diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
index 32d0102939..2783240ac6 100644
--- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
@@ -751,7 +751,7 @@ void async_block_start(VM& vm, NonnullRefPtr<Statement> const& async_body, Promi
return;
// 5. Resume the suspended evaluation of asyncContext. Let result be the value returned by the resumed computation.
- auto result = vm.call(*execution_steps, async_context.this_value.is_empty() ? js_undefined() : async_context.this_value);
+ auto result = call(global_object, *execution_steps, async_context.this_value.is_empty() ? js_undefined() : async_context.this_value);
// 6. Assert: When we return here, asyncContext has already been removed from the execution context stack and runningContext is the currently running execution context.
VERIFY(&vm.running_execution_context() == &running_context);
diff --git a/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp b/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp
index 25c6486033..aa2026fe33 100644
--- a/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp
+++ b/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/FinalizationRegistry.h>
namespace JS {
@@ -64,7 +65,7 @@ void FinalizationRegistry::cleanup(FunctionObject* callback)
for (auto it = m_records.begin(); it != m_records.end(); ++it) {
if (it->target != nullptr)
continue;
- (void)vm.call(*cleanup_callback, js_undefined(), it->held_value);
+ (void)call(global_object(), *cleanup_callback, js_undefined(), it->held_value);
it.remove(m_records);
if (vm.exception())
return;
diff --git a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp
index 92ccbf859e..a03b2bbda2 100644
--- a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp
@@ -52,9 +52,9 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::apply)
auto this_arg = vm.argument(0);
auto arg_array = vm.argument(1);
if (arg_array.is_nullish())
- return TRY(vm.call(function, this_arg));
+ return TRY(JS::call(global_object, function, this_arg));
auto arguments = TRY(create_list_from_array_like(global_object, arg_array));
- return TRY(vm.call(function, this_arg, move(arguments)));
+ return TRY(JS::call(global_object, function, this_arg, move(arguments)));
}
// 20.2.3.2 Function.prototype.bind ( thisArg, ...args ), https://tc39.es/ecma262/#sec-function.prototype.bind
@@ -88,7 +88,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::call)
for (size_t i = 1; i < vm.argument_count(); ++i)
arguments.append(vm.argument(i));
}
- return TRY(vm.call(function, this_arg, move(arguments)));
+ return TRY(JS::call(global_object, function, this_arg, move(arguments)));
}
// 20.2.3.5 Function.prototype.toString ( ), https://tc39.es/ecma262/#sec-function.prototype.tostring
diff --git a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp
index 3e6dd84926..02ec26b46b 100644
--- a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp
@@ -15,6 +15,7 @@
#include <LibJS/Runtime/BigIntObject.h>
#include <LibJS/Runtime/BooleanObject.h>
#include <LibJS/Runtime/Error.h>
+#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/JSONObject.h>
#include <LibJS/Runtime/NumberObject.h>
@@ -132,11 +133,11 @@ ThrowCompletionOr<String> JSONObject::serialize_json_property(GlobalObject& glob
auto* value_object = TRY(value.to_object(global_object));
auto to_json = TRY(value_object->get(vm.names.toJSON));
if (to_json.is_function())
- value = TRY(vm.call(to_json.as_function(), value, js_string(vm, key.to_string())));
+ value = TRY(call(global_object, to_json.as_function(), value, js_string(vm, key.to_string())));
}
if (state.replacer_function)
- value = TRY(vm.call(*state.replacer_function, holder, js_string(vm, key.to_string()), value));
+ value = TRY(call(global_object, *state.replacer_function, holder, js_string(vm, key.to_string()), value));
if (value.is_object()) {
auto& value_object = value.as_object();
@@ -431,7 +432,7 @@ ThrowCompletionOr<Value> JSONObject::internalize_json_property(GlobalObject& glo
}
}
- return TRY(vm.call(reviver, Value(holder), js_string(vm, name.to_string()), value));
+ return TRY(call(global_object, reviver, holder, js_string(vm, name.to_string()), value));
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp b/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp
index f4243e902a..4ca9c3ac2f 100644
--- a/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp
@@ -63,7 +63,7 @@ ThrowCompletionOr<Object*> MapConstructor::construct(FunctionObject& new_target)
auto key = TRY(iterator_value.as_object().get(0));
auto value = TRY(iterator_value.as_object().get(1));
- TRY(vm.call(adder.as_function(), Value(map), key, value));
+ TRY(JS::call(global_object, adder.as_function(), map, key, value));
return {};
}));
diff --git a/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp b/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp
index fe4a49ccf4..10d37f6b3b 100644
--- a/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp
@@ -6,6 +6,7 @@
#include <AK/HashMap.h>
#include <AK/TypeCasts.h>
+#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/MapIterator.h>
#include <LibJS/Runtime/MapPrototype.h>
@@ -73,7 +74,7 @@ JS_DEFINE_NATIVE_FUNCTION(MapPrototype::for_each)
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, vm.argument(0).to_string_without_side_effects());
auto this_value = vm.this_value(global_object);
for (auto& entry : map->entries())
- TRY(vm.call(vm.argument(0).as_function(), vm.argument(1), entry.value, entry.key, this_value));
+ TRY(call(global_object, vm.argument(0).as_function(), vm.argument(1), entry.value, entry.key, this_value));
return js_undefined();
}
diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp
index ce7aab7eb2..048eea5da9 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Object.cpp
@@ -524,7 +524,7 @@ ThrowCompletionOr<Value> Object::private_get(PrivateName const& name)
return vm().throw_completion<TypeError>(global_object(), ErrorType::PrivateFieldGetAccessorWithoutGetter, name.description);
// 8. Return ? Call(getter, Receiver).
- return TRY(vm().call(*getter, this));
+ return TRY(call(global_object(), *getter, this));
}
// 7.3.31 PrivateSet ( O, P, value ), https://tc39.es/ecma262/#sec-privateset
@@ -549,7 +549,7 @@ ThrowCompletionOr<void> Object::private_set(PrivateName const& name, Value value
if (!setter)
return vm().throw_completion<TypeError>(global_object(), ErrorType::PrivateFieldSetAccessorWithoutSetter, name.description);
- TRY(vm().call(*setter, this, value));
+ TRY(call(global_object(), *setter, this, value));
return {};
}
@@ -558,7 +558,7 @@ ThrowCompletionOr<void> Object::define_field(Variant<PropertyKey, PrivateName> n
{
Value init_value = js_undefined();
if (initializer)
- init_value = TRY(vm().call(*initializer, this));
+ init_value = TRY(call(global_object(), *initializer, this));
if (auto* property_name_ptr = name.get_pointer<PropertyKey>())
TRY(create_data_property_or_throw(*property_name_ptr, init_value));
@@ -730,7 +730,6 @@ ThrowCompletionOr<bool> Object::internal_has_property(PropertyKey const& propert
ThrowCompletionOr<Value> Object::internal_get(PropertyKey const& property_name, Value receiver) const
{
VERIFY(!receiver.is_empty());
- auto& vm = this->vm();
// 1. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
@@ -766,7 +765,7 @@ ThrowCompletionOr<Value> Object::internal_get(PropertyKey const& property_name,
return js_undefined();
// 8. Return ? Call(getter, Receiver).
- return TRY(vm.call(*getter, receiver));
+ return TRY(call(global_object(), *getter, receiver));
}
// 10.1.9 [[Set]] ( P, V, Receiver ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-set-p-v-receiver
@@ -788,8 +787,6 @@ ThrowCompletionOr<bool> Object::internal_set(PropertyKey const& property_name, V
// 10.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ), https://tc39.es/ecma262/#sec-ordinarysetwithowndescriptor
ThrowCompletionOr<bool> Object::ordinary_set_with_own_descriptor(PropertyKey const& property_name, Value value, Value receiver, Optional<PropertyDescriptor> own_descriptor)
{
- auto& vm = this->vm();
-
// 1. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
@@ -865,7 +862,7 @@ ThrowCompletionOr<bool> Object::ordinary_set_with_own_descriptor(PropertyKey con
return false;
// 7. Perform ? Call(setter, Receiver, « V »).
- (void)TRY(vm.call(*setter, receiver, value));
+ (void)TRY(call(global_object(), *setter, receiver, value));
// 8. Return true.
return true;
@@ -1226,7 +1223,7 @@ ThrowCompletionOr<Value> Object::ordinary_to_primitive(Value::PreferredType pref
// b. If IsCallable(method) is true, then
if (method.is_function()) {
// i. Let result be ? Call(method, O).
- auto result = TRY(vm.call(method.as_function(), const_cast<Object*>(this)));
+ auto result = TRY(call(global_object(), method.as_function(), const_cast<Object*>(this)));
// ii. If Type(result) is not Object, return result.
if (!result.is_object())
diff --git a/Userland/Libraries/LibJS/Runtime/Promise.cpp b/Userland/Libraries/LibJS/Runtime/Promise.cpp
index 4d4cf06fcb..c2a05e75ff 100644
--- a/Userland/Libraries/LibJS/Runtime/Promise.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Promise.cpp
@@ -37,7 +37,7 @@ ThrowCompletionOr<Object*> promise_resolve(GlobalObject& global_object, Object&
auto promise_capability = TRY(new_promise_capability(global_object, &constructor));
// 3. Perform ? Call(promiseCapability.[[Resolve]], undefined, « x »).
- (void)TRY(vm.call(*promise_capability.resolve, js_undefined(), value));
+ (void)TRY(call(global_object, *promise_capability.resolve, js_undefined(), value));
// 4. Return promiseCapability.[[Promise]].
return promise_capability.promise;
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
index 4049bd032f..7dfccdc21b 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
@@ -101,7 +101,7 @@ static ThrowCompletionOr<Value> perform_promise_common(GlobalObject& global_obje
values->values().append(js_undefined());
// i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
- auto next_promise = TRY(vm.call(promise_resolve.as_function(), constructor, next_value));
+ auto next_promise = TRY(call(global_object, promise_resolve.as_function(), constructor, next_value));
// j-q. are handled in `invoke_element_function`
@@ -125,10 +125,10 @@ static ThrowCompletionOr<Value> perform_promise_all(GlobalObject& global_object,
global_object, iterator_record, constructor, result_capability, promise_resolve,
[&](PromiseValueList& values) -> ThrowCompletionOr<Value> {
// 1. Let valuesArray be ! CreateArrayFromList(values).
- auto values_array = Array::create_from(global_object, values.values());
+ auto* values_array = Array::create_from(global_object, values.values());
// 2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
- TRY(vm.call(*result_capability.resolve, js_undefined(), values_array));
+ TRY(call(global_object, *result_capability.resolve, js_undefined(), values_array));
// iv. Return resultCapability.[[Promise]].
return Value(result_capability.promise);
@@ -158,9 +158,9 @@ static ThrowCompletionOr<Value> perform_promise_all_settled(GlobalObject& global
return perform_promise_common(
global_object, iterator_record, constructor, result_capability, promise_resolve,
[&](PromiseValueList& values) -> ThrowCompletionOr<Value> {
- auto values_array = Array::create_from(global_object, values.values());
+ auto* values_array = Array::create_from(global_object, values.values());
- TRY(vm.call(*result_capability.resolve, js_undefined(), values_array));
+ TRY(call(global_object, *result_capability.resolve, js_undefined(), values_array));
return Value(result_capability.promise);
},
@@ -304,14 +304,14 @@ ThrowCompletionOr<Object*> PromiseConstructor::construct(FunctionObject& new_tar
auto [resolve_function, reject_function] = promise->create_resolving_functions();
// 9. Let completion be Call(executor, undefined, « resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]] »).
- (void)vm.call(executor.as_function(), js_undefined(), &resolve_function, &reject_function);
+ (void)JS::call(global_object, executor.as_function(), js_undefined(), &resolve_function, &reject_function);
// 10. If completion is an abrupt completion, then
if (auto* exception = vm.exception()) {
vm.clear_exception();
// a. Perform ? Call(resolvingFunctions.[[Reject]], undefined, « completion.[[Value]] »).
- TRY(vm.call(reject_function, js_undefined(), exception->value()));
+ TRY(JS::call(global_object, reject_function, js_undefined(), exception->value()));
}
// 11. Return promise.
@@ -329,11 +329,11 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::all)
// 3. Let promiseResolve be GetPromiseResolve(C).
// 4. IfAbruptRejectPromise(promiseResolve, promiseCapability).
- auto promise_resolve = TRY_OR_REJECT(vm, promise_capability, get_promise_resolve(global_object, constructor));
+ auto promise_resolve = TRY_OR_REJECT(global_object, promise_capability, get_promise_resolve(global_object, constructor));
// 5. Let iteratorRecord be GetIterator(iterable).
// 6. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
- auto iterator_record = TRY_OR_REJECT(vm, promise_capability, get_iterator(global_object, vm.argument(0)));
+ auto iterator_record = TRY_OR_REJECT(global_object, promise_capability, get_iterator(global_object, vm.argument(0)));
// 7. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability, promiseResolve).
auto result = perform_promise_all(global_object, iterator_record, constructor, promise_capability, promise_resolve);
@@ -345,7 +345,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::all)
result = iterator_close(global_object, iterator_record, result.release_error());
// b. IfAbruptRejectPromise(result, promiseCapability).
- TRY_OR_REJECT(vm, promise_capability, result);
+ TRY_OR_REJECT(global_object, promise_capability, result);
}
// 9. Return Completion(result).
@@ -363,11 +363,11 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::all_settled)
// 3. Let promiseResolve be GetPromiseResolve(C).
// 4. IfAbruptRejectPromise(promiseResolve, promiseCapability).
- auto promise_resolve = TRY_OR_REJECT(vm, promise_capability, get_promise_resolve(global_object, constructor));
+ auto promise_resolve = TRY_OR_REJECT(global_object, promise_capability, get_promise_resolve(global_object, constructor));
// 5. Let iteratorRecord be GetIterator(iterable).
// 6. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
- auto iterator_record = TRY_OR_REJECT(vm, promise_capability, get_iterator(global_object, vm.argument(0)));
+ auto iterator_record = TRY_OR_REJECT(global_object, promise_capability, get_iterator(global_object, vm.argument(0)));
// 7. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability, promiseResolve).
auto result = perform_promise_all_settled(global_object, iterator_record, constructor, promise_capability, promise_resolve);
@@ -379,7 +379,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::all_settled)
result = iterator_close(global_object, iterator_record, result.release_error());
// b. IfAbruptRejectPromise(result, promiseCapability).
- TRY_OR_REJECT(vm, promise_capability, result);
+ TRY_OR_REJECT(global_object, promise_capability, result);
}
// 9. Return Completion(result).
@@ -397,11 +397,11 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::any)
// 3. Let promiseResolve be GetPromiseResolve(C).
// 4. IfAbruptRejectPromise(promiseResolve, promiseCapability).
- auto promise_resolve = TRY_OR_REJECT(vm, promise_capability, get_promise_resolve(global_object, constructor));
+ auto promise_resolve = TRY_OR_REJECT(global_object, promise_capability, get_promise_resolve(global_object, constructor));
// 5. Let iteratorRecord be GetIterator(iterable).
// 6. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
- auto iterator_record = TRY_OR_REJECT(vm, promise_capability, get_iterator(global_object, vm.argument(0)));
+ auto iterator_record = TRY_OR_REJECT(global_object, promise_capability, get_iterator(global_object, vm.argument(0)));
// 7. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability, promiseResolve).
auto result = perform_promise_any(global_object, iterator_record, constructor, promise_capability, promise_resolve);
@@ -413,7 +413,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::any)
result = iterator_close(global_object, iterator_record, result.release_error());
// b. IfAbruptRejectPromise(result, promiseCapability).
- TRY_OR_REJECT(vm, promise_capability, result);
+ TRY_OR_REJECT(global_object, promise_capability, result);
}
// 9. Return Completion(result).
@@ -431,11 +431,11 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::race)
// 3. Let promiseResolve be GetPromiseResolve(C).
// 4. IfAbruptRejectPromise(promiseResolve, promiseCapability).
- auto promise_resolve = TRY_OR_REJECT(vm, promise_capability, get_promise_resolve(global_object, constructor));
+ auto promise_resolve = TRY_OR_REJECT(global_object, promise_capability, get_promise_resolve(global_object, constructor));
// 5. Let iteratorRecord be GetIterator(iterable).
// 6. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
- auto iterator_record = TRY_OR_REJECT(vm, promise_capability, get_iterator(global_object, vm.argument(0)));
+ auto iterator_record = TRY_OR_REJECT(global_object, promise_capability, get_iterator(global_object, vm.argument(0)));
// 7. Let result be PerformPromiseRace(iteratorRecord, C, promiseCapability, promiseResolve).
auto result = perform_promise_race(global_object, iterator_record, constructor, promise_capability, promise_resolve);
@@ -447,7 +447,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::race)
result = iterator_close(global_object, iterator_record, result.release_error());
// b. IfAbruptRejectPromise(result, promiseCapability).
- TRY_OR_REJECT(vm, promise_capability, result);
+ TRY_OR_REJECT(global_object, promise_capability, result);
}
// 9. Return Completion(result).
@@ -466,7 +466,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::reject)
auto promise_capability = TRY(new_promise_capability(global_object, constructor));
// 3. Perform ? Call(promiseCapability.[[Reject]], undefined, « r »).
- [[maybe_unused]] auto result = TRY(vm.call(*promise_capability.reject, js_undefined(), reason));
+ [[maybe_unused]] auto result = TRY(JS::call(global_object, *promise_capability.reject, js_undefined(), reason));
// 4. Return promiseCapability.[[Promise]].
return promise_capability.promise;
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseJobs.cpp b/Userland/Libraries/LibJS/Runtime/PromiseJobs.cpp
index ccd8171e37..ea21bd2b55 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseJobs.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseJobs.cpp
@@ -88,14 +88,14 @@ ThrowCompletionOr<Value> PromiseReactionJob::call()
// i. Let status be Call(promiseCapability.[[Reject]], undefined, « handlerResult.[[Value]] »).
auto* reject_function = promise_capability.value().reject;
dbgln_if(PROMISE_DEBUG, "[PromiseReactionJob @ {}]: Calling PromiseCapability's reject function @ {}", this, reject_function);
- return vm.call(*reject_function, js_undefined(), *handler_result.value());
+ return JS::call(global_object, *reject_function, js_undefined(), *handler_result.value());
}
// i. Else,
else {
// i. Let status be Call(promiseCapability.[[Resolve]], undefined, « handlerResult.[[Value]] »).
auto* resolve_function = promise_capability.value().resolve;
dbgln_if(PROMISE_DEBUG, "[PromiseReactionJob @ {}]: Calling PromiseCapability's resolve function @ {}", this, resolve_function);
- return vm.call(*resolve_function, js_undefined(), *handler_result.value());
+ return JS::call(global_object, *resolve_function, js_undefined(), *handler_result.value());
}
// j. Return Completion(status).
diff --git a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
index f232d8c021..0a1afff773 100644
--- a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
@@ -106,7 +106,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
auto value = vm.argument(0);
// i. Let result be ? Call(onFinally, undefined).
- auto result = TRY(vm.call(on_finally, js_undefined()));
+ auto result = TRY(call(global_object, on_finally, js_undefined()));
// ii. Let promise be ? PromiseResolve(C, result).
auto* promise = TRY(promise_resolve(global_object, constructor, result));
@@ -132,7 +132,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
auto reason = vm.argument(0);
// i. Let result be ? Call(onFinally, undefined).
- auto result = TRY(vm.call(on_finally, js_undefined()));
+ auto result = TRY(call(global_object, on_finally, js_undefined()));
// ii. Let promise be ? PromiseResolve(C, result).
auto* promise = TRY(promise_resolve(global_object, constructor, result));
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseReaction.h b/Userland/Libraries/LibJS/Runtime/PromiseReaction.h
index 1cbba98e33..2d2c941412 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseReaction.h
+++ b/Userland/Libraries/LibJS/Runtime/PromiseReaction.h
@@ -20,22 +20,22 @@ struct PromiseCapability {
};
// 27.2.1.1.1 IfAbruptRejectPromise ( value, capability ), https://tc39.es/ecma262/#sec-ifabruptrejectpromise
-#define TRY_OR_REJECT(vm, capability, expression) \
- ({ \
- auto _temporary_try_or_reject_result = (expression); \
- /* 1. If value is an abrupt completion, then */ \
- if (_temporary_try_or_reject_result.is_error()) { \
- vm.clear_exception(); \
- \
- /* a. Perform ? Call(capability.[[Reject]], undefined, « value.[[Value]] »). */ \
- TRY(vm.call(*capability.reject, js_undefined(), *_temporary_try_or_reject_result.release_error().value())); \
- \
- /* b. Return capability.[[Promise]]. */ \
- return capability.promise; \
- } \
- \
- /* 2. Else if value is a Completion Record, set value to value.[[Value]]. */ \
- _temporary_try_or_reject_result.release_value(); \
+#define TRY_OR_REJECT(global_object, capability, expression) \
+ ({ \
+ auto _temporary_try_or_reject_result = (expression); \
+ /* 1. If value is an abrupt completion, then */ \
+ if (_temporary_try_or_reject_result.is_error()) { \
+ global_object.vm().clear_exception(); \
+ \
+ /* a. Perform ? Call(capability.[[Reject]], undefined, « value.[[Value]] »). */ \
+ TRY(JS::call(global_object, *capability.reject, js_undefined(), *_temporary_try_or_reject_result.release_error().value())); \
+ \
+ /* b. Return capability.[[Promise]]. */ \
+ return capability.promise; \
+ } \
+ \
+ /* 2. Else if value is a Completion Record, set value to value.[[Value]]. */ \
+ _temporary_try_or_reject_result.release_value(); \
})
// 27.2.1.5 NewPromiseCapability ( C ), https://tc39.es/ecma262/#sec-newpromisecapability
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp
index aeb205dac3..8d1acb7684 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingElementFunctions.cpp
@@ -73,7 +73,7 @@ ThrowCompletionOr<Value> PromiseAllResolveElementFunction::resolve_element()
auto* values_array = Array::create_from(global_object, m_values.values());
// b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
- return vm.call(*m_capability.resolve, js_undefined(), values_array);
+ return JS::call(global_object, *m_capability.resolve, js_undefined(), values_array);
}
// 11. Return undefined.
@@ -114,7 +114,7 @@ ThrowCompletionOr<Value> PromiseAllSettledResolveElementFunction::resolve_elemen
auto* values_array = Array::create_from(global_object, m_values.values());
// b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
- return vm.call(*m_capability.resolve, js_undefined(), values_array);
+ return JS::call(global_object, *m_capability.resolve, js_undefined(), values_array);
}
// 15. Return undefined.
@@ -152,10 +152,10 @@ ThrowCompletionOr<Value> PromiseAllSettledRejectElementFunction::resolve_element
// 14. If remainingElementsCount.[[Value]] is 0, then
if (--m_remaining_elements.value == 0) {
// a. Let valuesArray be ! CreateArrayFromList(values).
- auto values_array = Array::create_from(global_object, m_values.values());
+ auto* values_array = Array::create_from(global_object, m_values.values());
// b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
- return vm.call(*m_capability.resolve, js_undefined(), values_array);
+ return JS::call(global_object, *m_capability.resolve, js_undefined(), values_array);
}
// 15. Return undefined.
@@ -187,11 +187,11 @@ ThrowCompletionOr<Value> PromiseAnyRejectElementFunction::resolve_element()
auto* error = AggregateError::create(global_object);
// b. Perform ! DefinePropertyOrThrow(error, "errors", PropertyDescriptor { [[Configurable]]: true, [[Enumerable]]: false, [[Writable]]: true, [[Value]]: ! CreateArrayFromList(errors) }).
- auto errors_array = Array::create_from(global_object, m_values.values());
+ auto* errors_array = Array::create_from(global_object, m_values.values());
MUST(error->define_property_or_throw(vm.names.errors, { .value = errors_array, .writable = true, .enumerable = false, .configurable = true }));
// c. Return ? Call(promiseCapability.[[Reject]], undefined, « error »).
- return vm.call(*m_capability.reject, js_undefined(), error);
+ return JS::call(global_object, *m_capability.reject, js_undefined(), error);
}
return js_undefined();
diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
index 901ae4b18f..0fd95099e7 100644
--- a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp
@@ -69,7 +69,7 @@ ThrowCompletionOr<Object*> ProxyObject::internal_get_prototype_of() const
}
// 7. Let handlerProto be ? Call(trap, handler, « target »).
- auto handler_proto = TRY(vm.call(*trap, &m_handler, &m_target));
+ auto handler_proto = TRY(call(global_object, *trap, &m_handler, &m_target));
// 8. If Type(handlerProto) is neither Object nor Null, throw a TypeError exception.
if (!handler_proto.is_object() && !handler_proto.is_null())
@@ -119,7 +119,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_set_prototype_of(Object* prototype
}
// 8. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target, V »)).
- auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target, prototype)).to_boolean();
+ auto trap_result = TRY(call(global_object, *trap, &m_handler, &m_target, prototype)).to_boolean();
// 9. If booleanTrapResult is false, return false.
if (!trap_result)
@@ -168,7 +168,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_is_extensible() const
}
// 7. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target »)).
- auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target)).to_boolean();
+ auto trap_result = TRY(call(global_object, *trap, &m_handler, &m_target)).to_boolean();
// 8. Let targetResult be ? IsExtensible(target).
auto target_result = TRY(m_target.is_extensible());
@@ -206,7 +206,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_prevent_extensions()
}
// 7. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target »)).
- auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target)).to_boolean();
+ auto trap_result = TRY(call(global_object, *trap, &m_handler, &m_target)).to_boolean();
// 8. If booleanTrapResult is true, then
if (trap_result) {
@@ -250,7 +250,7 @@ ThrowCompletionOr<Optional<PropertyDescriptor>> ProxyObject::internal_get_own_pr
}
// 8. Let trapResultObj be ? Call(trap, handler, « target, P »).
- auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target, property_name_to_value(vm, property_name)));
+ auto trap_result = TRY(call(global_object, *trap, &m_handler, &m_target, property_name_to_value(vm, property_name)));
// 9. If Type(trapResultObj) is neither Object nor Undefined, throw a TypeError exception.
if (!trap_result.is_object() && !trap_result.is_undefined())
@@ -346,7 +346,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_define_own_property(PropertyKey co
auto descriptor_object = from_property_descriptor(global_object, property_descriptor);
// 9. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target, P, descObj »)).
- auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target, property_name_to_value(vm, property_name), descriptor_object)).to_boolean();
+ auto trap_result = TRY(call(global_object, *trap, &m_handler, &m_target, property_name_to_value(vm, property_name), descriptor_object)).to_boolean();
// 10. If booleanTrapResult is false, return false.
if (!trap_result)
@@ -427,7 +427,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_has_property(PropertyKey const& pr
}
// 8. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target, P »)).
- auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target, property_name_to_value(vm, property_name))).to_boolean();
+ auto trap_result = TRY(call(global_object, *trap, &m_handler, &m_target, property_name_to_value(vm, property_name))).to_boolean();
// 9. If booleanTrapResult is false, then
if (!trap_result) {
@@ -499,7 +499,7 @@ ThrowCompletionOr<Value> ProxyObject::internal_get(PropertyKey const& property_n
}
// 8. Let trapResult be ? Call(trap, handler, « target, P, Receiver »).
- auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target, property_name_to_value(vm, property_name), receiver));
+ auto trap_result = TRY(call(global_object, *trap, &m_handler, &m_target, property_name_to_value(vm, property_name), receiver));
// 9. Let targetDesc be ? target.[[GetOwnProperty]](P).
auto target_descriptor = TRY(m_target.internal_get_own_property(property_name));
@@ -555,7 +555,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_set(PropertyKey const& property_na
}
// 8. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target, P, V, Receiver »)).
- auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target, property_name_to_value(vm, property_name), value, receiver)).to_boolean();
+ auto trap_result = TRY(call(global_object, *trap, &m_handler, &m_target, property_name_to_value(vm, property_name), value, receiver)).to_boolean();
// 9. If booleanTrapResult is false, return false.
if (!trap_result)
@@ -612,7 +612,7 @@ ThrowCompletionOr<bool> ProxyObject::internal_delete(PropertyKey const& property
}
// 8. Let booleanTrapResult be ! ToBoolean(? Call(trap, handler, « target, P »)).
- auto trap_result = TRY(vm.call(*trap, &m_handler, &m_target, property_name_to_value(vm, property_name))).to_boolean();
+ auto trap_result = TRY(call(global_object, *trap, &m_handler, &m_target, property_name_to_value(vm, property_name))).to_boolean();
// 9. If booleanTrapResult is false, return false.
if (!trap_result)
@@ -665,7 +665,7 @@ ThrowCompletionOr<MarkedValueList> ProxyObject::internal_own_property_keys() con
}
// 7. Let trapResultArray be ? Call(trap, handler, « target »).
- auto trap_result_array = TRY(vm.call(*trap, &m_handler, &m_target));
+ auto trap_result_array = TRY(call(global_object, *trap, &m_handler, &m_target));
// 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, « String, Symbol »).
HashTable<PropertyKey> unique_keys;
diff --git a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp
index 74e6423da9..f784d39c1d 100644
--- a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp
@@ -63,7 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::apply)
// 3. Perform PrepareForTailCall().
// 4. Return ? Call(target, thisArgument, args).
- return TRY(vm.call(target.as_function(), this_argument, move(args)));
+ return TRY(call(global_object, target.as_function(), this_argument, move(args)));
}
// 28.1.2 Reflect.construct ( target, argumentsList [ , newTarget ] ), https://tc39.es/ecma262/#sec-reflect.construct
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
index 1e7f123a22..444bac067d 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
@@ -387,7 +387,7 @@ ThrowCompletionOr<Value> regexp_exec(GlobalObject& global_object, Object& regexp
// 2. If IsCallable(exec) is true, then
if (exec.is_function()) {
// a. Let result be ? Call(exec, R, « S »).
- auto result = TRY(vm.call(exec.as_function(), &regexp_object, js_string(vm, move(string))));
+ auto result = TRY(call(global_object, exec.as_function(), &regexp_object, js_string(vm, move(string))));
// b. If Type(result) is neither Object nor Null, throw a TypeError exception.
if (!result.is_object() && !result.is_null())
@@ -763,7 +763,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
}
// v. Let replValue be ? Call(replaceValue, undefined, replacerArgs).
- auto replace_result = TRY(vm.call(replace_value.as_function(), js_undefined(), move(replacer_args)));
+ auto replace_result = TRY(call(global_object, replace_value.as_function(), js_undefined(), move(replacer_args)));
// vi. Let replacement be ? ToString(replValue).
replacement = TRY(replace_result.to_string(global_object));
diff --git a/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp b/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp
index 7987986d0f..0122de555e 100644
--- a/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp
@@ -58,7 +58,7 @@ ThrowCompletionOr<Object*> SetConstructor::construct(FunctionObject& new_target)
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, "'add' property of Set");
(void)TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional<Completion> {
- TRY(vm.call(adder.as_function(), Value(set), iterator_value));
+ TRY(JS::call(global_object, adder.as_function(), set, iterator_value));
return {};
}));
diff --git a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp
index fdda3b25e9..6add2986f0 100644
--- a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp
@@ -6,6 +6,7 @@
#include <AK/HashTable.h>
#include <AK/TypeCasts.h>
+#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/SetIterator.h>
#include <LibJS/Runtime/SetPrototype.h>
@@ -86,7 +87,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::for_each)
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, vm.argument(0).to_string_without_side_effects());
auto this_value = vm.this_value(global_object);
for (auto& value : set->values())
- TRY(vm.call(vm.argument(0).as_function(), vm.argument(1), value, value, this_value));
+ TRY(call(global_object, vm.argument(0).as_function(), vm.argument(1), value, value, this_value));
return js_undefined();
}
diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
index ca715743b1..0cc985bfa7 100644
--- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
@@ -614,7 +614,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split)
if (!separator_argument.is_nullish()) {
auto splitter = TRY(separator_argument.get_method(global_object, *vm.well_known_symbol_split()));
if (splitter)
- return TRY(vm.call(*splitter, separator_argument, object, limit_argument));
+ return TRY(call(global_object, *splitter, separator_argument, object, limit_argument));
}
auto string = TRY(object.to_utf16_string(global_object));
@@ -739,7 +739,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match)
auto regexp = vm.argument(0);
if (!regexp.is_nullish()) {
if (auto* matcher = TRY(regexp.get_method(global_object, *vm.well_known_symbol_match())))
- return TRY(vm.call(*matcher, regexp, this_object));
+ return TRY(call(global_object, *matcher, regexp, this_object));
}
auto string = TRY(this_object.to_utf16_string(global_object));
@@ -763,7 +763,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match_all)
return vm.throw_completion<TypeError>(global_object, ErrorType::StringNonGlobalRegExp);
}
if (auto* matcher = TRY(regexp.get_method(global_object, *vm.well_known_symbol_match_all())))
- return TRY(vm.call(*matcher, regexp, this_object));
+ return TRY(call(global_object, *matcher, regexp, this_object));
}
auto string = TRY(this_object.to_utf16_string(global_object));
@@ -781,7 +781,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace)
if (!search_value.is_nullish()) {
if (auto* replacer = TRY(search_value.get_method(global_object, *vm.well_known_symbol_replace())))
- return TRY(vm.call(*replacer, search_value, this_object, replace_value));
+ return TRY(call(global_object, *replacer, search_value, this_object, replace_value));
}
auto string = TRY(this_object.to_utf16_string(global_object));
@@ -800,7 +800,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace)
String replacement;
if (replace_value.is_function()) {
- auto result = TRY(vm.call(replace_value.as_function(), js_undefined(), js_string(vm, search_string), Value(position.value()), js_string(vm, string)));
+ auto result = TRY(call(global_object, replace_value.as_function(), js_undefined(), js_string(vm, search_string), Value(position.value()), js_string(vm, string)));
replacement = TRY(result.to_string(global_object));
} else {
replacement = TRY(get_substitution(global_object, search_string.view(), string.view(), *position, {}, js_undefined(), replace_value));
@@ -834,7 +834,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace_all)
auto* replacer = TRY(search_value.get_method(global_object, *vm.well_known_symbol_replace()));
if (replacer)
- return TRY(vm.call(*replacer, search_value, this_object, replace_value));
+ return TRY(call(global_object, *replacer, search_value, this_object, replace_value));
}
auto string = TRY(this_object.to_utf16_string(global_object));
@@ -865,7 +865,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace_all)
String replacement;
if (replace_value.is_function()) {
- auto result = TRY(vm.call(replace_value.as_function(), js_undefined(), js_string(vm, search_string), Value(position), js_string(vm, string)));
+ auto result = TRY(call(global_object, replace_value.as_function(), js_undefined(), js_string(vm, search_string), Value(position), js_string(vm, string)));
replacement = TRY(result.to_string(global_object));
} else {
replacement = TRY(get_substitution(global_object, search_string.view(), string.view(), position, {}, js_undefined(), replace_value));
@@ -890,7 +890,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::search)
auto regexp = vm.argument(0);
if (!regexp.is_nullish()) {
if (auto* searcher = TRY(regexp.get_method(global_object, *vm.well_known_symbol_search())))
- return TRY(vm.call(*searcher, regexp, this_object));
+ return TRY(call(global_object, *searcher, regexp, this_object));
}
auto string = TRY(this_object.to_utf16_string(global_object));
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
index f615f17de4..61195355a6 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
@@ -99,7 +99,7 @@ ThrowCompletionOr<Vector<String>> calendar_fields(GlobalObject& global_object, O
// 3. If fields is not undefined, then
if (fields) {
// a. Set fieldsArray to ? Call(fields, calendar, « fieldsArray »).
- fields_array = TRY(vm.call(*fields, &calendar, fields_array));
+ fields_array = TRY(call(global_object, *fields, &calendar, fields_array));
}
// 4. Return ? IterableToListOfType(fieldsArray, « String »).
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp
index a9bb31d626..b94d8b5a82 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp
@@ -84,7 +84,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayConstructor::from)
auto k_value = values[k];
Value mapped_value;
if (map_fn)
- mapped_value = TRY(vm.call(*map_fn, this_arg, k_value, Value(k)));
+ mapped_value = TRY(JS::call(global_object, *map_fn, this_arg, k_value, Value(k)));
else
mapped_value = k_value;
TRY(target_object->set(k, mapped_value, Object::ShouldThrowExceptions::Yes));
@@ -104,7 +104,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayConstructor::from)
auto k_value = TRY(array_like->get(k));
Value mapped_value;
if (map_fn)
- mapped_value = TRY(vm.call(*map_fn, this_arg, k_value, Value(k)));
+ mapped_value = TRY(JS::call(global_object, *map_fn, this_arg, k_value, Value(k)));
else
mapped_value = k_value;
TRY(target_object->set(k, mapped_value, Object::ShouldThrowExceptions::Yes));
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp
index 895ea5465c..0ba83b5e1c 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp
@@ -109,7 +109,7 @@ static ThrowCompletionOr<void> for_each_item(VM& vm, GlobalObject& global_object
for (size_t i = 0; i < initial_length; ++i) {
auto value = TRY(typed_array->get(i));
- auto callback_result = TRY(vm.call(*callback_function, this_value, value, Value((i32)i), typed_array));
+ auto callback_result = TRY(call(global_object, *callback_function, this_value, value, Value((i32)i), typed_array));
if (callback(i, value, callback_result) == IterationDecision::Break)
break;
@@ -131,7 +131,7 @@ static ThrowCompletionOr<void> for_each_item_from_last(VM& vm, GlobalObject& glo
for (ssize_t i = (ssize_t)initial_length - 1; i >= 0; --i) {
auto value = TRY(typed_array->get(i));
- auto callback_result = TRY(vm.call(*callback_function, this_value, value, Value((i32)i), typed_array));
+ auto callback_result = TRY(call(global_object, *callback_function, this_value, value, Value((i32)i), typed_array));
if (callback(i, value, callback_result) == IterationDecision::Break)
break;
@@ -470,7 +470,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::reduce)
for (; k < length; ++k) {
auto k_value = MUST(typed_array->get(k));
- accumulator = TRY(vm.call(*callback_function, js_undefined(), accumulator, k_value, Value(k), typed_array));
+ accumulator = TRY(call(global_object, *callback_function, js_undefined(), accumulator, k_value, Value(k), typed_array));
}
return accumulator;
@@ -500,7 +500,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::reduce_right)
for (; k >= 0; --k) {
auto k_value = MUST(typed_array->get(k));
- accumulator = TRY(vm.call(*callback_function, js_undefined(), accumulator, k_value, Value(k), typed_array));
+ accumulator = TRY(call(global_object, *callback_function, js_undefined(), accumulator, k_value, Value(k), typed_array));
}
return accumulator;
@@ -845,7 +845,7 @@ static ThrowCompletionOr<void> typed_array_merge_sort(GlobalObject& global_objec
double comparison_result;
if (compare_function) {
- auto result = TRY(vm.call(*compare_function, js_undefined(), x, y));
+ auto result = TRY(call(global_object, *compare_function, js_undefined(), x, y));
auto value = TRY(result.to_number(global_object));
@@ -1214,7 +1214,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::filter)
auto value = MUST(typed_array->get(i));
// c. Let selected be ! ToBoolean(? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »)).
- auto callback_result = TRY(vm.call(*callback_function, this_value, value, Value((i32)i), typed_array)).to_boolean();
+ auto callback_result = TRY(call(global_object, *callback_function, this_value, value, Value((i32)i), typed_array)).to_boolean();
// d. If selected is true, then
if (callback_result) {
@@ -1277,7 +1277,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::map)
auto value = MUST(typed_array->get(i));
// c. Let mappedValue be ? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »).
- auto mapped_value = TRY(vm.call(*callback_function, this_value, value, Value((i32)i), typed_array));
+ auto mapped_value = TRY(call(global_object, *callback_function, this_value, value, Value((i32)i), typed_array));
// d. Perform ? Set(A, Pk, mappedValue, true).
TRY(return_array->set(i, mapped_value, Object::ShouldThrowExceptions::Yes));
diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp
index 0c0b31b62f..f0971404eb 100644
--- a/Userland/Libraries/LibJS/Runtime/VM.cpp
+++ b/Userland/Libraries/LibJS/Runtime/VM.cpp
@@ -69,7 +69,7 @@ VM::VM(OwnPtr<CustomData> custom_data)
auto error = vm.argument(0);
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « error »).
- MUST(JS::call(global_object, reject.cell(), js_undefined(), error));
+ MUST(call(global_object, reject.cell(), js_undefined(), error));
// b. Return undefined.
return js_undefined();
@@ -633,7 +633,7 @@ void VM::run_queued_promise_jobs()
pushed_execution_context = true;
}
- [[maybe_unused]] auto result = call(*job, js_undefined());
+ [[maybe_unused]] auto result = call(job->global_object(), *job, js_undefined());
// This doesn't match the spec, it actually defines that Job Abstract Closures must return
// a normal completion. In reality that's not the case however, and all major engines clear
@@ -984,12 +984,12 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu
// e. If namespace is an abrupt completion, then
if (namespace_.is_throw_completion()) {
// i. Perform ! Call(promiseCapability.[[Reject]], undefined, « namespace.[[Value]] »).
- MUST(JS::call(global_object, promise_capability.reject, js_undefined(), *namespace_.throw_completion().value()));
+ MUST(call(global_object, promise_capability.reject, js_undefined(), *namespace_.throw_completion().value()));
}
// f. Else,
else {
// i. Perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »).
- MUST(JS::call(global_object, promise_capability.resolve, js_undefined(), namespace_.release_value()));
+ MUST(call(global_object, promise_capability.resolve, js_undefined(), namespace_.release_value()));
}
// g. Return undefined.
return js_undefined();
@@ -1002,7 +1002,7 @@ void VM::finish_dynamic_import(ScriptOrModule referencing_script_or_module, Modu
auto rejected_closure = [promise_capability](VM& vm, GlobalObject& global_object) -> ThrowCompletionOr<Value> {
auto error = vm.argument(0);
// a. Perform ! Call(promiseCapability.[[Reject]], undefined, « error »).
- MUST(JS::call(global_object, promise_capability.reject, js_undefined(), error));
+ MUST(call(global_object, promise_capability.reject, js_undefined(), error));
// b. Return undefined.
return js_undefined();
};
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp
index 736cdd72ed..089bda8d69 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Value.cpp
@@ -11,6 +11,7 @@
#include <AK/Utf8View.h>
#include <LibCrypto/BigInt/SignedBigInteger.h>
#include <LibCrypto/NumberTheory/ModularFunctions.h>
+#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Accessor.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/BigInt.h>
@@ -421,7 +422,7 @@ ThrowCompletionOr<Value> Value::to_primitive(GlobalObject& global_object, Prefer
auto to_primitive_method = TRY(get_method(global_object, *vm.well_known_symbol_to_primitive()));
if (to_primitive_method) {
auto hint = get_hint_for_preferred_type();
- auto result = TRY(vm.call(*to_primitive_method, *this, js_string(vm, hint)));
+ auto result = TRY(call(global_object, *to_primitive_method, *this, js_string(vm, hint)));
if (!result.is_object())
return result;
return vm.throw_completion<TypeError>(global_object, ErrorType::ToPrimitiveReturnedObject, to_string_without_side_effects(), hint);
@@ -1180,7 +1181,7 @@ ThrowCompletionOr<Value> instance_of(GlobalObject& global_object, Value lhs, Val
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, rhs.to_string_without_side_effects());
auto has_instance_method = TRY(rhs.get_method(global_object, *vm.well_known_symbol_has_instance()));
if (has_instance_method) {
- auto has_instance_result = TRY(vm.call(*has_instance_method, rhs, lhs));
+ auto has_instance_result = TRY(call(global_object, *has_instance_method, rhs, lhs));
return Value(has_instance_result.to_boolean());
}
if (!rhs.is_function())
@@ -1507,7 +1508,7 @@ ThrowCompletionOr<Value> Value::invoke_internal(GlobalObject& global_object, JS:
if (!property.is_function())
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, property.to_string_without_side_effects());
- return vm.call(property.as_function(), *this, move(arguments));
+ return call(global_object, property.as_function(), *this, move(arguments));
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp b/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp
index 1883acfbaf..75d85f7ad1 100644
--- a/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp
@@ -61,7 +61,7 @@ ThrowCompletionOr<Object*> WeakMapConstructor::construct(FunctionObject& new_tar
auto key = TRY(iterator_value.as_object().get(0));
auto value = TRY(iterator_value.as_object().get(1));
- TRY(vm.call(adder.as_function(), Value(weak_map), key, value));
+ TRY(JS::call(global_object, adder.as_function(), weak_map, key, value));
return {};
}));
diff --git a/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp b/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp
index 07e13c3b2c..228ec083aa 100644
--- a/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp
@@ -56,7 +56,7 @@ ThrowCompletionOr<Object*> WeakSetConstructor::construct(FunctionObject& new_tar
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, "'add' property of WeakSet");
(void)TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional<Completion> {
- TRY(vm.call(adder.as_function(), Value(weak_set), iterator_value));
+ TRY(JS::call(global_object, adder.as_function(), weak_set, iterator_value));
return {};
}));
diff --git a/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp b/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp
index b7dba26c5d..d4ec043ebe 100644
--- a/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp
+++ b/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp
@@ -6,6 +6,7 @@
#include <AK/Assertions.h>
#include <AK/TypeCasts.h>
+#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibWeb/Bindings/EventTargetWrapper.h>
#include <LibWeb/Bindings/EventTargetWrapperFactory.h>
@@ -89,7 +90,7 @@ bool EventDispatcher::inner_invoke(Event& event, Vector<EventTarget::EventListen
auto* this_value = Bindings::wrap(global, *event.current_target());
auto* wrapped_event = Bindings::wrap(global, event);
auto& vm = global.vm();
- [[maybe_unused]] auto rc = vm.call(listener.listener->function(), this_value, wrapped_event);
+ [[maybe_unused]] auto rc = JS::call(global, function, this_value, wrapped_event);
if (vm.exception()) {
vm.clear_exception();
// FIXME: Set legacyOutputDidListenersThrowFlag if given. (Only used by IndexedDB currently)
diff --git a/Userland/Libraries/LibWeb/DOM/Window.cpp b/Userland/Libraries/LibWeb/DOM/Window.cpp
index 0ddac4e754..364b58f784 100644
--- a/Userland/Libraries/LibWeb/DOM/Window.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Window.cpp
@@ -6,6 +6,7 @@
*/
#include <LibGUI/DisplayLink.h>
+#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/ResolvedCSSStyleDeclaration.h>
@@ -171,7 +172,7 @@ void Window::timer_did_fire(Badge<Timer>, Timer& timer)
VERIFY(wrapper());
auto& vm = wrapper()->vm();
- [[maybe_unused]] auto rc = vm.call(strong_timer->callback(), wrapper());
+ [[maybe_unused]] auto rc = JS::call(wrapper()->global_object(), strong_timer->callback(), wrapper());
if (vm.exception())
vm.clear_exception();
});
@@ -202,7 +203,7 @@ i32 Window::request_animation_frame(JS::FunctionObject& js_callback)
auto callback = request_animation_frame_driver().add([this, handle = JS::make_handle(&js_callback)](i32 id) mutable {
auto& function = *handle.cell();
auto& vm = function.vm();
- (void)vm.call(function, JS::js_undefined(), JS::Value(performance().now()));
+ (void)JS::call(function.global_object(), function, JS::js_undefined(), JS::Value(performance().now()));
if (vm.exception())
vm.clear_exception();
m_request_animation_frame_callbacks.remove(id);
@@ -393,7 +394,7 @@ void Window::queue_microtask(JS::FunctionObject& callback)
// The queueMicrotask(callback) method must queue a microtask to invoke callback,
HTML::queue_a_microtask(associated_document(), [&callback, handle = JS::make_handle(&callback)]() {
auto& vm = callback.vm();
- [[maybe_unused]] auto rc = vm.call(callback, JS::js_null());
+ [[maybe_unused]] auto rc = JS::call(callback.global_object(), callback, JS::js_null());
// FIXME: ...and if callback throws an exception, report the exception.
if (vm.exception())
vm.clear_exception();
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
index 201613f6f0..929ca881e6 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
@@ -215,7 +215,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 = vm.call(function, JS::js_undefined(), move(argument_values));
+ auto result_or_error = JS::call(global_object, function, JS::js_undefined(), move(argument_values));
if (result_or_error.is_error()) {
vm.clear_exception();
return Wasm::Trap();