Skip to content

Editorial review: Document Wasm JS Promise integration#44484

Merged
chrisdavidmills merged 10 commits into
mdn:mainfrom
chrisdavidmills:wasm-js-pi
Jul 9, 2026
Merged

Editorial review: Document Wasm JS Promise integration#44484
chrisdavidmills merged 10 commits into
mdn:mainfrom
chrisdavidmills:wasm-js-pi

Conversation

@chrisdavidmills

@chrisdavidmills chrisdavidmills commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Description

Firefox 153 adds support for WebAssembly JS Promise Integration (JS-PI): see https://bugzilla.mozilla.org/show_bug.cgi?id=2044809.

This PR adds:

  • A WebAssembly.Suspending reference.
  • A WebAssembly.promising() reference.
  • A WebAssembly.SuspendError reference.
  • A Fx 153 release note for the overall feature.

Motivation

Additional details

Related issues and pull requests

See #44468 for tracking.

@chrisdavidmills chrisdavidmills requested review from a team as code owners June 16, 2026 14:12
@chrisdavidmills chrisdavidmills requested review from pepelsbey and removed request for a team June 16, 2026 14:12
@github-actions github-actions Bot added Content:wasm WebAssembly docs Content:Firefox Content in the Mozilla/Firefox subtree size/m [PR only] 51-500 LoC changed labels Jun 16, 2026
@chrisdavidmills chrisdavidmills changed the title Document Wasm JS Promise integration Technical review: Document Wasm JS Promise integration Jun 16, 2026
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@eqrion eqrion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Also, I think you're missing a page for WebAssembly.SuspendError [1] It's essentially the same thing as WebAssembly.CompileError, so I think you could just re-use that page. I've also mentioned the one place we throw a SuspendError.

[1] https://webassembly.github.io/js-promise-integration/js-api/#exceptiondef-suspenderror

Comment on lines +24 to +28
### Return value

A `Promise` that fulfills with the return value of the exported function.

### Exceptions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebAssembly.promising actually returns a new function that wraps the original one and can be called. The resulting wrapper function takes the same arguments as the wrapped function, but returns a promise instead of the results.

So you do:

let original = wasmInstance.exports.foo;
let promisingWrapper = WebAssembly.promising(original);
assert(promisingWrapper instanceof Function);
assert(promisingWrapper(...) instanceof Promise);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, makes sense. I updated it to:

A function that wraps the original function passed into the promising() call, and can itself be called. The wrapper function takes the same arguments as the wrapped function, and returns a promise that fulfills with the wrapped function's results.

sidebar: webassemblysidebar
---

The **`WebAssembly.Suspending()`** constructor creates a new [`Suspending`](/en-US/docs/WebAssembly/Reference/JavaScript_interface/Suspending) object instance representing a suspending function.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably worth adding that the only purpose of WebAssembly.Suspending is to mark which imported functions are suspending functions. You can't do anything with a Suspending interface except pass it into the imports object for a wasm module. It's a weird design, but the least bad of the options we could find.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a note to the main WebAssembly.Suspending page rather than the constructor page, as I thought it was a better location:

Note

The only purpose of WebAssembly.Suspending is to mark which imported functions are suspending functions when passing them into a Wasm module imports object.

};
```

This creates a suspending function. No changes are necessary to use it inside the Wasm module: when it is called, execution is suspended until the `Promise` resolves, then resumed with the resolving value available on the stack. However, when exporting a Wasm function that relies on the suspending imported function back to the JavaScript host, you need to wrap the export in a `WebAssembly.promising()` call:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to mention that if you don't wrap the export in WebAssembly.promising, then you will get a WebAssembly.SuspendError when you try to suspend.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've added an entry to the WebAssembly.Suspending() constructor's "Exceptions" section that reads:

@chrisdavidmills

Copy link
Copy Markdown
Contributor Author

LGTM. Also, I think you're missing a page for WebAssembly.SuspendError [1] It's essentially the same thing as WebAssembly.CompileError, so I think you could just re-use that page. I've also mentioned the one place we throw a SuspendError.

Comments answered, SuspendError docs added!

@chrisdavidmills chrisdavidmills requested a review from eqrion June 23, 2026 16:34

@eqrion eqrion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@chrisdavidmills

Copy link
Copy Markdown
Contributor Author

Looks good, thanks!

Awesome, cheers for the review!

@pepelsbey, do you have time to review this one?

@pepelsbey

Copy link
Copy Markdown
Member

@pepelsbey, do you have time to review this one?

Sure! Is it an editorial review now? I would wait for the technical one to be over first.

@chrisdavidmills chrisdavidmills changed the title Technical review: Document Wasm JS Promise integration Editorial review: Document Wasm JS Promise integration Jun 24, 2026
@chrisdavidmills

Copy link
Copy Markdown
Contributor Author

@pepelsbey, do you have time to review this one?

Sure! Is it an editorial review now? I would wait for the technical one to be over first.

Oops, yeah, sorry; marked as editorial now.

@pepelsbey pepelsbey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you 🙂

See suggestion below. Regarding the console.log(e instanceof…

I found a four more non-global WebAssembly demos that would fail if not prefixed with Webassembly: search for console.log(e instanceof in files/en-us/webassembly.

  • files/en-us/webassembly/reference/javascript_interface/compileerror/compileerror/index.md
  • files/en-us/webassembly/reference/javascript_interface/compileerror/index.md
  • files/en-us/webassembly/reference/javascript_interface/linkerror/index.md
  • files/en-us/webassembly/reference/javascript_interface/linkerror/linkerror/index.md

These two are prefixed:

  • files/en-us/webassembly/reference/javascript_interface/runtimeerror/index.md
  • files/en-us/webassembly/reference/javascript_interface/runtimeerror/runtimeerror/index.md

Comment thread files/en-us/webassembly/reference/javascript_interface/promising_static/index.md Outdated
Comment thread files/en-us/webassembly/reference/javascript_interface/suspending/index.md Outdated
Comment thread files/en-us/webassembly/reference/javascript_interface/index.md Outdated
Comment thread files/en-us/webassembly/reference/javascript_interface/promising_static/index.md Outdated
Comment thread files/en-us/webassembly/reference/javascript_interface/suspenderror/index.md Outdated
chrisdavidmills and others added 7 commits July 9, 2026 09:30
…ng_static/index.md

Co-authored-by: Vadim Makeev <hi@pepelsbey.dev>
…ing/index.md

Co-authored-by: Vadim Makeev <hi@pepelsbey.dev>
Co-authored-by: Vadim Makeev <hi@pepelsbey.dev>
…ng_static/index.md

Co-authored-by: Vadim Makeev <hi@pepelsbey.dev>
…error/index.md

Co-authored-by: Vadim Makeev <hi@pepelsbey.dev>
…error/suspenderror/index.md

Co-authored-by: Vadim Makeev <hi@pepelsbey.dev>
@chrisdavidmills chrisdavidmills requested a review from pepelsbey July 9, 2026 09:07

@pepelsbey pepelsbey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Thank you

@chrisdavidmills chrisdavidmills merged commit 3934778 into mdn:main Jul 9, 2026
9 checks passed
@chrisdavidmills chrisdavidmills deleted the wasm-js-pi branch July 9, 2026 10:05
@chrisdavidmills

Copy link
Copy Markdown
Contributor Author

Perfect! Thank you

Lovely, thanks for the reviews, @pepelsbey and @eqrion.

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

Labels

Content:Firefox Content in the Mozilla/Firefox subtree Content:wasm WebAssembly docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants