mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:17: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,15 +40,14 @@ ArrayBufferConstructor::~ArrayBufferConstructor()
|
|||
}
|
||||
|
||||
// 25.1.3.1 ArrayBuffer ( length ), https://tc39.es/ecma262/#sec-arraybuffer-length
|
||||
Value ArrayBufferConstructor::call()
|
||||
ThrowCompletionOr<Value> ArrayBufferConstructor::call()
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
vm.throw_exception<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, vm.names.ArrayBuffer);
|
||||
return {};
|
||||
return vm.throw_completion<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, vm.names.ArrayBuffer);
|
||||
}
|
||||
|
||||
// 25.1.3.1 ArrayBuffer ( length ), https://tc39.es/ecma262/#sec-arraybuffer-length
|
||||
Value ArrayBufferConstructor::construct(FunctionObject& new_target)
|
||||
ThrowCompletionOr<Object*> ArrayBufferConstructor::construct(FunctionObject& new_target)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto byte_length_or_error = vm.argument(0).to_index(global_object());
|
||||
|
@ -57,11 +56,11 @@ Value ArrayBufferConstructor::construct(FunctionObject& new_target)
|
|||
if (error.value().is_object() && is<RangeError>(error.value().as_object())) {
|
||||
// Re-throw more specific RangeError
|
||||
vm.clear_exception();
|
||||
vm.throw_exception<RangeError>(global_object(), ErrorType::InvalidLength, "array buffer");
|
||||
return vm.throw_completion<RangeError>(global_object(), ErrorType::InvalidLength, "array buffer");
|
||||
}
|
||||
return {};
|
||||
return error;
|
||||
}
|
||||
return TRY_OR_DISCARD(allocate_array_buffer(global_object(), new_target, byte_length_or_error.release_value()));
|
||||
return TRY(allocate_array_buffer(global_object(), new_target, byte_length_or_error.release_value()));
|
||||
}
|
||||
|
||||
// 25.1.4.1 ArrayBuffer.isView ( arg ), https://tc39.es/ecma262/#sec-arraybuffer.isview
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue