diff options
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp b/Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp index bb1133849a..a70fdd5d8e 100644 --- a/Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp @@ -33,56 +33,46 @@ DataViewConstructor::~DataViewConstructor() } // 25.3.2.1 DataView ( buffer [ , byteOffset [ , byteLength ] ] ), https://tc39.es/ecma262/#sec-dataview-buffer-byteoffset-bytelength -Value DataViewConstructor::call() +ThrowCompletionOr<Value> DataViewConstructor::call() { auto& vm = this->vm(); - vm.throw_exception<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, vm.names.DataView); - return {}; + return vm.throw_completion<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, vm.names.DataView); } // 25.3.2.1 DataView ( buffer [ , byteOffset [ , byteLength ] ] ), https://tc39.es/ecma262/#sec-dataview-buffer-byteoffset-bytelength -Value DataViewConstructor::construct(FunctionObject& new_target) +ThrowCompletionOr<Object*> DataViewConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); auto& global_object = this->global_object(); auto buffer = vm.argument(0); - if (!buffer.is_object() || !is<ArrayBuffer>(buffer.as_object())) { - vm.throw_exception<TypeError>(global_object, ErrorType::IsNotAn, buffer.to_string_without_side_effects(), vm.names.ArrayBuffer); - return {}; - } + if (!buffer.is_object() || !is<ArrayBuffer>(buffer.as_object())) + return vm.throw_completion<TypeError>(global_object, ErrorType::IsNotAn, buffer.to_string_without_side_effects(), vm.names.ArrayBuffer); + auto& array_buffer = static_cast<ArrayBuffer&>(buffer.as_object()); - auto offset = TRY_OR_DISCARD(vm.argument(1).to_index(global_object)); + auto offset = TRY(vm.argument(1).to_index(global_object)); - if (array_buffer.is_detached()) { - vm.throw_exception<TypeError>(global_object, ErrorType::DetachedArrayBuffer); - return {}; - } + if (array_buffer.is_detached()) + return vm.throw_completion<TypeError>(global_object, ErrorType::DetachedArrayBuffer); auto buffer_byte_length = array_buffer.byte_length(); - if (offset > buffer_byte_length) { - vm.throw_exception<RangeError>(global_object, ErrorType::DataViewOutOfRangeByteOffset, offset, buffer_byte_length); - return {}; - } + if (offset > buffer_byte_length) + return vm.throw_completion<RangeError>(global_object, ErrorType::DataViewOutOfRangeByteOffset, offset, buffer_byte_length); size_t view_byte_length; if (vm.argument(2).is_undefined()) { view_byte_length = buffer_byte_length - offset; } else { - 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 {}; - } + view_byte_length = TRY(vm.argument(2).to_index(global_object)); + if (offset + view_byte_length > buffer_byte_length) + return vm.throw_completion<RangeError>(global_object, ErrorType::InvalidLength, vm.names.DataView); } - auto* data_view = TRY_OR_DISCARD(ordinary_create_from_constructor<DataView>(global_object, new_target, &GlobalObject::data_view_prototype, &array_buffer, view_byte_length, offset)); + auto* data_view = TRY(ordinary_create_from_constructor<DataView>(global_object, new_target, &GlobalObject::data_view_prototype, &array_buffer, view_byte_length, offset)); - if (array_buffer.is_detached()) { - vm.throw_exception<TypeError>(global_object, ErrorType::DetachedArrayBuffer); - return {}; - } + if (array_buffer.is_detached()) + return vm.throw_completion<TypeError>(global_object, ErrorType::DetachedArrayBuffer); return data_view; } |