Browse Source

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>
pull/11557/head
Nicholas H.Tollervey 1 year ago
committed by Damien George
parent
commit
14c2b64131
  1. 4
      ports/webassembly/library.js

4
ports/webassembly/library.js

@ -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…
Cancel
Save