summaryrefslogtreecommitdiffstats
path: root/Tools/wasm/python.worker.js
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-05-31 09:25:39 (GMT)
committerGitHub <noreply@github.com>2024-05-31 09:25:39 (GMT)
commit7dae73b21b500e34ebb070a4d3774e09d83d6c1d (patch)
tree1b06f87fa5fe5935e94567f0fb7321c2d4ea181b /Tools/wasm/python.worker.js
parent8470593a98a5f17d72bea0df8287f43ba4f7f627 (diff)
downloadcpython-7dae73b21b500e34ebb070a4d3774e09d83d6c1d.zip
cpython-7dae73b21b500e34ebb070a4d3774e09d83d6c1d.tar.gz
cpython-7dae73b21b500e34ebb070a4d3774e09d83d6c1d.tar.bz2
[3.13] gh-97747: Improvements to WASM browser REPL. (GH-97665) (GH-119828)
(cherry picked from commit 010aaa32fb93c5033a698d7213469af02d76fef3) Co-authored-by: Katie Bell <katie@katharos.id.au>
Diffstat (limited to 'Tools/wasm/python.worker.js')
-rw-r--r--Tools/wasm/python.worker.js10
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',