]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-124621: Emscripten: Add support for async input devices (GH-136822)
authorHood Chatham <roberthoodchatham@gmail.com>
Sat, 19 Jul 2025 15:14:29 +0000 (17:14 +0200)
committerGitHub <noreply@github.com>
Sat, 19 Jul 2025 15:14:29 +0000 (17:14 +0200)
commit7ae4749d064bd49b0dd96172fee20c1f1678d9e9
tree1da9b1ce6cef794f2077ab9e74aae5331d5a72df
parent1ba23244f3306aa8d19eb4b98cfee6ad4cf514c9
gh-124621: Emscripten: Add support for async input devices (GH-136822)

This is useful for implementing proper `input()`. It requires the
JavaScript 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 that
checks for a readAsync operation. If it has it, we use our own async
variant of `fd_read()`, otherwise we use the original `fd_read()`.
We also add a variant of `FS.createDevice()` called
`FS.createAsyncInputDevice()`.

Finally, if JSPI is available, we wrap the `main()` symbol with
`WebAssembly.promising()` so that we can stack switch from `fd_read()`.
If JSPI is not available, attempting to read from an AsyncInputDevice
will raise an `OSError`.
Lib/test/test_capi/test_emscripten.py [new file with mode: 0644]
Modules/_testinternalcapi.c
Python/emscripten_syscalls.c
Tools/wasm/emscripten/__main__.py