Skip to content

Commit b2ad7e2

Browse files
elibdevdpgeorge
authored andcommitted
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 micropython#10692. Signed-off-by: Eli Bierman <[email protected]>
1 parent 0e215a9 commit b2ad7e2

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

ports/webassembly/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ using the require command and the general API outlined below. For example:
4949
var mp_js = require('./build/micropython.js');
5050

5151
mp_js_init(64 * 1024);
52-
mp_js_do_str("print('hello world')\n");
52+
await mp_js_do_str("print('hello world')\n");
5353
```
5454

5555
Running with HTML
@@ -77,7 +77,7 @@ something to stdout. The following code demonstrates basic functionality:
7777
Module["onRuntimeInitialized"] = async function() {
7878
mp_js_startup();
7979
mp_js_init(64 * 1024);
80-
mp_js_do_str("print('hello world')");
80+
await mp_js_do_str("print('hello world')");
8181
};
8282
</script>
8383
</body>
@@ -108,7 +108,7 @@ Initialize MicroPython with the given stack size in bytes. This must be
108108
called before attempting to interact with MicroPython.
109109

110110
```
111-
mp_js_do_str(code)
111+
await mp_js_do_str(code)
112112
```
113113

114114
Execute the input code. `code` must be a `string`.

ports/webassembly/wrapper.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var Module = {};
2929
var mainProgram = function()
3030
{
3131
mp_js_init = Module.cwrap('mp_js_init', 'null', ['number']);
32-
mp_js_do_str = Module.cwrap('mp_js_do_str', 'number', ['string']);
32+
mp_js_do_str = Module.cwrap('mp_js_do_str', 'number', ['string'], {async: true});
3333
mp_js_init_repl = Module.cwrap('mp_js_init_repl', 'null', ['null']);
3434
mp_js_process_char = Module.cwrap('mp_js_process_char', 'number', ['number']);
3535

@@ -75,7 +75,9 @@ var mainProgram = function()
7575
}
7676
});
7777
} else {
78-
process.exitCode = mp_js_do_str(contents);
78+
mp_js_do_str(contents).then(exitCode => {
79+
process.exitCode = exitCode
80+
})
7981
}
8082
}
8183
}

0 commit comments

Comments
 (0)