diff options
| author | elibdev <eli@elib.dev> | 2023-06-19 11:56:38 -0400 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-06-27 15:26:42 +1000 |
| commit | b2ad7e238b4e6de86aef646d715cf9a8a5144807 (patch) | |
| tree | 3ce822938245060fb3b94a79910b558fdbc3c39b | |
| parent | 0e215a9fbab5f15f8c459062b5ec75de2a83f403 (diff) | |
webassembly: Make mp_js_do_str asynchronous.
This fixes a bug where `gc.collect()` would crash due to
emscripten_scan_stack being called synchronously within mp_js_do_str. The
fix is to make mp_js_do_str asynchronous.
Fixes #10692.
Signed-off-by: Eli Bierman <eli@elib.dev>
| -rw-r--r-- | ports/webassembly/README.md | 6 | ||||
| -rw-r--r-- | ports/webassembly/wrapper.js | 6 |
2 files changed, 7 insertions, 5 deletions
diff --git a/ports/webassembly/README.md b/ports/webassembly/README.md index 5019d6f90..10cc6aa8c 100644 --- a/ports/webassembly/README.md +++ b/ports/webassembly/README.md @@ -49,7 +49,7 @@ using the require command and the general API outlined below. For example: var mp_js = require('./build/micropython.js'); mp_js_init(64 * 1024); -mp_js_do_str("print('hello world')\n"); +await mp_js_do_str("print('hello world')\n"); ``` Running with HTML @@ -77,7 +77,7 @@ something to stdout. The following code demonstrates basic functionality: Module["onRuntimeInitialized"] = async function() { mp_js_startup(); mp_js_init(64 * 1024); - mp_js_do_str("print('hello world')"); + await mp_js_do_str("print('hello world')"); }; </script> </body> @@ -108,7 +108,7 @@ Initialize MicroPython with the given stack size in bytes. This must be called before attempting to interact with MicroPython. ``` -mp_js_do_str(code) +await mp_js_do_str(code) ``` Execute the input code. `code` must be a `string`. diff --git a/ports/webassembly/wrapper.js b/ports/webassembly/wrapper.js index 981ade5d8..ab92045df 100644 --- a/ports/webassembly/wrapper.js +++ b/ports/webassembly/wrapper.js @@ -29,7 +29,7 @@ var Module = {}; var mainProgram = function() { mp_js_init = Module.cwrap('mp_js_init', 'null', ['number']); - mp_js_do_str = Module.cwrap('mp_js_do_str', 'number', ['string']); + mp_js_do_str = Module.cwrap('mp_js_do_str', 'number', ['string'], {async: true}); mp_js_init_repl = Module.cwrap('mp_js_init_repl', 'null', ['null']); mp_js_process_char = Module.cwrap('mp_js_process_char', 'number', ['number']); @@ -75,7 +75,9 @@ var mainProgram = function() } }); } else { - process.exitCode = mp_js_do_str(contents); + mp_js_do_str(contents).then(exitCode => { + process.exitCode = exitCode + }) } } } |
