Issue #2838 - Use ToIndex in TypedArray CTORs

Also adjusts index handling to be more accurate/spec compliant.
This commit is contained in:
Moonchild 2025-08-04 17:16:57 +02:00 committed by roytam1
commit c07ea665ea
5 changed files with 33 additions and 24 deletions

View file

@ -83,8 +83,7 @@ static bool
ReportOutOfRange(JSContext* cx)
{
// Use JSMSG_BAD_INDEX here even if it is generic, since that is
// the message used by ToIntegerIndex for its initial range
// checking.
// the message used by NonStandardToIndex for its initial range checking.
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_BAD_INDEX);
return false;
}
@ -114,7 +113,7 @@ static bool
GetTypedArrayIndex(JSContext* cx, HandleValue v, Handle<TypedArrayObject*> view, uint32_t* offset)
{
uint64_t index;
if (!js::ToIntegerIndex(cx, v, &index))
if (!NonStandardToIndex(cx, v, &index))
return false;
if (index >= view->length())
return ReportOutOfRange(cx);