Skip to content

Commit

Permalink
Remove Symbol.species from InitializeTypedArrayFromTypedArray (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
petamoriken committed Dec 7, 2022
1 parent ad1def0 commit bf2a98e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 60 deletions.
9 changes: 1 addition & 8 deletions src/Float16Array.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
isObject,
isOrdinaryArray,
isOrdinaryNativeTypedArray,
isSharedArrayBuffer,
} from "./_util/is.mjs";
import {
ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
64 changes: 12 additions & 52 deletions test/Float16Array.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,20 +341,6 @@ describe("Float16Array", () => {
assert.equalFloat16ArrayValues(float16_2, checkArray);
});

it("input TypedArray with custom ArrayBuffer", () => {
class FooArrayBuffer extends ArrayBuffer {}
const buffer = new FooArrayBuffer(16);

const float16 = new Float16Array(new Float32Array(buffer));

assert(float16.BYTES_PER_ELEMENT === 2);
assert(float16.byteOffset === 0);
assert(float16.byteLength === 8);
assert(float16.length === 4);
assert(float16.buffer instanceof FooArrayBuffer);
assert(float16.buffer !== buffer);
});

it("input TypedArray with custom SharedArrayBuffer", function () {
if (typeof SharedArrayBuffer === "undefined") {
this.skip();
Expand Down Expand Up @@ -414,26 +400,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 () {
Expand All @@ -455,26 +428,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));

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));
const float16 = new Float16Array(new AnotherRealmFloat16Array(array));

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", () => {
Expand Down

0 comments on commit bf2a98e

Please sign in to comment.