1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 15:55:06 +00:00

LibJS+LibWeb: Implement resizable ArrayBuffer support for DataView

This is (part of) a normative change in the ECMA-262 spec. See:
a9ae96e
This commit is contained in:
Timothy Flynn 2023-10-15 09:46:09 -04:00 committed by Andreas Kling
parent 29ac6e3689
commit c7fec9424c
12 changed files with 377 additions and 94 deletions

View file

@ -522,7 +522,23 @@ private:
{
// 14. Otherwise, if value has a [[ViewedArrayBuffer]] internal slot, then:
// FIXME: 1. If IsArrayBufferViewOutOfBounds(value) is true, then throw a "DataCloneError" DOMException.
auto view_record = [&]() {
if constexpr (IsSame<ViewType, JS::DataView>) {
return JS::make_data_view_with_buffer_witness_record(view, JS::ArrayBuffer::Order::SeqCst);
} else {
// FIXME: Create a TypedArray record when TypedArray supports resizable ArrayBuffer objects.
TODO();
return 0;
}
}();
// 1. If IsArrayBufferViewOutOfBounds(value) is true, then throw a "DataCloneError" DOMException.
if constexpr (IsSame<ViewType, JS::DataView>) {
if (JS::is_view_out_of_bounds(view_record))
return WebIDL::DataCloneError::create(*m_vm.current_realm(), MUST(String::formatted(JS::ErrorType::BufferOutOfBounds.message(), "DataView"sv)));
} else {
// FIXME: Check TypedArray bounds when TypedArray supports resizable ArrayBuffer objects.
}
// 2. Let buffer be the value of value's [[ViewedArrayBuffer]] internal slot.
auto* buffer = view.viewed_array_buffer();
@ -540,7 +556,7 @@ private:
vector.append(ValueTag::ArrayBufferView);
vector.extend(move(buffer_serialized)); // [[ArrayBufferSerialized]]
TRY(serialize_string(vector, "DataView"_string)); // [[Constructor]]
vector.append(view.byte_length());
vector.append(JS::get_view_byte_length(view_record));
vector.append(view.byte_offset());
}