mirror of
https://github.com/python/cpython.git
synced 2025-12-09 02:35:14 +00:00
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`.
This commit is contained in:
parent
1ba23244f3
commit
7ae4749d06
4 changed files with 245 additions and 1 deletions
|
|
@ -263,10 +263,20 @@ def configure_emscripten_python(context, working_dir):
|
|||
REALPATH=abs_path
|
||||
fi
|
||||
|
||||
# Before node 24, --experimental-wasm-jspi uses different API,
|
||||
# After node 24 JSPI is on by default.
|
||||
ARGS=$({host_runner} -e "$(cat <<"EOF"
|
||||
const major_version = Number(process.version.split(".")[0].slice(1));
|
||||
if (major_version === 24) {{
|
||||
process.stdout.write("--experimental-wasm-jspi");
|
||||
}}
|
||||
EOF
|
||||
)")
|
||||
|
||||
# We compute our own path, not following symlinks and pass it in so that
|
||||
# node_entry.mjs can set sys.executable correctly.
|
||||
# Intentionally allow word splitting on NODEFLAGS.
|
||||
exec {host_runner} $NODEFLAGS {node_entry} --this-program="$($REALPATH "$0")" "$@"
|
||||
exec {host_runner} $NODEFLAGS $ARGS {node_entry} --this-program="$($REALPATH "$0")" "$@"
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue