webassembly: Replace typeof window check with ENVIRONMENT_IS_NODE flag.
When the "typeof window" check is run within a web worker the window is undefined, causing an error because "require" is only defined in a Node environment. Change the logic to reflect the true intentions of when this code should run, ie in Node only. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
88771c1500
commit
14c2b64131
@ -27,7 +27,7 @@
|
||||
mergeInto(LibraryManager.library, {
|
||||
mp_js_write: function(ptr, len) {
|
||||
const buffer = HEAPU8.subarray(ptr, ptr + len)
|
||||
if (typeof window === 'undefined') {
|
||||
if (ENVIRONMENT_IS_NODE) {
|
||||
process.stdout.write(buffer);
|
||||
} else {
|
||||
const printEvent = new CustomEvent('micropython-print', { detail: buffer });
|
||||
@ -40,7 +40,7 @@ mergeInto(LibraryManager.library, {
|
||||
},
|
||||
|
||||
mp_js_hook: function() {
|
||||
if (typeof window === 'undefined') {
|
||||
if (ENVIRONMENT_IS_NODE) {
|
||||
var mp_interrupt_char = Module.ccall('mp_hal_get_interrupt_char', 'number', ['number'], ['null']);
|
||||
var fs = require('fs');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user