|
|
@ -68,12 +68,19 @@ module.paths = require('module')._nodeModulePaths(module.filename); |
|
|
|
exports.writer = util.inspect; |
|
|
|
|
|
|
|
|
|
|
|
function REPLServer(prompt, stream, eval) { |
|
|
|
function REPLServer(prompt, stream, eval, useGlobal) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
self.useGlobal = useGlobal; |
|
|
|
|
|
|
|
self.eval = eval || function(code, context, file, cb) { |
|
|
|
var err, result; |
|
|
|
try { |
|
|
|
var err, result = vm.runInContext(code, context, file); |
|
|
|
if (useGlobal) { |
|
|
|
result = vm.runInThisContext(code, file); |
|
|
|
} else { |
|
|
|
result = vm.runInContext(code, context, file); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
err = e; |
|
|
|
} |
|
|
@ -238,17 +245,21 @@ exports.REPLServer = REPLServer; |
|
|
|
|
|
|
|
// prompt is a string to print on each line for the prompt,
|
|
|
|
// source is a stream to use for I/O, defaulting to stdin/stdout.
|
|
|
|
exports.start = function(prompt, source, eval) { |
|
|
|
var repl = new REPLServer(prompt, source, eval); |
|
|
|
exports.start = function(prompt, source, eval, useGlobal) { |
|
|
|
var repl = new REPLServer(prompt, source, eval, useGlobal); |
|
|
|
if (!exports.repl) exports.repl = repl; |
|
|
|
return repl; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
REPLServer.prototype.createContext = function() { |
|
|
|
var context = vm.createContext(); |
|
|
|
if (!this.useGlobal) { |
|
|
|
var context = vm.createContext(); |
|
|
|
for (var i in global) context[i] = global[i]; |
|
|
|
} else { |
|
|
|
var context = global; |
|
|
|
} |
|
|
|
|
|
|
|
for (var i in global) context[i] = global[i]; |
|
|
|
context.module = module; |
|
|
|
context.require = require; |
|
|
|
context.global = context; |
|
|
@ -413,7 +424,9 @@ REPLServer.prototype.complete = function(line, callback) { |
|
|
|
if (!expr) { |
|
|
|
// If context is instance of vm.ScriptContext
|
|
|
|
// Get global vars synchronously
|
|
|
|
if (this.context.constructor.name === 'Context') { |
|
|
|
if (this.useGlobal || |
|
|
|
this.context.constructor && |
|
|
|
this.context.constructor.name === 'Context') { |
|
|
|
completionGroups.push(Object.getOwnPropertyNames(this.context)); |
|
|
|
addStandardGlobals(); |
|
|
|
completionGroupsLoaded(); |
|
|
|