mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
repl: make built-in modules available by default
Closes #3564. Closes #4578.
This commit is contained in:
committed by
Nathan Rajlich
parent
8e311d28b0
commit
9bce5e8f3e
28
lib/repl.js
28
lib/repl.js
@@ -218,16 +218,6 @@ 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 (!(cmd in self.context) && exports._builtinLibs.indexOf(cmd) !== -1) {
|
||||
var lib = require(cmd);
|
||||
self.context._ = self.context[cmd] = lib;
|
||||
self.outputStream.write(self.writer(lib) + '\n');
|
||||
self.displayPrompt();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!skipCatchall) {
|
||||
var evalCmd = self.bufferedCommand + cmd + '\n';
|
||||
|
||||
@@ -337,6 +327,24 @@ REPLServer.prototype.createContext = function() {
|
||||
this.lines = [];
|
||||
this.lines.level = [];
|
||||
|
||||
// make built-in modules available directly
|
||||
// (loaded lazily)
|
||||
exports._builtinLibs.forEach(function(name){
|
||||
Object.defineProperty(context, name, {
|
||||
get: function(){
|
||||
var lib = require(name);
|
||||
context._ = context[name] = lib;
|
||||
return lib;
|
||||
},
|
||||
// allow the creation of other globals with this name
|
||||
set: function(val){
|
||||
delete context[name];
|
||||
context[name] = val;
|
||||
},
|
||||
configurable: true
|
||||
});
|
||||
});
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
|
||||
@@ -172,7 +172,11 @@ function error_test() {
|
||||
{ client: client_unix, send: '(function () {\n\nreturn 1;\n})()',
|
||||
expect: '1' },
|
||||
{ client: client_unix, send: '{\n\na: 1\n}',
|
||||
expect: '{ a: 1 }' }
|
||||
expect: '{ a: 1 }' },
|
||||
{ client: client_unix, send: 'url.format("http://google.com")',
|
||||
expect: 'http://google.com/' },
|
||||
{ client: client_unix, send: 'var path = 42; path',
|
||||
expect: '42' }
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user