mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:57:46 +00:00
LibJS: Convert the NewPromiseCapability AO to ThrowCompletionOr
This commit is contained in:
parent
2b87f77578
commit
0d602c5ec5
6 changed files with 19 additions and 41 deletions
|
@ -13,13 +13,11 @@
|
|||
namespace JS {
|
||||
|
||||
// 27.2.1.5 NewPromiseCapability ( C ), https://tc39.es/ecma262/#sec-newpromisecapability
|
||||
PromiseCapability new_promise_capability(GlobalObject& global_object, Value constructor)
|
||||
ThrowCompletionOr<PromiseCapability> new_promise_capability(GlobalObject& global_object, Value constructor)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
if (!constructor.is_constructor()) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAConstructor, constructor.to_string_without_side_effects());
|
||||
return {};
|
||||
}
|
||||
if (!constructor.is_constructor())
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAConstructor, constructor.to_string_without_side_effects());
|
||||
|
||||
struct {
|
||||
Value resolve { js_undefined() };
|
||||
|
@ -46,18 +44,14 @@ PromiseCapability new_promise_capability(GlobalObject& global_object, Value cons
|
|||
|
||||
MarkedValueList arguments(vm.heap());
|
||||
arguments.append(executor);
|
||||
auto* promise = TRY_OR_DISCARD(construct(global_object, constructor.as_function(), move(arguments)));
|
||||
auto* promise = TRY(construct(global_object, constructor.as_function(), move(arguments)));
|
||||
|
||||
if (!promise_capability_functions.resolve.is_function()) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, promise_capability_functions.resolve.to_string_without_side_effects());
|
||||
return {};
|
||||
}
|
||||
if (!promise_capability_functions.reject.is_function()) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, promise_capability_functions.reject.to_string_without_side_effects());
|
||||
return {};
|
||||
}
|
||||
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());
|
||||
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 {
|
||||
return PromiseCapability {
|
||||
promise,
|
||||
&promise_capability_functions.resolve.as_function(),
|
||||
&promise_capability_functions.reject.as_function(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue