From 13b83e141b8515da9934ac82b5e25807cc66f522 Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Wed, 7 Dec 2022 22:45:42 +0900 Subject: [PATCH] Remove `Symbol.species` from InitializeTypedArrayFromTypedArray https://github.com/tc39/ecma262/pull/2719 --- src/Float16Array.mjs | 9 +------- test/Float16Array.js | 50 +++++++++++--------------------------------- 2 files changed, 13 insertions(+), 46 deletions(-) diff --git a/src/Float16Array.mjs b/src/Float16Array.mjs index 8a652a78..1d439377 100644 --- a/src/Float16Array.mjs +++ b/src/Float16Array.mjs @@ -9,7 +9,6 @@ import { isObject, isOrdinaryArray, isOrdinaryNativeTypedArray, - isSharedArrayBuffer, } from "./_util/is.mjs"; import { ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER, @@ -271,12 +270,6 @@ export class Float16Array { length = TypedArrayPrototypeGetLength(input); const buffer = TypedArrayPrototypeGetBuffer(input); - const BufferConstructor = !isSharedArrayBuffer(buffer) - ? /** @type {ArrayBufferConstructor} */ (SpeciesConstructor( - buffer, - NativeArrayBuffer - )) - : NativeArrayBuffer; if (IsDetachedBuffer(buffer)) { throw NativeTypeError(ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER); @@ -286,7 +279,7 @@ export class Float16Array { throw NativeTypeError(CANNOT_MIX_BIGINT_AND_OTHER_TYPES); } - const data = new BufferConstructor( + const data = new NativeArrayBuffer( length * BYTES_PER_ELEMENT ); float16bitsArray = ReflectConstruct(NativeUint16Array, [data], new.target); diff --git a/test/Float16Array.js b/test/Float16Array.js index ae1a1798..5e77814d 100644 --- a/test/Float16Array.js +++ b/test/Float16Array.js @@ -414,26 +414,13 @@ describe("Float16Array", () => { const array = [1, 1.1, 1.2, 1.3]; const checkArray = [1, 1.099609375, 1.19921875, 1.2998046875]; - const float16_1 = new Float16Array(new Float16Array(array)); + const float16 = new Float16Array(new Float16Array(array)); - assert(float16_1.BYTES_PER_ELEMENT === 2); - assert(float16_1.byteOffset === 0); - assert(float16_1.byteLength === 8); - assert(float16_1.length === 4); - assert.equalFloat16ArrayValues(float16_1, checkArray); - - class FooArrayBuffer extends ArrayBuffer {} - const buffer = new FooArrayBuffer(16); - - const float16_2 = new Float16Array(new Float16Array(buffer)); - - assert(float16_2.BYTES_PER_ELEMENT === 2); - assert(float16_2.byteOffset === 0); - assert(float16_2.byteLength === 16); - assert(float16_2.length === 8); - // Safari 13 bug - // assert( float16_2.buffer instanceof FooArrayBuffer ); - assert(float16_2.buffer !== buffer); + assert(float16.BYTES_PER_ELEMENT === 2); + assert(float16.byteOffset === 0); + assert(float16.byteLength === 8); + assert(float16.length === 4); + assert.equalFloat16ArrayValues(float16, checkArray); }); it("input Float16Array with detached ArrayBuffer", function () { @@ -455,26 +442,13 @@ describe("Float16Array", () => { const array = [1, 1.1, 1.2, 1.3]; const checkArray = [1, 1.099609375, 1.19921875, 1.2998046875]; - const float16_1 = new Float16Array(new AnotherRealmFloat16Array(array)); + const float16 = new Float16Array(new AnotherRealmFloat16Array(array)); - assert(float16_1.BYTES_PER_ELEMENT === 2); - assert(float16_1.byteOffset === 0); - assert(float16_1.byteLength === 8); - assert(float16_1.length === 4); - assert.equalFloat16ArrayValues(float16_1, checkArray); - - class FooArrayBuffer extends ArrayBuffer {} - const buffer = new FooArrayBuffer(16); - - const float16_2 = new Float16Array(new AnotherRealmFloat16Array(buffer)); - - assert(float16_2.BYTES_PER_ELEMENT === 2); - assert(float16_2.byteOffset === 0); - assert(float16_2.byteLength === 16); - assert(float16_2.length === 8); - // Safari 13 bug - // assert( float16_2.buffer instanceof FooArrayBuffer ); - assert(float16_2.buffer !== buffer); + assert(float16.BYTES_PER_ELEMENT === 2); + assert(float16.byteOffset === 0); + assert(float16.byteLength === 8); + assert(float16.length === 4); + assert.equalFloat16ArrayValues(float16, checkArray); }); it("input ArrayBuffer", () => {