1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:37:35 +00:00

LibJS: Change an error message used by %TypedArray%.prototype.with

ErrorType::InvalidIndex does not encapsulate the reasons why an index
may be invalid. For example:

    let array = new Uint8Array([1, 2, 3, 4, 5]);
    array.with(10, 0);

Will currently yield:

    [RangeError] Index must be a positive integer

Which is misleading because 10 *is* a positive integer.
This commit is contained in:
Timothy Flynn 2022-12-07 08:01:34 -05:00 committed by Linus Groh
parent 1dd8655514
commit 8f1f794bbd
2 changed files with 2 additions and 1 deletions

View file

@ -296,6 +296,7 @@
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(TypedArrayInvalidIntegerIndex, "Invalid integer index: {}") \
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 {}") \

View file

@ -1680,7 +1680,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::with)
// 9. If ! IsValidIntegerIndex(O, 𝔽(actualIndex)) is false, throw a RangeError exception.
if (!is_valid_integer_index(*typed_array, CanonicalIndex(CanonicalIndex::Type::Index, actual_index)))
return vm.throw_completion<RangeError>(ErrorType::InvalidIndex);
return vm.throw_completion<RangeError>(ErrorType::TypedArrayInvalidIntegerIndex, actual_index);
// 10. Let A be ? TypedArrayCreateSameType(O, « 𝔽(len) »).
MarkedVector<Value> arguments(vm.heap());