mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:07:46 +00:00
LibJS: Add content type check to InitializeTypedArrayFromTypedArray()
Resolves a FIXME.
This commit is contained in:
parent
d7750999b3
commit
e08702a235
3 changed files with 7 additions and 2 deletions
|
@ -154,6 +154,7 @@
|
|||
M(ThisIsAlreadyInitialized, "|this| is already initialized") \
|
||||
M(ToObjectNullOrUndefined, "ToObject on null or undefined") \
|
||||
M(ToPrimitiveReturnedObject, "Can't convert {} to primitive with hint \"{}\", its @@toPrimitive method returned an object") \
|
||||
M(TypedArrayContentTypeMismatch, "Can't create {} from {}") \
|
||||
M(TypedArrayInvalidBufferLength, "Invalid buffer length for {}: must be a multiple of {}, got {}") \
|
||||
M(TypedArrayInvalidByteOffset, "Invalid byte offset for {}: must be a multiple of {}, got {}") \
|
||||
M(TypedArrayOutOfRangeByteOffset, "Typed array byte offset {} is out of range for buffer with length {}") \
|
||||
|
|
|
@ -103,7 +103,6 @@ static void initialize_typed_array_from_typed_array(GlobalObject& global_object,
|
|||
return;
|
||||
}
|
||||
|
||||
// FIXME: 17.c If src_array.[[ContentType]] != dest_array.[[ContentType]], throw a TypeError exception.
|
||||
auto data = ArrayBuffer::create(global_object, byte_length.value());
|
||||
|
||||
if (src_data->is_detached()) {
|
||||
|
@ -111,6 +110,11 @@ static void initialize_typed_array_from_typed_array(GlobalObject& global_object,
|
|||
return;
|
||||
}
|
||||
|
||||
if (src_array.content_type() != dest_array.content_type()) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::TypedArrayContentTypeMismatch, dest_array.class_name(), src_array.class_name());
|
||||
return;
|
||||
}
|
||||
|
||||
dest_array.set_viewed_array_buffer(data);
|
||||
dest_array.set_byte_length(byte_length.value());
|
||||
dest_array.set_byte_offset(0);
|
||||
|
|
|
@ -158,7 +158,7 @@ test("typed array from TypedArray", () => {
|
|||
BIGINT_TYPED_ARRAYS.forEach(T => {
|
||||
expect(() => {
|
||||
const newTypedArray = new T(u8Array);
|
||||
}).toThrowWithMessage(TypeError, "Cannot convert number to BigInt");
|
||||
}).toThrowWithMessage(TypeError, `Can't create ${T.name} from Uint8Array`);
|
||||
|
||||
const newBigIntTypedArray = new T(bigU64Array);
|
||||
expect(newBigIntTypedArray[0]).toBe(1n);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue