summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas H.Tollervey <ntoll@ntoll.org>2023-07-11 18:05:28 +0100
committerDamien George <damien@micropython.org>2023-07-13 13:24:35 +1000
commit14c2b641312c7faec20b521b910a6354280ca068 (patch)
treeb7c2c9984bcfb36a194f0a5fed797cfccae28ca3
parent88771c150098df53aa6a3fedcdd25b11eeb4e134 (diff)
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>
-rw-r--r--ports/webassembly/library.js4
1 files changed, 2 insertions, 2 deletions
diff --git a/ports/webassembly/library.js b/ports/webassembly/library.js
index fc5b54248..009b0a4dc 100644
--- a/ports/webassembly/library.js
+++ b/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');