mirror of
https://github.com/tc39/test262.git
synced 2025-07-29 17:04:31 +02:00
Atomics: add setTimeout, getReportAsync & safeBroadcastAsync to harness/atomicsHelper .js
This commit is contained in:
parent
a46bbfd872
commit
e9ee3dcd62
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user