Skip to content

Commit

Permalink
repl: default useGlobal to true
Browse files Browse the repository at this point in the history
This is a partial revert of
15157c3. This change lead to a
regression that broke require() in the CLI REPL, as imported
files were evaluated in a different context.

Refs: #5703
Fixes: #7788
PR-URL: #7795
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
  • Loading branch information
cjihrig authored and evanlucas committed Aug 2, 2016
1 parent e82e804 commit 6e6cf36
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function createRepl(env, opts, cb) {
opts = opts || {
ignoreUndefined: false,
terminal: process.stdout.isTTY,
useGlobal: false,
useGlobal: true,
breakEvalOnSigint: true
};

Expand Down
28 changes: 28 additions & 0 deletions test/parallel/test-repl-require-context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const path = require('path');
const child = cp.spawn(process.execPath, ['--interactive']);
const fixture = path.join(common.fixturesDir, 'is-object.js').replace(/\\/g,
'/');
let output = '';

child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => {
output += data;
});

child.on('exit', common.mustCall(() => {
const results = output.split('\n').map((line) => {
return line.replace(/\w*>\w*/, '').trim();
});

assert.deepStrictEqual(results, ['undefined', 'true', 'true', '']);
}));

child.stdin.write('const isObject = (obj) => obj.constructor === Object;\n');
child.stdin.write('isObject({});\n');
child.stdin.write(`require('${fixture}').isObject({});\n`);
child.stdin.write('.exit');
child.stdin.end();

0 comments on commit 6e6cf36

Please sign in to comment.