This commit is contained in:
Amal Hussein 2018-03-20 10:40:33 -04:00 committed by Rick Waldron
parent 9d909ed681
commit 251a69acca
18 changed files with 712 additions and 8 deletions

View File

@ -6,6 +6,12 @@ esid: sec-atomics.wait
description: > description: >
Test that Atomics.wait returns the right result when it timed out and that Test that Atomics.wait returns the right result when it timed out and that
the time to time out is reasonable. the time to time out is reasonable.
info: |
17. Let awoken be Suspend(WL, W, t).
18. If awoken is true, then
a. Assert: W is not on the list of waiters in WL.
19. Else,
a.Perform RemoveWaiter(WL, W).
includes: [atomicsHelper.js] includes: [atomicsHelper.js]
features: [Atomics] features: [Atomics]
---*/ ---*/
@ -27,10 +33,6 @@ $262.agent.broadcast(ia.buffer);
assert.sameValue(getReport(), "timed-out"); assert.sameValue(getReport(), "timed-out");
assert.sameValue((getReport() | 0) >= 500 - $ATOMICS_MAX_TIME_EPSILON, true); assert.sameValue((getReport() | 0) >= 500 - $ATOMICS_MAX_TIME_EPSILON, true);
<<<<<<< HEAD
=======
>>>>>>> fixup from pr feedback
function getReport() { function getReport() {
var r; var r;
while ((r = $262.agent.getReport()) == null) while ((r = $262.agent.getReport()) == null)

View File

@ -15,12 +15,17 @@ info: |
features: [ Atomics, ArrayBuffer, TypedArray ] features: [ Atomics, ArrayBuffer, TypedArray ]
---*/ ---*/
var int32Array = new Int32Array(new ArrayBuffer(1024)); var int32Array = new Int32Array(new ArrayBuffer(4));
var poisoned = { var poisoned = {
valueOf: function() { valueOf: function() {
throw new Test262Error("should not evaluate this code"); throw new Test262Error("should not evaluate this code");
} }
}; };
assert.throws(TypeError, () => Atomics.wait(int32Array, 0, 0, 0)); assert.throws(TypeError, function() {
assert.throws(TypeError, () => Atomics.wait(int32Array, poisoned, poisoned, poisoned)); Atomics.wait(int32Array, 0, 0, 0)
});
assert.throws(TypeError, function() {
Atomics.wait(int32Array, poisoned, poisoned, poisoned)
});

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: >
Throws a TypeError if value arg is a Symbol
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]
---*/
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, 0, Symbol('foo'), poisonedWithString)
}, 'Symbol');
assert.throws(Test262Error, function() {
Atomics.wait(int32Array, 0, poisoned, poisonedWithString)
}, 'passing a poisoned object using valueOf');
assert.throws(Test262Error, function() {
Atomics.wait(int32Array, 0, poisoned, poisonedToPrimitive);
}, 'passing a poisoned object using @@ToPrimitive');

View File

@ -29,7 +29,7 @@ $262.agent.receiveBroadcast(function (sab) {
}) })
`); `);
var sab = new SharedArrayBuffer(1024); var sab = new SharedArrayBuffer(4);
var int32Array = new Int32Array(sab); var int32Array = new Int32Array(sab);
$262.agent.broadcast(int32Array.buffer); $262.agent.broadcast(int32Array.buffer);

View File

@ -0,0 +1,49 @@
// 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: >
Returns "not-equal" when value arg does not match an index in the typedArray
info: |
Atomics.wait( typedArray, index, value, timeout )
3.Let v be ? ToInt32(value).
...
14.If v is not equal to w, then
a.Perform LeaveCriticalSection(WL).
b. Return the String "not-equal".
features: [ Atomics, SharedArrayBuffer, TypedArray ]
includes: [atomicsHelper.js]
---*/
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null)
$262.agent.sleep(100);
return r;
}
var value = 42;
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report(Atomics.store(int32Array, 0, ${value}));
$262.agent.report(Atomics.wait(int32Array, 0, 0));
$262.agent.leaving();
})
`);
var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
$262.agent.broadcast(int32Array.buffer);
assert.sameValue(getReport(), value.toString());
assert.sameValue(getReport(), "not-equal");

View File

@ -0,0 +1,90 @@
// 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: >
New waiters should be applied to the end of the list and woken by order they entered the list (FIFO)
info: |
Atomics.wait( typedArray, index, value, timeout )
16.Perform AddWaiter(WL, W).
...
3.Add W to the end of the list of waiters in WL.
features: [ Atomics, SharedArrayBuffer, TypedArray ]
---*/
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null) {
$262.agent.sleep(100);
}
return r;
}
var agent1 = '1';
var agent2 = '2';
var agent3 = '3';
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report(${agent1});
Atomics.wait(int32Array, 0, 0);
$262.agent.report(${agent1});
$262.agent.leaving();
})
`);
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report(${agent2});
Atomics.wait(int32Array, 0, 0);
$262.agent.report(${agent2});
$262.agent.leaving();
})
`);
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report(${agent3});
Atomics.wait(int32Array, 0, 0);
$262.agent.report(${agent3});
$262.agent.leaving();
})
`);
var int32Array = new Int32Array(new SharedArrayBuffer(4));
$262.agent.broadcast(int32Array.buffer);
var orderWhichAgentsWereStarted = getReport() + getReport() + getReport(); // can be started in any order
assert.sameValue(Atomics.wake(int32Array, 0, 1), 1);
var orderAgentsWereWoken = getReport();
assert.sameValue(Atomics.wake(int32Array, 0, 1), 1);
orderAgentsWereWoken += getReport();
assert.sameValue(Atomics.wake(int32Array, 0, 1), 1);
orderAgentsWereWoken += getReport();
assert.sameValue(orderWhichAgentsWereStarted ,orderAgentsWereWoken); // agents should wake in the same order as they were started FIFO

View File

@ -0,0 +1,83 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description: >
Undefined count arg should result in an infinite count
info: |
Atomics.wake( typedArray, index, count )
3.If count is undefined, let c be +.
features: [ Atomics, SharedArrayBuffer, TypedArray ]
---*/
var NUMAGENT = 4; // Total number of agents started
var WAKEUP = 0; // Index all agents are waiting on
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null)
$262.agent.sleep(100);
return r;
}
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("A " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.leaving();
})
`);
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("B " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.leaving();
})
`);
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("C " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.leaving();
})
`);
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("D " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.leaving();
})
`);
var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
$262.agent.broadcast(int32Array.buffer);
$262.agent.sleep(200); // half of timeout
assert.sameValue($262.agent.getReport(), null);
assert.sameValue(Atomics.wake(int32Array, WAKEUP), NUMAGENT);
var sortedReports = [];
for (var i = 0; i < NUMAGENT; i++) {
sortedReports.push(getReport());
}
sortedReports.sort();
assert.sameValue(sortedReports[0], "A ok");
assert.sameValue(sortedReports[1], "B ok");
assert.sameValue(sortedReports[2], "C ok");
assert.sameValue(sortedReports[3], "D ok");

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.wake
description:
Throws a RangeError is index < 0
info: |
Atomics.wake( typedArray, index, count )
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.wake(int32Array, -Infinity, poisoned));
assert.throws(RangeError, () => Atomics.wake(int32Array, -7.999, poisoned));
assert.throws(RangeError, () => Atomics.wake(int32Array, -1, poisoned));
assert.throws(RangeError, () => Atomics.wake(int32Array, -300, poisoned));

View File

@ -0,0 +1,54 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description:
Throws a TypeError if typedArray arg is not an Int32Array
info: |
Atomics.wake( typedArray, index, count )
1.Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true).
...
5.If onlyInt32 is true, then
If typeName is not "Int32Array", throw a TypeError exception.
features: [ Atomics, TypedArray ]
---*/
var poisoned = {
valueOf: function() {
throw new Test262Error("should not evaluate this code");
}
};
assert.throws(TypeError, function() {
Atomics.wake(new Float64Array(), poisoned, poisoned);
}, 'Float64Array');
assert.throws(TypeError, function() {
Atomics.wake(new Float32Array(), poisoned, poisoned);
}, 'Float32Array');
assert.throws(TypeError, function() {
Atomics.wake(new Int16Array(), poisoned, poisoned);
}, 'Int16Array');
assert.throws(TypeError, function() {
Atomics.wake(new Int8Array(), poisoned, poisoned);
}, 'Int8Array');
assert.throws(TypeError, function() {
Atomics.wake(new Uint32Array(), poisoned, poisoned);
}, 'Uint32Array');
assert.throws(TypeError, function() {
Atomics.wake(new Uint16Array(), poisoned, poisoned);
}, 'Uint16Array');
assert.throws(TypeError, function() {
Atomics.wait(new Uint8Array(), poisoned, poisoned);
}, 'Uint8Array');
assert.throws(TypeError, function() {
Atomics.wake(new Uint8ClampedArray(), poisoned, poisoned);
}, 'Uint8ClampedArray');

View File

@ -0,0 +1,31 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description:
Throws a TypeError if typedArray.buffer is not a SharedArrayBuffer
info: |
Atomics.wake( typedArray, index, count )
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(4));
var poisoned = {
valueOf: function() {
throw new Test262Error("should not evaluate this code");
}
};
assert.throws(TypeError, function() {
Atomics.wake(int32Array, 0, 0)
});
assert.throws(TypeError, function() {
Atomics.wake(int32Array, poisoned, poisoned)
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description:
Throws a TypeError if the typedArray arg is not a TypedArray object
info: |
Atomics.wake( typedArray, index, count )
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, function() {
Atomics.wait({}, 0, 0, 0)
});
assert.throws(TypeError, function () {
Atomics.wait({}, poisoned, 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.wake
description:
Throws a TypeError if typedArray arg is not an Object
info: |
Atomics.wake( typedArray, index, count )
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.wake(null,poisoned,poisoned) }, 'null');
assert.throws(TypeError, function() { Atomics.wake(undefined,poisoned,poisoned) }, 'undefined');
assert.throws(TypeError, function() { Atomics.wake(true,poisoned,poisoned) }, 'true');
assert.throws(TypeError, function() { Atomics.wake(false,poisoned,poisoned) }, 'false');
assert.throws(TypeError, function() { Atomics.wake('***string***',poisoned,poisoned) }, 'String');
assert.throws(TypeError, function() { Atomics.wake(Number.NEGATIVE_INFINITY,poisoned,poisoned) }, '-Infinity');
assert.throws(TypeError, function() { Atomics.wake(Symbol('***symbol***'),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.wake
description:
A null value for bufferData throws a TypeError
info: |
Atomics.wake( typedArray, index, count )
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.wake(int32Array, poisoned, poisoned));

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.wake
description: >
Throws a RangeError if value of index arg is out of range
info: |
Atomics.wake( typedArray, index, count )
2.Let i be ? ValidateAtomicAccess(typedArray, index).
...
2.Let accessIndex be ? ToIndex(requestIndex).
...
5. If accessIndex length, throw a RangeError exception.
features: [ Atomics, SharedArrayBuffer, TypedArray ]
---*/
var int32Array = new Int32Array(new SharedArrayBuffer(4));
var poisoned = {
valueOf: function() {
throw new Test262Error("should not evaluate this code");
}
};
assert.throws(RangeError, () => Atomics.wake(int32Array, Infinity, poisoned));
assert.throws(RangeError, () => Atomics.wake(int32Array, 2, poisoned));
assert.throws(RangeError, () => Atomics.wake(int32Array, 200, poisoned));

View File

@ -0,0 +1,47 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description:
Throws a TypeError if index arg can not be converted to an Integer
info: |
Atomics.wake( typedArray, index, count )
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.wake(int32Array, Symbol('foo'), poisonedWithString, poisonedWithString)
}, 'Symbol');
assert.throws(Test262Error, function() {
Atomics.wake(int32Array, poisoned, poisonedWithString, poisonedWithString)
}, 'passing a poisoned object using valueOf');
assert.throws(Test262Error, function() {
Atomics.wake(int32Array, poisoned, poisonedToPrimitive, poisonedToPrimitive);
}, 'passing a poisoned object using @@ToPrimitive');

View File

@ -0,0 +1,83 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description: >
Undefined count arg should result in an infinite count
info: |
Atomics.wake( typedArray, index, count )
3.If count is undefined, let c be +.
features: [ Atomics, SharedArrayBuffer, TypedArray ]
---*/
var NUMAGENT = 4; // Total number of agents started
var WAKEUP = 0; // Index all agents are waiting on
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null)
$262.agent.sleep(100);
return r;
}
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("A " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.leaving();
})
`);
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("B " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.leaving();
})
`);
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("C " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.leaving();
})
`);
$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report("D " + Atomics.wait(int32Array, ${WAKEUP}, 0, 500));
$262.agent.leaving();
})
`);
var int32Array = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
$262.agent.broadcast(int32Array.buffer);
$262.agent.sleep(200); // half of timeout
assert.sameValue($262.agent.getReport(), null);
assert.sameValue(Atomics.wake(int32Array, WAKEUP, undefined), NUMAGENT);
var sortedReports = [];
for (var i = 0; i < NUMAGENT; i++) {
sortedReports.push(getReport());
}
sortedReports.sort();
assert.sameValue(sortedReports[0], "A ok");
assert.sameValue(sortedReports[1], "B ok");
assert.sameValue(sortedReports[2], "C ok");
assert.sameValue(sortedReports[3], "D ok");

View File

@ -0,0 +1,63 @@
// Copyright (C) 2018 Amal Hussein. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-atomics.wake
description:
An undefined index arg should translate to 0
info: |
Atomics.wake( typedArray, index, count )
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, 0, 0, 200));
$262.agent.leaving();
})
`)
;$262.agent.start(
`
$262.agent.receiveBroadcast(function (sab) {
var int32Array = new Int32Array(sab);
$262.agent.report(Atomics.wait(int32Array, 0, 0, 200));
$262.agent.leaving();
})
`);
var sab = new SharedArrayBuffer(4);
var int32Array = new Int32Array(sab);
$262.agent.broadcast(int32Array.buffer);
$262.agent.sleep(100); // halfway through timeout
assert.sameValue(Atomics.wake(int32Array, undefined, 1), 1); // wake at index 0
assert.sameValue(getReport(), "ok");
assert.sameValue(Atomics.wake(int32Array), 1); // wake again at index 0
assert.sameValue(getReport(), "ok");
function getReport() {
var r;
while ((r = $262.agent.getReport()) == null) {
$262.agent.sleep(100);
}
return r;
}