diff options
author | Linus Groh <mail@linusgroh.de> | 2021-06-27 20:51:51 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-27 21:01:01 +0100 |
commit | 48e7fd52e748609f96a23e5c7f39f5a8213d98b4 (patch) | |
tree | e6321f00b22cf4b82a5eee6952e60b0d5b0a75a0 /Userland/Libraries | |
parent | abb5a1f05c81057415203b6eec167a20d69abeb7 (diff) | |
download | serenity-48e7fd52e748609f96a23e5c7f39f5a8213d98b4.zip |
LibJS: Make variables in InitializeTypedArrayFromTypedArray() match spec
This makes it easier to follow the code and compare it to the spec.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/TypedArray.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index be71ef1be1..5922b5e82e 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -88,16 +88,16 @@ static void initialize_typed_array_from_typed_array(GlobalObject& global_object, if (vm.exception()) return; - auto* source_array_buffer = src_array.viewed_array_buffer(); - VERIFY(source_array_buffer); - if (source_array_buffer->is_detached()) { + auto* src_data = src_array.viewed_array_buffer(); + VERIFY(src_data); + if (src_data->is_detached()) { vm.throw_exception<TypeError>(global_object, ErrorType::DetachedArrayBuffer); return; } - auto src_array_length = src_array.array_length(); - auto dest_element_size = dest_array.element_size(); - Checked byte_length = src_array_length * dest_element_size; + auto element_length = src_array.array_length(); + auto element_size = dest_array.element_size(); + Checked byte_length = element_size * element_length; if (byte_length.has_overflow()) { vm.throw_exception<RangeError>(global_object, ErrorType::InvalidLength, "typed array"); 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.c If src_array.[[ContentType]] != dest_array.[[ContentType]], throw a TypeError exception. - auto array_buffer = ArrayBuffer::create(global_object, byte_length.value()); - dest_array.set_array_length(src_array_length); - dest_array.set_viewed_array_buffer(array_buffer); + auto data = ArrayBuffer::create(global_object, byte_length.value()); + + dest_array.set_viewed_array_buffer(data); + dest_array.set_byte_length(byte_length.value()); dest_array.set_byte_offset(0); - dest_array.set_byte_length(array_buffer->byte_length()); + dest_array.set_array_length(element_length); - for (u32 i = 0; i < src_array_length; i++) { + for (u32 i = 0; i < element_length; i++) { Value v; #undef __JS_ENUMERATE #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ |