Fix #1651 - Avoid leaks from the registered module (#1655)

This commit is contained in:
Andrea Giammarchi
2023-08-29 22:32:05 +02:00
committed by GitHub
parent e48e6276e1
commit 93539c9b5a
4 changed files with 40 additions and 38 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,26 +1,26 @@
{ {
"name": "@pyscript/core", "name": "@pyscript/core",
"version": "0.1.5", "version": "0.1.6",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@pyscript/core", "name": "@pyscript/core",
"version": "0.1.5", "version": "0.1.6",
"license": "APACHE-2.0", "license": "APACHE-2.0",
"dependencies": { "dependencies": {
"@ungap/with-resolvers": "^0.1.0", "@ungap/with-resolvers": "^0.1.0",
"basic-devtools": "^0.1.6", "basic-devtools": "^0.1.6",
"polyscript": "^0.1.10" "polyscript": "^0.1.13"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-node-resolve": "^15.1.0", "@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-terser": "^0.4.3", "@rollup/plugin-terser": "^0.4.3",
"rollup": "^3.28.0", "rollup": "^3.28.1",
"rollup-plugin-postcss": "^4.0.2", "rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-string": "^3.0.0", "rollup-plugin-string": "^3.0.0",
"static-handler": "^0.4.2", "static-handler": "^0.4.2",
"typescript": "^5.1.6" "typescript": "^5.2.2"
} }
}, },
"node_modules/@jridgewell/gen-mapping": { "node_modules/@jridgewell/gen-mapping": {
@@ -82,9 +82,9 @@
} }
}, },
"node_modules/@rollup/plugin-node-resolve": { "node_modules/@rollup/plugin-node-resolve": {
"version": "15.1.0", "version": "15.2.1",
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.1.0.tgz", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.2.1.tgz",
"integrity": "sha512-xeZHCgsiZ9pzYVgAo9580eCGqwh/XCEUM9q6iQfGNocjgkufHAqC3exA+45URvhiYV8sBF9RlBai650eNs7AsA==", "integrity": "sha512-nsbUg588+GDSu8/NS8T4UAshO6xeaOfINNuXeVHcKV02LJtoRaM1SiOacClw4kws1SFiNhdLGxlbMY9ga/zs/w==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@rollup/pluginutils": "^5.0.1", "@rollup/pluginutils": "^5.0.1",
@@ -318,9 +318,9 @@
} }
}, },
"node_modules/coincident": { "node_modules/coincident": {
"version": "0.11.3", "version": "0.11.5",
"resolved": "https://registry.npmjs.org/coincident/-/coincident-0.11.3.tgz", "resolved": "https://registry.npmjs.org/coincident/-/coincident-0.11.5.tgz",
"integrity": "sha512-a/jBWoCv8O/YyfqXt0P8ees64tkuGKKubHj3KHTezxVmKYcUPVnaSAk9kcZxzDUGfKB5/CgM1rhaPrlQ9el9eg==", "integrity": "sha512-aorzP9U2j4JzDj+2I9CM3HaU16J5rmaWptkzHMbgGDmR+c/r8PXJ/2Asq2FImoxIJVfZiMjFt8Vtglan/5i8/A==",
"dependencies": { "dependencies": {
"@ungap/structured-clone": "^1.2.0", "@ungap/structured-clone": "^1.2.0",
"@ungap/with-resolvers": "^0.1.0" "@ungap/with-resolvers": "^0.1.0"
@@ -935,14 +935,14 @@
} }
}, },
"node_modules/polyscript": { "node_modules/polyscript": {
"version": "0.1.10", "version": "0.1.13",
"resolved": "https://registry.npmjs.org/polyscript/-/polyscript-0.1.10.tgz", "resolved": "https://registry.npmjs.org/polyscript/-/polyscript-0.1.13.tgz",
"integrity": "sha512-NdO0inJIJyNgM8bYvD9z8aYbs1chQWq3iNtXjj7YrDT84A7IOVELPCFDlXzLU8UngpO/yQm3j4YrEoln89LbsA==", "integrity": "sha512-U7TXKnne6J8kaAGX5Q8vKDXArO5J3jnyMgKXHB6KaMNoyUhNtZfYwHfK9mOT60/9huXmN6D48vQkG3TuUevY3A==",
"dependencies": { "dependencies": {
"@ungap/structured-clone": "^1.2.0", "@ungap/structured-clone": "^1.2.0",
"@ungap/with-resolvers": "^0.1.0", "@ungap/with-resolvers": "^0.1.0",
"basic-devtools": "^0.1.6", "basic-devtools": "^0.1.6",
"coincident": "^0.11.3" "coincident": "^0.11.5"
} }
}, },
"node_modules/postcss": { "node_modules/postcss": {
@@ -1550,9 +1550,9 @@
} }
}, },
"node_modules/rollup": { "node_modules/rollup": {
"version": "3.28.0", "version": "3.28.1",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-3.28.0.tgz", "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.28.1.tgz",
"integrity": "sha512-d7zhvo1OUY2SXSM6pfNjgD5+d0Nz87CUp4mt8l/GgVP3oBsPwzNvSzyu1me6BSG9JIgWNTVcafIXBIyM8yQ3yw==", "integrity": "sha512-R9OMQmIHJm9znrU3m3cpE8uhN0fGdXiawME7aZIpQqvpS/85+Vt1Hq1/yVIcYfOmaQiHjvXkQAoJukvLpau6Yw==",
"dev": true, "dev": true,
"bin": { "bin": {
"rollup": "dist/bin/rollup" "rollup": "dist/bin/rollup"
@@ -1806,9 +1806,9 @@
"dev": true "dev": true
}, },
"node_modules/typescript": { "node_modules/typescript": {
"version": "5.1.6", "version": "5.2.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz",
"integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==",
"dev": true, "dev": true,
"bin": { "bin": {
"tsc": "bin/tsc", "tsc": "bin/tsc",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@pyscript/core", "name": "@pyscript/core",
"version": "0.1.5", "version": "0.1.6",
"type": "module", "type": "module",
"description": "PyScript", "description": "PyScript",
"main": "./core.js", "main": "./core.js",
@@ -33,16 +33,16 @@
"dependencies": { "dependencies": {
"@ungap/with-resolvers": "^0.1.0", "@ungap/with-resolvers": "^0.1.0",
"basic-devtools": "^0.1.6", "basic-devtools": "^0.1.6",
"polyscript": "^0.1.10" "polyscript": "^0.1.13"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-node-resolve": "^15.1.0", "@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-terser": "^0.4.3", "@rollup/plugin-terser": "^0.4.3",
"rollup": "^3.28.0", "rollup": "^3.28.1",
"rollup-plugin-postcss": "^4.0.2", "rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-string": "^3.0.0", "rollup-plugin-string": "^3.0.0",
"static-handler": "^0.4.2", "static-handler": "^0.4.2",
"typescript": "^5.1.6" "typescript": "^5.2.2"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -83,12 +83,13 @@ const registerModule = ({ XWorker: $XWorker, interpreter, io }) => {
// provide the regular Pyodide globals instead of those from xworker // provide the regular Pyodide globals instead of those from xworker
const pyDisplay = interpreter.runPython( const pyDisplay = interpreter.runPython(
[ [
"import js", "import js as window",
"document=js.document", "document=window.document",
"window=js",
display, display,
"display", "display",
].join("\n"), ].join("\n"),
// avoid leaking on global
{ globals: interpreter.runPython("{}") },
); );
interpreter.registerJsModule("pyscript", { interpreter.registerJsModule("pyscript", {
PyWorker, PyWorker,
@@ -140,16 +141,17 @@ export const hooks = {
}; };
const workerPyScriptModule = [ const workerPyScriptModule = [
"from pyodide_js import FS", "from pathlib import Path as _Path",
`FS.writeFile('./pyscript.py', ${JSON.stringify( `_Path("./pyscript.py").write_text(${JSON.stringify(
[ [
"import polyscript", "from polyscript import xworker as _xworker",
"document=polyscript.xworker.window.document", "window=_xworker.window",
"window=polyscript.xworker.window", "document=window.document",
"sync=polyscript.xworker.sync", "sync=_xworker.sync",
display, display,
].join("\n"), ].join("\n"),
)})`, )})`,
"del _Path",
].join("\n"); ].join("\n");
const workerHooks = { const workerHooks = {