Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion tsc/internal/bundled/libs/lib.dom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43547,6 +43547,29 @@ declare namespace WebAssembly {
(message?: string): RuntimeError;
};

/** The **`WebAssembly.SuspendError`** object indicates an error during WebAssembly function suspension. */
interface SuspendError extends Error {
}

var SuspendError: {
prototype: SuspendError;
new(message?: string): SuspendError;
(message?: string): SuspendError;
};

/**
* The **`WebAssembly.Suspending`** object represents a suspending function — an asynchronous (Promise-based) JavaScript function that, when imported into a Wasm module and called from inside, will result in execution being suspended until the promise resolves.
*
* [MDN Reference](https://developer.mozilla.org/docs/WebAssembly/Reference/JavaScript_interface/Suspending)
*/
interface Suspending {
}

var Suspending: {
prototype: Suspending;
new(jsFun: Function): Suspending;
};

/**
* The **`WebAssembly.Table`** object is a JavaScript wrapper object — an array-like structure representing a WebAssembly table, which stores homogeneous references. A table created by JavaScript or in WebAssembly code will be accessible and mutable from both JavaScript and WebAssembly.
*
Expand Down Expand Up @@ -43661,7 +43684,7 @@ declare namespace WebAssembly {
type AddressValue = number;
type ExportValue = Function | Global | Memory | Table;
type Exports = Record<string, ExportValue>;
type ImportValue = ExportValue | number;
type ImportValue = ExportValue | Suspending | number;
type Imports = Record<string, ModuleImports>;
type ModuleImports = Record<string, ImportValue>;
type ValueType = keyof ValueTypeMap;
Expand All @@ -43675,6 +43698,8 @@ declare namespace WebAssembly {
function instantiate(moduleObject: Module, importObject?: Imports): Promise<Instance>;
/** [MDN Reference](https://developer.mozilla.org/docs/WebAssembly/Reference/JavaScript_interface/instantiateStreaming_static) */
function instantiateStreaming(source: Response | PromiseLike<Response>, importObject?: Imports, options?: WebAssemblyCompileOptions): Promise<WebAssemblyInstantiatedSource>;
/** [MDN Reference](https://developer.mozilla.org/docs/WebAssembly/Reference/JavaScript_interface/promising_static) */
function promising(wasmFunc: Function): Function;
/** [MDN Reference](https://developer.mozilla.org/docs/WebAssembly/Reference/JavaScript_interface/validate_static) */
function validate(bytes: AllowSharedBufferSource, options?: WebAssemblyCompileOptions): boolean;
}
Expand Down
27 changes: 26 additions & 1 deletion tsc/internal/bundled/libs/lib.webworker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14896,6 +14896,29 @@ declare namespace WebAssembly {
(message?: string): RuntimeError;
};

/** The **`WebAssembly.SuspendError`** object indicates an error during WebAssembly function suspension. */
interface SuspendError extends Error {
}

var SuspendError: {
prototype: SuspendError;
new(message?: string): SuspendError;
(message?: string): SuspendError;
};

/**
* The **`WebAssembly.Suspending`** object represents a suspending function — an asynchronous (Promise-based) JavaScript function that, when imported into a Wasm module and called from inside, will result in execution being suspended until the promise resolves.
*
* [MDN Reference](https://developer.mozilla.org/docs/WebAssembly/Reference/JavaScript_interface/Suspending)
*/
interface Suspending {
}

var Suspending: {
prototype: Suspending;
new(jsFun: Function): Suspending;
};

/**
* The **`WebAssembly.Table`** object is a JavaScript wrapper object — an array-like structure representing a WebAssembly table, which stores homogeneous references. A table created by JavaScript or in WebAssembly code will be accessible and mutable from both JavaScript and WebAssembly.
*
Expand Down Expand Up @@ -15010,7 +15033,7 @@ declare namespace WebAssembly {
type AddressValue = number;
type ExportValue = Function | Global | Memory | Table;
type Exports = Record<string, ExportValue>;
type ImportValue = ExportValue | number;
type ImportValue = ExportValue | Suspending | number;
type Imports = Record<string, ModuleImports>;
type ModuleImports = Record<string, ImportValue>;
type ValueType = keyof ValueTypeMap;
Expand All @@ -15024,6 +15047,8 @@ declare namespace WebAssembly {
function instantiate(moduleObject: Module, importObject?: Imports): Promise<Instance>;
/** [MDN Reference](https://developer.mozilla.org/docs/WebAssembly/Reference/JavaScript_interface/instantiateStreaming_static) */
function instantiateStreaming(source: Response | PromiseLike<Response>, importObject?: Imports, options?: WebAssemblyCompileOptions): Promise<WebAssemblyInstantiatedSource>;
/** [MDN Reference](https://developer.mozilla.org/docs/WebAssembly/Reference/JavaScript_interface/promising_static) */
function promising(wasmFunc: Function): Function;
/** [MDN Reference](https://developer.mozilla.org/docs/WebAssembly/Reference/JavaScript_interface/validate_static) */
function validate(bytes: AllowSharedBufferSource, options?: WebAssemblyCompileOptions): boolean;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
webAssemblyPromiseIntegration.ts(33,28): error TS2345: Argument of type 'number' is not assignable to parameter of type 'Function'.
webAssemblyPromiseIntegration.ts(34,23): error TS2345: Argument of type 'string' is not assignable to parameter of type 'Function'.


