diff --git a/harness/atomicsHelper.js b/harness/atomicsHelper.js index 9c1217351e..7ffaf9d219 100644 --- a/harness/atomicsHelper.js +++ b/harness/atomicsHelper.js @@ -4,10 +4,12 @@ description: > Collection of functions used to interact with Atomics.* operations across agent boundaries. defines: + - $262.agent.getReportAsync - $262.agent.getReport + - $262.agent.safeBroadcastAsync - $262.agent.safeBroadcast - $262.agent.tryYield - - $262.trySleep + - $262.agent.trySleep ---*/ /** @@ -32,6 +34,38 @@ defines: } return r; }; + + if (this.setTimeout === undefined) { + (function(that) { + that.setTimeout = function(callback, delay) { + let p = Promise.resolve(); + let start = Date.now(); + let end = start + delay; + function check() { + if ((end - Date.now()) > 0) { + p.then(check); + } + else { + callback(); + } + } + p.then(check); + } + })(this); + } + + $262.agent.getReportAsync = function() { + return new Promise(function(resolve) { + (function loop() { + let result = getReport(id); + if (!result) { + setTimeout(loop, 1000); + } else { + resolve(result); + } + })(); + }); + }; } /** @@ -74,6 +108,14 @@ $262.agent.safeBroadcast = function(typedArray) { $262.agent.broadcast(typedArray.buffer); }; +$262.agent.safeBroadcastAsync = async function(ta, index, expected) { + await $262.agent.broadcast(ta.buffer); + await $262.agent.waitUntil(ta, index, expected); + await $262.agent.tryYield(); + return await Atomics.load(ta, index); +}; + + /** * With a given Int32Array or BigInt64Array, wait until the expected number of agents have * reported themselves by calling: