diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-12-07 08:01:34 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-12-07 16:43:19 +0000 |
commit | 8f1f794bbdae2e3fb71414bfbb6c05a58cba2858 (patch) | |
tree | 7200e7dd73502f61bcf5f5a91c69e92dbc9daa76 /Userland/Libraries/LibJS/Runtime | |
parent | 1dd865551497096befb147bd1ccaffcdaaf37260 (diff) | |
download | serenity-8f1f794bbdae2e3fb71414bfbb6c05a58cba2858.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ErrorTypes.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp | 2 |
2 files changed, 2 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h index 4d57ab2c84..a34395d0c6 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h +++ b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h @@ -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 {}") \ diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp index eea9610e4a..a7307920c0 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp @@ -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()); |