Skip to content

Commit

Permalink
Make resizableArrayBufferUtils not depend on syntax that may not be
Browse files Browse the repository at this point in the history
supported
  • Loading branch information
p-bakker authored and ptomato committed Jul 24, 2024
1 parent b6c2f55 commit 336115d
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions harness/resizableArrayBufferUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ defines:
features: [BigInt]
---*/

class MyUint8Array extends Uint8Array {
}

class MyFloat32Array extends Float32Array {
}

class MyBigInt64Array extends BigInt64Array {
}
// Using new Function()(); instead of just 'class x extends Y' as to not bomb out when `class` isn't supported
const MyUint8Array = new Function('return class MyUint8Array extends Uint8Array {}')();
const MyFloat32Array = new Function('return class MyFloat32Array extends Float32Array {}')();
const MyBigInt64Array = new Function('return class MyBigInt64Array extends BigInt64Array {}')();

const builtinCtors = [
Uint8Array,
Expand All @@ -39,15 +35,18 @@ const builtinCtors = [
Uint8ClampedArray,
];

// BigInt and Float16Array are newer features adding them above unconditionally
// Big(U)int64Array and Float16Array are newer features adding them above unconditionally
// would cause implementations lacking it to fail every test which uses it.
if (typeof Float16Array !== 'undefined') {
builtinCtors.push(Float16Array);
}

if (typeof BigInt !== 'undefined') {
builtinCtors.push(BigUint64Array);
builtinCtors.push(BigInt64Array);
if (typeof BigUint64Array !== 'undefined') {
builtinCtors.push(BigUint64Array);
}

if (typeof BigInt64Array !== 'undefined') {
builtinCtors.push(BigInt64Array);
}

const floatCtors = [
Expand All @@ -60,13 +59,9 @@ if (typeof Float16Array !== 'undefined') {
floatCtors.push(Float16Array);
}

const ctors = [
...builtinCtors,
MyUint8Array,
MyFloat32Array
];
const ctors = builtinCtors.concat(MyUint8Array, MyFloat32Array);

if (typeof BigInt !== 'undefined') {
if (typeof MyBigInt64Array !== 'undefined') {
ctors.push(MyBigInt64Array);
}

Expand Down Expand Up @@ -125,7 +120,7 @@ function TestIterationAndResize(iterable, expected, rab, resizeAfter, newByteLen
let resized = false;
var arrayValues = false;

for (const value of iterable) {
for (let value of iterable) {
if (Array.isArray(value)) {
arrayValues = true;
values.push([
Expand Down

0 comments on commit 336115d

Please sign in to comment.