From 2aaa661cb7fda183a0c63e4320abfd08c78b48e2 Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Tue, 26 Jul 2022 00:05:41 +0900 Subject: [PATCH] Remove `Float16Array#spliced` https://github.com/tc39/proposal-change-array-by-copy/issues/88#issuecomment-1190709637 --- src/Float16Array.mjs | 65 ------------------------------------------ src/_util/messages.mjs | 1 - test/Float16Array.js | 43 ---------------------------- 3 files changed, 109 deletions(-) diff --git a/src/Float16Array.mjs b/src/Float16Array.mjs index 05e691cc..20d49674 100644 --- a/src/Float16Array.mjs +++ b/src/Float16Array.mjs @@ -17,7 +17,6 @@ import { CANNOT_MIX_BIGINT_AND_OTHER_TYPES, DERIVED_CONSTRUCTOR_CREATED_TYPEDARRAY_OBJECT_WHICH_WAS_TOO_SMALL_LENGTH, ITERATOR_PROPERTY_IS_NOT_CALLABLE, - MAXIMUM_ALLOWED_LENGTH_EXCEEDED, OFFSET_IS_OUT_OF_BOUNDS, REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE, SPECIES_CONSTRUCTOR_DIDNT_RETURN_TYPEDARRAY_OBJECT, @@ -29,7 +28,6 @@ import { ArrayPrototypeJoin, ArrayPrototypePush, ArrayPrototypeToLocaleString, - MAX_SAFE_INTEGER, NativeArrayBuffer, NativeObject, NativeProxy, @@ -1026,69 +1024,6 @@ export class Float16Array { return /** @type {any} */ (array); } - /** @see https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.toSpliced */ - toSpliced(start, deleteCount, ...items) { - assertFloat16Array(this); - const float16bitsArray = getFloat16BitsArray(this); - - const length = TypedArrayPrototypeGetLength(float16bitsArray); - const relativeStart = ToIntegerOrInfinity(start); - - let actualStart; - if (relativeStart === -Infinity) { - actualStart = 0; - } else if (relativeStart < 0) { - actualStart = length + relativeStart > 0 ? length + relativeStart : 0; - } else { - actualStart = relativeStart < length ? relativeStart : length; - } - - const insertCount = items.length; - const converedItems = []; - for (let i = 0; i < insertCount; ++i) { - converedItems[i] = +items[i]; - } - - let actualDeleteCount; - const argumentLength = arguments.length; - if (argumentLength === 0) { - actualDeleteCount = 0; - } else if (argumentLength === 1) { - actualDeleteCount = length - actualStart; - } else { - const dc = ToIntegerOrInfinity(deleteCount); - actualDeleteCount = dc < 0 ? 0 : - dc > length - actualStart ? length - actualStart : dc; - } - - const newLength = length + insertCount - actualDeleteCount; - if (newLength > MAX_SAFE_INTEGER) { - throw NativeTypeError(MAXIMUM_ALLOWED_LENGTH_EXCEEDED); - } - - // don't use SpeciesConstructor - const proxy = new Float16Array(newLength); - const array = getFloat16BitsArray(proxy); - - let k = 0; - while (k < actualStart) { - array[k] = float16bitsArray[k]; - ++k; - } - - for (let i = 0; i < insertCount; ++i) { - array[k] = roundToFloat16Bits(converedItems[i]); - ++k; - } - - while (k < newLength) { - array[k] = float16bitsArray[k + actualDeleteCount - insertCount]; - ++k; - } - - return proxy; - } - /** @see https://tc39.es/ecma262/#sec-%typedarray%.prototype.subarray */ subarray(begin, end) { assertFloat16Array(this); diff --git a/src/_util/messages.mjs b/src/_util/messages.mjs index 831bd878..9786dd5c 100644 --- a/src/_util/messages.mjs +++ b/src/_util/messages.mjs @@ -17,5 +17,4 @@ export const CANNOT_MIX_BIGINT_AND_OTHER_TYPES = export const ITERATOR_PROPERTY_IS_NOT_CALLABLE = "@@iterator property is not callable"; export const REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE = "Reduce of empty array with no initial value"; -export const MAXIMUM_ALLOWED_LENGTH_EXCEEDED = "Maximum allowed length exceeded"; export const OFFSET_IS_OUT_OF_BOUNDS = "Offset is out of bounds"; diff --git a/test/Float16Array.js b/test/Float16Array.js index bff9e854..ae1a1798 100644 --- a/test/Float16Array.js +++ b/test/Float16Array.js @@ -1809,49 +1809,6 @@ describe("Float16Array", () => { }); }); - describe("#toSpliced()", () => { - it("property `name` is 'toSpliced'", () => { - assert(Float16Array.prototype.toSpliced.name === "toSpliced"); - }); - - it("property `length` is 2", () => { - assert(Float16Array.prototype.toSpliced.length === 2); - }); - - it("get spliced Array", () => { - const float16_1 = new Float16Array([1, 2, 3]); - const float16_2 = float16_1.toSpliced(); - - assert(float16_1.buffer !== float16_2.buffer); - assert.equalFloat16ArrayValues(float16_1, float16_2); - - const float16_3 = float16_1.toSpliced(1); - - assert(float16_1.buffer !== float16_3.buffer); - assert.equalFloat16ArrayValues(float16_3, [1]); - - const float16_4 = float16_1.toSpliced(1, -1); - - assert(float16_1.buffer !== float16_4.buffer); - assert.equalFloat16ArrayValues(float16_4, [1, 2, 3]); - - const float16_5 = float16_1.toSpliced(1, 10); - - assert(float16_1.buffer !== float16_5.buffer); - assert.equalFloat16ArrayValues(float16_5, [1]); - - const float16_6 = float16_1.toSpliced(1, 1); - - assert(float16_1.buffer !== float16_6.buffer); - assert.equalFloat16ArrayValues(float16_6, [1, 3]); - - const float16_7 = float16_1.toSpliced(1, 1, 5, 6); - - assert(float16_1.buffer !== float16_7.buffer); - assert.equalFloat16ArrayValues(float16_7, [1, 5, 6, 3]); - }); - }); - describe("#subarray()", () => { it("property `name` is 'subarray'", () => { assert(Float16Array.prototype.subarray.name === "subarray");