mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
repl: allow overriding builtins
Don't give names of built-in libraries special treatment. Changes the REPL's behavior from this: > var path = 42 > path A different "path" already exists globally To this: > var path = 42 > path 42 Fixes #4512.
This commit is contained in:
1 parent
875c1106c6
commit
aad2013508
2 files changed
+4
-9
No files matched your search
+3
-8
@@ -220,15 +220,10 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
|
||||
|
||||
// Check if a builtin module name was used and then include it
|
||||
// if there's no conflict.
|
||||
if (exports._builtinLibs.indexOf(cmd) !== -1) {
|
||||
if (!(cmd in self.context) && exports._builtinLibs.indexOf(cmd) !== -1) {
|
||||
var lib = require(cmd);
|
||||
if (cmd in self.context && lib !== self.context[cmd]) {
|
||||
self.outputStream.write('A different "' + cmd +
|
||||
'" already exists globally\n');
|
||||
} else {
|
||||
self.context._ = self.context[cmd] = lib;
|
||||
self.outputStream.write(self.writer(lib) + '\n');
|
||||
}
|
||||
self.context._ = self.context[cmd] = lib;
|
||||
self.outputStream.write(self.writer(lib) + '\n');
|
||||
self.displayPrompt();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ function test2(){
|
||||
gotWrite = true;
|
||||
if (data.length) {
|
||||
// repl response error message
|
||||
assert.equal(data.indexOf('A different'), 0);
|
||||
assert.equal(data, '{}\n');
|
||||
// original value wasn't overwritten
|
||||
assert.equal(val, global.url);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user