Skip to content

Commit f569285

Browse files
authored
[immutable-arraybuffer] Include immutable ArrayBuffers in TypedArray testing (#4545)
1 parent e6c9868 commit f569285

231 files changed

Lines changed: 359 additions & 352 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

harness/testTypedArray.js

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function makeArrayBuffer(TA, primitiveOrIterable) {
102102
return new TA(arr).buffer;
103103
}
104104

105-
var makeResizableArrayBuffer, makeGrownArrayBuffer, makeShrunkArrayBuffer;
105+
var makeResizableArrayBuffer, makeGrownArrayBuffer, makeShrunkArrayBuffer, makeImmutableArrayBuffer;
106106
if (ArrayBuffer.prototype.resize) {
107107
var copyIntoArrayBuffer = function(destBuffer, srcBuffer) {
108108
var destView = new Uint8Array(destBuffer);
@@ -152,16 +152,28 @@ if (ArrayBuffer.prototype.resize) {
152152
return shrunk;
153153
};
154154
}
155+
if (ArrayBuffer.prototype.transferToImmutable) {
156+
makeImmutableArrayBuffer = function makeImmutableArrayBuffer(TA, primitiveOrIterable) {
157+
if (isPrimitive(primitiveOrIterable)) {
158+
var n = Number(primitiveOrIterable) * TA.BYTES_PER_ELEMENT;
159+
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
160+
return (new ArrayBuffer(n)).transferToImmutable();
161+
}
162+
var mutable = makeArrayBuffer(TA, primitiveOrIterable);
163+
return mutable.transferToImmutable();
164+
};
165+
}
155166

156167
var typedArrayCtorArgFactories = [makePassthrough, makeArray, makeArrayLike];
157168
if (makeIterable) typedArrayCtorArgFactories.push(makeIterable);
158169
typedArrayCtorArgFactories.push(makeArrayBuffer);
159170
if (makeResizableArrayBuffer) typedArrayCtorArgFactories.push(makeResizableArrayBuffer);
160171
if (makeGrownArrayBuffer) typedArrayCtorArgFactories.push(makeGrownArrayBuffer);
161172
if (makeShrunkArrayBuffer) typedArrayCtorArgFactories.push(makeShrunkArrayBuffer);
173+
if (makeImmutableArrayBuffer) typedArrayCtorArgFactories.push(makeImmutableArrayBuffer);
162174

163175
/**
164-
* @typedef {"passthrough" | "arraylike" | "iterable" | "arraybuffer" | "resizable"} typedArrayArgFactoryFeature
176+
* @typedef {"passthrough" | "arraylike" | "iterable" | "arraybuffer" | "resizable" | "immutable"} typedArrayArgFactoryFeature
165177
*/
166178

167179
/**
@@ -189,7 +201,8 @@ function ctorArgFactoryMatchesSome(argFactory, features) {
189201
argFactory === makeArrayBuffer ||
190202
argFactory === makeResizableArrayBuffer ||
191203
argFactory === makeGrownArrayBuffer ||
192-
argFactory === makeShrunkArrayBuffer
204+
argFactory === makeShrunkArrayBuffer ||
205+
argFactory === makeImmutableArrayBuffer
193206
) {
194207
return true;
195208
}
@@ -203,6 +216,9 @@ function ctorArgFactoryMatchesSome(argFactory, features) {
203216
return true;
204217
}
205218
break;
219+
case "immutable":
220+
if (argFactory === makeImmutableArrayBuffer) return true;
221+
break;
206222
default:
207223
throw Test262Error("unknown feature: " + features[i]);
208224
}
@@ -317,26 +333,46 @@ var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Ui
317333
*
318334
* @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
319335
* @param {Array} selected - An optional Array with filtered typed arrays
336+
* @param {typedArrayArgFactoryFeature[]} [includeArgFactories] - for selecting
337+
* initial constructor argument factory functions, rather than starting with
338+
* all argument factories
339+
* @param {typedArrayArgFactoryFeature[]} [excludeArgFactories] - for excluding
340+
* constructor argument factory functions, after an initial selection
320341
*/
321-
function testWithNonAtomicsFriendlyTypedArrayConstructors(f) {
322-
testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors);
342+
function testWithNonAtomicsFriendlyTypedArrayConstructors(f, includeArgFactories, excludeArgFactories) {
343+
testWithAllTypedArrayConstructors(
344+
f,
345+
nonAtomicsFriendlyTypedArrayConstructors,
346+
includeArgFactories,
347+
excludeArgFactories
348+
);
323349
}
324350

325351
/**
326352
* Calls the provided function for every "Atomics Friendly" typed array constructor.
327353
*
328354
* @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
329355
* @param {Array} selected - An optional Array with filtered typed arrays
356+
* @param {typedArrayArgFactoryFeature[]} [includeArgFactories] - for selecting
357+
* initial constructor argument factory functions, rather than starting with
358+
* all argument factories
359+
* @param {typedArrayArgFactoryFeature[]} [excludeArgFactories] - for excluding
360+
* constructor argument factory functions, after an initial selection
330361
*/
331-
function testWithAtomicsFriendlyTypedArrayConstructors(f) {
332-
testWithTypedArrayConstructors(f, [
333-
Int32Array,
334-
Int16Array,
335-
Int8Array,
336-
Uint32Array,
337-
Uint16Array,
338-
Uint8Array,
339-
]);
362+
function testWithAtomicsFriendlyTypedArrayConstructors(f, includeArgFactories, excludeArgFactories) {
363+
testWithAllTypedArrayConstructors(
364+
f,
365+
[
366+
Int32Array,
367+
Int16Array,
368+
Int8Array,
369+
Uint32Array,
370+
Uint16Array,
371+
Uint8Array,
372+
],
373+
includeArgFactories,
374+
excludeArgFactories
375+
);
340376
}
341377

342378
/**
@@ -363,7 +399,7 @@ function testTypedArrayConversions(byteConversionValues, fn) {
363399
}
364400
fn(TA, value, exp, initial);
365401
});
366-
});
402+
}, null, ["passthrough"]);
367403
}
368404

369405
/**

test/built-ins/ArrayBuffer/isView/arg-is-typedarray-buffer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ features: [TypedArray]
1515
includes: [testTypedArray.js]
1616
---*/
1717

18-
testWithTypedArrayConstructors(function(ctor) {
19-
var sample = new ctor().buffer;
18+
testWithAllTypedArrayConstructors(function(ctor, makeCtorArg) {
19+
var sample = new ctor(makeCtorArg(0)).buffer;
2020

2121
assert.sameValue(ArrayBuffer.isView(sample), false);
22-
}, null, ["passthrough"]);
22+
});

test/built-ins/ArrayBuffer/isView/arg-is-typedarray-constructor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ features: [TypedArray]
1515
includes: [testTypedArray.js]
1616
---*/
1717

18-
testWithTypedArrayConstructors(function(ctor) {
18+
testWithAllTypedArrayConstructors(function(ctor) {
1919
assert.sameValue(ArrayBuffer.isView(ctor), false);
2020
}, null, ["passthrough"]);

test/built-ins/ArrayBuffer/isView/arg-is-typedarray-subclass-instance.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ features: [class, TypedArray]
1515
includes: [testTypedArray.js]
1616
---*/
1717

18-
testWithTypedArrayConstructors(function(ctor) {
18+
testWithAllTypedArrayConstructors(function(ctor, makeCtorArg) {
1919
class TA extends ctor {}
2020

21-
var sample = new TA();
21+
var sample = new TA(makeCtorArg(0));
2222

2323
assert(ArrayBuffer.isView(sample));
24-
}, null, ["passthrough"]);
24+
});

test/built-ins/ArrayBuffer/isView/arg-is-typedarray.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ features: [TypedArray]
1515
includes: [testTypedArray.js]
1616
---*/
1717

18-
testWithTypedArrayConstructors(function(ctor) {
19-
var sample = new ctor();
18+
testWithAllTypedArrayConstructors(function(ctor, makeCtorArg) {
19+
var sample = new ctor(makeCtorArg(0));
2020

2121
assert.sameValue(ArrayBuffer.isView(sample), true);
22-
}, null, ["passthrough"]);
22+
});

test/built-ins/ArrayBuffer/isView/invoked-as-a-fn.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ includes: [testTypedArray.js]
1717

1818
var isView = ArrayBuffer.isView;
1919

20-
testWithTypedArrayConstructors(function(ctor) {
21-
var sample = new ctor();
20+
testWithAllTypedArrayConstructors(function(ctor, makeCtorArg) {
21+
var sample = new ctor(makeCtorArg(0));
2222
assert.sameValue(isView(sample), true, "instance of TypedArray");
23-
}, null, ["passthrough"]);
23+
});
2424

2525
var dv = new DataView(new ArrayBuffer(1), 0, 0);
2626
assert.sameValue(isView(dv), true, "instance of DataView");

test/built-ins/ArrayIteratorPrototype/next/detach-typedarray-in-progress.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ includes: [testTypedArray.js, detachArrayBuffer.js]
1313
features: [TypedArray]
1414
---*/
1515

16-
testWithTypedArrayConstructors(TA => {
17-
var typedArray = new TA(5);
16+
testWithAllTypedArrayConstructors((TA, makeCtorArg) => {
17+
var typedArray = new TA(makeCtorArg(5));
1818
var i = 0;
1919
assert.throws(TypeError, () => {
2020
for (let key of typedArray.keys()) {
@@ -23,4 +23,4 @@ testWithTypedArrayConstructors(TA => {
2323
}
2424
});
2525
assert.sameValue(i, 1);
26-
}, null, ["passthrough"]);
26+
}, null, null, ["immutable"]);

test/built-ins/Atomics/add/bad-range.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ testWithTypedArrayConstructors(function(TA) {
1919
Atomics.add(view, IdxGen(view), 10);
2020
});
2121
});
22-
}, views);
22+
}, views, ["passthrough"]);

test/built-ins/Atomics/add/bigint/non-shared-bufferdata.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ description: >
77
includes: [testTypedArray.js]
88
features: [ArrayBuffer, Atomics, BigInt, TypedArray]
99
---*/
10-
testWithBigIntTypedArrayConstructors(TA => {
11-
const buffer = new ArrayBuffer(TA.BYTES_PER_ELEMENT * 4);
10+
testWithBigIntTypedArrayConstructors((TA, makeCtorArg) => {
11+
const buffer = makeCtorArg(4);
1212
const view = new TA(buffer);
1313
assert.sameValue(Atomics.add(view, 0, 1n), 0n, 'Atomics.add(view, 0, 1n) returns 0n');
1414
assert.sameValue(Atomics.load(view, 0), 1n, 'Atomics.load(view, 0) returns 1n');
15-
}, null, ["passthrough"]);
15+
}, null, ["arraybuffer"], ["immutable"]);

test/built-ins/Atomics/add/good-views.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ testWithTypedArrayConstructors(function(TA) {
5151
Atomics.store(view, Idx, 37);
5252
assert.sameValue(Atomics.add(view, Idx, 0), 37, 'Atomics.add(view, Idx, 0) returns 37');
5353
});
54-
}, views);
54+
}, views, ["passthrough"]);

0 commit comments

Comments
 (0)