==== webAssemblyPromiseIntegration.ts (2 errors) ====
function someAsyncFunction() {
return fetch("https://example.com").then(result => result.status);
}

const suspending: WebAssembly.Suspending = new WebAssembly.Suspending(someAsyncFunction);

const importObj = {
someAsyncFunction: suspending,
};

async function main() {
const { instance } = await WebAssembly.instantiateStreaming(fetch("module.wasm"), { importObj });
const run: Function = WebAssembly.promising(instance.exports.run as Function);
await run();
}

const imports: WebAssembly.Imports = {
env: {
sync: () => 0,
async: new WebAssembly.Suspending(async () => 0),
},
};

function handle(e: unknown) {
if (e instanceof WebAssembly.SuspendError) {
const err: Error = e;
}
}

const err1: WebAssembly.SuspendError = new WebAssembly.SuspendError("message");
const err2: WebAssembly.SuspendError = WebAssembly.SuspendError();

new WebAssembly.Suspending(42); // error
~~
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'Function'.
WebAssembly.promising("not a function"); // error
~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'Function'.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//// [tests/cases/compiler/webAssemblyPromiseIntegration.ts] ////

//// [webAssemblyPromiseIntegration.ts]
function someAsyncFunction() {
return fetch("https://example.com").then(result => result.status);
}

const suspending: WebAssembly.Suspending = new WebAssembly.Suspending(someAsyncFunction);

const importObj = {
someAsyncFunction: suspending,
};

async function main() {
const { instance } = await WebAssembly.instantiateStreaming(fetch("module.wasm"), { importObj });
const run: Function = WebAssembly.promising(instance.exports.run as Function);
await run();
}

const imports: WebAssembly.Imports = {
env: {
sync: () => 0,
async: new WebAssembly.Suspending(async () => 0),
},
};

function handle(e: unknown) {
if (e instanceof WebAssembly.SuspendError) {
const err: Error = e;
}
}

const err1: WebAssembly.SuspendError = new WebAssembly.SuspendError("message");
const err2: WebAssembly.SuspendError = WebAssembly.SuspendError();

new WebAssembly.Suspending(42); // error
WebAssembly.promising("not a function"); // error


//// [webAssemblyPromiseIntegration.js]
"use strict";
function someAsyncFunction() {
return fetch("https://example.com").then(result => result.status);
}
const suspending = new WebAssembly.Suspending(someAsyncFunction);
const importObj = {
someAsyncFunction: suspending,
};
async function main() {
const { instance } = await WebAssembly.instantiateStreaming(fetch("module.wasm"), { importObj });
const run = WebAssembly.promising(instance.exports.run);
await run();
}
const imports = {
env: {
sync: () => 0,
async: new WebAssembly.Suspending(async () => 0),
},
};
function handle(e) {
if (e instanceof WebAssembly.SuspendError) {
const err = e;
}
}
const err1 = new WebAssembly.SuspendError("message");
const err2 = WebAssembly.SuspendError();
new WebAssembly.Suspending(42); // error
WebAssembly.promising("not a function"); // error
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
//// [tests/cases/compiler/webAssemblyPromiseIntegration.ts] ////

=== webAssemblyPromiseIntegration.ts ===
function someAsyncFunction() {
>someAsyncFunction : Symbol(someAsyncFunction, Decl(webAssemblyPromiseIntegration.ts, 0, 0))

return fetch("https://example.com").then(result => result.status);
>fetch("https://example.com").then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>fetch : Symbol(fetch, Decl(lib.dom.d.ts, --, --))
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>result : Symbol(result, Decl(webAssemblyPromiseIntegration.ts, 1, 45))
>result.status : Symbol(Response.status, Decl(lib.dom.d.ts, --, --))
>result : Symbol(result, Decl(webAssemblyPromiseIntegration.ts, 1, 45))
>status : Symbol(Response.status, Decl(lib.dom.d.ts, --, --))
}

