1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:38:13 +00:00

LibJS: Convert NativeFunction callback to ThrowCompletionOr

This commit is contained in:
Idan Horowitz 2021-10-19 22:53:27 +03:00 committed by Linus Groh
parent 20163c0584
commit ca27e5eff5
13 changed files with 91 additions and 65 deletions

View file

@ -26,17 +26,15 @@ PromiseCapability new_promise_capability(GlobalObject& global_object, Value cons
} promise_capability_functions;
// 27.2.1.5.1 GetCapabilitiesExecutor Functions, https://tc39.es/ecma262/#sec-getcapabilitiesexecutor-functions
auto* executor = NativeFunction::create(global_object, "", [&promise_capability_functions](auto& vm, auto& global_object) -> Value {
auto* executor = NativeFunction::create(global_object, "", [&promise_capability_functions](auto& vm, auto& global_object) -> ThrowCompletionOr<Value> {
auto resolve = vm.argument(0);
auto reject = vm.argument(1);
// No idea what other engines say here.
if (!promise_capability_functions.resolve.is_undefined()) {
vm.template throw_exception<TypeError>(global_object, ErrorType::GetCapabilitiesExecutorCalledMultipleTimes);
return {};
return vm.template throw_completion<TypeError>(global_object, ErrorType::GetCapabilitiesExecutorCalledMultipleTimes);
}
if (!promise_capability_functions.reject.is_undefined()) {
vm.template throw_exception<TypeError>(global_object, ErrorType::GetCapabilitiesExecutorCalledMultipleTimes);
return {};
return vm.template throw_completion<TypeError>(global_object, ErrorType::GetCapabilitiesExecutorCalledMultipleTimes);
}
promise_capability_functions.resolve = resolve;
promise_capability_functions.reject = reject;