Skip to content

Commit

Permalink
repl: do not defined wasi on global with no flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cola119 committed Nov 23, 2022
1 parent 80dcc06 commit 2546e42
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 Down Expand Up @@ -37,6 +36,7 @@ if (process.env.NODE_REPL_EXTERNAL_MODULE) {
process.exit(kGenericUserError);
}

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 2546e42

Please sign in to comment.