Skip to content

Commit

Permalink
Remove Float16Array#toSpliced
Browse files Browse the repository at this point in the history
  • Loading branch information
petamoriken committed Dec 6, 2022
1 parent 307ae1e commit 61154f7
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 109 deletions.
65 changes: 0 additions & 65 deletions src/Float16Array.mjs
Expand Up @@ -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,
Expand All @@ -29,7 +28,6 @@ import {
ArrayPrototypeJoin,
ArrayPrototypePush,
ArrayPrototypeToLocaleString,
MAX_SAFE_INTEGER,
NativeArrayBuffer,
NativeObject,
NativeProxy,
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/_util/messages.mjs
Expand Up @@ -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";
43 changes: 0 additions & 43 deletions test/Float16Array.js
Expand Up @@ -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");
Expand Down

0 comments on commit 61154f7

Please sign in to comment.