diff options
author | Katie Bell <katie@katharos.id.au> | 2024-05-31 07:58:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-31 07:58:46 (GMT) |
commit | 010aaa32fb93c5033a698d7213469af02d76fef3 (patch) | |
tree | b4d67e42c08c036e66f5395f8bd485fb55d91592 /Tools/wasm/python.worker.js | |
parent | 0d07182821fad7b95a043d006f1ce13a2d22edcb (diff) | |
download | cpython-010aaa32fb93c5033a698d7213469af02d76fef3.zip cpython-010aaa32fb93c5033a698d7213469af02d76fef3.tar.gz cpython-010aaa32fb93c5033a698d7213469af02d76fef3.tar.bz2 |
gh-97747: Improvements to WASM browser REPL. (#97665)
Improvements to WASM browser REPL.
Adds a text box to write and run code outside the REPL, a stop button, and handling of Ctrl-D for EOF.
Diffstat (limited to 'Tools/wasm/python.worker.js')
-rw-r--r-- | Tools/wasm/python.worker.js | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Tools/wasm/python.worker.js b/Tools/wasm/python.worker.js index 1b79460..4ce4e16 100644 --- a/Tools/wasm/python.worker.js +++ b/Tools/wasm/python.worker.js @@ -19,18 +19,18 @@ class StdinBuffer { } stdin = () => { - if (this.numberOfCharacters + 1 === this.readIndex) { + while (this.numberOfCharacters + 1 === this.readIndex) { if (!this.sentNull) { // Must return null once to indicate we're done for now. this.sentNull = true return null } this.sentNull = false + // Prompt will reset this.readIndex to 1 this.prompt() } const char = this.buffer[this.readIndex] this.readIndex += 1 - // How do I send an EOF?? return char } } @@ -71,7 +71,11 @@ var Module = { onmessage = (event) => { if (event.data.type === 'run') { - // TODO: Set up files from event.data.files + if (event.data.files) { + for (const [filename, contents] of Object.entries(event.data.files)) { + Module.FS.writeFile(filename, contents) + } + } const ret = callMain(event.data.args) postMessage({ type: 'finished', |