repl: don't override all internal repl defaults
The createInternalRepl() module accepts an options object as an argument. However, if one is provided, it overrides all of the default options. This commit applies the options object to the defaults, only changing the values that are explicitly set. PR-URL: https://github.com/nodejs/node/pull/7826 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
f18b1c91b8
commit
2d4a521d58
@ -5,7 +5,8 @@ const REPL = require('repl');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const debug = require('util').debuglog('repl');
|
const util = require('util');
|
||||||
|
const debug = util.debuglog('repl');
|
||||||
|
|
||||||
module.exports = Object.create(REPL);
|
module.exports = Object.create(REPL);
|
||||||
module.exports.createInternalRepl = createRepl;
|
module.exports.createInternalRepl = createRepl;
|
||||||
@ -19,12 +20,12 @@ function createRepl(env, opts, cb) {
|
|||||||
cb = opts;
|
cb = opts;
|
||||||
opts = null;
|
opts = null;
|
||||||
}
|
}
|
||||||
opts = opts || {
|
opts = util._extend({
|
||||||
ignoreUndefined: false,
|
ignoreUndefined: false,
|
||||||
terminal: process.stdout.isTTY,
|
terminal: process.stdout.isTTY,
|
||||||
useGlobal: true,
|
useGlobal: true,
|
||||||
breakEvalOnSigint: true
|
breakEvalOnSigint: true
|
||||||
};
|
}, opts);
|
||||||
|
|
||||||
if (parseInt(env.NODE_NO_READLINE)) {
|
if (parseInt(env.NODE_NO_READLINE)) {
|
||||||
opts.terminal = false;
|
opts.terminal = false;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// Flags: --expose-internals
|
// Flags: --expose-internals
|
||||||
|
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const stream = require('stream');
|
const stream = require('stream');
|
||||||
const REPL = require('internal/repl');
|
const REPL = require('internal/repl');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
@ -46,6 +46,10 @@ function run(test) {
|
|||||||
|
|
||||||
REPL.createInternalRepl(env, opts, function(err, repl) {
|
REPL.createInternalRepl(env, opts, function(err, repl) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
|
// The REPL registers 'module' and 'require' globals
|
||||||
|
common.allowGlobals(repl.context.module, repl.context.require);
|
||||||
|
|
||||||
assert.equal(expected.terminal, repl.terminal,
|
assert.equal(expected.terminal, repl.terminal,
|
||||||
'Expected ' + inspect(expected) + ' with ' + inspect(env));
|
'Expected ' + inspect(expected) + ' with ' + inspect(env));
|
||||||
assert.equal(expected.useColors, repl.useColors,
|
assert.equal(expected.useColors, repl.useColors,
|
||||||
|
@ -35,6 +35,10 @@ const replHistoryPath = path.join(common.tmpDir, '.node_repl_history');
|
|||||||
const checkResults = common.mustCall(function(err, r) {
|
const checkResults = common.mustCall(function(err, r) {
|
||||||
if (err)
|
if (err)
|
||||||
throw err;
|
throw err;
|
||||||
|
|
||||||
|
// The REPL registers 'module' and 'require' globals
|
||||||
|
common.allowGlobals(r.context.module, r.context.require);
|
||||||
|
|
||||||
r.input.end();
|
r.input.end();
|
||||||
const stat = fs.statSync(replHistoryPath);
|
const stat = fs.statSync(replHistoryPath);
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
|
@ -262,6 +262,9 @@ function runTest(assertCleaned) {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The REPL registers 'module' and 'require' globals
|
||||||
|
common.allowGlobals(repl.context.module, repl.context.require);
|
||||||
|
|
||||||
repl.once('close', () => {
|
repl.once('close', () => {
|
||||||
if (repl._flushing) {
|
if (repl._flushing) {
|
||||||
repl.once('flushHistory', onClose);
|
repl.once('flushHistory', onClose);
|
||||||
|
@ -7,8 +7,6 @@ const stream = require('stream');
|
|||||||
const repl = require('internal/repl');
|
const repl = require('internal/repl');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
common.globalCheck = false;
|
|
||||||
|
|
||||||
// Array of [useGlobal, expectedResult] pairs
|
// Array of [useGlobal, expectedResult] pairs
|
||||||
const globalTestCases = [
|
const globalTestCases = [
|
||||||
[false, 'undefined'],
|
[false, 'undefined'],
|
||||||
@ -20,6 +18,9 @@ const globalTest = (useGlobal, cb, output) => (err, repl) => {
|
|||||||
if (err)
|
if (err)
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
|
||||||
|
// The REPL registers 'module' and 'require' globals
|
||||||
|
common.allowGlobals(repl.context.module, repl.context.require);
|
||||||
|
|
||||||
let str = '';
|
let str = '';
|
||||||
output.on('data', (data) => (str += data));
|
output.on('data', (data) => (str += data));
|
||||||
global.lunch = 'tacos';
|
global.lunch = 'tacos';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user