1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 02:13:56 +09:00

LibJS: Convert NativeFunction::{call,construct}() to ThrowCompletionOr

Both at the same time because many of them call construct() in call()
and I'm not keen on adding a bunch of temporary plumbing to turn
exceptions into throw completions.
Also changes the return value of construct() to Object* instead of Value
as it always needs to return an object; allowing an arbitrary Value is a
massive foot gun.
This commit is contained in:
Linus Groh 2021-10-20 21:16:30 +01:00
parent 0881f8160f
commit 5832de62fe
Notes: sideshowbarker 2024-07-18 02:06:32 +09:00
99 changed files with 597 additions and 669 deletions

View file

@ -251,26 +251,23 @@ void PromiseConstructor::initialize(GlobalObject& global_object)
}
// 27.2.3.1 Promise ( executor ), https://tc39.es/ecma262/#sec-promise-executor
Value PromiseConstructor::call()
ThrowCompletionOr<Value> PromiseConstructor::call()
{
auto& vm = this->vm();
vm.throw_exception<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, vm.names.Promise);
return {};
return vm.throw_completion<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, vm.names.Promise);
}
// 27.2.3.1 Promise ( executor ), https://tc39.es/ecma262/#sec-promise-executor
Value PromiseConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<Object*> PromiseConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto executor = vm.argument(0);
if (!executor.is_function()) {
vm.throw_exception<TypeError>(global_object, ErrorType::PromiseExecutorNotAFunction);
return {};
}
if (!executor.is_function())
return vm.throw_completion<TypeError>(global_object, ErrorType::PromiseExecutorNotAFunction);
auto* promise = TRY_OR_DISCARD(ordinary_create_from_constructor<Promise>(global_object, new_target, &GlobalObject::promise_prototype));
auto* promise = TRY(ordinary_create_from_constructor<Promise>(global_object, new_target, &GlobalObject::promise_prototype));
auto [resolve_function, reject_function] = promise->create_resolving_functions();
@ -278,7 +275,7 @@ Value PromiseConstructor::construct(FunctionObject& new_target)
if (auto* exception = vm.exception()) {
vm.clear_exception();
vm.stop_unwind();
(void)vm.call(reject_function, js_undefined(), exception->value());
TRY(vm.call(reject_function, js_undefined(), exception->value()));
}
return promise;
}