diff --git a/src/Float16Array.mjs b/src/Float16Array.mjs index f67c5149..25abe57f 100644 --- a/src/Float16Array.mjs +++ b/src/Float16Array.mjs @@ -28,7 +28,6 @@ import { ArrayBufferIsView, ArrayPrototypeJoin, ArrayPrototypePush, - ArrayPrototypeSlice, ArrayPrototypeToLocaleString, NativeArrayBuffer, NativeNumber, @@ -938,7 +937,7 @@ export class Float16Array { } /** @see https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.toSorted */ - toSorted(...opts) { + toSorted(compareFn) { assertFloat16Array(this); const float16bitsArray = getFloat16BitsArray(this); @@ -955,9 +954,9 @@ export class Float16Array { ); const clonedFloat16bitsArray = getFloat16BitsArray(cloned); - const compare = opts[0] !== undefined ? opts[0] : defaultCompare; + const sortCompare = compareFn !== undefined ? compareFn : defaultCompare; TypedArrayPrototypeSort(clonedFloat16bitsArray, (x, y) => { - return compare(convertToNumber(x), convertToNumber(y)); + return sortCompare(convertToNumber(x), convertToNumber(y)); }); return cloned; @@ -1030,12 +1029,12 @@ export class Float16Array { } /** @see https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.toSpliced */ - toSpliced(...opts) { + toSpliced(start, deleteCount, ...items) { assertFloat16Array(this); const float16bitsArray = getFloat16BitsArray(this); const length = TypedArrayPrototypeGetLength(float16bitsArray); - const relativeStart = ToIntegerOrInfinity(opts[0]); + const relativeStart = ToIntegerOrInfinity(start); let actualStart; if (relativeStart === -Infinity) { @@ -1046,21 +1045,19 @@ export class Float16Array { actualStart = relativeStart < length ? relativeStart : length; } - let insertCount, actualDeleteCount; - switch (opts.length) { + const insertCount = items.length; + let actualDeleteCount; + switch (arguments.length) { case 0: - insertCount = 0; actualDeleteCount = 0; break; case 1: - insertCount = 0; actualDeleteCount = length - actualStart; break; default: { - const dc = ToIntegerOrInfinity(opts[1]); - insertCount = opts.length - 2; + const dc = ToIntegerOrInfinity(deleteCount); if (dc < 0) { actualDeleteCount = 0; } else if (dc > length - actualStart) { @@ -1085,8 +1082,7 @@ export class Float16Array { ++k; } - const items = ArrayPrototypeSlice(opts, 2); - for (let i = 0, l = items.length; i < l; ++i) { + for (let i = 0; i < insertCount; ++i) { array[k] = roundToFloat16Bits(items[i]); ++k; } diff --git a/src/_util/primordials.mjs b/src/_util/primordials.mjs index f3e1a46c..350bc030 100644 --- a/src/_util/primordials.mjs +++ b/src/_util/primordials.mjs @@ -95,8 +95,6 @@ const ArrayPrototype = NativeArray.prototype; export const ArrayPrototypeJoin = uncurryThis(ArrayPrototype.join); /** @type {(array: T[], ...items: T[]) => number} */ export const ArrayPrototypePush = uncurryThis(ArrayPrototype.push); -/** @type {(array: T[], start?: number, end?: number) => T[]} */ -export const ArrayPrototypeSlice = uncurryThis(ArrayPrototype.slice); /** @type {(array: ArrayLike, ...opts: any[]) => string} */ export const ArrayPrototypeToLocaleString = uncurryThis( ArrayPrototype.toLocaleString diff --git a/test/Float16Array.js b/test/Float16Array.js index 3cb67fef..bff9e854 100644 --- a/test/Float16Array.js +++ b/test/Float16Array.js @@ -1616,8 +1616,8 @@ describe("Float16Array", () => { assert(Float16Array.prototype.toSorted.name === "toSorted"); }); - it("property `length` is 0", () => { - assert(Float16Array.prototype.toSorted.length === 0); + it("property `length` is 1", () => { + assert(Float16Array.prototype.toSorted.length === 1); }); it("check default compare", () => { @@ -1814,8 +1814,8 @@ describe("Float16Array", () => { assert(Float16Array.prototype.toSpliced.name === "toSpliced"); }); - it("property `length` is 0", () => { - assert(Float16Array.prototype.toSpliced.length === 0); + it("property `length` is 2", () => { + assert(Float16Array.prototype.toSpliced.length === 2); }); it("get spliced Array", () => {