diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp index c140108a95..89cba9b86d 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp @@ -48,7 +48,7 @@ Value ArrayBufferConstructor::call() } // 25.1.3.1 ArrayBuffer ( length ), https://tc39.es/ecma262/#sec-arraybuffer-length -Value ArrayBufferConstructor::construct(FunctionObject&) +Value ArrayBufferConstructor::construct(FunctionObject& new_target) { auto& vm = this->vm(); auto byte_length = vm.argument(0).to_index(global_object()); @@ -60,11 +60,7 @@ Value ArrayBufferConstructor::construct(FunctionObject&) } return {}; } - auto array_buffer = ArrayBuffer::create(global_object(), byte_length); - if (!array_buffer) - return {}; - - return array_buffer; + return TRY_OR_DISCARD(allocate_array_buffer(global_object(), new_target, byte_length)); } // 25.1.4.1 ArrayBuffer.isView ( arg ), https://tc39.es/ecma262/#sec-arraybuffer.isview diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index 83076eac38..21240371cc 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -186,9 +187,7 @@ static ThrowCompletionOr initialize_typed_array_from_typed_array(GlobalObj // 15. Else, // a. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength). - auto data = ArrayBuffer::create(global_object, byte_length.value()); - if (auto* exception = vm.exception()) - return throw_completion(exception->value()); + auto* data = TRY(allocate_array_buffer(global_object, *global_object.array_buffer_constructor(), byte_length.value())); // b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception. if (src_data->is_detached()) @@ -266,9 +265,7 @@ static ThrowCompletionOr initialize_typed_array_from_array_like(GlobalObje auto byte_length = element_size * length; // 5. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength). - auto* data = ArrayBuffer::create(global_object, byte_length); - if (auto* exception = vm.exception()) - return throw_completion(exception->value()); + auto* data = TRY(allocate_array_buffer(global_object, *global_object.array_buffer_constructor(), byte_length)); // 6. Set O.[[ViewedArrayBuffer]] to data. typed_array.set_viewed_array_buffer(data); @@ -319,9 +316,7 @@ static ThrowCompletionOr initialize_typed_array_from_list(GlobalObject& gl if (Checked::multiplication_would_overflow(element_size, length)) return vm.template throw_completion(global_object, ErrorType::InvalidLength, "typed array"); auto byte_length = element_size * length; - auto array_buffer = ArrayBuffer::create(global_object, byte_length); - if (auto* exception = vm.exception()) - return throw_completion(exception->value()); + auto array_buffer = TRY(allocate_array_buffer(global_object, *global_object.array_buffer_constructor(), byte_length)); typed_array.set_viewed_array_buffer(array_buffer); typed_array.set_byte_length(byte_length); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp index 1033bb8268..461e5b4ff9 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp @@ -55,7 +55,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter) if (!memory) return JS::js_undefined(); - auto array_buffer = JS::ArrayBuffer::create(global_object, &memory->data()); + auto array_buffer = TRY_OR_DISCARD(JS::ArrayBuffer::create(global_object, &memory->data())); array_buffer->set_detach_key(JS::js_string(vm, "WebAssembly.Memory")); return array_buffer; }