From aad2013508eae5ee29a410c6fe44d27d6470ad24 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 3 Jan 2013 18:21:52 +0100 Subject: [PATCH] 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. --- lib/repl.js | 11 +++-------- test/simple/test-repl-autolibs.js | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index d67aa0ab48..e257f55e23 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -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; } diff --git a/test/simple/test-repl-autolibs.js b/test/simple/test-repl-autolibs.js index a8ee68ccc3..b6f9294711 100644 --- a/test/simple/test-repl-autolibs.js +++ b/test/simple/test-repl-autolibs.js @@ -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); }