1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

LibJS: Convert to_index() to ThrowCompletionOr

This commit is contained in:
Idan Horowitz 2021-10-18 00:05:01 +03:00
parent aad12b050b
commit 85a28a6555
7 changed files with 25 additions and 40 deletions

View file

@ -53,9 +53,7 @@ Value DataViewConstructor::construct(FunctionObject& new_target)
}
auto& array_buffer = static_cast<ArrayBuffer&>(buffer.as_object());
auto offset = vm.argument(1).to_index(global_object);
if (vm.exception())
return {};
auto offset = TRY_OR_DISCARD(vm.argument(1).to_index(global_object));
if (array_buffer.is_detached()) {
vm.throw_exception<TypeError>(global_object, ErrorType::DetachedArrayBuffer);
@ -72,9 +70,7 @@ Value DataViewConstructor::construct(FunctionObject& new_target)
if (vm.argument(2).is_undefined()) {
view_byte_length = buffer_byte_length - offset;
} else {
view_byte_length = vm.argument(2).to_index(global_object);
if (vm.exception())
return {};
view_byte_length = TRY_OR_DISCARD(vm.argument(2).to_index(global_object));
if (offset + view_byte_length > buffer_byte_length) {
vm.throw_exception<RangeError>(global_object, ErrorType::InvalidLength, vm.names.DataView);
return {};