diff options
Diffstat (limited to 'lib/repl.js')
-rw-r--r-- | lib/repl.js | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/repl.js b/lib/repl.js index 5980bef1ce..2fd5821e3c 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -83,7 +83,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) { EventEmitter.call(this); var options, input, output, dom; - if (typeof prompt == 'object') { + if (IS_OBJECT(prompt)) { // an options object was given options = prompt; stream = options.stream || options.socket; @@ -94,7 +94,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) { ignoreUndefined = options.ignoreUndefined; prompt = options.prompt; dom = options.domain; - } else if (typeof prompt != 'string') { + } else if (!IS_STRING(prompt)) { throw new Error('An options Object, or a prompt String are required'); } else { options = {}; @@ -160,7 +160,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) { self.resetContext(); self.bufferedCommand = ''; - self.prompt = (prompt != undefined ? prompt : '> '); + self.prompt = !IS_UNDEFINED(prompt) ? prompt : '> '; function complete(text, callback) { self.complete(text, callback); @@ -180,7 +180,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) { // figure out which "writer" function to use self.writer = options.writer || exports.writer; - if (typeof options.useColors === 'undefined') { + if (IS_UNDEFINED(options.useColors)) { options.useColors = rli.terminal; } self.useColors = !!options.useColors; @@ -256,9 +256,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) { function(e, ret) { if (e && !isSyntaxError(e)) return finish(e); - if (typeof ret === 'function' && - /^[\r\n\s]*function/.test(evalCmd) || - e) { + if (IS_FUNCTION(ret) && /^[\r\n\s]*function/.test(evalCmd) || e) { // Now as statement without parens. self.eval(evalCmd, self.context, 'repl', finish); } else { @@ -300,7 +298,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) { self.bufferedCommand = ''; // If we got any output - print it (if no error) - if (!e && (!self.ignoreUndefined || ret !== undefined)) { + if (!e && (!self.ignoreUndefined || !IS_UNDEFINED(ret))) { self.context._ = ret; self.outputStream.write(self.writer(ret) + '\n'); } @@ -422,7 +420,7 @@ var simpleExpressionRE = // getter code. REPLServer.prototype.complete = function(line, callback) { // There may be local variables to evaluate, try a nested REPL - if (this.bufferedCommand != undefined && this.bufferedCommand.length) { + if (!IS_UNDEFINED(this.bufferedCommand) && this.bufferedCommand.length) { // Get a new array of inputed lines var tmp = this.lines.slice(); // Kill off all function declarations to push all local variables into @@ -564,7 +562,7 @@ REPLServer.prototype.complete = function(line, callback) { this.eval('.scope', this.context, 'repl', function(err, globals) { if (err || !globals) { addStandardGlobals(completionGroups, filter); - } else if (Array.isArray(globals[0])) { + } else if (IS_ARRAY(globals[0])) { // Add grouped globals globals.forEach(function(group) { completionGroups.push(group); @@ -581,19 +579,19 @@ REPLServer.prototype.complete = function(line, callback) { // if (e) console.log(e); if (obj != null) { - if (typeof obj === 'object' || typeof obj === 'function') { + if (IS_OBJECT(obj) || IS_FUNCTION(obj)) { memberGroups.push(Object.getOwnPropertyNames(obj)); } // works for non-objects try { var sentinel = 5; var p; - if (typeof obj === 'object' || typeof obj === 'function') { + if (IS_OBJECT(obj) || IS_FUNCTION(obj)) { p = Object.getPrototypeOf(obj); } else { p = obj.constructor ? obj.constructor.prototype : null; } - while (p !== null) { + while (!IS_NULL(p)) { memberGroups.push(Object.getOwnPropertyNames(p)); p = Object.getPrototypeOf(p); // Circular refs possible? Let's guard against that. @@ -692,9 +690,9 @@ REPLServer.prototype.parseREPLKeyword = function(keyword, rest) { REPLServer.prototype.defineCommand = function(keyword, cmd) { - if (typeof cmd === 'function') { + if (IS_FUNCTION(cmd)) { cmd = {action: cmd}; - } else if (typeof cmd.action !== 'function') { + } else if (!IS_FUNCTION(cmd.action)) { throw new Error('bad argument, action must be a function'); } this.commands['.' + keyword] = cmd; |