diff --git a/test/built-ins/Atomics/wait/did-timeout.js b/test/built-ins/Atomics/wait/did-timeout.js index 1083d4c4c7e30860967d68bac069c82d972913b3..70e644507ed65fb1b2abd8472284c9186e294ac1 100644 --- a/test/built-ins/Atomics/wait/did-timeout.js +++ b/test/built-ins/Atomics/wait/did-timeout.js @@ -6,6 +6,12 @@ esid: sec-atomics.wait description: > Test that Atomics.wait returns the right result when it timed out and that 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] features: [Atomics] ---*/ @@ -27,10 +33,6 @@ $262.agent.broadcast(ia.buffer); assert.sameValue(getReport(), "timed-out"); assert.sameValue((getReport() | 0) >= 500 - $ATOMICS_MAX_TIME_EPSILON, true); -<<<<<<< HEAD -======= - ->>>>>>> fixup from pr feedback function getReport() { var r; while ((r = $262.agent.getReport()) == null) diff --git a/test/built-ins/Atomics/wait/nonshared-bufferdata-throws.js b/test/built-ins/Atomics/wait/non-shared-bufferdata-throws.js similarity index 74% rename from test/built-ins/Atomics/wait/nonshared-bufferdata-throws.js rename to test/built-ins/Atomics/wait/non-shared-bufferdata-throws.js index 640550c0b20827951daf9370cd24a196684d8987..a3bcfceb7943dedd812ae099cc17a62223d2fcc4 100644 --- a/test/built-ins/Atomics/wait/nonshared-bufferdata-throws.js +++ b/test/built-ins/Atomics/wait/non-shared-bufferdata-throws.js @@ -15,12 +15,17 @@ info: | features: [ Atomics, ArrayBuffer, TypedArray ] ---*/ -var int32Array = new Int32Array(new ArrayBuffer(1024)); +var int32Array = new Int32Array(new ArrayBuffer(4)); 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)); +assert.throws(TypeError, function() { + Atomics.wait(int32Array, 0, 0, 0) +}); + +assert.throws(TypeError, function() { + Atomics.wait(int32Array, poisoned, poisoned, poisoned) +}); diff --git a/test/built-ins/Atomics/wait/symbol-for-value-throws.js b/test/built-ins/Atomics/wait/symbol-for-value-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..ae63cceef6747eca54c3f7151302526f45f0fec4 --- /dev/null +++ b/test/built-ins/Atomics/wait/symbol-for-value-throws.js @@ -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'); diff --git a/test/built-ins/Atomics/wait/undefined-index-defaults-to-zero.js b/test/built-ins/Atomics/wait/undefined-index-defaults-to-zero.js index 11604f758ae2120f7b51ed5b04cbe9b818819c98..48d6689a667fb6e161990b5777e6c825fe928c7d 100644 --- a/test/built-ins/Atomics/wait/undefined-index-defaults-to-zero.js +++ b/test/built-ins/Atomics/wait/undefined-index-defaults-to-zero.js @@ -29,7 +29,7 @@ $262.agent.receiveBroadcast(function (sab) { }) `); -var sab = new SharedArrayBuffer(1024); +var sab = new SharedArrayBuffer(4); var int32Array = new Int32Array(sab); $262.agent.broadcast(int32Array.buffer); diff --git a/test/built-ins/Atomics/wait/value-not-equal.js b/test/built-ins/Atomics/wait/value-not-equal.js new file mode 100644 index 0000000000000000000000000000000000000000..6ed56aef0a76cb71a8f1a8b3e5064e251a06cab7 --- /dev/null +++ b/test/built-ins/Atomics/wait/value-not-equal.js @@ -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"); + diff --git a/test/built-ins/Atomics/wait/waitlist-order-of-operations-is-fifo.js b/test/built-ins/Atomics/wait/waitlist-order-of-operations-is-fifo.js new file mode 100644 index 0000000000000000000000000000000000000000..3cb36272646db4e673c3e4325cd682a8ef714cba --- /dev/null +++ b/test/built-ins/Atomics/wait/waitlist-order-of-operations-is-fifo.js @@ -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 diff --git a/test/built-ins/Atomics/wake/missing-count.js b/test/built-ins/Atomics/wake/missing-count.js new file mode 100644 index 0000000000000000000000000000000000000000..85b0877990b887a896b187e29d87754afbf01fc6 --- /dev/null +++ b/test/built-ins/Atomics/wake/missing-count.js @@ -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"); diff --git a/test/built-ins/Atomics/wake/wake-negative.js b/test/built-ins/Atomics/wake/negative-count.js similarity index 100% rename from test/built-ins/Atomics/wake/wake-negative.js rename to test/built-ins/Atomics/wake/negative-count.js diff --git a/test/built-ins/Atomics/wake/negative-index-throws.js b/test/built-ins/Atomics/wake/negative-index-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..abb5f5462402495771a4cbbf3f9a06f8cbc6fa3a --- /dev/null +++ b/test/built-ins/Atomics/wake/negative-index-throws.js @@ -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)); diff --git a/test/built-ins/Atomics/wake/non-int32-typedarray-throws.js b/test/built-ins/Atomics/wake/non-int32-typedarray-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..df3a1a589283c5283412fbdad33a7b627c70347e --- /dev/null +++ b/test/built-ins/Atomics/wake/non-int32-typedarray-throws.js @@ -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'); diff --git a/test/built-ins/Atomics/wake/non-shared-bufferdata-throws.js b/test/built-ins/Atomics/wake/non-shared-bufferdata-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..82a38f9cc549198bbf19469a54a5e87215dccc0c --- /dev/null +++ b/test/built-ins/Atomics/wake/non-shared-bufferdata-throws.js @@ -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) +}); diff --git a/test/built-ins/Atomics/wake/not-a-typedarray-throws.js b/test/built-ins/Atomics/wake/not-a-typedarray-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..965b2c48fcdc0bcf0983f5bf297ded699649bcf0 --- /dev/null +++ b/test/built-ins/Atomics/wake/not-a-typedarray-throws.js @@ -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) +}); diff --git a/test/built-ins/Atomics/wake/not-an-object-throws.js b/test/built-ins/Atomics/wake/not-an-object-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..0d1c42ba0f1daa64651d60ecfe202f3909c82ac4 --- /dev/null +++ b/test/built-ins/Atomics/wake/not-an-object-throws.js @@ -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'); diff --git a/test/built-ins/Atomics/wake/null-bufferdata-throws.js b/test/built-ins/Atomics/wake/null-bufferdata-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..0c232d94e8c6fa05e958b22c40fedcded342d7fd --- /dev/null +++ b/test/built-ins/Atomics/wake/null-bufferdata-throws.js @@ -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)); diff --git a/test/built-ins/Atomics/wake/out-of-range-index-throws.js b/test/built-ins/Atomics/wake/out-of-range-index-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..a7893f15718a4a97015d14b999c6e68b417c6671 --- /dev/null +++ b/test/built-ins/Atomics/wake/out-of-range-index-throws.js @@ -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)); diff --git a/test/built-ins/Atomics/wake/symbol-for-index-throws.js b/test/built-ins/Atomics/wake/symbol-for-index-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..92899d54c079f3a76d1733425c776cddb6888bed --- /dev/null +++ b/test/built-ins/Atomics/wake/symbol-for-index-throws.js @@ -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'); diff --git a/test/built-ins/Atomics/wake/undefined-for-count.js b/test/built-ins/Atomics/wake/undefined-for-count.js new file mode 100644 index 0000000000000000000000000000000000000000..8b6c618684744fa285a0d0fa3df08a0fdbd0f6c3 --- /dev/null +++ b/test/built-ins/Atomics/wake/undefined-for-count.js @@ -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"); diff --git a/test/built-ins/Atomics/wake/undefined-index-defaults-to-zero.js b/test/built-ins/Atomics/wake/undefined-index-defaults-to-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..d5cf16730cb402c5c2cd90c27aedd04f983a4056 --- /dev/null +++ b/test/built-ins/Atomics/wake/undefined-index-defaults-to-zero.js @@ -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; +}