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 2024-04-24 13:00:20 +10:00
rodzic 49ce7a6075
commit 45848f77ca
1 zmienionych plików z 2 dodań i 6 usunięć

Wyświetl plik

@ -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) => {