]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.14] gh-124621: Emscripten: Add support for async input devices (GH-136822) (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 22 Jul 2025 09:51:02 +0000 (11:51 +0200)
committerGitHub <noreply@github.com>
Tue, 22 Jul 2025 09:51:02 +0000 (11:51 +0200)
commitd118bc061b4f7ea916bb25f19c5c7f8e1923fbc7
tree945aa1e722086603c1ed8f07eea8b339e39226a0
parent8e43b130f7b27657a8bb775e398c0dce325b4741
[3.14] gh-124621: Emscripten: Add support for async input devices (GH-136822) (GH-136935)

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`.
(cherry picked from commit 7ae4749d064bd49b0dd96172fee20c1f1678d9e9)

Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
Lib/test/test_capi/test_emscripten.py [new file with mode: 0644]
Modules/_testinternalcapi.c
Python/emscripten_syscalls.c
Tools/wasm/emscripten/__main__.py