From 14c2b641312c7faec20b521b910a6354280ca068 Mon Sep 17 00:00:00 2001 From: "Nicholas H.Tollervey" Date: Tue, 11 Jul 2023 18:05:28 +0100 Subject: [PATCH] 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 --- ports/webassembly/library.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/webassembly/library.js b/ports/webassembly/library.js index fc5b542488..009b0a4dcc 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');