From b999983c30632ad28ab9c749cf70455d4691866a Mon Sep 17 00:00:00 2001 From: Kohei Ueno Date: Sat, 26 Nov 2022 19:51:15 +0900 Subject: [PATCH] repl: do not define `wasi` on global with no flag PR-URL: https://github.com/nodejs/node/pull/45595 Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca --- lib/internal/main/repl.js | 2 +- test/parallel/test-repl-built-in-modules.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/internal/main/repl.js b/lib/internal/main/repl.js index 7da68dc05e84b4..34fe20b18ad4d8 100644 --- a/lib/internal/main/repl.js +++ b/lib/internal/main/repl.js @@ -8,7 +8,6 @@ const { markBootstrapComplete } = require('internal/process/pre_execution'); -const esmLoader = require('internal/process/esm_loader'); const { evalScript } = require('internal/process/execution'); @@ -34,6 +33,7 @@ if (process.env.NODE_REPL_EXTERNAL_MODULE) { process.exit(1); } + const esmLoader = require('internal/process/esm_loader'); esmLoader.loadESM(() => { console.log(`Welcome to Node.js ${process.version}.\n` + 'Type ".help" for more information.'); diff --git a/test/parallel/test-repl-built-in-modules.js b/test/parallel/test-repl-built-in-modules.js index b1845d83e68332..6273367e65a2a7 100644 --- a/test/parallel/test-repl-built-in-modules.js +++ b/test/parallel/test-repl-built-in-modules.js @@ -30,3 +30,19 @@ assert.doesNotMatch( stdout, /Uncaught Error: Cannot find module 'wasi'[\w\W]+- \n/); assert.match(stdout, /{ WASI: \[class WASI\] }/); + +{ + const res = cp.execFileSync(process.execPath, ['-i'], { + input: "'wasi' in global", + encoding: 'utf8', + }); + // `wasi` shouldn't be defined on global when the flag is not set + assert.match(res, /false\n/); +} +{ + const res = cp.execFileSync(process.execPath, ['-i', '--experimental-wasi-unstable-preview1'], { + input: "'wasi' in global", + encoding: 'utf8', + }); + assert.match(res, /true\n/); +}