Atomics: Atomics.wake cleanup pass

This commit is contained in:
Rick Waldron 2018-05-21 14:55:47 -04:00
parent 695e1babd5
commit c5527b6d16
38 changed files with 302 additions and 178 deletions

View File

@ -15,7 +15,7 @@ includes: [testAtomics.js]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray] features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/ ---*/
var i32a = new Int32Array( const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
); );

View File

@ -16,7 +16,7 @@ features: [ArrayBuffer, Atomics, TypedArray]
---*/ ---*/
const i32a = new Int32Array( const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
); );
const poisoned = { const poisoned = {

View File

@ -15,14 +15,12 @@ includes: [testAtomics.js, testTypedArray.js]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray] features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/ ---*/
var sab = new SharedArrayBuffer(8); const i32a = new Int32Array(
var views = [Int32Array]; new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
);
testWithTypedArrayConstructors(function(TA) { testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let view = new TA(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, function() { assert.throws(RangeError, function() {
Atomics.wake(view, IdxGen(view), 0); Atomics.wake(i32a, IdxGen(i32a), 0);
}, '`Atomics.wake(view, IdxGen(view), 0)` throws RangeError'); // Even with waking zero }, 'Atomics.wake(i32a, IdxGen(i32a), 0) throws RangeError');
}); });
}, views);

View File

@ -15,11 +15,12 @@ includes: [testAtomics.js]
features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray] features: [ArrayBuffer, arrow-function, Atomics, BigInt, DataView, for-of, let, SharedArrayBuffer, TypedArray]
---*/ ---*/
var sab = new SharedArrayBuffer(8); const i64a = new BigInt64Array(
let i64a = new BigInt64Array(sab); new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)
);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) { testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
assert.throws(RangeError, function() { assert.throws(RangeError, function() {
Atomics.wake(view, IdxGen(i64a), 0); Atomics.wake(i64a, IdxGen(i64a), 0);
}, '`Atomics.wake(view, IdxGen(i64a), 0)` throws RangeError'); }, '`Atomics.wake(i64a, IdxGen(i64a), 0)` throws RangeError');
}); });

View File

@ -15,12 +15,20 @@ info: |
features: [Atomics, BigInt, TypedArray] features: [Atomics, BigInt, TypedArray]
---*/ ---*/
var poisoned = { const i64a = new BigUint64Array(
new SharedArrayBuffer(BigUint64Array.BYTES_PER_ELEMENT)
);
const poisoned = {
valueOf: function() { valueOf: function() {
throw new Test262Error('should not evaluate this code'); throw new Test262Error('should not evaluate this code');
} }
}; };
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wake(new BigUint64Array(), poisoned, poisoned); Atomics.wait(i64a, 0, 0);
}, '`Atomics.wake(new BigUint64Array(), poisoned, poisoned)` throws TypeError'); }, 'BigUint64Array');
assert.throws(TypeError, function() {
Atomics.wait(i64a, poisoned, poisoned);
}, 'BigUint64Array');

View File

@ -14,9 +14,11 @@ info: |
4.If bufferData is a Data Block, return false. 4.If bufferData is a Data Block, return false.
features: [ArrayBuffer, Atomics, BigInt, TypedArray] features: [ArrayBuffer, Atomics, BigInt, TypedArray]
---*/ ---*/
const i64a = new BigInt64Array(
new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)
);
var i64a = new BigInt64Array(new ArrayBuffer(4)); const poisoned = {
var poisoned = {
valueOf: function() { valueOf: function() {
throw new Test262Error('should not evaluate this code'); throw new Test262Error('should not evaluate this code');
} }
@ -24,8 +26,8 @@ var poisoned = {
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wake(i64a, 0, 0); Atomics.wake(i64a, 0, 0);
}, '`Atomics.wake(i64a, 0, 0)` throws TypeError'); }, 'Atomics.wake(i64a, 0, 0) on ArrayBuffer throws TypeError');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wake(i64a, poisoned, poisoned); Atomics.wake(i64a, poisoned, poisoned);
}, '`Atomics.wake(i64a, poisoned, poisoned)` throws TypeError'); }, 'Atomics.wake(i64a, poisoned, poisoned) on ArrayBuffer throws TypeError');

View File

@ -16,16 +16,21 @@ includes: [detachArrayBuffer.js]
features: [ArrayBuffer, Atomics, BigInt, TypedArray] features: [ArrayBuffer, Atomics, BigInt, TypedArray]
---*/ ---*/
var i64a = new BigInt64Array(new ArrayBuffer(1024)); const i64a = new BigInt64Array(
var poisoned = { new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)
);
const poisoned = {
valueOf: function() { valueOf: function() {
throw new Test262Error('should not evaluate this code'); throw new Test262Error('should not evaluate this code');
} }
}; };
// Detaching a non-shared ArrayBuffer sets the [[ArrayBufferData]] value to null try {
$DETACHBUFFER(i64a.buffer); $DETACHBUFFER(i64a.buffer); // Detaching a non-shared ArrayBuffer sets the [[ArrayBufferData]] value to null
} catch (error) {
$ERROR(`An unexpected error occurred when detaching ArrayBuffer: ${error.message}`);
}
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wake(i64a, poisoned, poisoned); Atomics.wake(i64a, poisoned, poisoned);
}, '`Atomics.wake(i64a, poisoned, poisoned)` throws TypeError'); }, 'Atomics.wake(i64a, poisoned, poisoned) on detached buffer throwes TypeError');

View File

@ -28,13 +28,13 @@ for (var i = 0; i < NUMAGENT; i++) {
} }
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
const i64a = new BigInt64Array(sab); const i64a = new BigInt64Array(sab);
Atomics.add(i64a, ${RUNNING}, 1); Atomics.add(i64a, ${RUNNING}, 1);
// This will always time out. // This will always time out.
$262.agent.report("B " + Atomics.wait(i64a, ${DUMMY}, 0, 10)); $262.agent.report("B " + Atomics.wait(i64a, ${DUMMY}, 0, 10));
$262.agent.leaving(); $262.agent.leaving();
}); });
`); `);
const i64a = new BigInt64Array( const i64a = new BigInt64Array(
@ -63,7 +63,7 @@ for (var i = 0; i < NUMAGENT + 1; i++) {
rs.sort(); rs.sort();
for (var i = 0; i < NUMAGENT; i++) { for (var i = 0; i < NUMAGENT; i++) {
assert.sameValue(rs[i], "A ok", 'The value of rs[i] is "A ok"'); assert.sameValue(rs[i], 'A ok', 'The value of rs[i] is "A ok"');
} }
assert.sameValue(rs[NUMAGENT], "B timed-out", 'The value of rs[NUMAGENT] is "B timed-out"'); assert.sameValue(rs[NUMAGENT], 'B timed-out', 'The value of rs[NUMAGENT] is "B timed-out"');

View File

@ -25,24 +25,37 @@ info: |
features: [Atomics, SharedArrayBuffer, TypedArray] features: [Atomics, SharedArrayBuffer, TypedArray]
---*/ ---*/
var sab = new SharedArrayBuffer(4); const i32a = new Int32Array(
var view = new Int32Array(sab); new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
);
assert.sameValue(Atomics.wake(view, 0, -3), 0, 'Atomics.wake(view, 0, -3) returns 0');
assert.sameValue( assert.sameValue(
Atomics.wake(view, 0, Number.POSITIVE_INFINITY), Atomics.wake(i32a, 0, -3),
0, 0,
'Atomics.wake(view, 0, Number.POSITIVE_INFINITY) returns 0' 'Atomics.wake(i32a, 0, -3) returns 0'
); );
assert.sameValue( assert.sameValue(
Atomics.wake(view, 0, undefined), Atomics.wake(i32a, 0, Number.POSITIVE_INFINITY),
0, 0,
'Atomics.wake(view, 0, undefined) returns 0' 'Atomics.wake(i32a, 0, Number.POSITIVE_INFINITY) returns 0'
); );
assert.sameValue(Atomics.wake(view, 0, "33"), 0, 'Atomics.wake(view, 0, "33") returns 0');
assert.sameValue( assert.sameValue(
Atomics.wake(view, 0, { valueOf: 8 }), Atomics.wake(i32a, 0, undefined),
0, 0,
'Atomics.wake(view, 0, {valueOf: 8}) returns 0' 'Atomics.wake(i32a, 0, undefined) returns 0'
);
assert.sameValue(
Atomics.wake(i32a, 0, '33'),
0,
'Atomics.wake(i32a, 0, "33") returns 0'
);
assert.sameValue(
Atomics.wake(i32a, 0, { valueOf: 8 }),
0,
'Atomics.wake(i32a, 0, {valueOf: 8}) returns 0'
);
assert.sameValue(
Atomics.wake(i32a, 0),
0,
'Atomics.wake(i32a, 0) returns 0'
); );
assert.sameValue(Atomics.wake(view, 0), 0, 'Atomics.wake(view, 0) returns 0');

View File

@ -16,16 +16,8 @@ includes: [atomicsHelper.js]
features: [Atomics, SharedArrayBuffer, TypedArray] features: [Atomics, SharedArrayBuffer, TypedArray]
---*/ ---*/
var NUMAGENT = 4; // Total number of agents started const NUMAGENT = 4; // Total number of agents started
var WAKEUP = 0; // Index all agents are waiting on const WAKEUP = 0; // Index all agents are waiting on
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null) {
$262.agent.sleep(10);
}
return r;
}
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
@ -64,7 +56,7 @@ const i32a = new Int32Array(
); );
$262.agent.broadcast(i32a.buffer); $262.agent.broadcast(i32a.buffer);
$262.agent.sleep(20); $262.agent.sleep(100);
assert.sameValue( assert.sameValue(
Atomics.wake(i32a, WAKEUP /*, count missing */), Atomics.wake(i32a, WAKEUP /*, count missing */),
@ -72,13 +64,13 @@ assert.sameValue(
'Atomics.wake(i32a, WAKEUP /*, count missing */) equals the value of `NUMAGENT` (4)' 'Atomics.wake(i32a, WAKEUP /*, count missing */) equals the value of `NUMAGENT` (4)'
); );
var sortedReports = []; const sortedReports = [];
for (var i = 0; i < NUMAGENT; i++) { for (var i = 0; i < NUMAGENT; i++) {
sortedReports.push(getReport()); sortedReports.push(getReport());
} }
sortedReports.sort(); sortedReports.sort();
assert.sameValue(sortedReports[0], "A ok", 'The value of sortedReports[0] is "A ok"'); assert.sameValue(sortedReports[0], 'A ok', 'The value of sortedReports[0] is "A ok"');
assert.sameValue(sortedReports[1], "B ok", 'The value of sortedReports[1] is "B ok"'); assert.sameValue(sortedReports[1], 'B ok', 'The value of sortedReports[1] is "B ok"');
assert.sameValue(sortedReports[2], "C ok", 'The value of sortedReports[2] is "C ok"'); assert.sameValue(sortedReports[2], 'C ok', 'The value of sortedReports[2] is "C ok"');
assert.sameValue(sortedReports[3], "D ok", 'The value of sortedReports[3] is "D ok"'); assert.sameValue(sortedReports[3], 'D ok', 'The value of sortedReports[3] is "D ok"');

View File

@ -33,7 +33,6 @@ $262.agent.start(`
}); });
`); `);
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
const i32a = new Int32Array(sab); const i32a = new Int32Array(sab);
@ -42,7 +41,6 @@ $262.agent.start(`
}); });
`); `);
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
const i32a = new Int32Array(sab); const i32a = new Int32Array(sab);
@ -65,13 +63,13 @@ assert.sameValue(
'Atomics.wake(i32a, WAKEUP, undefined) equals the value of `NUMAGENT` (4)' 'Atomics.wake(i32a, WAKEUP, undefined) equals the value of `NUMAGENT` (4)'
); );
var sortedReports = []; const sortedReports = [];
for (var i = 0; i < NUMAGENT; i++) { for (var i = 0; i < NUMAGENT; i++) {
sortedReports.push(getReport()); sortedReports.push(getReport());
} }
sortedReports.sort(); sortedReports.sort();
assert.sameValue(sortedReports[0], "A ok", 'The value of sortedReports[0] is "A ok"'); assert.sameValue(sortedReports[0], 'A ok', 'The value of sortedReports[0] is "A ok"');
assert.sameValue(sortedReports[1], "B ok", 'The value of sortedReports[1] is "B ok"'); assert.sameValue(sortedReports[1], 'B ok', 'The value of sortedReports[1] is "B ok"');
assert.sameValue(sortedReports[2], "C ok", 'The value of sortedReports[2] is "C ok"'); assert.sameValue(sortedReports[2], 'C ok', 'The value of sortedReports[2] is "C ok"');
assert.sameValue(sortedReports[3], "D ok", 'The value of sortedReports[3] is "D ok"'); assert.sameValue(sortedReports[3], 'D ok', 'The value of sortedReports[3] is "D ok"');

View File

@ -20,13 +20,14 @@ info: |
2. If number is NaN, return +0. 2. If number is NaN, return +0.
... ...
includes: [nans.js, atomicsHelper.js]
features: [Atomics, SharedArrayBuffer, TypedArray] features: [Atomics, SharedArrayBuffer, TypedArray]
includes: [nans.js]
---*/ ---*/
var sab = new SharedArrayBuffer(4); const i32a = new Int32Array(
var view = new Int32Array(sab); new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
);
NaNs.forEach(nan => { NaNs.forEach(nan => {
assert.sameValue(Atomics.wake(view, 0, nan), 0, 'Atomics.wake(view, 0, nan) returns 0'); assert.sameValue(Atomics.wake(i32a, 0, nan), 0, 'Atomics.wake(i32a, 0, nan) returns 0');
}); });

View File

@ -17,9 +17,10 @@ info: |
features: [Atomics, SharedArrayBuffer, TypedArray] features: [Atomics, SharedArrayBuffer, TypedArray]
---*/ ---*/
var sab = new SharedArrayBuffer(4); const i32a = new Int32Array(
var view = new Int32Array(sab); new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
);
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wake(view, 0, Symbol()); Atomics.wake(i32a, 0, Symbol());
}, '`Atomics.wake(view, 0, Symbol())` throws TypeError'); }, '`Atomics.wake(i32a, 0, Symbol())` throws TypeError');

View File

@ -17,14 +17,16 @@ info: |
features: [Atomics, SharedArrayBuffer, TypedArray] features: [Atomics, SharedArrayBuffer, TypedArray]
---*/ ---*/
var sab = new SharedArrayBuffer(4); const i32a = new Int32Array(
var view = new Int32Array(sab); new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
var poisoned = { );
const poisoned = {
valueOf: function() { valueOf: function() {
throw new Test262Error('should not evaluate this code'); throw new Test262Error('should not evaluate this code');
} }
}; };
assert.throws(Test262Error, function() { assert.throws(Test262Error, function() {
Atomics.wake(view, 0, poisoned); Atomics.wake(i32a, 0, poisoned);
}, '`Atomics.wake(view, 0, poisoned)` throws Test262Error'); }, '`Atomics.wake(i32a, 0, poisoned)` throws Test262Error');

View File

@ -11,7 +11,7 @@ features: [Atomics, SharedArrayBuffer, TypedArray]
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
var i32a = new Int32Array(sab); const i32a = new Int32Array(sab);
$262.agent.report(Atomics.wait(i32a, 0, 0, 1000)); // Timeout after 1 second $262.agent.report(Atomics.wait(i32a, 0, 0, 1000)); // Timeout after 1 second
$262.agent.leaving(); $262.agent.leaving();
}); });

View File

@ -16,9 +16,11 @@ info: |
features: [Atomics, SharedArrayBuffer, TypedArray] features: [Atomics, SharedArrayBuffer, TypedArray]
---*/ ---*/
var sab = new SharedArrayBuffer(1024); const i32a = new Int32Array(
var i32a = new Int32Array(sab); new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
var poisoned = { );
const poisoned = {
valueOf: function() { valueOf: function() {
throw new Test262Error('should not evaluate this code'); throw new Test262Error('should not evaluate this code');
} }

View File

@ -15,40 +15,64 @@ info: |
features: [Atomics, Float32Array, Float64Array, Int8Array, TypedArray, Uint16Array, Uint8Array, Uint8ClampedArray] features: [Atomics, Float32Array, Float64Array, Int8Array, TypedArray, Uint16Array, Uint8Array, Uint8ClampedArray]
---*/ ---*/
var poisoned = { const poisoned = {
valueOf: function() { valueOf: function() {
throw new Test262Error('should not evaluate this code'); throw new Test262Error('should not evaluate this code');
} }
}; };
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wake(new Float64Array(), poisoned, poisoned); const view = new Float64Array(
}, '`Atomics.wake(new Float64Array(), poisoned, poisoned)` throws TypeError'); new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT)
);
Atomics.wake(view, poisoned, poisoned);
}, '`Atomics.wake(view), poisoned, poisoned)` throws TypeError');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wake(new Float32Array(), poisoned, poisoned); const view = new Float32Array(
}, '`Atomics.wake(new Float32Array(), poisoned, poisoned)` throws TypeError'); new SharedArrayBuffer(Float32Array.BYTES_PER_ELEMENT)
);
Atomics.wake(view, poisoned, poisoned);
}, '`Atomics.wake(view), poisoned, poisoned)` throws TypeError');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wake(new Int16Array(), poisoned, poisoned); const view = new Int16Array(
}, '`Atomics.wake(new Int16Array(), poisoned, poisoned)` throws TypeError'); new SharedArrayBuffer(Int16Array.BYTES_PER_ELEMENT)
);
Atomics.wake(view, poisoned, poisoned);
}, '`Atomics.wake(view), poisoned, poisoned)` throws TypeError');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wake(new Int8Array(), poisoned, poisoned); const view = new Int8Array(
}, '`Atomics.wake(new Int8Array(), poisoned, poisoned)` throws TypeError'); new SharedArrayBuffer(Int8Array.BYTES_PER_ELEMENT)
);
Atomics.wake(view, poisoned, poisoned);
}, '`Atomics.wake(view), poisoned, poisoned)` throws TypeError');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
const view = new Uint32Array(
new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT)
);
Atomics.wake(new Uint32Array(), poisoned, poisoned); Atomics.wake(new Uint32Array(), poisoned, poisoned);
}, '`Atomics.wake(new Uint32Array(), poisoned, poisoned)` throws TypeError'); }, '`Atomics.wake(view), poisoned, poisoned)` throws TypeError');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wake(new Uint16Array(), poisoned, poisoned); const view = new Uint16Array(
}, '`Atomics.wake(new Uint16Array(), poisoned, poisoned)` throws TypeError'); new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT)
);
Atomics.wake(view, poisoned, poisoned);
}, '`Atomics.wake(view), poisoned, poisoned)` throws TypeError');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wait(new Uint8Array(), poisoned, poisoned); const view = new Uint8Array(
}, '`Atomics.wait(new Uint8Array(), poisoned, poisoned)` throws TypeError'); new SharedArrayBuffer(Uint8Array.BYTES_PER_ELEMENT)
);
Atomics.wake(view, poisoned, poisoned);
}, '`Atomics.wait(view), poisoned, poisoned)` throws TypeError');
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wake(new Uint8ClampedArray(), poisoned, poisoned); const view = new Uint8ClampedArray(
}, '`Atomics.wake(new Uint8ClampedArray(), poisoned, poisoned)` throws TypeError'); new SharedArrayBuffer(Uint8ClampedArray.BYTES_PER_ELEMENT)
);
Atomics.wake(view, poisoned, poisoned);
}, '`Atomics.wake(view), poisoned, poisoned)` throws TypeError');

View File

@ -15,8 +15,11 @@ info: |
features: [ArrayBuffer, Atomics, TypedArray] features: [ArrayBuffer, Atomics, TypedArray]
---*/ ---*/
var i32a = new Int32Array(new ArrayBuffer(4)); const i32a = new Int32Array(
var poisoned = { new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
);
const poisoned = {
valueOf: function() { valueOf: function() {
throw new Test262Error('should not evaluate this code'); throw new Test262Error('should not evaluate this code');
} }

View File

@ -0,0 +1,42 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description: >
Test Atomics.wake on non-shared integer TypedArrays
includes: [testTypedArray.js]
features: [ArrayBuffer, Atomics, TypedArray]
---*/
const nonsab = new ArrayBuffer(16);
const poisoned = {
valueOf: function() {
throw new Test262Error('should not evaluate this code');
}
};
assert.throws(TypeError, function() {
Atomics.wake(new Int16Array(nonsab), poisoned, poisoned);
}, 'Atomics.wake(new Int16Array(nonsab)) throws TypeError');
assert.throws(TypeError, function() {
Atomics.wake(new Int8Array(nonsab), poisoned, poisoned);
}, 'Atomics.wake(new Int8Array(nonsab)) throws TypeError');
assert.throws(TypeError, function() {
Atomics.wake(new Uint32Array(nonsab), poisoned, poisoned);
}, 'Atomics.wake(new Uint32Array(nonsab)) throws TypeError');
assert.throws(TypeError, function() {
Atomics.wake(new Uint16Array(nonsab), poisoned, poisoned);
}, 'Atomics.wake(new Uint16Array(nonsab)) throws TypeError');
assert.throws(TypeError, function() {
Atomics.wake(new Uint8Array(nonsab), poisoned, poisoned);
}, 'Atomics.wake(new Uint8Array(nonsab)) throws TypeError');
assert.throws(TypeError, function() {
Atomics.wake(new Uint8ClampedArray(nonsab), poisoned, poisoned);
}, 'Atomics.wake(new Uint8ClampedArray(nonsab)) throws TypeError');

View File

@ -0,0 +1,42 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description: >
Test Atomics.wake on non-shared integer TypedArrays
includes: [testTypedArray.js]
features: [Atomics, SharedArrayBuffer, TypedArray]
---*/
const sab = new SharedArrayBuffer(16);
const poisoned = {
valueOf: function() {
throw new Test262Error('should not evaluate this code');
}
};
assert.throws(TypeError, function() {
Atomics.wake(new Int16Array(sab), poisoned, poisoned);
}, 'Atomics.wake(new Int16Array(sab)) throws TypeError');
assert.throws(TypeError, function() {
Atomics.wake(new Int8Array(sab), poisoned, poisoned);
}, 'Atomics.wake(new Int8Array(sab)) throws TypeError');
assert.throws(TypeError, function() {
Atomics.wake(new Uint32Array(sab), poisoned, poisoned);
}, 'Atomics.wake(new Uint32Array(sab)) throws TypeError');
assert.throws(TypeError, function() {
Atomics.wake(new Uint16Array(sab), poisoned, poisoned);
}, 'Atomics.wake(new Uint16Array(sab)) throws TypeError');
assert.throws(TypeError, function() {
Atomics.wake(new Uint8Array(sab), poisoned, poisoned);
}, 'Atomics.wake(new Uint8Array(sab)) throws TypeError');
assert.throws(TypeError, function() {
Atomics.wake(new Uint8ClampedArray(sab), poisoned, poisoned);
}, 'Atomics.wake(new Uint8ClampedArray(sab)) throws TypeError');

View File

@ -9,8 +9,8 @@ includes: [testAtomics.js]
features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer] features: [ArrayBuffer, arrow-function, Atomics, DataView, for-of, let, SharedArrayBuffer]
---*/ ---*/
testWithAtomicsNonViewValues(function(view) { testWithAtomicsNonViewValues(function(nonView) {
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wake(view, 0, 0); Atomics.wake(nonView, 0, 0);
}, '`Atomics.wake(view, 0, 0)` throws TypeError'); // Even with count == 0 }, '`Atomics.wake(nonView, 0, 0)` throws TypeError'); // Even with count == 0
}); });

View File

@ -1,20 +0,0 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description: >
Test Atomics.wake on non-shared integer TypedArrays
includes: [testTypedArray.js]
features: [ArrayBuffer, Atomics, TypedArray]
---*/
var buffer = new ArrayBuffer(16);
var views = intArrayConstructors.slice();
testWithTypedArrayConstructors(function(TA) {
// Should fail even if waking zero waiters
assert.throws(TypeError, function() {
Atomics.wake(new TA(buffer), 0, 0);
}, '`Atomics.wake(new TA(buffer), 0, 0)` throws TypeError');
}, views);

View File

@ -14,7 +14,7 @@ info: |
features: [Atomics] features: [Atomics]
---*/ ---*/
var poisoned = { const poisoned = {
valueOf: function() { valueOf: function() {
throw new Test262Error('should not evaluate this code'); throw new Test262Error('should not evaluate this code');
} }

View File

@ -13,7 +13,7 @@ info: |
features: [Atomics, Symbol] features: [Atomics, Symbol]
---*/ ---*/
var poisoned = { const poisoned = {
valueOf: function() { valueOf: function() {
throw new Test262Error('should not evaluate this code'); throw new Test262Error('should not evaluate this code');
} }

View File

@ -16,15 +16,22 @@ includes: [detachArrayBuffer.js]
features: [ArrayBuffer, Atomics, TypedArray] features: [ArrayBuffer, Atomics, TypedArray]
---*/ ---*/
var i32a = new Int32Array(new ArrayBuffer(1024)); const i32a = new Int32Array(
var poisoned = { new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
);
const poisoned = {
valueOf: function() { valueOf: function() {
throw new Test262Error('should not evaluate this code'); throw new Test262Error('should not evaluate this code');
} }
}; };
$DETACHBUFFER(i32a.buffer); // Detaching a non-shared ArrayBuffer sets the [[ArrayBufferData]] value to null try {
$DETACHBUFFER(i32a.buffer); // Detaching a non-shared ArrayBuffer sets the [[ArrayBufferData]] value to null
} catch (error) {
$ERROR(`An unexpected error occurred when detaching ArrayBuffer: ${error.message}`);
}
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
Atomics.wake(i32a, poisoned, poisoned); Atomics.wake(i32a, poisoned, poisoned);
}, '`Atomics.wake(i32a, poisoned, poisoned)` throws TypeError'); }, 'Atomics.wake(i32a, poisoned, poisoned) on detached buffer throwes TypeError');

View File

@ -16,7 +16,10 @@ description: >
features: [Atomics, SharedArrayBuffer, TypedArray] features: [Atomics, SharedArrayBuffer, TypedArray]
---*/ ---*/
var i32a = new Int32Array(new SharedArrayBuffer(4)); const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
);
var poisoned = { var poisoned = {
valueOf: function() { valueOf: function() {
throw new Test262Error('should not evaluate this code'); throw new Test262Error('should not evaluate this code');

View File

@ -28,16 +28,17 @@ info: |
features: [Atomics, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray] features: [Atomics, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray]
---*/ ---*/
var buffer = new SharedArrayBuffer(1024); const i32a = new Int32Array(
var i32a = new Int32Array(buffer); new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
);
var poisonedValueOf = { const poisonedValueOf = {
valueOf: function() { valueOf: function() {
throw new Test262Error('should not evaluate this code'); throw new Test262Error('should not evaluate this code');
} }
}; };
var poisonedToPrimitive = { const poisonedToPrimitive = {
[Symbol.toPrimitive]: function() { [Symbol.toPrimitive]: function() {
throw new Test262Error("passing a poisoned object using @@ToPrimitive"); throw new Test262Error("passing a poisoned object using @@ToPrimitive");
} }

View File

@ -39,7 +39,7 @@ $262.agent.start(`
`); `);
const i32a = new Int32Array( const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT); new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
); );
$262.agent.broadcast(i32a.buffer); $262.agent.broadcast(i32a.buffer);
@ -51,7 +51,7 @@ assert.sameValue(
1, 1,
'Atomics.wake(i32a, undefined, 1) returns 1' 'Atomics.wake(i32a, undefined, 1) returns 1'
); );
assert.sameValue(getReport(), "ok", 'getReport() returns "ok"'); assert.sameValue(getReport(), 'ok', 'getReport() returns "ok"');
// wake again at index 0 // wake again at index 0
@ -60,4 +60,4 @@ assert.sameValue(
1, 1,
'Atomics.wake(i32a) returns 1' 'Atomics.wake(i32a) returns 1'
); );
assert.sameValue(getReport(), "ok", 'getReport() returns "ok"'); assert.sameValue(getReport(), 'ok', 'getReport() returns "ok"');

View File

@ -20,7 +20,7 @@ const NUMAGENT = 3;
for (var i=0; i < NUMAGENT; i++) { for (var i=0; i < NUMAGENT; i++) {
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
var i32a = new Int32Array(sab); const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1); Atomics.add(i32a, ${RUNNING}, 1);
$262.agent.report("A " + Atomics.wait(i32a, ${WAKEUP}, 0)); $262.agent.report("A " + Atomics.wait(i32a, ${WAKEUP}, 0));
$262.agent.leaving(); $262.agent.leaving();
@ -30,7 +30,7 @@ for (var i=0; i < NUMAGENT; i++) {
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
var i32a = new Int32Array(sab); const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1); Atomics.add(i32a, ${RUNNING}, 1);
// This will always time out. // This will always time out.
$262.agent.report("B " + Atomics.wait(i32a, ${DUMMY}, 0, 10)); $262.agent.report("B " + Atomics.wait(i32a, ${DUMMY}, 0, 10));

View File

@ -15,10 +15,10 @@ const RUNNING = 2; // Accounting of live agents
const NUMELEM = 3; const NUMELEM = 3;
const NUMAGENT = 3; const NUMAGENT = 3;
for (var i=0; i < NUMAGENT; i++) { for (var i = 0; i < NUMAGENT; i++) {
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
var i32a = new Int32Array(sab); const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1); Atomics.add(i32a, ${RUNNING}, 1);
$262.agent.report("A " + Atomics.wait(i32a, ${WAKEUP}, 0)); $262.agent.report("A " + Atomics.wait(i32a, ${WAKEUP}, 0));
$262.agent.leaving(); $262.agent.leaving();
@ -28,7 +28,7 @@ for (var i=0; i < NUMAGENT; i++) {
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
var i32a = new Int32Array(sab); const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1); Atomics.add(i32a, ${RUNNING}, 1);
// This will always time out. // This will always time out.
$262.agent.report("B " + Atomics.wait(i32a, ${DUMMY}, 0, 10)); $262.agent.report("B " + Atomics.wait(i32a, ${DUMMY}, 0, 10));
@ -36,7 +36,10 @@ $262.agent.start(`
}); });
`); `);
var i32a = new Int32Array(new SharedArrayBuffer(NUMELEM * Int32Array.BYTES_PER_ELEMENT)); const i32a = new Int32Array(
new SharedArrayBuffer(NUMELEM * Int32Array.BYTES_PER_ELEMENT)
);
$262.agent.broadcast(i32a.buffer); $262.agent.broadcast(i32a.buffer);
// Wait for agents to be running. // Wait for agents to be running.
@ -60,6 +63,6 @@ for (var i = 0; i < NUMAGENT + 1; i++) {
rs.sort(); rs.sort();
for (var i = 0; i < NUMAGENT; i++) { for (var i = 0; i < NUMAGENT; i++) {
assert.sameValue(rs[i], "A ok", 'The value of rs[i] is "A ok"'); assert.sameValue(rs[i], 'A ok', 'The value of rs[i] is "A ok"');
} }
assert.sameValue(rs[NUMAGENT], "B timed-out", 'The value of rs[NUMAGENT] is "B timed-out"'); assert.sameValue(rs[NUMAGENT], 'B timed-out', 'The value of rs[NUMAGENT] is "B timed-out"');

View File

@ -22,7 +22,7 @@ const NUMELEM = RUNNING + 1;
for (var i = 0; i < NUMAGENT; i++) { for (var i = 0; i < NUMAGENT; i++) {
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
var i32a = new Int32Array(sab); const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1); Atomics.add(i32a, ${RUNNING}, 1);
while (Atomics.load(i32a, ${SPIN + i}) === 0) while (Atomics.load(i32a, ${SPIN + i}) === 0)
/* nothing */ ; /* nothing */ ;
@ -35,6 +35,7 @@ for (var i = 0; i < NUMAGENT; i++) {
const i32a = new Int32Array( const i32a = new Int32Array(
new SharedArrayBuffer(NUMELEM * Int32Array.BYTES_PER_ELEMENT) new SharedArrayBuffer(NUMELEM * Int32Array.BYTES_PER_ELEMENT)
); );
$262.agent.broadcast(i32a.buffer); $262.agent.broadcast(i32a.buffer);
// Wait for agents to be running. // Wait for agents to be running.
@ -53,5 +54,5 @@ for (var i = 0; i < NUMAGENT; i++) {
// Wake them up one at a time and check the order is 0 1 2 // Wake them up one at a time and check the order is 0 1 2
for (var i = 0; i < NUMAGENT; i++) { for (var i = 0; i < NUMAGENT; i++) {
assert.sameValue(Atomics.wake(i32a, WAKEUP, 1), 1, 'Atomics.wake(i32a, WAKEUP, 1) returns 1'); assert.sameValue(Atomics.wake(i32a, WAKEUP, 1), 1, 'Atomics.wake(i32a, WAKEUP, 1) returns 1');
assert.sameValue(getReport(), i + "ok", 'getReport() returns i + "ok"'); assert.sameValue(getReport(), i + 'ok', 'getReport() returns i + "ok"');
} }

View File

@ -24,4 +24,4 @@ const i32a = new Int32Array(
$262.agent.broadcast(i32a.buffer); $262.agent.broadcast(i32a.buffer);
$262.agent.sleep(500); // Give the agent a chance to wait $262.agent.sleep(500); // Give the agent a chance to wait
assert.sameValue(Atomics.wake(i32a, 0, NaN), 0, 'Atomics.wake(i32a, 0, NaN) returns 0'); // Don't actually wake it assert.sameValue(Atomics.wake(i32a, 0, NaN), 0, 'Atomics.wake(i32a, 0, NaN) returns 0'); // Don't actually wake it
assert.sameValue(getReport(), "timed-out", 'getReport() returns "timed-out"'); assert.sameValue(getReport(), 'timed-out', 'getReport() returns "timed-out"');

View File

@ -18,7 +18,7 @@ const WAKECOUNT = 1;
for (var i = 0; i < NUMAGENT; i++ ) { for (var i = 0; i < NUMAGENT; i++ ) {
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
var i32a = new Int32Array(sab); const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1); Atomics.add(i32a, ${RUNNING}, 1);
// Waiters that are not woken will time out eventually. // Waiters that are not woken will time out eventually.
$262.agent.report(Atomics.wait(i32a, ${WAKEUP}, 0, 2000)); $262.agent.report(Atomics.wait(i32a, ${WAKEUP}, 0, 2000));
@ -30,6 +30,7 @@ for (var i = 0; i < NUMAGENT; i++ ) {
const i32a = new Int32Array( const i32a = new Int32Array(
new SharedArrayBuffer(NUMELEM * Int32Array.BYTES_PER_ELEMENT) new SharedArrayBuffer(NUMELEM * Int32Array.BYTES_PER_ELEMENT)
); );
$262.agent.broadcast(i32a.buffer); $262.agent.broadcast(i32a.buffer);
// Wait for agents to be running. // Wait for agents to be running.

View File

@ -11,15 +11,15 @@ features: [Atomics, SharedArrayBuffer, TypedArray]
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
var i32a = new Int32Array(sab); const i32a = new Int32Array(sab);
Atomics.add(i32a, 1, 1); Atomics.add(i32a, 1, 1);
$262.agent.report(Atomics.wait(i32a, 0, 0, 2000)); $262.agent.report(Atomics.wait(i32a, 0, 0, 2000));
$262.agent.leaving(); $262.agent.leaving();
}); });
`); `);
var i32a = new Int32Array( const i32a = new Int32Array(
new SharedArrayBuffer(2 * Int32Array.BYTES_PER_ELEMENT) new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
); );
$262.agent.broadcast(i32a.buffer); $262.agent.broadcast(i32a.buffer);

View File

@ -16,10 +16,10 @@ var RUNNING = 1; // Accounting of live agents here
var NUMELEM = 2; var NUMELEM = 2;
var WAKECOUNT = 2; var WAKECOUNT = 2;
for ( var i=0 ; i < NUMAGENT ; i++ ) { for (var i = 0; i < NUMAGENT; i++ ) {
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
var i32a = new Int32Array(sab); const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1); Atomics.add(i32a, ${RUNNING}, 1);
// Waiters that are not woken will time out eventually. // Waiters that are not woken will time out eventually.
$262.agent.report(Atomics.wait(i32a, ${WAKEUP}, 0, 2000)); $262.agent.report(Atomics.wait(i32a, ${WAKEUP}, 0, 2000));
@ -28,9 +28,10 @@ for ( var i=0 ; i < NUMAGENT ; i++ ) {
`); `);
} }
var i32a = new Int32Array( const i32a = new Int32Array(
new SharedArrayBuffer(NUMELEM * Int32Array.BYTES_PER_ELEMENT) new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
); );
$262.agent.broadcast(i32a.buffer); $262.agent.broadcast(i32a.buffer);
// Wait for agents to be running. // Wait for agents to be running.

View File

@ -18,9 +18,10 @@ $262.agent.start(`
}); });
`); `);
var i32a = new Int32Array( const i32a = new Int32Array(
new SharedArrayBuffer(2 * Int32Array.BYTES_PER_ELEMENT) new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
); );
$262.agent.broadcast(i32a.buffer); $262.agent.broadcast(i32a.buffer);
waitUntil(i32a, 1, 1); waitUntil(i32a, 1, 1);

View File

@ -6,7 +6,7 @@ esid: sec-atomics.wake
description: > description: >
Test that Atomics.wake wakes zero waiters if there are no agents that match Test that Atomics.wake wakes zero waiters if there are no agents that match
its arguments waiting. its arguments waiting.
includes: [testAtomics.js] includes: [atomicsHelper.js]
features: [Atomics, SharedArrayBuffer, TypedArray] features: [Atomics, SharedArrayBuffer, TypedArray]
---*/ ---*/
@ -19,20 +19,13 @@ $262.agent.start(`
}); });
`); `);
var i32a = new Int32Array(new SharedArrayBuffer(2 * Int32Array.BYTES_PER_ELEMENT)); const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)
);
$262.agent.broadcast(i32a.buffer); $262.agent.broadcast(i32a.buffer);
waitUntil(i32a, 1, 1); waitUntil(i32a, 1, 1);
// There are ZERO matching agents... // There are ZERO matching agents...
assert.sameValue(Atomics.wake(i32a, 1, 1), 0, 'Atomics.wake(i32a, 1, 1) returns 0'); assert.sameValue(Atomics.wake(i32a, 1, 1), 0, 'Atomics.wake(i32a, 1, 1) returns 0');
function waitUntil(i32a, index, numberOfAgentsExpected) {
var i = 0;
while (Atomics.load(i32a, index) !== numberOfAgentsExpected && i < 15) {
$262.agent.sleep(10);
i++;
}
const numberOfAgentsReady = Atomics.load(i32a, index);
assert.sameValue(numberOfAgentsReady, numberOfAgentsExpected, `'numberOfAgentsReady' equals the value of numberOfAgentsExpected (${numberOfAgentsExpected})`);
}

View File

@ -18,7 +18,7 @@ var WAKECOUNT = 0;
for (var i = 0; i < NUMAGENT; i++) { for (var i = 0; i < NUMAGENT; i++) {
$262.agent.start(` $262.agent.start(`
$262.agent.receiveBroadcast(function(sab) { $262.agent.receiveBroadcast(function(sab) {
var i32a = new Int32Array(sab); const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1); Atomics.add(i32a, ${RUNNING}, 1);
// Waiters that are not woken will time out eventually. // Waiters that are not woken will time out eventually.
$262.agent.report(Atomics.wait(i32a, ${WAKEUP}, 0, 200)); $262.agent.report(Atomics.wait(i32a, ${WAKEUP}, 0, 200));
@ -33,7 +33,6 @@ const i32a = new Int32Array(
$262.agent.broadcast(i32a.buffer); $262.agent.broadcast(i32a.buffer);
// Wait for agents to be running. // Wait for agents to be running.
waitUntil(i32a, RUNNING, NUMAGENT); waitUntil(i32a, RUNNING, NUMAGENT);