1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:18:12 +00: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
99 changed files with 597 additions and 669 deletions

View file

@ -113,8 +113,6 @@ ThrowCompletionOr<Value> NativeFunction::internal_call(Value this_argument, Mark
vm.pop_execution_context();
// 12. Return result.
if (auto* exception = vm.exception())
return throw_completion(exception->value());
return result;
}
@ -179,17 +177,15 @@ ThrowCompletionOr<Object*> NativeFunction::internal_construct(MarkedValueList ar
vm.pop_execution_context();
// 12. Return result.
if (auto* exception = vm.exception())
return throw_completion(exception->value());
return &result.as_object();
return result;
}
Value NativeFunction::call()
ThrowCompletionOr<Value> NativeFunction::call()
{
return TRY_OR_DISCARD(m_native_function(vm(), global_object()));
return m_native_function(vm(), global_object());
}
Value NativeFunction::construct(FunctionObject&)
ThrowCompletionOr<Object*> NativeFunction::construct(FunctionObject&)
{
// Needs to be overridden if [[Construct]] is needed.
VERIFY_NOT_REACHED();