mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 01:51:03 +09:00
LibJS: Add explicit ErrorType values for TypedArray prototype exceptions
This commit is contained in:
parent
c20e8cea19
commit
0174993bea
Notes:
sideshowbarker
2024-07-17 11:46:49 +09:00
Author: https://github.com/trflynn89
Commit: 0174993bea
Pull-request: https://github.com/SerenityOS/serenity/pull/13695
Reviewed-by: https://github.com/linusg ✅
2 changed files with 12 additions and 8 deletions
|
@ -277,8 +277,12 @@
|
|||
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(TypedArrayInvalidCopy, "Copy between arrays of different content types ({} and {}) is prohibited") \
|
||||
M(TypedArrayInvalidTargetOffset, "Invalid target offset: must be {}") \
|
||||
M(TypedArrayOutOfRangeByteOffset, "Typed array byte offset {} is out of range for buffer with length {}") \
|
||||
M(TypedArrayOutOfRangeByteOffsetOrLength, "Typed array range {}:{} is out of range for buffer with length {}") \
|
||||
M(TypedArrayOverflow, "Overflow in {}") \
|
||||
M(TypedArrayOverflowOrOutOfBounds, "Overflow or out of bounds in {}") \
|
||||
M(TypedArrayPrototypeOneArg, "TypedArray.prototype.{}() requires at least one argument") \
|
||||
M(TypedArrayFailedSettingIndex, "Failed setting value of index {} of typed array") \
|
||||
M(TypedArrayTypeIsNot, "Typed array {} element type is not {}") \
|
||||
|
|
|
@ -647,17 +647,17 @@ static ThrowCompletionOr<void> set_typed_array_from_typed_array(GlobalObject& gl
|
|||
|
||||
// 15. If targetOffset is +∞, throw a RangeError exception.
|
||||
if (isinf(target_offset))
|
||||
return vm.throw_completion<RangeError>(global_object, "Invalid target offset");
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TypedArrayInvalidTargetOffset, "finite");
|
||||
|
||||
// 16. If srcLength + targetOffset > targetLength, throw a RangeError exception.
|
||||
Checked<size_t> checked = source_length;
|
||||
checked += static_cast<u32>(target_offset);
|
||||
if (checked.has_overflow() || checked.value() > target_length)
|
||||
return vm.throw_completion<RangeError>(global_object, "Overflow or out of bounds in target length");
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TypedArrayOverflowOrOutOfBounds, "target length");
|
||||
|
||||
// 17. If target.[[ContentType]] ≠ source.[[ContentType]], throw a TypeError exception.
|
||||
if (target.content_type() != source.content_type())
|
||||
return vm.throw_completion<TypeError>(global_object, "Copy between arrays of different content types is prohibited");
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::TypedArrayInvalidCopy, target.class_name(), source.class_name());
|
||||
|
||||
// FIXME: 18. If both IsSharedArrayBuffer(srcBuffer) and IsSharedArrayBuffer(targetBuffer) are true, then
|
||||
// FIXME: a. If srcBuffer.[[ArrayBufferData]] and targetBuffer.[[ArrayBufferData]] are the same Shared Data Block values, let same be true; else let same be false.
|
||||
|
@ -688,7 +688,7 @@ static ThrowCompletionOr<void> set_typed_array_from_typed_array(GlobalObject& gl
|
|||
checked_target_byte_index *= target_element_size;
|
||||
checked_target_byte_index += target_byte_offset;
|
||||
if (checked_target_byte_index.has_overflow())
|
||||
return vm.throw_completion<RangeError>(global_object, "Overflow in target byte index");
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TypedArrayOverflow, "target byte index");
|
||||
auto target_byte_index = checked_target_byte_index.value();
|
||||
|
||||
// 23. Let limit be targetByteIndex + targetElementSize × srcLength.
|
||||
|
@ -696,7 +696,7 @@ static ThrowCompletionOr<void> set_typed_array_from_typed_array(GlobalObject& gl
|
|||
checked_limit *= target_element_size;
|
||||
checked_limit += target_byte_index;
|
||||
if (checked_limit.has_overflow())
|
||||
return vm.throw_completion<RangeError>(global_object, "Overflow in target limit");
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TypedArrayOverflow, "target limit");
|
||||
auto limit = checked_limit.value();
|
||||
|
||||
// 24. If srcType is the same as targetType, then
|
||||
|
@ -748,13 +748,13 @@ static ThrowCompletionOr<void> set_typed_array_from_array_like(GlobalObject& glo
|
|||
|
||||
// 6. If targetOffset is +∞, throw a RangeError exception.
|
||||
if (isinf(target_offset))
|
||||
return vm.throw_completion<RangeError>(global_object, "Invalid target offset");
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TypedArrayInvalidTargetOffset, "finite");
|
||||
|
||||
// 7. If srcLength + targetOffset > targetLength, throw a RangeError exception.
|
||||
Checked<size_t> checked = source_length;
|
||||
checked += static_cast<u32>(target_offset);
|
||||
if (checked.has_overflow() || checked.value() > target_length)
|
||||
return vm.throw_completion<RangeError>(global_object, "Overflow or out of bounds in target length");
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TypedArrayOverflowOrOutOfBounds, "target length");
|
||||
|
||||
// 8. Let k be 0.
|
||||
size_t k = 0;
|
||||
|
@ -800,7 +800,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::set)
|
|||
|
||||
// 5. If targetOffset < 0, throw a RangeError exception.
|
||||
if (target_offset < 0)
|
||||
return vm.throw_completion<RangeError>(global_object, "Invalid target offset");
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::TypedArrayInvalidTargetOffset, "positive");
|
||||
|
||||
// 6. If source is an Object that has a [[TypedArrayName]] internal slot, then
|
||||
if (source.is_object() && is<TypedArrayBase>(source.as_object())) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue