summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJonas Westerlund <jonas.westerlund@me.com>2012-07-04 23:14:27 +0200
committerNathan Rajlich <nathan@tootallnate.net>2012-07-06 19:28:35 -0700
commit7e7d5d38eae74ac92daf304624a81c951be6ebf6 (patch)
tree2f3ce635d4aa61d816d52ed502c2cd64b4458e28 /lib
parent0b0b72c2fab5bdf32f5476e47a1e7f2da9db2064 (diff)
downloadnodejs-7e7d5d38eae74ac92daf304624a81c951be6ebf6.tar.gz
nodejs-7e7d5d38eae74ac92daf304624a81c951be6ebf6.tar.bz2
nodejs-7e7d5d38eae74ac92daf304624a81c951be6ebf6.zip
Move function declaration out of conditional
Also avoid using eval as identifier. Fixes crashes in strict mode.
Diffstat (limited to 'lib')
-rw-r--r--lib/repl.js65
1 files changed, 30 insertions, 35 deletions
diff --git a/lib/repl.js b/lib/repl.js
index 3e5f33a47..98c14e734 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -75,9 +75,9 @@ exports._builtinLibs = ['assert', 'buffer', 'child_process', 'cluster',
'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)) {
- return new REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined);
+ return new REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined);
}
EventEmitter.call(this);
@@ -89,7 +89,7 @@ function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) {
stream = options.stream || options.socket;
input = options.input;
output = options.output;
- eval = options.eval;
+ eval_ = options.eval;
useGlobal = options.useGlobal;
ignoreUndefined = options.ignoreUndefined;
prompt = options.prompt;
@@ -104,7 +104,7 @@ function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) {
self.useGlobal = !!useGlobal;
self.ignoreUndefined = !!ignoreUndefined;
- self.eval = eval || function(code, context, file, cb) {
+ self.eval = eval_ || function(code, context, file, cb) {
var err, result;
try {
if (self.useGlobal) {
@@ -327,8 +327,8 @@ 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, useGlobal, ignoreUndefined) {
- var repl = new REPLServer(prompt, source, eval, useGlobal, ignoreUndefined);
+exports.start = function(prompt, source, eval_, useGlobal, ignoreUndefined) {
+ var repl = new REPLServer(prompt, source, eval_, useGlobal, ignoreUndefined);
if (!exports.repl) exports.repl = repl;
return repl;
};
@@ -536,9 +536,6 @@ REPLServer.prototype.complete = function(line, callback) {
expr = bits.join('.');
}
- // console.log("expression completion: completeOn='" + completeOn +
- // "' expr='" + expr + "'");
-
// Resolve expr and get its completions.
var obj, memberGroups = [];
if (!expr) {
@@ -552,12 +549,12 @@ REPLServer.prototype.complete = function(line, callback) {
completionGroups.push(Object.getOwnPropertyNames(contextProto));
}
completionGroups.push(Object.getOwnPropertyNames(this.context));
- addStandardGlobals();
+ addStandardGlobals(completionGroups, filter);
completionGroupsLoaded();
} else {
this.eval('.scope', this.context, 'repl', function(err, globals) {
if (err || !globals) {
- addStandardGlobals();
+ addStandardGlobals(completionGroups, filter);
} else if (Array.isArray(globals[0])) {
// Add grouped globals
globals.forEach(function(group) {
@@ -565,34 +562,11 @@ REPLServer.prototype.complete = function(line, callback) {
});
} else {
completionGroups.push(globals);
- addStandardGlobals();
+ addStandardGlobals(completionGroups, filter);
}
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 {
this.eval(expr, this.context, 'repl', function(e, obj) {
// 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) {
// TODO remove me after 0.3.x