const suspending: WebAssembly.Suspending = new WebAssembly.Suspending(someAsyncFunction);
>suspending : Symbol(suspending, Decl(webAssemblyPromiseIntegration.ts, 4, 5))
>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --))
>Suspending : Symbol(WebAssembly.Suspending, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
>WebAssembly.Suspending : Symbol(WebAssembly.Suspending, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --))
>Suspending : Symbol(WebAssembly.Suspending, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
>someAsyncFunction : Symbol(someAsyncFunction, Decl(webAssemblyPromiseIntegration.ts, 0, 0))

const importObj = {
>importObj : Symbol(importObj, Decl(webAssemblyPromiseIntegration.ts, 6, 5))

someAsyncFunction: suspending,
>someAsyncFunction : Symbol(someAsyncFunction, Decl(webAssemblyPromiseIntegration.ts, 6, 19))
>suspending : Symbol(suspending, Decl(webAssemblyPromiseIntegration.ts, 4, 5))

};

async function main() {
>main : Symbol(main, Decl(webAssemblyPromiseIntegration.ts, 8, 2))

const { instance } = await WebAssembly.instantiateStreaming(fetch("module.wasm"), { importObj });
>instance : Symbol(instance, Decl(webAssemblyPromiseIntegration.ts, 11, 11))
>WebAssembly.instantiateStreaming : Symbol(WebAssembly.instantiateStreaming, Decl(lib.dom.d.ts, --, --))
>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --))
>instantiateStreaming : Symbol(WebAssembly.instantiateStreaming, Decl(lib.dom.d.ts, --, --))
>fetch : Symbol(fetch, Decl(lib.dom.d.ts, --, --))
>importObj : Symbol(importObj, Decl(webAssemblyPromiseIntegration.ts, 11, 87))

const run: Function = WebAssembly.promising(instance.exports.run as Function);
>run : Symbol(run, Decl(webAssemblyPromiseIntegration.ts, 12, 9))
>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.decorators.d.ts, --, --))
>WebAssembly.promising : Symbol(WebAssembly.promising, Decl(lib.dom.d.ts, --, --))
>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --))
>promising : Symbol(WebAssembly.promising, Decl(lib.dom.d.ts, --, --))
>instance.exports : Symbol(WebAssembly.Instance.exports, Decl(lib.dom.d.ts, --, --))
>instance : Symbol(instance, Decl(webAssemblyPromiseIntegration.ts, 11, 11))
>exports : Symbol(WebAssembly.Instance.exports, Decl(lib.dom.d.ts, --, --))
>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.decorators.d.ts, --, --))

await run();
>run : Symbol(run, Decl(webAssemblyPromiseIntegration.ts, 12, 9))
}

const imports: WebAssembly.Imports = {
>imports : Symbol(imports, Decl(webAssemblyPromiseIntegration.ts, 16, 5))
>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --))
>Imports : Symbol(WebAssembly.Imports, Decl(lib.dom.d.ts, --, --))

env: {
>env : Symbol(env, Decl(webAssemblyPromiseIntegration.ts, 16, 38))

sync: () => 0,
>sync : Symbol(sync, Decl(webAssemblyPromiseIntegration.ts, 17, 10))

async: new WebAssembly.Suspending(async () => 0),
>async : Symbol(async, Decl(webAssemblyPromiseIntegration.ts, 18, 22))
>WebAssembly.Suspending : Symbol(WebAssembly.Suspending, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --))
>Suspending : Symbol(WebAssembly.Suspending, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))

},
};

function handle(e: unknown) {
>handle : Symbol(handle, Decl(webAssemblyPromiseIntegration.ts, 21, 2))
>e : Symbol(e, Decl(webAssemblyPromiseIntegration.ts, 23, 16))

if (e instanceof WebAssembly.SuspendError) {
>e : Symbol(e, Decl(webAssemblyPromiseIntegration.ts, 23, 16))
>WebAssembly.SuspendError : Symbol(WebAssembly.SuspendError, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --))
>SuspendError : Symbol(WebAssembly.SuspendError, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))

const err: Error = e;
>err : Symbol(err, Decl(webAssemblyPromiseIntegration.ts, 25, 13))
>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2022.error.d.ts, --, --))
>e : Symbol(e, Decl(webAssemblyPromiseIntegration.ts, 23, 16))
}
}

const err1: WebAssembly.SuspendError = new WebAssembly.SuspendError("message");
>err1 : Symbol(err1, Decl(webAssemblyPromiseIntegration.ts, 29, 5))
>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --))
>SuspendError : Symbol(WebAssembly.SuspendError, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
>WebAssembly.SuspendError : Symbol(WebAssembly.SuspendError, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --))
>SuspendError : Symbol(WebAssembly.SuspendError, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))

const err2: WebAssembly.SuspendError = WebAssembly.SuspendError();
>err2 : Symbol(err2, Decl(webAssemblyPromiseIntegration.ts, 30, 5))
>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --))
>SuspendError : Symbol(WebAssembly.SuspendError, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
>WebAssembly.SuspendError : Symbol(WebAssembly.SuspendError, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --))
>SuspendError : Symbol(WebAssembly.SuspendError, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))

new WebAssembly.Suspending(42); // error
>WebAssembly.Suspending : Symbol(WebAssembly.Suspending, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --))
>Suspending : Symbol(WebAssembly.Suspending, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))

WebAssembly.promising("not a function"); // error
>WebAssembly.promising : Symbol(WebAssembly.promising, Decl(lib.dom.d.ts, --, --))
>WebAssembly : Symbol(WebAssembly, Decl(lib.dom.d.ts, --, --))
>promising : Symbol(WebAssembly.promising, Decl(lib.dom.d.ts, --, --))

Loading