Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

JSPI integration

Open
#131 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
wasm
Domain
compilers

Research direction

Start with the JSPI integration description, especially WebAssembly.Suspending, WebAssembly.promising, Promise.then, the imported JSPI event tag, and resume_throw. Determine whether the JSPI event should be importable and specify the behavior and use cases clearly enough for a follow-up proposal or implementation.

Written by the indexing model from the issue text.

Description

JSPI can be seen (and potentially re-specified) as using core stack switching. Specifically, the WebAssembly.Suspending import wrappers can be seen as suspending with a JSPI event tag with type [externref] -> [externref]. The externref sent on the suspension is the Promise whose resolution will resume the suspended WebAssembly. The JSPI event is handled in the WebAssembly.promising export wrapper, which calls Promise.then to arrange for the continuation to be resumed when the promise is resolved. When the continuation is resumed, the WebAssembly.Suspending wrapper has to do some additional work to unbox the values from the resolved Promise and return them back into Wasm.

This formulation of JSPI raises the questions of what would happen if the JSPI event tag were made available to be imported into user Wasm modules and whether this would be useful to allow.

Suspending with the imported JSPI tag and accompanying externref holding a Promise would be equivalent to calling an imported JSPI-wrapped JS function that simply takes and returns that Promise, but without the overhead of actually calling an import. If the suspension reaches a WebAssembly.promising export wrapper, it would chain the resumption of the resulting continuation onto the Promise just like it would for a "normal" JSPI suspension.

Handling an event with the JSPI tag would give you an externref holding a Promise and a continuation. At that point you could call out to JS to manually chain the continuation onto the Promise like the normal WebAssembly.promising export wrapper does, or alternatively you could do anything else. For example, you might chain a callback onto the Promise that does not immediately resume the continuation, but rather puts it onto some application-managed scheduling queue. Or maybe you could arrange for the continuation to be canceled with resume_throw if the Promise is not resolved within a certain amount of time. The possibilities are endless, and more importantly, they cannot be fully replicated just by JSPI and import calls.

In conclusion, I think that yes, it would be reasonable and useful to make the JSPI event importable. (But of course we can always add this as a follow-up once demand for it materializes.)

Dominant language
WebAssembly
Stars
216
Forks
19
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from WebAssembly/stack-switching

All issues in WebAssembly/stack-switching

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.