Skip to content

Commit 4fd0804

Browse files
committed
.toSpliced should throw a TypeError instead of RangeError
tc39/proposal-change-array-by-copy#70
1 parent 6295f24 commit 4fd0804

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

src/Float16Array.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
CANNOT_MIX_BIGINT_AND_OTHER_TYPES,
1818
DERIVED_CONSTRUCTOR_CREATED_TYPEDARRAY_OBJECT_WHICH_WAS_TOO_SMALL_LENGTH,
1919
ITERATOR_PROPERTY_IS_NOT_CALLABLE,
20+
MAXIMUM_ALLOWED_LENGTH_EXCEEDED,
2021
OFFSET_IS_OUT_OF_BOUNDS,
2122
REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE,
2223
SPECIES_CONSTRUCTOR_DIDNT_RETURN_TYPEDARRAY_OBJECT,
@@ -38,6 +39,7 @@ import {
3839
NativeWeakMap,
3940
NativeWeakSet,
4041
NumberIsNaN,
42+
NumberMAX_SAFE_INTEGER,
4143
ObjectDefineProperty,
4244
ObjectFreeze,
4345
ObjectHasOwn,
@@ -1067,6 +1069,9 @@ export class Float16Array {
10671069

10681070
// don't use SpeciesConstructor
10691071
const newLength = length + insertCount - actualDeleteCount;
1072+
if (newLength > NumberMAX_SAFE_INTEGER) {
1073+
throw NativeTypeError(MAXIMUM_ALLOWED_LENGTH_EXCEEDED);
1074+
}
10701075
const proxy = new Float16Array(newLength);
10711076
const array = getFloat16BitsArray(proxy);
10721077

src/_util/messages.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ export const CANNOT_MIX_BIGINT_AND_OTHER_TYPES =
1919
export const ITERATOR_PROPERTY_IS_NOT_CALLABLE = "@@iterator property is not callable";
2020
export const REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE =
2121
"Reduce of empty array with no initial value";
22+
export const MAXIMUM_ALLOWED_LENGTH_EXCEEDED = "Maximum allowed length exceeded";
2223
export const OFFSET_IS_OUT_OF_BOUNDS = "Offset is out of bounds";

src/_util/primordials.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const NativeNumber = Number;
4242
export const {
4343
isFinite: NumberIsFinite,
4444
isNaN: NumberIsNaN,
45+
MAX_SAFE_INTEGER: NumberMAX_SAFE_INTEGER,
4546
} = NativeNumber;
4647

4748
// Symbol

0 commit comments

Comments
 (0)