Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/internal/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const REPL = require('repl');
const path = require('path');
const fs = require('fs');
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.createInternalRepl = createRepl;
Expand All @@ -19,11 +20,11 @@ function createRepl(env, opts, cb) {
cb = opts;
opts = null;
}
opts = opts || {
opts = util._extend({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why you wouldn't just use Object.assign here. Looking at the source of util._extend it looks to be identical. What am I missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.assign() was shown to be slower in a few previous issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not in critical path, May be Object.assign() is ok enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a backport, so I don't think it's a good idea to change things here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 If you have problem with implementation fix on master and it can come in another backport

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info. Just for the record, I asked out of curiosity - not because I expected it to change. I had no idea that Object.assign was slower. To see for myself, I ran some tests and also found that to be the case. Thanks for the clarification.

ignoreUndefined: false,
terminal: process.stdout.isTTY,
useGlobal: true
};
}, opts);

if (parseInt(env.NODE_NO_READLINE)) {
opts.terminal = false;
Expand Down
5 changes: 5 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ if (global.Symbol) {
knownGlobals.push(Symbol);
}

function allowGlobals() {
knownGlobals = knownGlobals.concat(Array.from(arguments));
}
exports.allowGlobals = allowGlobals;

function leakedGlobals() {
var leaked = [];

Expand Down
6 changes: 5 additions & 1 deletion test/parallel/test-repl-envvars.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Flags: --expose-internals

require('../common');
const common = require('../common');
const stream = require('stream');
const REPL = require('internal/repl');
const assert = require('assert');
Expand Down Expand Up @@ -46,6 +46,10 @@ function run(test) {

REPL.createInternalRepl(env, opts, function(err, repl) {
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,
'Expected ' + inspect(expected) + ' with ' + inspect(env));
assert.equal(expected.useColors, repl.useColors,
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-repl-history-perm.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const replHistoryPath = path.join(common.tmpDir, '.node_repl_history');
const checkResults = common.mustCall(function(err, r) {
if (err)
throw err;

// The REPL registers 'module' and 'require' globals
common.allowGlobals(r.context.module, r.context.require);

r.input.end();
const stat = fs.statSync(replHistoryPath);
assert.strictEqual(
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-repl-persistent-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ function runTest(assertCleaned) {
throw err;
}

// The REPL registers 'module' and 'require' globals.
// This test also registers '_'.
common.allowGlobals(repl.context.module,
repl.context.require,
repl.context._);

repl.once('close', () => {
if (repl._flushing) {
repl.once('flushHistory', onClose);
Expand Down