mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:07:35 +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:
parent
0881f8160f
commit
5832de62fe
99 changed files with 597 additions and 669 deletions
|
@ -40,7 +40,7 @@ BigIntConstructor::~BigIntConstructor()
|
|||
}
|
||||
|
||||
// 21.2.1.1 BigInt ( value ), https://tc39.es/ecma262/#sec-bigint-constructor-number-value
|
||||
Value BigIntConstructor::call()
|
||||
ThrowCompletionOr<Value> BigIntConstructor::call()
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
@ -48,21 +48,20 @@ Value BigIntConstructor::call()
|
|||
auto value = vm.argument(0);
|
||||
|
||||
// 2. Let prim be ? ToPrimitive(value, number).
|
||||
auto primitive = TRY_OR_DISCARD(value.to_primitive(global_object, Value::PreferredType::Number));
|
||||
auto primitive = TRY(value.to_primitive(global_object, Value::PreferredType::Number));
|
||||
|
||||
// 3. If Type(prim) is Number, return ? NumberToBigInt(prim).
|
||||
if (primitive.is_number())
|
||||
return number_to_bigint(global_object, primitive);
|
||||
|
||||
// 4. Otherwise, return ? ToBigInt(value).
|
||||
return TRY_OR_DISCARD(value.to_bigint(global_object));
|
||||
return TRY(value.to_bigint(global_object));
|
||||
}
|
||||
|
||||
// 21.2.1.1 BigInt ( value ), https://tc39.es/ecma262/#sec-bigint-constructor-number-value
|
||||
Value BigIntConstructor::construct(FunctionObject&)
|
||||
ThrowCompletionOr<Object*> BigIntConstructor::construct(FunctionObject&)
|
||||
{
|
||||
vm().throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, "BigInt");
|
||||
return {};
|
||||
return vm().throw_completion<TypeError>(global_object(), ErrorType::NotAConstructor, "BigInt");
|
||||
}
|
||||
|
||||
// 21.2.2.1 BigInt.asIntN ( bits, bigint ), https://tc39.es/ecma262/#sec-bigint.asintn
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue