repl: don't override all internal repl defaults · nodejs/node@2d4a521

5 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -5,7 +5,8 @@ const REPL = require('repl');

55

const path = require('path');

66

const fs = require('fs');

77

const os = require('os');

8-

const debug = require('util').debuglog('repl');

8+

const util = require('util');

9+

const debug = util.debuglog('repl');

910
1011

module.exports = Object.create(REPL);

1112

module.exports.createInternalRepl = createRepl;

@@ -19,12 +20,12 @@ function createRepl(env, opts, cb) {

1920

cb = opts;

2021

opts = null;

2122

}

22-

opts = opts || {

23+

opts = util._extend({

2324

ignoreUndefined: false,

2425

terminal: process.stdout.isTTY,

2526

useGlobal: true,

2627

breakEvalOnSigint: true

27-

};

28+

}, opts);

2829
2930

if (parseInt(env.NODE_NO_READLINE)) {

3031

opts.terminal = false;

Original file line numberDiff line numberDiff line change

@@ -2,7 +2,7 @@

22
33

// Flags: --expose-internals

44
5-

require('../common');

5+

const common = require('../common');

66

const stream = require('stream');

77

const REPL = require('internal/repl');

88

const assert = require('assert');

@@ -46,6 +46,10 @@ function run(test) {

4646
4747

REPL.createInternalRepl(env, opts, function(err, repl) {

4848

if (err) throw err;

49+
50+

// The REPL registers 'module' and 'require' globals

51+

common.allowGlobals(repl.context.module, repl.context.require);

52+
4953

assert.equal(expected.terminal, repl.terminal,

5054

'Expected ' + inspect(expected) + ' with ' + inspect(env));

5155

assert.equal(expected.useColors, repl.useColors,

Original file line numberDiff line numberDiff line change

@@ -35,6 +35,10 @@ const replHistoryPath = path.join(common.tmpDir, '.node_repl_history');

3535

const checkResults = common.mustCall(function(err, r) {

3636

if (err)

3737

throw err;

38+
39+

// The REPL registers 'module' and 'require' globals

40+

common.allowGlobals(r.context.module, r.context.require);

41+
3842

r.input.end();

3943

const stat = fs.statSync(replHistoryPath);

4044

assert.strictEqual(

Original file line numberDiff line numberDiff line change

@@ -262,6 +262,9 @@ function runTest(assertCleaned) {

262262

throw err;

263263

}

264264
265+

// The REPL registers 'module' and 'require' globals

266+

common.allowGlobals(repl.context.module, repl.context.require);

267+
265268

repl.once('close', () => {

266269

if (repl._flushing) {

267270

repl.once('flushHistory', onClose);

Original file line numberDiff line numberDiff line change

@@ -7,8 +7,6 @@ const stream = require('stream');

77

const repl = require('internal/repl');

88

const assert = require('assert');

99
10-

common.globalCheck = false;

11-
1210

// Array of [useGlobal, expectedResult] pairs

1311

const globalTestCases = [

1412

[false, 'undefined'],

@@ -20,6 +18,9 @@ const globalTest = (useGlobal, cb, output) => (err, repl) => {

2018

if (err)

2119

return cb(err);

2220
21+

// The REPL registers 'module' and 'require' globals

22+

common.allowGlobals(repl.context.module, repl.context.require);

23+
2324

let str = '';

2425

output.on('data', (data) => (str += data));

2526

global.lunch = 'tacos';