mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:57:47 +00:00
LibJS: Make variables in InitializeTypedArrayFromTypedArray() match spec
This makes it easier to follow the code and compare it to the spec.
This commit is contained in:
parent
abb5a1f05c
commit
48e7fd52e7
1 changed files with 13 additions and 12 deletions
|
@ -88,16 +88,16 @@ static void initialize_typed_array_from_typed_array(GlobalObject& global_object,
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto* source_array_buffer = src_array.viewed_array_buffer();
|
auto* src_data = src_array.viewed_array_buffer();
|
||||||
VERIFY(source_array_buffer);
|
VERIFY(src_data);
|
||||||
if (source_array_buffer->is_detached()) {
|
if (src_data->is_detached()) {
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::DetachedArrayBuffer);
|
vm.throw_exception<TypeError>(global_object, ErrorType::DetachedArrayBuffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto src_array_length = src_array.array_length();
|
auto element_length = src_array.array_length();
|
||||||
auto dest_element_size = dest_array.element_size();
|
auto element_size = dest_array.element_size();
|
||||||
Checked byte_length = src_array_length * dest_element_size;
|
Checked byte_length = element_size * element_length;
|
||||||
if (byte_length.has_overflow()) {
|
if (byte_length.has_overflow()) {
|
||||||
vm.throw_exception<RangeError>(global_object, ErrorType::InvalidLength, "typed array");
|
vm.throw_exception<RangeError>(global_object, ErrorType::InvalidLength, "typed array");
|
||||||
return;
|
return;
|
||||||
|
@ -105,13 +105,14 @@ static void initialize_typed_array_from_typed_array(GlobalObject& global_object,
|
||||||
|
|
||||||
// FIXME: 17.b If IsDetachedBuffer(array_buffer) is true, throw a TypeError exception.
|
// FIXME: 17.b If IsDetachedBuffer(array_buffer) is true, throw a TypeError exception.
|
||||||
// FIXME: 17.c If src_array.[[ContentType]] != dest_array.[[ContentType]], throw a TypeError exception.
|
// FIXME: 17.c If src_array.[[ContentType]] != dest_array.[[ContentType]], throw a TypeError exception.
|
||||||
auto array_buffer = ArrayBuffer::create(global_object, byte_length.value());
|
auto data = ArrayBuffer::create(global_object, byte_length.value());
|
||||||
dest_array.set_array_length(src_array_length);
|
|
||||||
dest_array.set_viewed_array_buffer(array_buffer);
|
|
||||||
dest_array.set_byte_offset(0);
|
|
||||||
dest_array.set_byte_length(array_buffer->byte_length());
|
|
||||||
|
|
||||||
for (u32 i = 0; i < src_array_length; i++) {
|
dest_array.set_viewed_array_buffer(data);
|
||||||
|
dest_array.set_byte_length(byte_length.value());
|
||||||
|
dest_array.set_byte_offset(0);
|
||||||
|
dest_array.set_array_length(element_length);
|
||||||
|
|
||||||
|
for (u32 i = 0; i < element_length; i++) {
|
||||||
Value v;
|
Value v;
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue