mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:57:44 +00:00
LibJS: Remove cloneConstructor parameter from CloneArrayBuffer
This is a normative change in the ECMA-262 spec. See:
e7979fd
Note that this implements a FIXME in InitializeTypedArrayFromTypedArray,
now that shared array buffers are no longer a concern there. We already
have test coverage for the now-handled case.
This commit is contained in:
parent
39b308ba52
commit
6654efcd82
4 changed files with 48 additions and 51 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <LibJS/Runtime/AbstractOperations.h>
|
#include <LibJS/Runtime/AbstractOperations.h>
|
||||||
#include <LibJS/Runtime/ArrayBuffer.h>
|
#include <LibJS/Runtime/ArrayBuffer.h>
|
||||||
|
#include <LibJS/Runtime/ArrayBufferConstructor.h>
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
@ -121,16 +122,13 @@ ThrowCompletionOr<Value> detach_array_buffer(GlobalObject& global_object, ArrayB
|
||||||
}
|
}
|
||||||
|
|
||||||
// 25.1.2.4 CloneArrayBuffer ( srcBuffer, srcByteOffset, srcLength, cloneConstructor ), https://tc39.es/ecma262/#sec-clonearraybuffer
|
// 25.1.2.4 CloneArrayBuffer ( srcBuffer, srcByteOffset, srcLength, cloneConstructor ), https://tc39.es/ecma262/#sec-clonearraybuffer
|
||||||
ThrowCompletionOr<ArrayBuffer*> clone_array_buffer(GlobalObject& global_object, ArrayBuffer& source_buffer, size_t source_byte_offset, size_t source_length, FunctionObject& clone_constructor)
|
ThrowCompletionOr<ArrayBuffer*> clone_array_buffer(GlobalObject& global_object, ArrayBuffer& source_buffer, size_t source_byte_offset, size_t source_length)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
// 1. Assert: IsDetachedBuffer(srcBuffer) is false.
|
||||||
|
VERIFY(!source_buffer.is_detached());
|
||||||
|
|
||||||
// 1. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, srcLength).
|
// 2. Let targetBuffer be ? AllocateArrayBuffer(%ArrayBuffer%, srcLength).
|
||||||
auto* target_buffer = TRY(allocate_array_buffer(global_object, clone_constructor, source_length));
|
auto* target_buffer = TRY(allocate_array_buffer(global_object, *global_object.array_buffer_constructor(), source_length));
|
||||||
|
|
||||||
// 2. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
|
|
||||||
if (source_buffer.is_detached())
|
|
||||||
return vm.throw_completion<TypeError>(global_object, ErrorType::DetachedArrayBuffer);
|
|
||||||
|
|
||||||
// 3. Let srcBlock be srcBuffer.[[ArrayBufferData]].
|
// 3. Let srcBlock be srcBuffer.[[ArrayBufferData]].
|
||||||
auto& source_block = source_buffer.buffer();
|
auto& source_block = source_buffer.buffer();
|
||||||
|
|
|
@ -82,7 +82,7 @@ private:
|
||||||
|
|
||||||
ThrowCompletionOr<ArrayBuffer*> allocate_array_buffer(GlobalObject&, FunctionObject& constructor, size_t byte_length, Optional<size_t> max_byte_length = {});
|
ThrowCompletionOr<ArrayBuffer*> allocate_array_buffer(GlobalObject&, FunctionObject& constructor, size_t byte_length, Optional<size_t> max_byte_length = {});
|
||||||
ThrowCompletionOr<Value> detach_array_buffer(GlobalObject&, ArrayBuffer& array_buffer, Optional<Value> key = {});
|
ThrowCompletionOr<Value> detach_array_buffer(GlobalObject&, ArrayBuffer& array_buffer, Optional<Value> key = {});
|
||||||
ThrowCompletionOr<ArrayBuffer*> clone_array_buffer(GlobalObject&, ArrayBuffer& source_buffer, size_t source_byte_offset, size_t source_length, FunctionObject& clone_constructor);
|
ThrowCompletionOr<ArrayBuffer*> clone_array_buffer(GlobalObject&, ArrayBuffer& source_buffer, size_t source_byte_offset, size_t source_length);
|
||||||
|
|
||||||
// 25.1.2.9 RawBytesToNumeric ( type, rawBytes, isLittleEndian ), https://tc39.es/ecma262/#sec-rawbytestonumeric
|
// 25.1.2.9 RawBytesToNumeric ( type, rawBytes, isLittleEndian ), https://tc39.es/ecma262/#sec-rawbytestonumeric
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -164,17 +164,17 @@ static ThrowCompletionOr<void> initialize_typed_array_from_typed_array(GlobalObj
|
||||||
if (byte_length.has_overflow())
|
if (byte_length.has_overflow())
|
||||||
return vm.template throw_completion<RangeError>(global_object, ErrorType::InvalidLength, "typed array");
|
return vm.template throw_completion<RangeError>(global_object, ErrorType::InvalidLength, "typed array");
|
||||||
|
|
||||||
// FIXME:
|
ArrayBuffer* data = nullptr;
|
||||||
// 10. If IsSharedArrayBuffer(srcData) is false, then
|
|
||||||
// a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%).
|
|
||||||
// 11. Else,
|
|
||||||
// a. Let bufferConstructor be %ArrayBuffer%.
|
|
||||||
// 12. If elementType is the same as srcType, then
|
|
||||||
// a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset, byteLength, bufferConstructor).
|
|
||||||
// 13. Else,
|
|
||||||
|
|
||||||
|
// 10. If elementType is the same as srcType, then
|
||||||
|
if (dest_array.element_name() == src_array.element_name()) {
|
||||||
|
// a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset, byteLength).
|
||||||
|
data = TRY(clone_array_buffer(global_object, *src_data, src_byte_offset, byte_length.value()));
|
||||||
|
}
|
||||||
|
// 11. Else,
|
||||||
|
else {
|
||||||
// a. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
|
// a. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength).
|
||||||
auto* data = TRY(allocate_array_buffer(global_object, *global_object.array_buffer_constructor(), byte_length.value()));
|
data = TRY(allocate_array_buffer(global_object, *global_object.array_buffer_constructor(), byte_length.value()));
|
||||||
|
|
||||||
// b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception.
|
// b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception.
|
||||||
if (src_data->is_detached())
|
if (src_data->is_detached())
|
||||||
|
@ -207,20 +207,21 @@ static ThrowCompletionOr<void> initialize_typed_array_from_typed_array(GlobalObj
|
||||||
|
|
||||||
// v. Set count to count - 1.
|
// v. Set count to count - 1.
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 14. Set O.[[ViewedArrayBuffer]] to data.
|
// 12. Set O.[[ViewedArrayBuffer]] to data.
|
||||||
dest_array.set_viewed_array_buffer(data);
|
dest_array.set_viewed_array_buffer(data);
|
||||||
|
|
||||||
// 15. Set O.[[ByteLength]] to byteLength.
|
// 13. Set O.[[ByteLength]] to byteLength.
|
||||||
dest_array.set_byte_length(byte_length.value());
|
dest_array.set_byte_length(byte_length.value());
|
||||||
|
|
||||||
// 16. Set O.[[ByteOffset]] to 0.
|
// 14. Set O.[[ByteOffset]] to 0.
|
||||||
dest_array.set_byte_offset(0);
|
dest_array.set_byte_offset(0);
|
||||||
|
|
||||||
// 17. Set O.[[ArrayLength]] to elementLength.
|
// 15. Set O.[[ArrayLength]] to elementLength.
|
||||||
dest_array.set_array_length(element_length);
|
dest_array.set_array_length(element_length);
|
||||||
|
|
||||||
// 18. Return unused.
|
// 16. Return unused.
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibJS/Runtime/AbstractOperations.h>
|
#include <LibJS/Runtime/AbstractOperations.h>
|
||||||
#include <LibJS/Runtime/ArrayBufferConstructor.h>
|
|
||||||
#include <LibJS/Runtime/ArrayIterator.h>
|
#include <LibJS/Runtime/ArrayIterator.h>
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
#include <LibJS/Runtime/TypedArray.h>
|
#include <LibJS/Runtime/TypedArray.h>
|
||||||
|
@ -670,11 +669,10 @@ static ThrowCompletionOr<void> set_typed_array_from_typed_array(GlobalObject& gl
|
||||||
// a. Let srcByteLength be source.[[ByteLength]].
|
// a. Let srcByteLength be source.[[ByteLength]].
|
||||||
auto source_byte_length = source.byte_length();
|
auto source_byte_length = source.byte_length();
|
||||||
|
|
||||||
// b. Set srcBuffer to ? CloneArrayBuffer(srcBuffer, srcByteOffset, srcByteLength, %ArrayBuffer%).
|
// b. Set srcBuffer to ? CloneArrayBuffer(srcBuffer, srcByteOffset, srcByteLength).
|
||||||
source_buffer = TRY(clone_array_buffer(global_object, *source_buffer, source_byte_offset, source_byte_length, *global_object.array_buffer_constructor()));
|
source_buffer = TRY(clone_array_buffer(global_object, *source_buffer, source_byte_offset, source_byte_length));
|
||||||
// c. NOTE: %ArrayBuffer% is used to clone srcBuffer because is it known to not have any observable side-effects.
|
|
||||||
|
|
||||||
// d. Let srcByteIndex be 0.
|
// c. Let srcByteIndex be 0.
|
||||||
source_byte_index = 0;
|
source_byte_index = 0;
|
||||||
}
|
}
|
||||||
// 19. Else, let srcByteIndex be srcByteOffset.
|
// 19. Else, let srcByteIndex be srcByteOffset.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue