1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:27:45 +00:00

LibJS: Replace GlobalObject with VM in common AOs [Part 18/19]

This commit is contained in:
Linus Groh 2022-08-21 19:24:32 +01:00
parent 7856886ed5
commit 25849f8a6d
95 changed files with 536 additions and 677 deletions

View file

@ -18,9 +18,6 @@ namespace JS {
// 27.2.2.1 NewPromiseReactionJob ( reaction, argument ), https://tc39.es/ecma262/#sec-newpromisereactionjob
static ThrowCompletionOr<Value> run_reaction_job(VM& vm, PromiseReaction& reaction, Value argument)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// a. Let promiseCapability be reaction.[[Capability]].
auto& promise_capability = reaction.capability();
@ -78,23 +75,20 @@ static ThrowCompletionOr<Value> run_reaction_job(VM& vm, PromiseReaction& reacti
// i. Return ? Call(promiseCapability.[[Reject]], undefined, « handlerResult.[[Value]] »).
auto* reject_function = promise_capability.value().reject;
dbgln_if(PROMISE_DEBUG, "run_reaction_job: Calling PromiseCapability's reject function @ {}", reject_function);
return call(global_object, *reject_function, js_undefined(), *handler_result.value());
return call(vm, *reject_function, js_undefined(), *handler_result.value());
}
// i. Else,
else {
// i. Return ? Call(promiseCapability.[[Resolve]], undefined, « handlerResult.[[Value]] »).
auto* resolve_function = promise_capability.value().resolve;
dbgln_if(PROMISE_DEBUG, "[PromiseReactionJob]: Calling PromiseCapability's resolve function @ {}", resolve_function);
return call(global_object, *resolve_function, js_undefined(), *handler_result.value());
return call(vm, *resolve_function, js_undefined(), *handler_result.value());
}
}
// 27.2.2.1 NewPromiseReactionJob ( reaction, argument ), https://tc39.es/ecma262/#sec-newpromisereactionjob
PromiseJob create_promise_reaction_job(VM& vm, PromiseReaction& reaction, Value argument)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 1. Let job be a new Job Abstract Closure with no parameters that captures reaction and argument and performs the following steps when called:
// See run_reaction_job for "the following steps".
auto job = [&vm, reaction = make_handle(&reaction), argument = make_handle(argument)]() mutable {
@ -108,7 +102,7 @@ PromiseJob create_promise_reaction_job(VM& vm, PromiseReaction& reaction, Value
auto& handler = reaction.handler();
if (handler.has_value()) {
// a. Let getHandlerRealmResult be Completion(GetFunctionRealm(reaction.[[Handler]].[[Callback]])).
auto get_handler_realm_result = get_function_realm(global_object, *handler->callback.cell());
auto get_handler_realm_result = get_function_realm(vm, *handler->callback.cell());
// b. If getHandlerRealmResult is a normal completion, set handlerRealm to getHandlerRealmResult.[[Value]].
if (!get_handler_realm_result.is_throw_completion()) {
@ -128,9 +122,6 @@ PromiseJob create_promise_reaction_job(VM& vm, PromiseReaction& reaction, Value
// 27.2.2.2 NewPromiseResolveThenableJob ( promiseToResolve, thenable, then ), https://tc39.es/ecma262/#sec-newpromiseresolvethenablejob
static ThrowCompletionOr<Value> run_resolve_thenable_job(VM& vm, Promise& promise_to_resolve, Value thenable, JobCallback& then)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// a. Let resolvingFunctions be CreateResolvingFunctions(promiseToResolve).
auto [resolve_function, reject_function] = promise_to_resolve.create_resolving_functions();
@ -145,7 +136,7 @@ static ThrowCompletionOr<Value> run_resolve_thenable_job(VM& vm, Promise& promis
if (then_call_result.is_error()) {
// i. Return ? Call(resolvingFunctions.[[Reject]], undefined, « thenCallResult.[[Value]] »).
dbgln_if(PROMISE_DEBUG, "run_resolve_thenable_job: then_call_result is an abrupt completion, calling reject function with value {}", *then_call_result.throw_completion().value());
return call(global_object, &reject_function, js_undefined(), *then_call_result.throw_completion().value());
return call(vm, &reject_function, js_undefined(), *then_call_result.throw_completion().value());
}
// d. Return ? thenCallResult.
@ -156,11 +147,8 @@ static ThrowCompletionOr<Value> run_resolve_thenable_job(VM& vm, Promise& promis
// 27.2.2.2 NewPromiseResolveThenableJob ( promiseToResolve, thenable, then ), https://tc39.es/ecma262/#sec-newpromiseresolvethenablejob
PromiseJob create_promise_resolve_thenable_job(VM& vm, Promise& promise_to_resolve, Value thenable, JobCallback then)
{
auto& realm = *vm.current_realm();
auto& global_object = realm.global_object();
// 2. Let getThenRealmResult be Completion(GetFunctionRealm(then.[[Callback]])).
auto get_then_realm_result = get_function_realm(global_object, *then.callback.cell());
auto get_then_realm_result = get_function_realm(vm, *then.callback.cell());
Realm* then_realm;