node/deps/v8/test/mjsunit/harmony/atomics-waitasync-1thread-wake-up-all.js
Michaël Zasso 17a74ddd3d
deps: update V8 to 11.8.172.13
PR-URL: https://github.com/nodejs/node/pull/49639
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2023-10-10 08:25:41 +02:00

40 lines
1.1 KiB
JavaScript

// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
(function test() {
const sab = new SharedArrayBuffer(16);
const i32a = new Int32Array(sab);
const N = 10;
let log = [];
// Create N async waiters.
for (let i = 0; i < N; ++i) {
const result = Atomics.waitAsync(i32a, 0, 0);
assertEquals(true, result.async);
result.value.then(
(value) => { assertEquals("ok", value); log.push(i); },
() => { assertUnreachable(); });
}
assertEquals(N, %AtomicsNumWaitersForTesting(i32a, 0));
assertEquals(0, %AtomicsNumUnresolvedAsyncPromisesForTesting(i32a, 0));
// Wake up all waiters.
let notify_return_value = Atomics.notify(i32a, 0);
assertEquals(N, notify_return_value);
assertEquals(0, %AtomicsNumWaitersForTesting(i32a, 0));
assertEquals(N, %AtomicsNumUnresolvedAsyncPromisesForTesting(i32a, 0));
function continuation() {
assertEquals(N, log.length);
for (let i = 0; i < N; ++i) {
assertEquals(i, log[i]);
}
}
setTimeout(continuation, 0);
})();