Browse Source

webassembly/api: Fix waiting for Emscripten module to be loaded.

In modularize mode, the `_createMicroPythonModule()` constructor must be
await'ed on, before `Module` is ready to use.

Signed-off-by: Damien George <damien@micropython.org>
pull/14318/head
Damien George 7 months ago
parent
commit
45848f77ca
  1. 8
      ports/webassembly/api.js

8
ports/webassembly/api.js

@ -38,7 +38,7 @@ export async function loadMicroPython(options) {
{ heapsize: 1024 * 1024, linebuffer: true }, { heapsize: 1024 * 1024, linebuffer: true },
options, options,
); );
const Module = {}; let Module = {};
Module.locateFile = (path, scriptDirectory) => Module.locateFile = (path, scriptDirectory) =>
url || scriptDirectory + path; url || scriptDirectory + path;
Module._textDecoder = new TextDecoder(); Module._textDecoder = new TextDecoder();
@ -83,11 +83,7 @@ export async function loadMicroPython(options) {
Module.stderr = (c) => stderr(new Uint8Array([c])); Module.stderr = (c) => stderr(new Uint8Array([c]));
} }
} }
const moduleLoaded = new Promise((r) => { Module = await _createMicroPythonModule(Module);
Module.postRun = r;
});
_createMicroPythonModule(Module);
await moduleLoaded;
globalThis.Module = Module; globalThis.Module = Module;
proxy_js_init(); proxy_js_init();
const pyimport = (name) => { const pyimport = (name) => {

Loading…
Cancel
Save