Skip to content

Add WebAssembly.Suspending, WebAssembly.promising, and WebAssembly.SuspendError to DOM and WebWorker libs - #65793

Closed
Ryan Cavanaugh (RyanCavanaugh) wants to merge 3 commits into
mainfrom
copilot/add-webassembly-suspending-promising
Closed

Ryan Cavanaugh (RyanCavanaugh) wants to merge 3 commits into
mainfrom
copilot/add-webassembly-suspending-promising

Conversation

@RyanCavanaugh

@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

The libs had no declarations for the WebAssembly JavaScript Promise Integration (JSPI) API. ImportValue also rejected Suspending objects, which the spec explicitly allows in import objects. Per MDN compatibility data, JSPI ships unprefixed in Chrome 137, Firefox 153 and Safari 27.

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

Changes (lib.dom.d.ts and lib.webworker.d.ts, identical edits)

  • Suspending: an empty interface plus a var with new(jsFun: Function), following the spec's IDL.
  • SuspendError: an error class shaped like CompileError, LinkError and RuntimeError. It is part of the same spec and shipped in the same browser versions.
  • promising(wasmFunc: Function): Function: a new function on the namespace.
  • ImportValue: changed from ExportValue | number to ExportValue | Suspending | number.

These files are normally generated by TypeScript-DOM-lib-generator, which doesn't have JSPI yet. The edits are by hand but follow the generator's member ordering, doc-comment style and IDL-to-TS type mapping. That should keep the diff small when the generator is updated.

Review notes

  • ImportValue now accepts almost any value. Suspending has no members, so adding it to the union means values in an import object are only required to be non-nullish. For example, { env: { s: "str" } } used to be an error and is now accepted. The namespace already does this: instantiate(moduleObject: Module) takes the empty Module interface and so accepts any non-nullish value too. The alternative was to leave ImportValue unchanged and make users cast every Suspending in an import object.
  • promising keeps the spec's Function signature. It is not typed generically (e.g. (...a: A) => R → (...a: A) => Promise<R>). This matches what the generator will emit, and wasm exports are typed as ExportValue anyway, so callers already cast.

Tests

webAssemblyPromiseIntegration.ts (dom) and webAssemblyPromiseIntegrationWebworker.ts (webworker) cover:

  • the issue's instantiateStreaming example
  • an Imports object containing a Suspending
  • promising
  • SuspendError via new, a plain call and instanceof narrowing
  • expected errors when Suspending or promising gets a non-function

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug and removed For Milestone Bug PRs that fix a bug with a specific milestone labels Dec 4, 2026
…spendError to DOM and WebWorker libs

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) changed the title [WIP] Add WebAssembly.Suspending and WebAssembly.promising Add WebAssembly.Suspending, WebAssembly.promising, and WebAssembly.SuspendError to DOM and WebWorker libs Dec 4, 2026
@RyanCavanaugh

Copy link
Copy Markdown
Member Author

We need to put this in the DOM generator repo and should brand the interface

interface Suspending {
    readonly [Symbol.toStringTag]: "WebAssembly.Suspending";
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing WebAssembly.Suspending and WebAssembly.promising

2 participants