mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-28 10:37:17 +02:00
LibJS: Partially implement resizable ArrayBuffer objects
This is (part of) a normative change in the ECMA-262 spec. See: https://github.com/tc39/ecma262/commit/a9ae96e This implements just support for resizing ArrayBuffer objects. This does not implement the SharedArrayBuffer changes, as we do not have enough support to do so.
This commit is contained in:
committed by
Andreas Kling
parent
a1e2f131c4
commit
29ac6e3689
Notes:
sideshowbarker
2024-07-17 09:37:30 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/29ac6e3689 Pull-request: https://github.com/SerenityOS/serenity/pull/22424 Reviewed-by: https://github.com/shannonbooth ✅
@@ -52,8 +52,11 @@ ThrowCompletionOr<NonnullGCPtr<Object>> ArrayBufferConstructor::construct(Functi
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
auto length = vm.argument(0);
|
||||
auto options = vm.argument(1);
|
||||
|
||||
// 2. Let byteLength be ? ToIndex(length).
|
||||
auto byte_length_or_error = vm.argument(0).to_index(vm);
|
||||
auto byte_length_or_error = length.to_index(vm);
|
||||
|
||||
if (byte_length_or_error.is_error()) {
|
||||
auto error = byte_length_or_error.release_error();
|
||||
@@ -64,8 +67,11 @@ ThrowCompletionOr<NonnullGCPtr<Object>> ArrayBufferConstructor::construct(Functi
|
||||
return error;
|
||||
}
|
||||
|
||||
// 3. Return ? AllocateArrayBuffer(NewTarget, byteLength).
|
||||
return *TRY(allocate_array_buffer(vm, new_target, byte_length_or_error.release_value()));
|
||||
// 3. Let requestedMaxByteLength be ? GetArrayBufferMaxByteLengthOption(options).
|
||||
auto requested_max_byte_length = TRY(get_array_buffer_max_byte_length_option(vm, options));
|
||||
|
||||
// 3. Return ? AllocateArrayBuffer(NewTarget, byteLength, requestedMaxByteLength).
|
||||
return *TRY(allocate_array_buffer(vm, new_target, byte_length_or_error.release_value(), requested_max_byte_length));
|
||||
}
|
||||
|
||||
// 25.1.5.1 ArrayBuffer.isView ( arg ), https://tc39.es/ecma262/#sec-arraybuffer.isview
|
||||
|
||||
Reference in New Issue
Block a user