From 71f6c9c7d0e2ac7c949fdbccedd589ae741e3457 Mon Sep 17 00:00:00 2001 From: Eyal Shalev Date: Sun, 20 Nov 2022 21:49:12 +0200 Subject: [PATCH 1/6] Added method overloading for Atomics.waitAsync(Int32Array, number, number, number) --- src/lib/es2022.sharedmemory.d.ts | 20 ++- .../reference/es2022SharedMemory.symbols | 114 ++++++++----- .../reference/es2022SharedMemory.types | 150 +++++++++++------- .../conformance/es2022/es2022SharedMemory.ts | 16 +- 4 files changed, 190 insertions(+), 110 deletions(-) diff --git a/src/lib/es2022.sharedmemory.d.ts b/src/lib/es2022.sharedmemory.d.ts index ea56abe980bfe..571c95a1b7088 100644 --- a/src/lib/es2022.sharedmemory.d.ts +++ b/src/lib/es2022.sharedmemory.d.ts @@ -1,7 +1,13 @@ -interface Atomics { - /** - * A non-blocking, asynchronous version of wait which is usable on the main thread. - * Waits asynchronously on a shared memory location and returns a Promise - */ - 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"> }; -} +interface Atomics { + /** + * A non-blocking, asynchronous version of wait which is usable on the main thread. + * Waits asynchronously on a shared memory location and returns a Promise + */ + waitAsync(typedArray: Int32Array, index: number, value: number, timeout?: number): { async: false, value: "ok" | "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "not-equal" | "timed-out"> }; + + /** + * A non-blocking, asynchronous version of wait which is usable on the main thread. + * Waits asynchronously on a shared memory location and returns a Promise + */ + waitAsync(typedArray: BigInt64Array, index: number, value: bigint, timeout?: number): { async: false, value: "ok" | "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "not-equal" | "timed-out"> }; +} diff --git a/tests/baselines/reference/es2022SharedMemory.symbols b/tests/baselines/reference/es2022SharedMemory.symbols index 8eedea4a5bed0..dea21f40918dd 100644 --- a/tests/baselines/reference/es2022SharedMemory.symbols +++ b/tests/baselines/reference/es2022SharedMemory.symbols @@ -1,42 +1,72 @@ -=== tests/cases/conformance/es2022/es2022SharedMemory.ts === -const sab = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); ->sab : Symbol(sab, Decl(es2022SharedMemory.ts, 0, 5)) ->SharedArrayBuffer : Symbol(SharedArrayBuffer, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --)) ->Int32Array.BYTES_PER_ELEMENT : Symbol(Int32ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es5.d.ts, --, --)) ->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) ->BYTES_PER_ELEMENT : Symbol(Int32ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es5.d.ts, --, --)) - -const int32 = new Int32Array(sab); ->int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 1, 5)) ->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) ->sab : Symbol(sab, Decl(es2022SharedMemory.ts, 0, 5)) - -const waitValue = Atomics.wait(int32, 0, 0); ->waitValue : Symbol(waitValue, Decl(es2022SharedMemory.ts, 2, 5)) ->Atomics.wait : Symbol(Atomics.wait, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --)) ->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, --, --)) ->wait : Symbol(Atomics.wait, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --)) ->int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 1, 5)) - -const { async, value } = Atomics.waitAsync(int32, 0, BigInt(0)); ->async : Symbol(async, Decl(es2022SharedMemory.ts, 3, 7)) ->value : Symbol(value, Decl(es2022SharedMemory.ts, 3, 14)) ->Atomics.waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --)) ->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, --, --)) ->waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --)) ->int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 1, 5)) ->BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) - -const main = async () => { ->main : Symbol(main, Decl(es2022SharedMemory.ts, 5, 5)) - - if (async) { ->async : Symbol(async, Decl(es2022SharedMemory.ts, 3, 7)) - - await value; ->value : Symbol(value, Decl(es2022SharedMemory.ts, 3, 14)) - } -} -main(); ->main : Symbol(main, Decl(es2022SharedMemory.ts, 5, 5)) - +=== tests/cases/conformance/es2022/es2022SharedMemory.ts === +const sab32 = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); +>sab32 : Symbol(sab32, Decl(es2022SharedMemory.ts, 0, 5)) +>SharedArrayBuffer : Symbol(SharedArrayBuffer, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --)) +>Int32Array.BYTES_PER_ELEMENT : Symbol(Int32ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es5.d.ts, --, --)) +>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) +>BYTES_PER_ELEMENT : Symbol(Int32ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es5.d.ts, --, --)) + +const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024); +>sab64 : Symbol(sab64, Decl(es2022SharedMemory.ts, 1, 5)) +>SharedArrayBuffer : Symbol(SharedArrayBuffer, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --)) +>BigInt64Array.BYTES_PER_ELEMENT : Symbol(BigInt64ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es2020.bigint.d.ts, --, --)) +>BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2022.array.d.ts, --, --)) +>BYTES_PER_ELEMENT : Symbol(BigInt64ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es2020.bigint.d.ts, --, --)) + +const int32 = new Int32Array(sab32); +>int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 2, 5)) +>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) +>sab32 : Symbol(sab32, Decl(es2022SharedMemory.ts, 0, 5)) + +const int64 = new BigInt64Array(sab64); +>int64 : Symbol(int64, Decl(es2022SharedMemory.ts, 3, 5)) +>BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2022.array.d.ts, --, --)) +>sab64 : Symbol(sab64, Decl(es2022SharedMemory.ts, 1, 5)) + +const waitValue = Atomics.wait(int32, 0, 0); +>waitValue : Symbol(waitValue, Decl(es2022SharedMemory.ts, 4, 5)) +>Atomics.wait : Symbol(Atomics.wait, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --)) +>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, --, --)) +>wait : Symbol(Atomics.wait, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --)) +>int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 2, 5)) + +const { async: async32, value: value32 } = Atomics.waitAsync(int32, 0, 0); +>async : Symbol(async, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>async32 : Symbol(async32, Decl(es2022SharedMemory.ts, 5, 7)) +>value : Symbol(value, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>value32 : Symbol(value32, Decl(es2022SharedMemory.ts, 5, 23)) +>Atomics.waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>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, --, --)) +>waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 2, 5)) + +const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0)); +>async : Symbol(async, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>async64 : Symbol(async64, Decl(es2022SharedMemory.ts, 6, 7)) +>value : Symbol(value, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>value64 : Symbol(value64, Decl(es2022SharedMemory.ts, 6, 23)) +>Atomics.waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>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, --, --)) +>waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>int64 : Symbol(int64, Decl(es2022SharedMemory.ts, 3, 5)) +>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) + +const main = async () => { +>main : Symbol(main, Decl(es2022SharedMemory.ts, 8, 5)) + + if (async32) { +>async32 : Symbol(async32, Decl(es2022SharedMemory.ts, 5, 7)) + + await value32; +>value32 : Symbol(value32, Decl(es2022SharedMemory.ts, 5, 23)) + } + if (async64) { +>async64 : Symbol(async64, Decl(es2022SharedMemory.ts, 6, 7)) + + await value64; +>value64 : Symbol(value64, Decl(es2022SharedMemory.ts, 6, 23)) + } +} +main(); +>main : Symbol(main, Decl(es2022SharedMemory.ts, 8, 5)) + diff --git a/tests/baselines/reference/es2022SharedMemory.types b/tests/baselines/reference/es2022SharedMemory.types index d3bf7f66c016a..b2ba654b47d97 100644 --- a/tests/baselines/reference/es2022SharedMemory.types +++ b/tests/baselines/reference/es2022SharedMemory.types @@ -1,56 +1,94 @@ -=== tests/cases/conformance/es2022/es2022SharedMemory.ts === -const sab = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); ->sab : SharedArrayBuffer ->new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024) : SharedArrayBuffer ->SharedArrayBuffer : SharedArrayBufferConstructor ->Int32Array.BYTES_PER_ELEMENT * 1024 : number ->Int32Array.BYTES_PER_ELEMENT : number ->Int32Array : Int32ArrayConstructor ->BYTES_PER_ELEMENT : number ->1024 : 1024 - -const int32 = new Int32Array(sab); ->int32 : Int32Array ->new Int32Array(sab) : Int32Array ->Int32Array : Int32ArrayConstructor ->sab : SharedArrayBuffer - -const waitValue = Atomics.wait(int32, 0, 0); ->waitValue : "ok" | "not-equal" | "timed-out" ->Atomics.wait(int32, 0, 0) : "ok" | "not-equal" | "timed-out" ->Atomics.wait : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; } ->Atomics : Atomics ->wait : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; } ->int32 : Int32Array ->0 : 0 ->0 : 0 - -const { async, value } = Atomics.waitAsync(int32, 0, BigInt(0)); ->async : boolean ->value : "ok" | "not-equal" | "timed-out" | Promise<"ok" | "not-equal" | "timed-out"> ->Atomics.waitAsync(int32, 0, BigInt(0)) : { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; } ->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">; } ->Atomics : 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">; } ->int32 : Int32Array ->0 : 0 ->BigInt(0) : bigint ->BigInt : BigIntConstructor ->0 : 0 - -const main = async () => { ->main : () => Promise ->async () => { if (async) { await value; }} : () => Promise - - if (async) { ->async : boolean - - await value; ->await value : "ok" | "not-equal" | "timed-out" ->value : Promise<"ok" | "not-equal" | "timed-out"> - } -} -main(); ->main() : Promise ->main : () => Promise - +=== tests/cases/conformance/es2022/es2022SharedMemory.ts === +const sab32 = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); +>sab32 : SharedArrayBuffer +>new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024) : SharedArrayBuffer +>SharedArrayBuffer : SharedArrayBufferConstructor +>Int32Array.BYTES_PER_ELEMENT * 1024 : number +>Int32Array.BYTES_PER_ELEMENT : number +>Int32Array : Int32ArrayConstructor +>BYTES_PER_ELEMENT : number +>1024 : 1024 + +const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024); +>sab64 : SharedArrayBuffer +>new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024) : SharedArrayBuffer +>SharedArrayBuffer : SharedArrayBufferConstructor +>BigInt64Array.BYTES_PER_ELEMENT * 1024 : number +>BigInt64Array.BYTES_PER_ELEMENT : number +>BigInt64Array : BigInt64ArrayConstructor +>BYTES_PER_ELEMENT : number +>1024 : 1024 + +const int32 = new Int32Array(sab32); +>int32 : Int32Array +>new Int32Array(sab32) : Int32Array +>Int32Array : Int32ArrayConstructor +>sab32 : SharedArrayBuffer + +const int64 = new BigInt64Array(sab64); +>int64 : BigInt64Array +>new BigInt64Array(sab64) : BigInt64Array +>BigInt64Array : BigInt64ArrayConstructor +>sab64 : SharedArrayBuffer + +const waitValue = Atomics.wait(int32, 0, 0); +>waitValue : "ok" | "not-equal" | "timed-out" +>Atomics.wait(int32, 0, 0) : "ok" | "not-equal" | "timed-out" +>Atomics.wait : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; } +>Atomics : Atomics +>wait : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; } +>int32 : Int32Array +>0 : 0 +>0 : 0 + +const { async: async32, value: value32 } = Atomics.waitAsync(int32, 0, 0); +>async : any +>async32 : boolean +>value : any +>value32 : "ok" | "not-equal" | "timed-out" | Promise<"ok" | "not-equal" | "timed-out"> +>Atomics.waitAsync(int32, 0, 0) : { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; } +>Atomics.waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } +>Atomics : Atomics +>waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } +>int32 : Int32Array +>0 : 0 +>0 : 0 + +const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0)); +>async : any +>async64 : boolean +>value : any +>value64 : "ok" | "not-equal" | "timed-out" | Promise<"ok" | "not-equal" | "timed-out"> +>Atomics.waitAsync(int64, 0, BigInt(0)) : { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; } +>Atomics.waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } +>Atomics : Atomics +>waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } +>int64 : BigInt64Array +>0 : 0 +>BigInt(0) : bigint +>BigInt : BigIntConstructor +>0 : 0 + +const main = async () => { +>main : () => Promise +>async () => { if (async32) { await value32; } if (async64) { await value64; }} : () => Promise + + if (async32) { +>async32 : boolean + + await value32; +>await value32 : "ok" | "not-equal" | "timed-out" +>value32 : Promise<"ok" | "not-equal" | "timed-out"> + } + if (async64) { +>async64 : boolean + + await value64; +>await value64 : "ok" | "not-equal" | "timed-out" +>value64 : Promise<"ok" | "not-equal" | "timed-out"> + } +} +main(); +>main() : Promise +>main : () => Promise + diff --git a/tests/cases/conformance/es2022/es2022SharedMemory.ts b/tests/cases/conformance/es2022/es2022SharedMemory.ts index c28d50bbefd7a..b99bf6830be8f 100644 --- a/tests/cases/conformance/es2022/es2022SharedMemory.ts +++ b/tests/cases/conformance/es2022/es2022SharedMemory.ts @@ -3,14 +3,20 @@ // @noemit: true // @strict: true -const sab = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); -const int32 = new Int32Array(sab); +const sab32 = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); +const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024); +const int32 = new Int32Array(sab32); +const int64 = new BigInt64Array(sab64); const waitValue = Atomics.wait(int32, 0, 0); -const { async, value } = Atomics.waitAsync(int32, 0, BigInt(0)); +const { async: async32, value: value32 } = Atomics.waitAsync(int32, 0, 0); +const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0)); const main = async () => { - if (async) { - await value; + if (async32) { + await value32; + } + if (async64) { + await value64; } } main(); \ No newline at end of file From da59cd10a47b4c3c062d1a514d53df384452e1fa Mon Sep 17 00:00:00 2001 From: Eyal Shalev Date: Sun, 20 Nov 2022 22:05:25 +0200 Subject: [PATCH 2/6] fixed types --- src/lib/es2022.sharedmemory.d.ts | 34 +++++++++------ .../conformance/es2022/es2022SharedMemory.ts | 42 +++++++++---------- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/src/lib/es2022.sharedmemory.d.ts b/src/lib/es2022.sharedmemory.d.ts index 571c95a1b7088..46258e2249055 100644 --- a/src/lib/es2022.sharedmemory.d.ts +++ b/src/lib/es2022.sharedmemory.d.ts @@ -1,13 +1,21 @@ -interface Atomics { - /** - * A non-blocking, asynchronous version of wait which is usable on the main thread. - * Waits asynchronously on a shared memory location and returns a Promise - */ - waitAsync(typedArray: Int32Array, index: number, value: number, timeout?: number): { async: false, value: "ok" | "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "not-equal" | "timed-out"> }; - - /** - * A non-blocking, asynchronous version of wait which is usable on the main thread. - * Waits asynchronously on a shared memory location and returns a Promise - */ - waitAsync(typedArray: BigInt64Array, index: number, value: bigint, timeout?: number): { async: false, value: "ok" | "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "not-equal" | "timed-out"> }; -} +interface Atomics { + /** + * A non-blocking, asynchronous version of wait which is usable on the main thread. + * Waits asynchronously on a shared memory location and returns a Promise + * @param typedArray A shared Int32Array or BigInt64Array. + * @param index The position in the typedArray to wait on. + * @param value The expected value to test. + * @param [timeout] The expected value to test. + */ + waitAsync(typedArray: Int32Array, index: number, value: number, timeout?: number): { async: false, value: "ok" | "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "not-equal" | "timed-out"> }; + + /** + * A non-blocking, asynchronous version of wait which is usable on the main thread. + * Waits asynchronously on a shared memory location and returns a Promise + * @param typedArray A shared Int32Array or BigInt64Array. + * @param index The position in the typedArray to wait on. + * @param value The expected value to test. + * @param [timeout] The expected value to test. + */ + waitAsync(typedArray: BigInt64Array, index: number, value: bigint, timeout?: number): { async: false, value: "ok" | "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "not-equal" | "timed-out"> }; +} diff --git a/tests/cases/conformance/es2022/es2022SharedMemory.ts b/tests/cases/conformance/es2022/es2022SharedMemory.ts index b99bf6830be8f..863f4cd5477bb 100644 --- a/tests/cases/conformance/es2022/es2022SharedMemory.ts +++ b/tests/cases/conformance/es2022/es2022SharedMemory.ts @@ -1,22 +1,22 @@ -// @target: esnext -// @lib: es2022 -// @noemit: true -// @strict: true - -const sab32 = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); -const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024); -const int32 = new Int32Array(sab32); -const int64 = new BigInt64Array(sab64); -const waitValue = Atomics.wait(int32, 0, 0); -const { async: async32, value: value32 } = Atomics.waitAsync(int32, 0, 0); -const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0)); - -const main = async () => { - if (async32) { - await value32; - } - if (async64) { - await value64; - } -} +// @target: esnext +// @lib: es2022 +// @noemit: true +// @strict: true + +const sab = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); +const int32 = new Int32Array(sab); +const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024); +const int64 = new BigInt64Array(sab64); +const waitValue = Atomics.wait(int32, 0, 0); +const { async, value } = Atomics.waitAsync(int32, 0, 0); +const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0)); + +const main = async () => { + if (async) { + await value; + } + if (async64) { + await value64; + } +} main(); \ No newline at end of file From fff03ff2ad0ca14917f523c56ffd2f9825c1f0c3 Mon Sep 17 00:00:00 2001 From: Eyal Shalev Date: Sun, 20 Nov 2022 22:07:14 +0200 Subject: [PATCH 3/6] fixed types --- .../reference/es2022SharedMemory.symbols | 142 +++++++------ .../reference/es2022SharedMemory.types | 186 +++++++++--------- 2 files changed, 162 insertions(+), 166 deletions(-) diff --git a/tests/baselines/reference/es2022SharedMemory.symbols b/tests/baselines/reference/es2022SharedMemory.symbols index dea21f40918dd..966c5ee5bc806 100644 --- a/tests/baselines/reference/es2022SharedMemory.symbols +++ b/tests/baselines/reference/es2022SharedMemory.symbols @@ -1,72 +1,70 @@ -=== tests/cases/conformance/es2022/es2022SharedMemory.ts === -const sab32 = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); ->sab32 : Symbol(sab32, Decl(es2022SharedMemory.ts, 0, 5)) ->SharedArrayBuffer : Symbol(SharedArrayBuffer, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --)) ->Int32Array.BYTES_PER_ELEMENT : Symbol(Int32ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es5.d.ts, --, --)) ->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) ->BYTES_PER_ELEMENT : Symbol(Int32ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es5.d.ts, --, --)) - -const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024); ->sab64 : Symbol(sab64, Decl(es2022SharedMemory.ts, 1, 5)) ->SharedArrayBuffer : Symbol(SharedArrayBuffer, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --)) ->BigInt64Array.BYTES_PER_ELEMENT : Symbol(BigInt64ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es2020.bigint.d.ts, --, --)) ->BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2022.array.d.ts, --, --)) ->BYTES_PER_ELEMENT : Symbol(BigInt64ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es2020.bigint.d.ts, --, --)) - -const int32 = new Int32Array(sab32); ->int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 2, 5)) ->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) ->sab32 : Symbol(sab32, Decl(es2022SharedMemory.ts, 0, 5)) - -const int64 = new BigInt64Array(sab64); ->int64 : Symbol(int64, Decl(es2022SharedMemory.ts, 3, 5)) ->BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2022.array.d.ts, --, --)) ->sab64 : Symbol(sab64, Decl(es2022SharedMemory.ts, 1, 5)) - -const waitValue = Atomics.wait(int32, 0, 0); ->waitValue : Symbol(waitValue, Decl(es2022SharedMemory.ts, 4, 5)) ->Atomics.wait : Symbol(Atomics.wait, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --)) ->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, --, --)) ->wait : Symbol(Atomics.wait, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --)) ->int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 2, 5)) - -const { async: async32, value: value32 } = Atomics.waitAsync(int32, 0, 0); ->async : Symbol(async, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) ->async32 : Symbol(async32, Decl(es2022SharedMemory.ts, 5, 7)) ->value : Symbol(value, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) ->value32 : Symbol(value32, Decl(es2022SharedMemory.ts, 5, 23)) ->Atomics.waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) ->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, --, --)) ->waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) ->int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 2, 5)) - -const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0)); ->async : Symbol(async, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) ->async64 : Symbol(async64, Decl(es2022SharedMemory.ts, 6, 7)) ->value : Symbol(value, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) ->value64 : Symbol(value64, Decl(es2022SharedMemory.ts, 6, 23)) ->Atomics.waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) ->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, --, --)) ->waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) ->int64 : Symbol(int64, Decl(es2022SharedMemory.ts, 3, 5)) ->BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) - -const main = async () => { ->main : Symbol(main, Decl(es2022SharedMemory.ts, 8, 5)) - - if (async32) { ->async32 : Symbol(async32, Decl(es2022SharedMemory.ts, 5, 7)) - - await value32; ->value32 : Symbol(value32, Decl(es2022SharedMemory.ts, 5, 23)) - } - if (async64) { ->async64 : Symbol(async64, Decl(es2022SharedMemory.ts, 6, 7)) - - await value64; ->value64 : Symbol(value64, Decl(es2022SharedMemory.ts, 6, 23)) - } -} -main(); ->main : Symbol(main, Decl(es2022SharedMemory.ts, 8, 5)) - +=== tests/cases/conformance/es2022/es2022SharedMemory.ts === +const sab = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); +>sab : Symbol(sab, Decl(es2022SharedMemory.ts, 0, 5)) +>SharedArrayBuffer : Symbol(SharedArrayBuffer, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --)) +>Int32Array.BYTES_PER_ELEMENT : Symbol(Int32ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es5.d.ts, --, --)) +>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) +>BYTES_PER_ELEMENT : Symbol(Int32ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es5.d.ts, --, --)) + +const int32 = new Int32Array(sab); +>int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 1, 5)) +>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) +>sab : Symbol(sab, Decl(es2022SharedMemory.ts, 0, 5)) + +const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024); +>sab64 : Symbol(sab64, Decl(es2022SharedMemory.ts, 2, 5)) +>SharedArrayBuffer : Symbol(SharedArrayBuffer, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --)) +>BigInt64Array.BYTES_PER_ELEMENT : Symbol(BigInt64ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es2020.bigint.d.ts, --, --)) +>BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2022.array.d.ts, --, --)) +>BYTES_PER_ELEMENT : Symbol(BigInt64ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es2020.bigint.d.ts, --, --)) + +const int64 = new BigInt64Array(sab64); +>int64 : Symbol(int64, Decl(es2022SharedMemory.ts, 3, 5)) +>BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2022.array.d.ts, --, --)) +>sab64 : Symbol(sab64, Decl(es2022SharedMemory.ts, 2, 5)) + +const waitValue = Atomics.wait(int32, 0, 0); +>waitValue : Symbol(waitValue, Decl(es2022SharedMemory.ts, 4, 5)) +>Atomics.wait : Symbol(Atomics.wait, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --)) +>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, --, --)) +>wait : Symbol(Atomics.wait, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --)) +>int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 1, 5)) + +const { async, value } = Atomics.waitAsync(int32, 0, 0); +>async : Symbol(async, Decl(es2022SharedMemory.ts, 5, 7)) +>value : Symbol(value, Decl(es2022SharedMemory.ts, 5, 14)) +>Atomics.waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>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, --, --)) +>waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 1, 5)) + +const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0)); +>async : Symbol(async, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>async64 : Symbol(async64, Decl(es2022SharedMemory.ts, 6, 7)) +>value : Symbol(value, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>value64 : Symbol(value64, Decl(es2022SharedMemory.ts, 6, 23)) +>Atomics.waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>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, --, --)) +>waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --)) +>int64 : Symbol(int64, Decl(es2022SharedMemory.ts, 3, 5)) +>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) + +const main = async () => { +>main : Symbol(main, Decl(es2022SharedMemory.ts, 8, 5)) + + if (async) { +>async : Symbol(async, Decl(es2022SharedMemory.ts, 5, 7)) + + await value; +>value : Symbol(value, Decl(es2022SharedMemory.ts, 5, 14)) + } + if (async64) { +>async64 : Symbol(async64, Decl(es2022SharedMemory.ts, 6, 7)) + + await value64; +>value64 : Symbol(value64, Decl(es2022SharedMemory.ts, 6, 23)) + } +} +main(); +>main : Symbol(main, Decl(es2022SharedMemory.ts, 8, 5)) + diff --git a/tests/baselines/reference/es2022SharedMemory.types b/tests/baselines/reference/es2022SharedMemory.types index b2ba654b47d97..3277ad119878f 100644 --- a/tests/baselines/reference/es2022SharedMemory.types +++ b/tests/baselines/reference/es2022SharedMemory.types @@ -1,94 +1,92 @@ -=== tests/cases/conformance/es2022/es2022SharedMemory.ts === -const sab32 = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); ->sab32 : SharedArrayBuffer ->new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024) : SharedArrayBuffer ->SharedArrayBuffer : SharedArrayBufferConstructor ->Int32Array.BYTES_PER_ELEMENT * 1024 : number ->Int32Array.BYTES_PER_ELEMENT : number ->Int32Array : Int32ArrayConstructor ->BYTES_PER_ELEMENT : number ->1024 : 1024 - -const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024); ->sab64 : SharedArrayBuffer ->new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024) : SharedArrayBuffer ->SharedArrayBuffer : SharedArrayBufferConstructor ->BigInt64Array.BYTES_PER_ELEMENT * 1024 : number ->BigInt64Array.BYTES_PER_ELEMENT : number ->BigInt64Array : BigInt64ArrayConstructor ->BYTES_PER_ELEMENT : number ->1024 : 1024 - -const int32 = new Int32Array(sab32); ->int32 : Int32Array ->new Int32Array(sab32) : Int32Array ->Int32Array : Int32ArrayConstructor ->sab32 : SharedArrayBuffer - -const int64 = new BigInt64Array(sab64); ->int64 : BigInt64Array ->new BigInt64Array(sab64) : BigInt64Array ->BigInt64Array : BigInt64ArrayConstructor ->sab64 : SharedArrayBuffer - -const waitValue = Atomics.wait(int32, 0, 0); ->waitValue : "ok" | "not-equal" | "timed-out" ->Atomics.wait(int32, 0, 0) : "ok" | "not-equal" | "timed-out" ->Atomics.wait : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; } ->Atomics : Atomics ->wait : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; } ->int32 : Int32Array ->0 : 0 ->0 : 0 - -const { async: async32, value: value32 } = Atomics.waitAsync(int32, 0, 0); ->async : any ->async32 : boolean ->value : any ->value32 : "ok" | "not-equal" | "timed-out" | Promise<"ok" | "not-equal" | "timed-out"> ->Atomics.waitAsync(int32, 0, 0) : { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; } ->Atomics.waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } ->Atomics : Atomics ->waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } ->int32 : Int32Array ->0 : 0 ->0 : 0 - -const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0)); ->async : any ->async64 : boolean ->value : any ->value64 : "ok" | "not-equal" | "timed-out" | Promise<"ok" | "not-equal" | "timed-out"> ->Atomics.waitAsync(int64, 0, BigInt(0)) : { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; } ->Atomics.waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } ->Atomics : Atomics ->waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } ->int64 : BigInt64Array ->0 : 0 ->BigInt(0) : bigint ->BigInt : BigIntConstructor ->0 : 0 - -const main = async () => { ->main : () => Promise ->async () => { if (async32) { await value32; } if (async64) { await value64; }} : () => Promise - - if (async32) { ->async32 : boolean - - await value32; ->await value32 : "ok" | "not-equal" | "timed-out" ->value32 : Promise<"ok" | "not-equal" | "timed-out"> - } - if (async64) { ->async64 : boolean - - await value64; ->await value64 : "ok" | "not-equal" | "timed-out" ->value64 : Promise<"ok" | "not-equal" | "timed-out"> - } -} -main(); ->main() : Promise ->main : () => Promise - +=== tests/cases/conformance/es2022/es2022SharedMemory.ts === +const sab = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); +>sab : SharedArrayBuffer +>new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024) : SharedArrayBuffer +>SharedArrayBuffer : SharedArrayBufferConstructor +>Int32Array.BYTES_PER_ELEMENT * 1024 : number +>Int32Array.BYTES_PER_ELEMENT : number +>Int32Array : Int32ArrayConstructor +>BYTES_PER_ELEMENT : number +>1024 : 1024 + +const int32 = new Int32Array(sab); +>int32 : Int32Array +>new Int32Array(sab) : Int32Array +>Int32Array : Int32ArrayConstructor +>sab : SharedArrayBuffer + +const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024); +>sab64 : SharedArrayBuffer +>new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024) : SharedArrayBuffer +>SharedArrayBuffer : SharedArrayBufferConstructor +>BigInt64Array.BYTES_PER_ELEMENT * 1024 : number +>BigInt64Array.BYTES_PER_ELEMENT : number +>BigInt64Array : BigInt64ArrayConstructor +>BYTES_PER_ELEMENT : number +>1024 : 1024 + +const int64 = new BigInt64Array(sab64); +>int64 : BigInt64Array +>new BigInt64Array(sab64) : BigInt64Array +>BigInt64Array : BigInt64ArrayConstructor +>sab64 : SharedArrayBuffer + +const waitValue = Atomics.wait(int32, 0, 0); +>waitValue : "ok" | "not-equal" | "timed-out" +>Atomics.wait(int32, 0, 0) : "ok" | "not-equal" | "timed-out" +>Atomics.wait : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; } +>Atomics : Atomics +>wait : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): "ok" | "not-equal" | "timed-out"; } +>int32 : Int32Array +>0 : 0 +>0 : 0 + +const { async, value } = Atomics.waitAsync(int32, 0, 0); +>async : boolean +>value : "ok" | "not-equal" | "timed-out" | Promise<"ok" | "not-equal" | "timed-out"> +>Atomics.waitAsync(int32, 0, 0) : { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; } +>Atomics.waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } +>Atomics : Atomics +>waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } +>int32 : Int32Array +>0 : 0 +>0 : 0 + +const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0)); +>async : any +>async64 : boolean +>value : any +>value64 : "ok" | "not-equal" | "timed-out" | Promise<"ok" | "not-equal" | "timed-out"> +>Atomics.waitAsync(int64, 0, BigInt(0)) : { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; } +>Atomics.waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } +>Atomics : Atomics +>waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } +>int64 : BigInt64Array +>0 : 0 +>BigInt(0) : bigint +>BigInt : BigIntConstructor +>0 : 0 + +const main = async () => { +>main : () => Promise +>async () => { if (async) { await value; } if (async64) { await value64; }} : () => Promise + + if (async) { +>async : boolean + + await value; +>await value : "ok" | "not-equal" | "timed-out" +>value : Promise<"ok" | "not-equal" | "timed-out"> + } + if (async64) { +>async64 : boolean + + await value64; +>await value64 : "ok" | "not-equal" | "timed-out" +>value64 : Promise<"ok" | "not-equal" | "timed-out"> + } +} +main(); +>main() : Promise +>main : () => Promise + From a105b9e5abee9ec1b452a5979bd0cab1e6f68dcd Mon Sep 17 00:00:00 2001 From: Eyal Shalev Date: Sun, 20 Nov 2022 22:26:05 +0200 Subject: [PATCH 4/6] fixed line ending --- .../conformance/es2022/es2022SharedMemory.ts | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/cases/conformance/es2022/es2022SharedMemory.ts b/tests/cases/conformance/es2022/es2022SharedMemory.ts index 863f4cd5477bb..efc391bbed7b4 100644 --- a/tests/cases/conformance/es2022/es2022SharedMemory.ts +++ b/tests/cases/conformance/es2022/es2022SharedMemory.ts @@ -1,22 +1,22 @@ -// @target: esnext -// @lib: es2022 -// @noemit: true -// @strict: true - -const sab = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); -const int32 = new Int32Array(sab); -const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024); -const int64 = new BigInt64Array(sab64); -const waitValue = Atomics.wait(int32, 0, 0); -const { async, value } = Atomics.waitAsync(int32, 0, 0); -const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0)); - -const main = async () => { - if (async) { - await value; - } - if (async64) { - await value64; - } -} +// @target: esnext +// @lib: es2022 +// @noemit: true +// @strict: true + +const sab = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024); +const int32 = new Int32Array(sab); +const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024); +const int64 = new BigInt64Array(sab64); +const waitValue = Atomics.wait(int32, 0, 0); +const { async, value } = Atomics.waitAsync(int32, 0, 0); +const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0)); + +const main = async () => { + if (async) { + await value; + } + if (async64) { + await value64; + } +} main(); \ No newline at end of file From 29e11415efedcd9ccf08862c6264d134ad596017 Mon Sep 17 00:00:00 2001 From: Eyal Shalev Date: Mon, 21 Nov 2022 20:32:34 +0200 Subject: [PATCH 5/6] CR fix --- src/lib/es2022.sharedmemory.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/es2022.sharedmemory.d.ts b/src/lib/es2022.sharedmemory.d.ts index 46258e2249055..fe6c26d02cf79 100644 --- a/src/lib/es2022.sharedmemory.d.ts +++ b/src/lib/es2022.sharedmemory.d.ts @@ -7,7 +7,7 @@ interface Atomics { * @param value The expected value to test. * @param [timeout] The expected value to test. */ - waitAsync(typedArray: Int32Array, index: number, value: number, timeout?: number): { async: false, value: "ok" | "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "not-equal" | "timed-out"> }; + waitAsync(typedArray: Int32Array, index: number, value: number, timeout?: number): { async: false, value: "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "timed-out"> }; /** * A non-blocking, asynchronous version of wait which is usable on the main thread. @@ -17,5 +17,5 @@ interface Atomics { * @param value The expected value to test. * @param [timeout] The expected value to test. */ - waitAsync(typedArray: BigInt64Array, index: number, value: bigint, timeout?: number): { async: false, value: "ok" | "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "not-equal" | "timed-out"> }; + waitAsync(typedArray: BigInt64Array, index: number, value: bigint, timeout?: number): { async: false, value: "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "timed-out"> }; } From 235d98b60b467a2ae0e9344ab51d22348b5371bf Mon Sep 17 00:00:00 2001 From: Eyal Shalev Date: Mon, 21 Nov 2022 20:39:28 +0200 Subject: [PATCH 6/6] Forgot the baseline --- .../reference/es2022SharedMemory.types | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/baselines/reference/es2022SharedMemory.types b/tests/baselines/reference/es2022SharedMemory.types index 3277ad119878f..15e9d0b1a3521 100644 --- a/tests/baselines/reference/es2022SharedMemory.types +++ b/tests/baselines/reference/es2022SharedMemory.types @@ -43,11 +43,11 @@ const waitValue = Atomics.wait(int32, 0, 0); const { async, value } = Atomics.waitAsync(int32, 0, 0); >async : boolean ->value : "ok" | "not-equal" | "timed-out" | Promise<"ok" | "not-equal" | "timed-out"> ->Atomics.waitAsync(int32, 0, 0) : { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; } ->Atomics.waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } +>value : "not-equal" | "timed-out" | Promise<"ok" | "timed-out"> +>Atomics.waitAsync(int32, 0, 0) : { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; } +>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">; }; } >Atomics : Atomics ->waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } +>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">; }; } >int32 : Int32Array >0 : 0 >0 : 0 @@ -56,11 +56,11 @@ const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0) >async : any >async64 : boolean >value : any ->value64 : "ok" | "not-equal" | "timed-out" | Promise<"ok" | "not-equal" | "timed-out"> ->Atomics.waitAsync(int64, 0, BigInt(0)) : { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; } ->Atomics.waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } +>value64 : "not-equal" | "timed-out" | Promise<"ok" | "timed-out"> +>Atomics.waitAsync(int64, 0, BigInt(0)) : { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; } +>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">; }; } >Atomics : Atomics ->waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }; (typedArray: 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">; }; } +>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">; }; } >int64 : BigInt64Array >0 : 0 >BigInt(0) : bigint @@ -75,15 +75,15 @@ const main = async () => { >async : boolean await value; ->await value : "ok" | "not-equal" | "timed-out" ->value : Promise<"ok" | "not-equal" | "timed-out"> +>await value : "ok" | "timed-out" +>value : Promise<"ok" | "timed-out"> } if (async64) { >async64 : boolean await value64; ->await value64 : "ok" | "not-equal" | "timed-out" ->value64 : Promise<"ok" | "not-equal" | "timed-out"> +>await value64 : "ok" | "timed-out" +>value64 : Promise<"ok" | "timed-out"> } } main();