mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:37:36 +00:00
LibJS: Remove GlobalObject from VM::throw_completion()
This is a continuation of the previous five commits. A first big step into the direction of no longer having to pass a realm (or currently, a global object) trough layers upon layers of AOs! Unlike the create() APIs we can safely assume that this is only ever called when a running execution context and therefore current realm exists. If not, you can always manually allocate the Error and put it in a Completion :^) In the spec, throw exceptions implicitly use the current realm's intrinsics as well: https://tc39.es/ecma262/#sec-throw-an-exception
This commit is contained in:
parent
5398dcc55e
commit
f3117d46dc
165 changed files with 892 additions and 900 deletions
|
@ -19,7 +19,7 @@ ThrowCompletionOr<PromiseCapability> new_promise_capability(GlobalObject& global
|
|||
|
||||
// 1. If IsConstructor(C) is false, throw a TypeError exception.
|
||||
if (!constructor.is_constructor())
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAConstructor, constructor.to_string_without_side_effects());
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAConstructor, constructor.to_string_without_side_effects());
|
||||
|
||||
// 2. NOTE: C is assumed to be a constructor function that supports the parameter conventions of the Promise constructor (see 27.2.3.1).
|
||||
|
||||
|
@ -32,18 +32,18 @@ ThrowCompletionOr<PromiseCapability> new_promise_capability(GlobalObject& global
|
|||
} promise_capability_functions;
|
||||
|
||||
// 4. Let executorClosure be a new Abstract Closure with parameters (resolve, reject) that captures promiseCapability and performs the following steps when called:
|
||||
auto executor_closure = [&promise_capability_functions](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
|
||||
auto executor_closure = [&promise_capability_functions](auto& vm, auto&) -> ThrowCompletionOr<Value> {
|
||||
auto resolve = vm.argument(0);
|
||||
auto reject = vm.argument(1);
|
||||
|
||||
// No idea what other engines say here.
|
||||
// a. If promiseCapability.[[Resolve]] is not undefined, throw a TypeError exception.
|
||||
if (!promise_capability_functions.resolve.is_undefined())
|
||||
return vm.template throw_completion<TypeError>(global_object, ErrorType::GetCapabilitiesExecutorCalledMultipleTimes);
|
||||
return vm.template throw_completion<TypeError>(ErrorType::GetCapabilitiesExecutorCalledMultipleTimes);
|
||||
|
||||
// b. If promiseCapability.[[Reject]] is not undefined, throw a TypeError exception.
|
||||
if (!promise_capability_functions.reject.is_undefined())
|
||||
return vm.template throw_completion<TypeError>(global_object, ErrorType::GetCapabilitiesExecutorCalledMultipleTimes);
|
||||
return vm.template throw_completion<TypeError>(ErrorType::GetCapabilitiesExecutorCalledMultipleTimes);
|
||||
|
||||
// c. Set promiseCapability.[[Resolve]] to resolve.
|
||||
promise_capability_functions.resolve = resolve;
|
||||
|
@ -63,11 +63,11 @@ ThrowCompletionOr<PromiseCapability> new_promise_capability(GlobalObject& global
|
|||
|
||||
// 7. If IsCallable(promiseCapability.[[Resolve]]) is false, throw a TypeError exception.
|
||||
if (!promise_capability_functions.resolve.is_function())
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, promise_capability_functions.resolve.to_string_without_side_effects());
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAFunction, promise_capability_functions.resolve.to_string_without_side_effects());
|
||||
|
||||
// 8. If IsCallable(promiseCapability.[[Reject]]) is false, throw a TypeError exception.
|
||||
if (!promise_capability_functions.reject.is_function())
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, promise_capability_functions.reject.to_string_without_side_effects());
|
||||
return vm.throw_completion<TypeError>(ErrorType::NotAFunction, promise_capability_functions.reject.to_string_without_side_effects());
|
||||
|
||||
// 9. Set promiseCapability.[[Promise]] to promise.
|
||||
// 10. Return promiseCapability.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue