Initial tests for extending Atomics.wait test coverage (#1488)

This commit is contained in:
Amal Hussein 2018-03-13 17:22:10 -04:00 committed by Leo Balter
parent cdbf81856b
commit b07c546b8a
7 changed files with 236 additions and 0 deletions

View File

@ -0,0 +1,26 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description:
Throws a TypeError if typedArray.buffer is not a SharedArrayBuffer
info: |
Atomics.wait( typedArray, index, value, timeout )
1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true).
...
9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception.
...
4.If bufferData is a Data Block, return false.
features: [ Atomics, ArrayBuffer, TypedArray ]
---*/
var int32Array = new Int32Array(new ArrayBuffer(1024));
var poisoned = {
valueOf: function() {
throw new Test262Error("should not evaluate this code");
}
};
assert.throws(TypeError, () => Atomics.wait(int32Array, 0, 0, 0));
assert.throws(TypeError, () => Atomics.wait(int32Array, poisoned, poisoned, poisoned));

View File

@ -0,0 +1,24 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description:
Throws a TypeError if the typedArray arg is not a TypedArray object
info: |
Atomics.wait( typedArray, index, value, timeout )
1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true).
...
3.If typedArray does not have a [[TypedArrayName]] internal slot, throw a TypeError exception.
features: [ Atomics ]
---*/
var poisoned = {
valueOf: function() {
throw new Test262Error("should not evaluate this code");
}
};
assert.throws(TypeError, () => Atomics.wait({}, 0, 0, 0));
assert.throws(TypeError, () => Atomics.wait({}, poisoned, poisoned, poisoned));

View File

@ -0,0 +1,30 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description:
Throws a RangeError is index < 0
info: |
Atomics.wait( typedArray, index, value, timeout )
2.Let i be ? ValidateAtomicAccess(typedArray, index).
...
2.Let accessIndex be ? ToIndex(requestIndex).
...
2.b If integerIndex < 0, throw a RangeError exception
features: [ Atomics , SharedArrayBuffer, TypedArray ]
---*/
var sab = new SharedArrayBuffer(1024);
var int32Array = new Int32Array(sab);
var poisoned = {
valueOf: function() {
throw new Test262Error("should not evaluate this code");
}
};
assert.throws(RangeError, () => Atomics.wait(int32Array, -Infinity, poisoned, poisoned));
assert.throws(RangeError, () => Atomics.wait(int32Array, -0.999, poisoned, poisoned));
assert.throws(RangeError, () => Atomics.wait(int32Array, -1, poisoned, poisoned));
assert.throws(RangeError, () => Atomics.wait(int32Array, -0.00000000000000001, poisoned, poisoned));
assert.throws(RangeError, () => Atomics.wait(int32Array, NaN, poisoned, poisoned));

View File

@ -0,0 +1,34 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description:
Throws a TypeError if typedArray arg is not an Object
info: |
Atomics.wait( typedArray, index, value, timeout )
1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true).
...
2. if Type(typedArray) is not Object, throw a TypeError exception
features: [ Atomics, Symbol ]
---*/
var poisoned = {
valueOf: function() {
throw new Test262Error("should not evaluate this code");
}
};
assert.throws(TypeError, function() { Atomics.wait(null,poisoned,poisoned,poisoned) }, 'null');
assert.throws(TypeError, function() { Atomics.wait(undefined,poisoned,poisoned,poisoned) }, 'undefined');
assert.throws(TypeError, function() { Atomics.wait(true,poisoned,poisoned,poisoned) }, 'true');
assert.throws(TypeError, function() { Atomics.wait(false,poisoned,poisoned,poisoned) }, 'false');
assert.throws(TypeError, function() { Atomics.wait('***string***',poisoned,poisoned,poisoned) }, 'String');
assert.throws(TypeError, function() { Atomics.wait(Number.NEGATIVE_INFINITY,poisoned,poisoned,poisoned) }, '-Infinity');
assert.throws(TypeError, function() { Atomics.wait(Symbol('***symbol***'),poisoned,poisoned,poisoned) }, 'Symbol');

View File

@ -0,0 +1,28 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description:
A null value for bufferData throws a TypeError
info: |
Atomics.wait( typedArray, index, value, timeout )
1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true).
...
9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception.
...
3.If bufferData is null, return false.
includes: [detachArrayBuffer.js]
features: [ Atomics, ArrayBuffer, TypedArray ]
---*/
var int32Array = new Int32Array(new ArrayBuffer(1024));
var poisoned = {
valueOf: function() {
throw new Test262Error("should not evaluate this code");
}
};
$DETACHBUFFER(int32Array.buffer); // Detaching a non-shared ArrayBuffer sets the [[ArrayBufferData]] value to null
assert.throws(TypeError, () => Atomics.wait(int32Array, poisoned, poisoned, poisoned));

View File

@ -0,0 +1,46 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description:
Throws a TypeError if index arg can not be converted to an Integer
info: |
Atomics.wait( typedArray, index, value, timeout )
3.Let v be ? ToInt32(value).
...
1.Let number be ? ToNumber(argument).
Symbol --> Throw a TypeError exception.
features: [ Atomics, SharedArrayBuffer, TypedArray, Symbol, Symbol.toPrimitive]
---*/
var sab = new SharedArrayBuffer(1024);
var int32Array = new Int32Array(sab);
var poisoned = {
valueOf: function() {
throw new Test262Error("should not evaluate this code");
}
};
var poisonedWithString = {
get valueOf() { throw "should not evaluate this code"; }
};
var poisonedToPrimitive = {
get [Symbol.ToPrimitive]() {
throw new Test262Error('passing a poisoned object using @@ToPrimitive');
}
};
assert.throws(TypeError, function() {
Atomics.wait(int32Array, Symbol('foo'), poisonedWithString, poisonedWithString)
}, 'Symbol');
assert.throws(Test262Error, function() {
Atomics.wait(int32Array, poisoned, poisonedWithString, poisonedWithString)
}, 'passing a poisoned object using valueOf');
assert.throws(Test262Error, function() {
Atomics.wait(int32Array, poisoned, poisonedToPrimitive, poisonedToPrimitive);
}, 'passing a poisoned object using @@ToPrimitive');

View File

@ -0,0 +1,48 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wait
description:
An undefined index arg should translate to 0
info: |
Atomics.wait( typedArray, index, value, timeout )
2.Let i be ? ValidateAtomicAccess(typedArray, index).
...
2.Let accessIndex be ? ToIndex(requestIndex).
9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception.
...
3.If bufferData is a Data Block, return false
If value is undefined, then
Let index be 0.
features: [ Atomics, SharedArrayBuffer, TypedArray ]
---*/
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report(Atomics.wait(int32Array, undefined, 0, 10)); // undefined index => 0
$262.agent.leaving();
})
`);
var sab = new SharedArrayBuffer(1024);
var int32Array = new Int32Array(sab);
$262.agent.broadcast(int32Array.buffer);
$262.agent.sleep(5);
assert.sameValue(Atomics.wake(int32Array, 0), 1); // wake at index 0
assert.sameValue(Atomics.wake(int32Array, 0), 0); // wake again at index 0, and 0 agents should be woken
assert.sameValue(getReport(), "ok");
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null)
$262.agent.sleep(100);
return r;
}