From 6edc900b9579dcf4b556565e9b9161d8d927e35e Mon Sep 17 00:00:00 2001 From: Yazhong Liu Date: Tue, 12 May 2015 16:00:35 +0800 Subject: [PATCH] repl: support non-array `.scope`, document it REPL evaluate `.scope` when it needs to get a list of the variable names available in the current scope. Do not throw if the output of such evaluation is not array, just ignore it. PR-URL: https://github.com/nodejs/io.js/pull/1682 Reviewed-By: Fedor Indutny --- doc/api/repl.markdown | 4 ++++ lib/repl.js | 2 +- test/parallel/test-repl-tab.js | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-repl-tab.js diff --git a/doc/api/repl.markdown b/doc/api/repl.markdown index 18722b9..99cef9f 100644 --- a/doc/api/repl.markdown +++ b/doc/api/repl.markdown @@ -90,6 +90,9 @@ You can use your own `eval` function if it has following signature: callback(null, result); } +On tab completion - `eval` will be called with `.scope` as an input string. It +is expected to return an array of scope names to be used for the auto-completion. + Multiple REPLs may be started against the same running instance of io.js. Each will share the same global object but will have unique I/O. @@ -232,4 +235,5 @@ The following key combinations in the REPL have these special effects: - `C` - Similar to the `.break` keyword. Terminates the current command. Press twice on a blank line to forcibly exit. - `D` - Similar to the `.exit` keyword. + - `` - Show both global and local(scope) variables diff --git a/lib/repl.js b/lib/repl.js index fae6dc4..7d2a77a 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -624,7 +624,7 @@ REPLServer.prototype.complete = function(line, callback) { completionGroupsLoaded(); } else { this.eval('.scope', this.context, 'repl', function(err, globals) { - if (err || !globals) { + if (err || !globals || !Array.isArray(globals)) { addStandardGlobals(completionGroups, filter); } else if (Array.isArray(globals[0])) { // Add grouped globals diff --git a/test/parallel/test-repl-tab.js b/test/parallel/test-repl-tab.js new file mode 100644 index 0000000..79d3c63 --- /dev/null +++ b/test/parallel/test-repl-tab.js @@ -0,0 +1,18 @@ +var assert = require('assert'); +var util = require('util'); +var repl = require('repl'); +var zlib = require('zlib'); + +// just use builtin stream inherited from Duplex +var putIn = zlib.createGzip(); +var testMe = repl.start('', putIn, function(cmd, context, filename, callback) { + callback(null, cmd); +}); + +testMe._domain.on('error', function (e) { + assert.fail(); +}); + +testMe.complete('', function(err, results) { + assert.equal(err, null); +}); -- 2.7.4