From abb5a1f05c81057415203b6eec167a20d69abeb7 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 27 Jun 2021 20:49:06 +0100 Subject: [PATCH] LibJS: Add missing InitializeTypedArrayFromTypedArray() spec link Also move the others outside of their functions. --- Userland/Libraries/LibJS/Runtime/TypedArray.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index a3c50fd3d1..be71ef1be1 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -15,10 +15,9 @@ namespace JS { +// 22.2.5.1.3 InitializeTypedArrayFromArrayBuffer, https://tc39.es/ecma262/#sec-initializetypedarrayfromarraybuffer static void initialize_typed_array_from_array_buffer(GlobalObject& global_object, TypedArrayBase& typed_array, ArrayBuffer& array_buffer, Value byte_offset, Value length) { - // 22.2.5.1.3 InitializeTypedArrayFromArrayBuffer, https://tc39.es/ecma262/#sec-initializetypedarrayfromarraybuffer - auto& vm = global_object.vm(); auto element_size = typed_array.element_size(); auto offset = byte_offset.to_index(global_object); @@ -80,6 +79,8 @@ static void initialize_typed_array_from_array_buffer(GlobalObject& global_object typed_array.set_byte_offset(offset); typed_array.set_array_length(new_byte_length.value() / element_size); } + +// 23.2.5.1.2 InitializeTypedArrayFromTypedArray ( O, srcArray ), https://tc39.es/ecma262/#sec-initializetypedarrayfromtypedarray template static void initialize_typed_array_from_typed_array(GlobalObject& global_object, TypedArray& dest_array, TypedArrayBase& src_array) { @@ -126,11 +127,11 @@ static void initialize_typed_array_from_typed_array(GlobalObject& global_object, dest_array.put_by_index(i, v); } } + +// 23.2.5.1.5 InitializeTypedArrayFromArrayLike, https://tc39.es/ecma262/#sec-initializetypedarrayfromarraylike template static void initialize_typed_array_from_array_like(GlobalObject& global_object, TypedArray& typed_array, const Object& array_like) { - // 23.2.5.1.5 InitializeTypedArrayFromArrayLike, https://tc39.es/ecma262/#sec-initializetypedarrayfromarraylike - auto& vm = global_object.vm(); auto length = length_of_array_like(global_object, array_like); if (vm.exception()) @@ -157,11 +158,11 @@ static void initialize_typed_array_from_array_like(GlobalObject& global_object, return; } } + +// 23.2.5.1.4 InitializeTypedArrayFromList, https://tc39.es/ecma262/#sec-initializetypedarrayfromlist template static void initialize_typed_array_from_list(GlobalObject& global_object, TypedArray& typed_array, const MarkedValueList& list) { - // 23.2.5.1.4 InitializeTypedArrayFromList, https://tc39.es/ecma262/#sec-initializetypedarrayfromlist - auto element_size = typed_array.element_size(); if (Checked::multiplication_would_overflow(element_size, list.size())) { global_object.vm().throw_exception(global_object, ErrorType::InvalidLength, "typed array");