From 251a69acca0af0f575b7179041797e5fcc5ba2d7 Mon Sep 17 00:00:00 2001
From: Amal Hussein <amal@bocoup.com>
Date: Tue, 20 Mar 2018 10:40:33 -0400
Subject: [PATCH] wip

---
 test/built-ins/Atomics/wait/did-timeout.js    | 10 ++-
 ...ows.js => non-shared-bufferdata-throws.js} | 11 ++-
 .../Atomics/wait/symbol-for-value-throws.js   | 48 ++++++++++
 .../wait/undefined-index-defaults-to-zero.js  |  2 +-
 .../built-ins/Atomics/wait/value-not-equal.js | 49 ++++++++++
 .../waitlist-order-of-operations-is-fifo.js   | 90 +++++++++++++++++++
 test/built-ins/Atomics/wake/missing-count.js  | 83 +++++++++++++++++
 .../{wake-negative.js => negative-count.js}   |  0
 .../Atomics/wake/negative-index-throws.js     | 30 +++++++
 .../wake/non-int32-typedarray-throws.js       | 54 +++++++++++
 .../wake/non-shared-bufferdata-throws.js      | 31 +++++++
 .../Atomics/wake/not-a-typedarray-throws.js   | 29 ++++++
 .../Atomics/wake/not-an-object-throws.js      | 34 +++++++
 .../Atomics/wake/null-bufferdata-throws.js    | 28 ++++++
 .../Atomics/wake/out-of-range-index-throws.js | 28 ++++++
 .../Atomics/wake/symbol-for-index-throws.js   | 47 ++++++++++
 .../Atomics/wake/undefined-for-count.js       | 83 +++++++++++++++++
 .../wake/undefined-index-defaults-to-zero.js  | 63 +++++++++++++
 18 files changed, 712 insertions(+), 8 deletions(-)
 rename test/built-ins/Atomics/wait/{nonshared-bufferdata-throws.js => non-shared-bufferdata-throws.js} (74%)
 create mode 100644 test/built-ins/Atomics/wait/symbol-for-value-throws.js
 create mode 100644 test/built-ins/Atomics/wait/value-not-equal.js
 create mode 100644 test/built-ins/Atomics/wait/waitlist-order-of-operations-is-fifo.js
 create mode 100644 test/built-ins/Atomics/wake/missing-count.js
 rename test/built-ins/Atomics/wake/{wake-negative.js => negative-count.js} (100%)
 create mode 100644 test/built-ins/Atomics/wake/negative-index-throws.js
 create mode 100644 test/built-ins/Atomics/wake/non-int32-typedarray-throws.js
 create mode 100644 test/built-ins/Atomics/wake/non-shared-bufferdata-throws.js
 create mode 100644 test/built-ins/Atomics/wake/not-a-typedarray-throws.js
 create mode 100644 test/built-ins/Atomics/wake/not-an-object-throws.js
 create mode 100644 test/built-ins/Atomics/wake/null-bufferdata-throws.js
 create mode 100644 test/built-ins/Atomics/wake/out-of-range-index-throws.js
 create mode 100644 test/built-ins/Atomics/wake/symbol-for-index-throws.js
 create mode 100644 test/built-ins/Atomics/wake/undefined-for-count.js
 create mode 100644 test/built-ins/Atomics/wake/undefined-index-defaults-to-zero.js

diff --git a/test/built-ins/Atomics/wait/did-timeout.js b/test/built-ins/Atomics/wait/did-timeout.js
index 1083d4c4c7..70e644507e 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 640550c0b2..a3bcfceb79 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 0000000000..ae63cceef6
--- /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 11604f758a..48d6689a66 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 0000000000..6ed56aef0a
--- /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 0000000000..3cb3627264
--- /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 0000000000..85b0877990
--- /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 0000000000..abb5f54624
--- /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 0000000000..df3a1a5892
--- /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 0000000000..82a38f9cc5
--- /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 0000000000..965b2c48fc
--- /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 0000000000..0d1c42ba0f
--- /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 0000000000..0c232d94e8
--- /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 0000000000..a7893f1571
--- /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 0000000000..92899d54c0
--- /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 0000000000..8b6c618684
--- /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 0000000000..d5cf16730c
--- /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;
+}
-- 
GitLab