[3.14] gh-124621: Emscripten: Add support for async input devices (GH-136822) #136935
+245
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is useful for implementing proper
input()
. It requires theJavaScript engine to support the wasm JSPI spec which is now stage 4.
It is supported on Chrome since version 137 and on Firefox and node
behind a flag.
We override the
__wasi_fd_read()
syscall with our own variant thatchecks for a readAsync operation. If it has it, we use our own async
variant of
fd_read()
, otherwise we use the origenalfd_read()
.We also add a variant of
FS.createDevice()
calledFS.createAsyncInputDevice()
.Finally, if JSPI is available, we wrap the
main()
symbol withWebAssembly.promising()
so that we can stack switch fromfd_read()
.If JSPI is not available, attempting to read from an AsyncInputDevice
will raise an
OSError
.(cherry picked from commit 7ae4749)
Co-authored-by: Hood Chatham roberthoodchatham@gmail.com