From daa9af846df55de9350d471d7d005d1850eaeec6 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Fri, 18 May 2018 20:52:31 -0400 Subject: [PATCH] Atomics: wait/bigint cleanup --- .../wait/bigint/cannot-suspend-throws.js | 2 +- .../Atomics/wait/bigint/did-timeout.js | 21 ++++---- .../wait/bigint/false-for-timeout-agent.js | 50 ++++++++--------- .../Atomics/wait/bigint/good-views.js | 46 ++++++++-------- .../Atomics/wait/bigint/nan-for-timeout.js | 20 +++---- .../wait/bigint/negative-index-throws.js | 7 +-- .../wait/bigint/negative-timeout-agent.js | 15 +++--- .../Atomics/wait/bigint/negative-timeout.js | 5 +- .../wait/bigint/out-of-range-index-throws.js | 6 ++- .../Atomics/wait/bigint/value-not-equal.js | 19 ++++--- .../waiterlist-block-indexedposition-wake.js | 39 ++++++++------ .../Atomics/wait/false-for-timeout-agent.js | 15 +++--- .../Atomics/wait/false-for-timeout.js | 9 ++-- .../waiterlist-block-indexedposition-wake.js | 33 ++++++------ .../waiterlist-order-of-operations-is-fifo.js | 53 +++++++++---------- 15 files changed, 179 insertions(+), 161 deletions(-) diff --git a/test/built-ins/Atomics/wait/bigint/cannot-suspend-throws.js b/test/built-ins/Atomics/wait/bigint/cannot-suspend-throws.js index a78000ac82..f982fd14e7 100644 --- a/test/built-ins/Atomics/wait/bigint/cannot-suspend-throws.js +++ b/test/built-ins/Atomics/wait/bigint/cannot-suspend-throws.js @@ -18,7 +18,7 @@ features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] flags: [CanBlockIsFalse] ---*/ -var buffer = new SharedArrayBuffer(4); +var buffer = new SharedArrayBuffer(8); var i64a = new BigInt64Array(buffer); assert.throws(TypeError, function() { diff --git a/test/built-ins/Atomics/wait/bigint/did-timeout.js b/test/built-ins/Atomics/wait/bigint/did-timeout.js index 47d99e1b68..e98c78ef51 100644 --- a/test/built-ins/Atomics/wait/bigint/did-timeout.js +++ b/test/built-ins/Atomics/wait/bigint/did-timeout.js @@ -24,18 +24,21 @@ function getReport() { } $262.agent.start(` -$262.agent.receiveBroadcast(function(sab, id) { - var ia = new BigInt64Array(sab); - var then = $262.agent.monotonicNow(); - $262.agent.report(Atomics.wait(ia, 0, 0, 500)); // Timeout 500ms - $262.agent.report($262.agent.monotonicNow() - then); // Actual time can be more than 500ms - $262.agent.leaving(); -}); + $262.agent.receiveBroadcast(function(sab, id) { + const i64a = new BigInt64Array(sab); + const then = $262.agent.monotonicNow(); + $262.agent.report(Atomics.wait(i64a, 0, 0, 500)); // Timeout 500ms + $262.agent.report($262.agent.monotonicNow() - then); // Actual time can be more than 500ms + $262.agent.leaving(); + }); `); -var ia = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)); +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); -$262.agent.broadcast(ia.buffer); +$262.agent.broadcast(i64a.buffer); +$262.agent.sleep(100); assert.sameValue(getReport(), "timed-out"); assert.sameValue((getReport() | 0) >= 500 - $ATOMICS_MAX_TIME_EPSILON, true); diff --git a/test/built-ins/Atomics/wait/bigint/false-for-timeout-agent.js b/test/built-ins/Atomics/wait/bigint/false-for-timeout-agent.js index 93f3bc8c33..8adec5ce05 100644 --- a/test/built-ins/Atomics/wait/bigint/false-for-timeout-agent.js +++ b/test/built-ins/Atomics/wait/bigint/false-for-timeout-agent.js @@ -24,43 +24,45 @@ function getReport() { } $262.agent.start(` -var valueOf = { - valueOf: function() { - return false; - } -}; + var valueOf = { + valueOf: function() { + return false; + } + }; -var toPrimitive = { - [Symbol.toPrimitive]: function() { - return false; - } -}; + var toPrimitive = { + [Symbol.toPrimitive]: function() { + return false; + } + }; -$262.agent.receiveBroadcast(function(sab) { - var i64a = new BigInt64Array(sab); - var start = $262.agent.monotonicNow(); - $262.agent.report(Atomics.wait(i64a, 0, 0, false)); - $262.agent.report(Atomics.wait(i64a, 0, 0, valueOf)); - $262.agent.report(Atomics.wait(i64a, 0, 0, toPrimitive)); - $262.agent.report($262.agent.monotonicNow() - start); - $262.agent.leaving(); -}); + $262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + var start = $262.agent.monotonicNow(); + $262.agent.report(Atomics.wait(i64a, 0, 0, false)); + $262.agent.report(Atomics.wait(i64a, 0, 0, valueOf)); + $262.agent.report(Atomics.wait(i64a, 0, 0, toPrimitive)); + $262.agent.report($262.agent.monotonicNow() - start); + $262.agent.leaving(); + }); `); -var i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)); +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); $262.agent.broadcast(i64a.buffer); -$262.agent.sleep(150); +$262.agent.sleep(100); assert.sameValue(getReport(), 'timed-out'); assert.sameValue(getReport(), 'timed-out'); assert.sameValue(getReport(), 'timed-out'); -var timeDiffReport = getReport(); +var lapse = getReport(); -assert(timeDiffReport >= 0, 'timeout should be a min of 0ms'); +assert(lapse >= 0, 'timeout should be a min of 0ms'); -assert(timeDiffReport <= $ATOMICS_MAX_TIME_EPSILON, 'timeout should be a max of $$ATOMICS_MAX_TIME_EPSILON'); +assert(lapse <= $ATOMICS_MAX_TIME_EPSILON, 'timeout should be a max of $$ATOMICS_MAX_TIME_EPSILON'); assert.sameValue(Atomics.wake(i64a, 0), 0); diff --git a/test/built-ins/Atomics/wait/bigint/good-views.js b/test/built-ins/Atomics/wait/bigint/good-views.js index 063d52ea82..eee639f78c 100644 --- a/test/built-ins/Atomics/wait/bigint/good-views.js +++ b/test/built-ins/Atomics/wait/bigint/good-views.js @@ -13,34 +13,34 @@ features: [Atomics, BigInt] // even in the shell. $262.agent.start(` -var sab = new SharedArrayBuffer(1024); -var ab = new ArrayBuffer(16); + var sab = new SharedArrayBuffer(1024); + var ab = new ArrayBuffer(16); -var good_indices = [ (view) => 0/-1, // -0 - (view) => '-0', - (view) => view.length - 1, - (view) => ({ valueOf: () => 0 }), - (view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString - ]; + var good_indices = [ (view) => 0/-1, // -0 + (view) => '-0', + (view) => view.length - 1, + (view) => ({ valueOf: () => 0 }), + (view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString + ]; -var view = new BigInt64Array(sab, 32, 20); + var view = new BigInt64Array(sab, 32, 20); -view[0] = 0; -$262.agent.report("A " + Atomics.wait(view, 0, 0, 0)) -$262.agent.report("B " + Atomics.wait(view, 0, 37, 0)); + view[0] = 0; + $262.agent.report("A " + Atomics.wait(view, 0, 0, 0)) + $262.agent.report("B " + Atomics.wait(view, 0, 37, 0)); -// In-bounds boundary cases for indexing -for ( let IdxGen of good_indices ) { - let Idx = IdxGen(view); - view.fill(0); - // Atomics.store() computes an index from Idx in the same way as other - // Atomics operations, not quite like view[Idx]. - Atomics.store(view, Idx, 37); - $262.agent.report("C " + Atomics.wait(view, Idx, 0)); -} + // In-bounds boundary cases for indexing + for ( let IdxGen of good_indices ) { + let Idx = IdxGen(view); + view.fill(0); + // Atomics.store() computes an index from Idx in the same way as other + // Atomics operations, not quite like view[Idx]. + Atomics.store(view, Idx, 37); + $262.agent.report("C " + Atomics.wait(view, Idx, 0)); + } -$262.agent.report("done"); -$262.agent.leaving(); + $262.agent.report("done"); + $262.agent.leaving(); `); assert.sameValue(getReport(), "A timed-out"); diff --git a/test/built-ins/Atomics/wait/bigint/nan-for-timeout.js b/test/built-ins/Atomics/wait/bigint/nan-for-timeout.js index 2ff89fe540..9543c6118e 100644 --- a/test/built-ins/Atomics/wait/bigint/nan-for-timeout.js +++ b/test/built-ins/Atomics/wait/bigint/nan-for-timeout.js @@ -24,19 +24,19 @@ function getReport() { return r; } -$262.agent.start( - ` -$262.agent.receiveBroadcast(function(sab) { - var i64a = new BigInt64Array(sab); - $262.agent.report(Atomics.wait(i64a, 0, 0, NaN)); // NaN => +Infinity - $262.agent.leaving(); -}); +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); + $262.agent.report(Atomics.wait(i64a, 0, 0, NaN)); // NaN => +Infinity + $262.agent.leaving(); + }); `); -var i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)); +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); $262.agent.broadcast(i64a.buffer); -$262.agent.sleep(500); // Ample time - +$262.agent.sleep(100); assert.sameValue(Atomics.wake(i64a, 0), 1); assert.sameValue(getReport(), "ok"); diff --git a/test/built-ins/Atomics/wait/bigint/negative-index-throws.js b/test/built-ins/Atomics/wait/bigint/negative-index-throws.js index d3871ce5de..8037e55295 100644 --- a/test/built-ins/Atomics/wait/bigint/negative-index-throws.js +++ b/test/built-ins/Atomics/wait/bigint/negative-index-throws.js @@ -16,9 +16,10 @@ info: | features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] ---*/ -var sab = new SharedArrayBuffer(1024); -var i64a = new BigInt64Array(sab); -var poisoned = { +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); +const poisoned = { valueOf: function() { throw new Test262Error("should not evaluate this code"); } diff --git a/test/built-ins/Atomics/wait/bigint/negative-timeout-agent.js b/test/built-ins/Atomics/wait/bigint/negative-timeout-agent.js index ed8d10f020..a3de63681a 100644 --- a/test/built-ins/Atomics/wait/bigint/negative-timeout-agent.js +++ b/test/built-ins/Atomics/wait/bigint/negative-timeout-agent.js @@ -17,15 +17,16 @@ function getReport() { } $262.agent.start(` -$262.agent.receiveBroadcast(function(sab, id) { - var ia = new BigInt64Array(sab); - $262.agent.report(Atomics.wait(ia, 0, 0, -5)); // -5 => 0 - $262.agent.leaving(); -}); + $262.agent.receiveBroadcast(function(sab, id) { + var ia = new BigInt64Array(sab); + $262.agent.report(Atomics.wait(ia, 0, 0, -5)); // -5 => 0 + $262.agent.leaving(); + }); `); -var buffer = new SharedArrayBuffer(1024); -var i64a = new BigInt64Array(buffer); +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); $262.agent.broadcast(i64a.buffer); assert.sameValue(getReport(), "timed-out"); diff --git a/test/built-ins/Atomics/wait/bigint/negative-timeout.js b/test/built-ins/Atomics/wait/bigint/negative-timeout.js index f0838f673e..f37745cc9a 100644 --- a/test/built-ins/Atomics/wait/bigint/negative-timeout.js +++ b/test/built-ins/Atomics/wait/bigint/negative-timeout.js @@ -9,7 +9,8 @@ features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] flags: [CanBlockIsFalse] ---*/ -var buffer = new SharedArrayBuffer(1024); -var i64a = new BigInt64Array(buffer); +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); assert.sameValue(Atomics.wait(i64a, 0, 0, -1), "timed-out"); diff --git a/test/built-ins/Atomics/wait/bigint/out-of-range-index-throws.js b/test/built-ins/Atomics/wait/bigint/out-of-range-index-throws.js index e325592fa1..d192847026 100644 --- a/test/built-ins/Atomics/wait/bigint/out-of-range-index-throws.js +++ b/test/built-ins/Atomics/wait/bigint/out-of-range-index-throws.js @@ -16,9 +16,11 @@ info: | features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] ---*/ -var i64a = new BigInt64Array(new SharedArrayBuffer(4)); +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); -var poisoned = { +const poisoned = { valueOf: function() { throw new Test262Error("should not evaluate this code"); } diff --git a/test/built-ins/Atomics/wait/bigint/value-not-equal.js b/test/built-ins/Atomics/wait/bigint/value-not-equal.js index df97451291..b6e07e27e2 100644 --- a/test/built-ins/Atomics/wait/bigint/value-not-equal.js +++ b/test/built-ins/Atomics/wait/bigint/value-not-equal.js @@ -28,19 +28,22 @@ function getReport() { var value = 42; $262.agent.start(` -$262.agent.receiveBroadcast(function(sab) { - var i64a = new BigInt64Array(sab); + $262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); - $262.agent.report(Atomics.store(i64a, 0, ${value})); - $262.agent.report(Atomics.wait(i64a, 0, 0)); - $262.agent.leaving(); -}); + $262.agent.report(Atomics.store(i64a, 0, ${value})); + $262.agent.report(Atomics.wait(i64a, 0, 0)); + $262.agent.leaving(); + }); `); -var i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT)); +const i64a = new BigInt64Array( + new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) +); $262.agent.broadcast(i64a.buffer); +$262.agent.sleep(100); assert.sameValue(getReport(), value.toString()); -assert.sameValue(getReport(), "not-equal"); +assert.sameValue(getReport(), 'not-equal'); diff --git a/test/built-ins/Atomics/wait/bigint/waiterlist-block-indexedposition-wake.js b/test/built-ins/Atomics/wait/bigint/waiterlist-block-indexedposition-wake.js index 8f8c396e9b..8d4e994d78 100644 --- a/test/built-ins/Atomics/wait/bigint/waiterlist-block-indexedposition-wake.js +++ b/test/built-ins/Atomics/wait/bigint/waiterlist-block-indexedposition-wake.js @@ -29,34 +29,39 @@ function getReport() { } $262.agent.start(` -$262.agent.receiveBroadcast(function(sab) { - var i64a = new BigInt64Array(sab); + $262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); - // Wait on index 0 - Atomics.wait(i64a, 0, 0, 200); - $262.agent.report("fail"); - $262.agent.leaving(); -}); + // Wait on index 0 + Atomics.wait(i64a, 0, 0, 200); + $262.agent.report(0); + $262.agent.leaving(); + }); `); $262.agent.start(` -$262.agent.receiveBroadcast(function(sab) { - var i64a = new BigInt64Array(sab); + $262.agent.receiveBroadcast(function(sab) { + var i64a = new BigInt64Array(sab); - // Wait on index 2 - Atomics.wait(i64a, 2, 0, 200); - $262.agent.report("pass"); - $262.agent.leaving(); -}); + // Wait on index 2 + Atomics.wait(i64a, 2, 0, 200); + $262.agent.report(2); + $262.agent.leaving(); + }); `); -var length = 4 * BigInt64Array.BYTES_PER_ELEMENT; -var i64a = new BigInt64Array(new SharedArrayBuffer(length)); +const i64a = new BigInt64Array( + new SharedArrayBuffer(4 * BigInt64Array.BYTES_PER_ELEMENT) +); $262.agent.broadcast(i64a.buffer); $262.agent.sleep(10); // Wake index 2 Atomics.wake(i64a, 2, 1); +assert.sameValue(getReport(), "2"); + +// Wake index 0 +Atomics.wake(i64a, 2, 1); +assert.sameValue(getReport(), "0"); -assert.sameValue(getReport(), "pass"); diff --git a/test/built-ins/Atomics/wait/false-for-timeout-agent.js b/test/built-ins/Atomics/wait/false-for-timeout-agent.js index 71a396bc10..3322d669b7 100644 --- a/test/built-ins/Atomics/wait/false-for-timeout-agent.js +++ b/test/built-ins/Atomics/wait/false-for-timeout-agent.js @@ -24,8 +24,7 @@ function getReport() { return r; } -$262.agent.start( - ` +$262.agent.start(` var valueOf = { valueOf: function() { return false; @@ -49,20 +48,22 @@ $262.agent.receiveBroadcast(function(sab) { }); `); -var i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); +const i32a = new Int32Array( + new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) +); $262.agent.broadcast(i32a.buffer); -$262.agent.sleep(150); +$262.agent.sleep(100); assert.sameValue(getReport(), 'timed-out'); assert.sameValue(getReport(), 'timed-out'); assert.sameValue(getReport(), 'timed-out'); -var timeDiffReport = getReport(); +var lapse = getReport(); -assert(timeDiffReport >= 0, 'timeout should be a min of 0ms'); +assert(lapse >= 0, 'timeout should be a min of 0ms'); -assert(timeDiffReport <= $ATOMICS_MAX_TIME_EPSILON, 'timeout should be a max of $$ATOMICS_MAX_TIME_EPSILON'); +assert(lapse <= $ATOMICS_MAX_TIME_EPSILON, `timeout should be a max of ${$ATOMICS_MAX_TIME_EPSILON}`); assert.sameValue(Atomics.wake(i32a, 0), 0); diff --git a/test/built-ins/Atomics/wait/false-for-timeout.js b/test/built-ins/Atomics/wait/false-for-timeout.js index c33ac86270..86463f3d61 100644 --- a/test/built-ins/Atomics/wait/false-for-timeout.js +++ b/test/built-ins/Atomics/wait/false-for-timeout.js @@ -16,16 +16,17 @@ features: [Atomics, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray] flags: [CanBlockIsFalse] ---*/ -var buffer = new SharedArrayBuffer(1024); -var i32a = new Int32Array(buffer); +const i32a = new Int32Array( + new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) +); -var valueOf = { +const valueOf = { valueOf: function() { return false; } }; -var toPrimitive = { +const toPrimitive = { [Symbol.toPrimitive]: function() { return false; } diff --git a/test/built-ins/Atomics/wait/waiterlist-block-indexedposition-wake.js b/test/built-ins/Atomics/wait/waiterlist-block-indexedposition-wake.js index 6c59ebabc1..6c800db525 100644 --- a/test/built-ins/Atomics/wait/waiterlist-block-indexedposition-wake.js +++ b/test/built-ins/Atomics/wait/waiterlist-block-indexedposition-wake.js @@ -29,25 +29,25 @@ function getReport() { } $262.agent.start(` -$262.agent.receiveBroadcast(function(sab) { - var i32a = new Int32Array(sab); + $262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); - // Wait on index 0 - Atomics.wait(i32a, 0, 0, 200); - $262.agent.report("fail"); - $262.agent.leaving(); -}); + // Wait on index 0 + Atomics.wait(i32a, 0, 0, 200); + $262.agent.report(0); + $262.agent.leaving(); + }); `); $262.agent.start(` -$262.agent.receiveBroadcast(function(sab) { - var i32a = new Int32Array(sab); + $262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); - // Wait on index 2 - Atomics.wait(i32a, 2, 0, 200); - $262.agent.report("pass"); - $262.agent.leaving(); -}); + // Wait on index 2 + Atomics.wait(i32a, 2, 0, 200); + $262.agent.report(0); + $262.agent.leaving(); + }); `); var length = 4 * Int32Array.BYTES_PER_ELEMENT; @@ -58,5 +58,8 @@ $262.agent.sleep(10); // Wake index 2 Atomics.wake(i32a, 2, 1); +assert.sameValue(getReport(), '2'); -assert.sameValue(getReport(), "pass"); +// Wake index 0 +Atomics.wake(i32a, 2, 1); +assert.sameValue(getReport(), '0'); diff --git a/test/built-ins/Atomics/wait/waiterlist-order-of-operations-is-fifo.js b/test/built-ins/Atomics/wait/waiterlist-order-of-operations-is-fifo.js index 20bfe22a5c..d049f9676b 100644 --- a/test/built-ins/Atomics/wait/waiterlist-order-of-operations-is-fifo.js +++ b/test/built-ins/Atomics/wait/waiterlist-order-of-operations-is-fifo.js @@ -23,46 +23,41 @@ function getReport() { return r; } -var agent1 = '1'; -var agent2 = '2'; -var agent3 = '3'; +const agent1 = '1'; +const agent2 = '2'; +const agent3 = '3'; $262.agent.start(` -$262.agent.receiveBroadcast(function(sab) { - var i32a = new Int32Array(sab); + $262.agent.receiveBroadcast(function(sab) { + const i32a = new Int32Array(sab); - $262.agent.report(${agent1}); - Atomics.wait(i32a, 0, 0); - $262.agent.report(${agent1}); - - $262.agent.leaving(); -}); + $262.agent.report(${agent1}); + Atomics.wait(i32a, 0, 0); + $262.agent.report(${agent1}); + $262.agent.leaving(); + }); `); $262.agent.start(` -$262.agent.receiveBroadcast(function(sab) { - var i32a = new Int32Array(sab); + $262.agent.receiveBroadcast(function(sab) { + const i32a = new Int32Array(sab); - $262.agent.report(${agent2}); - - Atomics.wait(i32a, 0, 0); - $262.agent.report(${agent2}); - - $262.agent.leaving(); -}); + $262.agent.report(${agent2}); + Atomics.wait(i32a, 0, 0); + $262.agent.report(${agent2}); + $262.agent.leaving(); + }); `); $262.agent.start(` -$262.agent.receiveBroadcast(function(sab) { - var i32a = new Int32Array(sab); + $262.agent.receiveBroadcast(function(sab) { + const i32a = new Int32Array(sab); - $262.agent.report(${agent3}); - - Atomics.wait(i32a, 0, 0); - $262.agent.report(${agent3}); - - $262.agent.leaving(); -}); + $262.agent.report(${agent3}); + Atomics.wait(i32a, 0, 0); + $262.agent.report(${agent3}); + $262.agent.leaving(); + }); `);