Skip to content

Commit 5435efb

Browse files
authored
Fixed method signature of Atomics.waitAsync (#51602)
* Added method overloading for Atomics.waitAsync(Int32Array, number, number, number) * fixed types * fixed types * fixed line ending * CR fix * Forgot the baseline
1 parent 1b75edc commit 5435efb

File tree

4 files changed

+104
-20
lines changed

4 files changed

+104
-20
lines changed

src/lib/es2022.sharedmemory.d.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ interface Atomics {
22
/**
33
* A non-blocking, asynchronous version of wait which is usable on the main thread.
44
* Waits asynchronously on a shared memory location and returns a Promise
5+
* @param typedArray A shared Int32Array or BigInt64Array.
6+
* @param index The position in the typedArray to wait on.
7+
* @param value The expected value to test.
8+
* @param [timeout] The expected value to test.
59
*/
6-
waitAsync(typedArray: BigInt64Array | Int32Array, index: number, value: bigint, timeout?: number): { async: false, value: "ok" | "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "not-equal" | "timed-out"> };
10+
waitAsync(typedArray: Int32Array, index: number, value: number, timeout?: number): { async: false, value: "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "timed-out"> };
11+
12+
/**
13+
* A non-blocking, asynchronous version of wait which is usable on the main thread.
14+
* Waits asynchronously on a shared memory location and returns a Promise
15+
* @param typedArray A shared Int32Array or BigInt64Array.
16+
* @param index The position in the typedArray to wait on.
17+
* @param value The expected value to test.
18+
* @param [timeout] The expected value to test.
19+
*/
20+
waitAsync(typedArray: BigInt64Array, index: number, value: bigint, timeout?: number): { async: false, value: "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "timed-out"> };
721
}

tests/baselines/reference/es2022SharedMemory.symbols

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,60 @@ const int32 = new Int32Array(sab);
1111
>Int32Array : Symbol(Int32Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --) ... and 1 more)
1212
>sab : Symbol(sab, Decl(es2022SharedMemory.ts, 0, 5))
1313

14+
const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024);
15+
>sab64 : Symbol(sab64, Decl(es2022SharedMemory.ts, 2, 5))
16+
>SharedArrayBuffer : Symbol(SharedArrayBuffer, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --))
17+
>BigInt64Array.BYTES_PER_ELEMENT : Symbol(BigInt64ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es2020.bigint.d.ts, --, --))
18+
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2022.array.d.ts, --, --))
19+
>BYTES_PER_ELEMENT : Symbol(BigInt64ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es2020.bigint.d.ts, --, --))
20+
21+
const int64 = new BigInt64Array(sab64);
22+
>int64 : Symbol(int64, Decl(es2022SharedMemory.ts, 3, 5))
23+
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2022.array.d.ts, --, --))
24+
>sab64 : Symbol(sab64, Decl(es2022SharedMemory.ts, 2, 5))
25+
1426
const waitValue = Atomics.wait(int32, 0, 0);
15-
>waitValue : Symbol(waitValue, Decl(es2022SharedMemory.ts, 2, 5))
27+
>waitValue : Symbol(waitValue, Decl(es2022SharedMemory.ts, 4, 5))
1628
>Atomics.wait : Symbol(Atomics.wait, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --))
1729
>Atomics : Symbol(Atomics, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
1830
>wait : Symbol(Atomics.wait, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --))
1931
>int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 1, 5))
2032

21-
const { async, value } = Atomics.waitAsync(int32, 0, BigInt(0));
22-
>async : Symbol(async, Decl(es2022SharedMemory.ts, 3, 7))
23-
>value : Symbol(value, Decl(es2022SharedMemory.ts, 3, 14))
24-
>Atomics.waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --))
33+
const { async, value } = Atomics.waitAsync(int32, 0, 0);
34+
>async : Symbol(async, Decl(es2022SharedMemory.ts, 5, 7))
35+
>value : Symbol(value, Decl(es2022SharedMemory.ts, 5, 14))
36+
>Atomics.waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
2537
>Atomics : Symbol(Atomics, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
26-
>waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --))
38+
>waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
2739
>int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 1, 5))
40+
41+
const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0));
42+
>async : Symbol(async, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
43+
>async64 : Symbol(async64, Decl(es2022SharedMemory.ts, 6, 7))
44+
>value : Symbol(value, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
45+
>value64 : Symbol(value64, Decl(es2022SharedMemory.ts, 6, 23))
46+
>Atomics.waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
47+
>Atomics : Symbol(Atomics, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
48+
>waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
49+
>int64 : Symbol(int64, Decl(es2022SharedMemory.ts, 3, 5))
2850
>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
2951

3052
const main = async () => {
31-
>main : Symbol(main, Decl(es2022SharedMemory.ts, 5, 5))
53+
>main : Symbol(main, Decl(es2022SharedMemory.ts, 8, 5))
3254

3355
if (async) {
34-
>async : Symbol(async, Decl(es2022SharedMemory.ts, 3, 7))
56+
>async : Symbol(async, Decl(es2022SharedMemory.ts, 5, 7))
3557

3658
await value;
37-
>value : Symbol(value, Decl(es2022SharedMemory.ts, 3, 14))
59+
>value : Symbol(value, Decl(es2022SharedMemory.ts, 5, 14))
60+
}
61+
if (async64) {
62+
>async64 : Symbol(async64, Decl(es2022SharedMemory.ts, 6, 7))
63+
64+
await value64;
65+
>value64 : Symbol(value64, Decl(es2022SharedMemory.ts, 6, 23))
3866
}
3967
}
4068
main();
41-
>main : Symbol(main, Decl(es2022SharedMemory.ts, 5, 5))
69+
>main : Symbol(main, Decl(es2022SharedMemory.ts, 8, 5))
4270

tests/baselines/reference/es2022SharedMemory.types

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ const int32 = new Int32Array(sab);
1515
>Int32Array : Int32ArrayConstructor
1616
>sab : SharedArrayBuffer
1717

18+
const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024);
19+
>sab64 : SharedArrayBuffer
20+
>new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024) : SharedArrayBuffer
21+
>SharedArrayBuffer : SharedArrayBufferConstructor
22+
>BigInt64Array.BYTES_PER_ELEMENT * 1024 : number
23+
>BigInt64Array.BYTES_PER_ELEMENT : number
24+
>BigInt64Array : BigInt64ArrayConstructor
25+
>BYTES_PER_ELEMENT : number
26+
>1024 : 1024
27+
28+
const int64 = new BigInt64Array(sab64);
29+
>int64 : BigInt64Array
30+
>new BigInt64Array(sab64) : BigInt64Array
31+
>BigInt64Array : BigInt64ArrayConstructor
32+
>sab64 : SharedArrayBuffer
33+
1834
const waitValue = Atomics.wait(int32, 0, 0);
1935
>waitValue : "ok" | "not-equal" | "timed-out"
2036
>Atomics.wait(int32, 0, 0) : "ok" | "not-equal" | "timed-out"
@@ -25,29 +41,49 @@ const waitValue = Atomics.wait(int32, 0, 0);
2541
>0 : 0
2642
>0 : 0
2743

28-
const { async, value } = Atomics.waitAsync(int32, 0, BigInt(0));
44+
const { async, value } = Atomics.waitAsync(int32, 0, 0);
2945
>async : boolean
30-
>value : "ok" | "not-equal" | "timed-out" | Promise<"ok" | "not-equal" | "timed-out">
31-
>Atomics.waitAsync(int32, 0, BigInt(0)) : { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }
32-
>Atomics.waitAsync : (typedArray: Int32Array | BigInt64Array, index: number, value: bigint, timeout?: number | undefined) => { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }
46+
>value : "not-equal" | "timed-out" | Promise<"ok" | "timed-out">
47+
>Atomics.waitAsync(int32, 0, 0) : { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }
48+
>Atomics.waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; }
3349
>Atomics : Atomics
34-
>waitAsync : (typedArray: Int32Array | BigInt64Array, index: number, value: bigint, timeout?: number | undefined) => { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }
50+
>waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; }
3551
>int32 : Int32Array
3652
>0 : 0
53+
>0 : 0
54+
55+
const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0));
56+
>async : any
57+
>async64 : boolean
58+
>value : any
59+
>value64 : "not-equal" | "timed-out" | Promise<"ok" | "timed-out">
60+
>Atomics.waitAsync(int64, 0, BigInt(0)) : { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }
61+
>Atomics.waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; }
62+
>Atomics : Atomics
63+
>waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; }
64+
>int64 : BigInt64Array
65+
>0 : 0
3766
>BigInt(0) : bigint
3867
>BigInt : BigIntConstructor
3968
>0 : 0
4069

4170
const main = async () => {
4271
>main : () => Promise<void>
43-
>async () => { if (async) { await value; }} : () => Promise<void>
72+
>async () => { if (async) { await value; } if (async64) { await value64; }} : () => Promise<void>
4473

4574
if (async) {
4675
>async : boolean
4776

4877
await value;
49-
>await value : "ok" | "not-equal" | "timed-out"
50-
>value : Promise<"ok" | "not-equal" | "timed-out">
78+
>await value : "ok" | "timed-out"
79+
>value : Promise<"ok" | "timed-out">
80+
}
81+
if (async64) {
82+
>async64 : boolean
83+
84+
await value64;
85+
>await value64 : "ok" | "timed-out"
86+
>value64 : Promise<"ok" | "timed-out">
5187
}
5288
}
5389
main();

tests/cases/conformance/es2022/es2022SharedMemory.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55

66
const sab = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024);
77
const int32 = new Int32Array(sab);
8+
const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024);
9+
const int64 = new BigInt64Array(sab64);
810
const waitValue = Atomics.wait(int32, 0, 0);
9-
const { async, value } = Atomics.waitAsync(int32, 0, BigInt(0));
11+
const { async, value } = Atomics.waitAsync(int32, 0, 0);
12+
const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0));
1013

1114
const main = async () => {
1215
if (async) {
1316
await value;
1417
}
18+
if (async64) {
19+
await value64;
20+
}
1521
}
1622
main();

0 commit comments

Comments
 (0)