Move function declaration out of conditional
Also avoid using eval as identifier. Fixes crashes in strict mode.
This commit is contained in:
parent
0b0b72c2fa
commit
7e7d5d38ea
65
lib/repl.js
65
lib/repl.js
@ -75,9 +75,9 @@ exports._builtinLibs = ['assert', 'buffer', 'child_process', 'cluster',
|
|||||||
'string_decoder', 'tls', 'tty', 'url', 'util', 'vm', 'zlib'];
|
'string_decoder', 'tls', 'tty', 'url', 'util', 'vm', 'zlib'];
|
||||||
|
|
||||||
|
|
||||||
function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) {
|
function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
|
||||||
if (!(this instanceof REPLServer)) {
|
if (!(this instanceof REPLServer)) {
|
||||||
return new REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined);
|
return new REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
@ -89,7 +89,7 @@ function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) {
|
|||||||
stream = options.stream || options.socket;
|
stream = options.stream || options.socket;
|
||||||
input = options.input;
|
input = options.input;
|
||||||
output = options.output;
|
output = options.output;
|
||||||
eval = options.eval;
|
eval_ = options.eval;
|
||||||
useGlobal = options.useGlobal;
|
useGlobal = options.useGlobal;
|
||||||
ignoreUndefined = options.ignoreUndefined;
|
ignoreUndefined = options.ignoreUndefined;
|
||||||
prompt = options.prompt;
|
prompt = options.prompt;
|
||||||
@ -104,7 +104,7 @@ function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) {
|
|||||||
self.useGlobal = !!useGlobal;
|
self.useGlobal = !!useGlobal;
|
||||||
self.ignoreUndefined = !!ignoreUndefined;
|
self.ignoreUndefined = !!ignoreUndefined;
|
||||||
|
|
||||||
self.eval = eval || function(code, context, file, cb) {
|
self.eval = eval_ || function(code, context, file, cb) {
|
||||||
var err, result;
|
var err, result;
|
||||||
try {
|
try {
|
||||||
if (self.useGlobal) {
|
if (self.useGlobal) {
|
||||||
@ -327,8 +327,8 @@ exports.REPLServer = REPLServer;
|
|||||||
|
|
||||||
// prompt is a string to print on each line for the prompt,
|
// 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.
|
// source is a stream to use for I/O, defaulting to stdin/stdout.
|
||||||
exports.start = function(prompt, source, eval, useGlobal, ignoreUndefined) {
|
exports.start = function(prompt, source, eval_, useGlobal, ignoreUndefined) {
|
||||||
var repl = new REPLServer(prompt, source, eval, useGlobal, ignoreUndefined);
|
var repl = new REPLServer(prompt, source, eval_, useGlobal, ignoreUndefined);
|
||||||
if (!exports.repl) exports.repl = repl;
|
if (!exports.repl) exports.repl = repl;
|
||||||
return repl;
|
return repl;
|
||||||
};
|
};
|
||||||
@ -536,9 +536,6 @@ REPLServer.prototype.complete = function(line, callback) {
|
|||||||
expr = bits.join('.');
|
expr = bits.join('.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log("expression completion: completeOn='" + completeOn +
|
|
||||||
// "' expr='" + expr + "'");
|
|
||||||
|
|
||||||
// Resolve expr and get its completions.
|
// Resolve expr and get its completions.
|
||||||
var obj, memberGroups = [];
|
var obj, memberGroups = [];
|
||||||
if (!expr) {
|
if (!expr) {
|
||||||
@ -552,12 +549,12 @@ REPLServer.prototype.complete = function(line, callback) {
|
|||||||
completionGroups.push(Object.getOwnPropertyNames(contextProto));
|
completionGroups.push(Object.getOwnPropertyNames(contextProto));
|
||||||
}
|
}
|
||||||
completionGroups.push(Object.getOwnPropertyNames(this.context));
|
completionGroups.push(Object.getOwnPropertyNames(this.context));
|
||||||
addStandardGlobals();
|
addStandardGlobals(completionGroups, filter);
|
||||||
completionGroupsLoaded();
|
completionGroupsLoaded();
|
||||||
} else {
|
} else {
|
||||||
this.eval('.scope', this.context, 'repl', function(err, globals) {
|
this.eval('.scope', this.context, 'repl', function(err, globals) {
|
||||||
if (err || !globals) {
|
if (err || !globals) {
|
||||||
addStandardGlobals();
|
addStandardGlobals(completionGroups, filter);
|
||||||
} else if (Array.isArray(globals[0])) {
|
} else if (Array.isArray(globals[0])) {
|
||||||
// Add grouped globals
|
// Add grouped globals
|
||||||
globals.forEach(function(group) {
|
globals.forEach(function(group) {
|
||||||
@ -565,34 +562,11 @@ REPLServer.prototype.complete = function(line, callback) {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
completionGroups.push(globals);
|
completionGroups.push(globals);
|
||||||
addStandardGlobals();
|
addStandardGlobals(completionGroups, filter);
|
||||||
}
|
}
|
||||||
completionGroupsLoaded();
|
completionGroupsLoaded();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addStandardGlobals() {
|
|
||||||
// Global object properties
|
|
||||||
// (http://www.ecma-international.org/publications/standards/Ecma-262.htm)
|
|
||||||
completionGroups.push(['NaN', 'Infinity', 'undefined',
|
|
||||||
'eval', 'parseInt', 'parseFloat', 'isNaN', 'isFinite', 'decodeURI',
|
|
||||||
'decodeURIComponent', 'encodeURI', 'encodeURIComponent',
|
|
||||||
'Object', 'Function', 'Array', 'String', 'Boolean', 'Number',
|
|
||||||
'Date', 'RegExp', 'Error', 'EvalError', 'RangeError',
|
|
||||||
'ReferenceError', 'SyntaxError', 'TypeError', 'URIError',
|
|
||||||
'Math', 'JSON']);
|
|
||||||
// Common keywords. Exclude for completion on the empty string, b/c
|
|
||||||
// they just get in the way.
|
|
||||||
if (filter) {
|
|
||||||
completionGroups.push(['break', 'case', 'catch', 'const',
|
|
||||||
'continue', 'debugger', 'default', 'delete', 'do', 'else',
|
|
||||||
'export', 'false', 'finally', 'for', 'function', 'if',
|
|
||||||
'import', 'in', 'instanceof', 'let', 'new', 'null', 'return',
|
|
||||||
'switch', 'this', 'throw', 'true', 'try', 'typeof', 'undefined',
|
|
||||||
'var', 'void', 'while', 'with', 'yield']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.eval(expr, this.context, 'repl', function(e, obj) {
|
this.eval(expr, this.context, 'repl', function(e, obj) {
|
||||||
// if (e) console.log(e);
|
// if (e) console.log(e);
|
||||||
@ -790,6 +764,27 @@ REPLServer.prototype.memory = function memory(cmd) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function addStandardGlobals(completionGroups, filter) {
|
||||||
|
// Global object properties
|
||||||
|
// (http://www.ecma-international.org/publications/standards/Ecma-262.htm)
|
||||||
|
completionGroups.push(['NaN', 'Infinity', 'undefined',
|
||||||
|
'eval', 'parseInt', 'parseFloat', 'isNaN', 'isFinite', 'decodeURI',
|
||||||
|
'decodeURIComponent', 'encodeURI', 'encodeURIComponent',
|
||||||
|
'Object', 'Function', 'Array', 'String', 'Boolean', 'Number',
|
||||||
|
'Date', 'RegExp', 'Error', 'EvalError', 'RangeError',
|
||||||
|
'ReferenceError', 'SyntaxError', 'TypeError', 'URIError',
|
||||||
|
'Math', 'JSON']);
|
||||||
|
// Common keywords. Exclude for completion on the empty string, b/c
|
||||||
|
// they just get in the way.
|
||||||
|
if (filter) {
|
||||||
|
completionGroups.push(['break', 'case', 'catch', 'const',
|
||||||
|
'continue', 'debugger', 'default', 'delete', 'do', 'else',
|
||||||
|
'export', 'false', 'finally', 'for', 'function', 'if',
|
||||||
|
'import', 'in', 'instanceof', 'let', 'new', 'null', 'return',
|
||||||
|
'switch', 'this', 'throw', 'true', 'try', 'typeof', 'undefined',
|
||||||
|
'var', 'void', 'while', 'with', 'yield']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function defineDefaultCommands(repl) {
|
function defineDefaultCommands(repl) {
|
||||||
// TODO remove me after 0.3.x
|
// TODO remove me after 0.3.x
|
||||||
|
Loading…
x
Reference in New Issue
Block a user