1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:47:45 +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

@ -40,18 +40,17 @@ SymbolConstructor::~SymbolConstructor()
}
// 20.4.1.1 Symbol ( [ description ] ), https://tc39.es/ecma262/#sec-symbol-description
Value SymbolConstructor::call()
ThrowCompletionOr<Value> SymbolConstructor::call()
{
if (vm().argument(0).is_undefined())
return js_symbol(heap(), {}, false);
return js_symbol(heap(), TRY_OR_DISCARD(vm().argument(0).to_string(global_object())), false);
return js_symbol(heap(), TRY(vm().argument(0).to_string(global_object())), false);
}
// 20.4.1.1 Symbol ( [ description ] ), https://tc39.es/ecma262/#sec-symbol-description
Value SymbolConstructor::construct(FunctionObject&)
ThrowCompletionOr<Object*> SymbolConstructor::construct(FunctionObject&)
{
vm().throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, "Symbol");
return {};
return vm().throw_completion<TypeError>(global_object(), ErrorType::NotAConstructor, "Symbol");
}
// 20.4.2.2 Symbol.for ( key ), https://tc39.es/ecma262/#sec-symbol.for