From e0fd7652b66b177d5d645601cd78b639d762568b Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 13 Apr 2018 10:03:38 -0400 Subject: [PATCH] Don't dump everything in the global namespace --- Makefile | 1 + src/pyodide.js | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index cb7da329d..ca8c6b3ae 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ CXX=em++ OPTFLAGS=-O3 CXXFLAGS=-std=c++14 $(OPTFLAGS) -g -I$(CPYTHONINC) -Wno-warn-absolute-paths LDFLAGS=\ + -s MODULARIZE=1 \ $(CPYTHONROOT)/installs/python-$(PYVERSION)/lib/libpython$(PYMINOR).a \ -s "BINARYEN_METHOD='native-wasm'" \ -s TOTAL_MEMORY=268435456 \ diff --git a/src/pyodide.js b/src/pyodide.js index 813db45cd..b5b47670a 100644 --- a/src/pyodide.js +++ b/src/pyodide.js @@ -1,4 +1,3 @@ -var pyodide = {} { let baseURL = "{{DEPLOY}}"; @@ -7,14 +6,17 @@ var pyodide = {} wasmXHR.open('GET', wasmURL, true); wasmXHR.responseType = 'arraybuffer'; wasmXHR.onload = function() { + let Module = {}; + if (wasmXHR.status === 200 || wasmXHR.status === 0) { - pyodide.wasmBinary = wasmXHR.response; + Module.wasmBinary = wasmXHR.response; } else { alert("Couldn't download the pyodide.asm.wasm binary. Response was " + wasmXHR.status); } - pyodide.baseURL = baseURL; + Module.baseURL = baseURL; var script = document.createElement('script'); + script.onload = function() { window.pyodide = pyodide(Module); }; script.src = baseURL + "pyodide.asm.js"; document.body.appendChild(script); };