Fix #1531 - Remove overall need for globalThis pollution (#1543)

This commit is contained in:
Andrea Giammarchi
2023-06-19 18:05:45 +02:00
committed by GitHub
parent d6b1c393f6
commit 0a7e1ce0d7
20 changed files with 83 additions and 124 deletions

View File

@@ -1,12 +1,5 @@
import { fetchPaths, stdio } from "./_utils.js";
import {
run,
runAsync,
runEvent,
runWorker,
runWorkerAsync,
writeFile,
} from "./_python.js";
import { run, runAsync, writeFile } from "./_python.js";
const type = "micropython";
@@ -23,11 +16,18 @@ export default {
if (config.fetch) await fetchPaths(this, runtime, config.fetch);
return runtime;
},
setGlobal(interpreter, name, value) {
const id = `__pyscript_${this.type}_${name}`;
globalThis[id] = value;
this.run(interpreter, `from js import ${id};${name}=${id};`);
},
deleteGlobal(interpreter, name) {
const id = `__pyscript_${this.type}_${name}`;
this.run(interpreter, `del ${id};del ${name}`);
delete globalThis[id];
},
run,
runAsync,
runEvent,
runWorker,
runWorkerAsync,
writeFile,
};
/* c8 ignore stop */