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:
Ben Noordhuis committed 2013-01-03 19:58:47 +01:00
1 parent 875c1106c6
commit aad2013508
2 files changed
+4 -9

No files matched your search

+3 -8
View File
@@ -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;
}
+1 -1
View File
@@ -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);
}