1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:57:35 +00:00

LibJS: Add content type check to InitializeTypedArrayFromTypedArray()

Resolves a FIXME.
This commit is contained in:
Linus Groh 2021-06-27 20:58:43 +01:00
parent d7750999b3
commit e08702a235
3 changed files with 7 additions and 2 deletions

View file

@ -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 {}") \

View file

@ -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);