Skip to content

Commit

Permalink
repl: do not define wasi on global with no flag
Browse files Browse the repository at this point in the history
PR-URL: #45595
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
cola119 authored and danielleadams committed Jan 3, 2023
1 parent ebc89f1 commit b999983
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/main/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {
markBootstrapComplete
} = require('internal/process/pre_execution');

const esmLoader = require('internal/process/esm_loader');
const {
evalScript
} = require('internal/process/execution');
Expand All @@ -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.');
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-repl-built-in-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ assert.doesNotMatch(
stdout,
/Uncaught Error: Cannot find module 'wasi'[\w\W]+- <repl>\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/);
}

0 comments on commit b999983

Please sign in to comment.