From 8f1f794bbdae2e3fb71414bfbb6c05a58cba2858 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 7 Dec 2022 08:01:34 -0500 Subject: [PATCH] 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. --- Userland/Libraries/LibJS/Runtime/ErrorTypes.h | 1 + Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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(ErrorType::InvalidIndex); + return vm.throw_completion(ErrorType::TypedArrayInvalidIntegerIndex, actual_index); // 10. Let A be ? TypedArrayCreateSameType(O, « 𝔽(len) »). MarkedVector arguments(vm.heap());