summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlandre Scarlet <panyilinlove@qq.com>2017-07-20 16:05:39 +0800
committerXadillaX <admin@xcoder.in>2017-07-23 11:52:29 +0800
commitf37e3b143ae9c4de54cdb7e606f83a75cec4ae58 (patch)
treee67ae235425b8bf712bd668d86d1d8711389e26d
parenta5352d9f1f399a1a4d4a2f445ce08fb88da66695 (diff)
downloadandroid-node-v8-f37e3b143ae9c4de54cdb7e606f83a75cec4ae58.tar.gz
android-node-v8-f37e3b143ae9c4de54cdb7e606f83a75cec4ae58.tar.bz2
android-node-v8-f37e3b143ae9c4de54cdb7e606f83a75cec4ae58.zip
readline: name some anonymous functions
PR-URL: https://github.com/nodejs/node/pull/14297 Refs: https://github.com/nodejs/node/issues/8913 Refs: https://github.com/nodejs/node/pull/14297#pullrequestreview-50206772 Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r--lib/readline.js42
1 files changed, 24 insertions, 18 deletions
diff --git a/lib/readline.js b/lib/readline.js
index a022a1991c..fb6ffb8f06 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -130,9 +130,11 @@ function Interface(input, output, completer, terminal) {
// Check arity, 2 - for async, 1 for sync
if (typeof completer === 'function') {
- this.completer = completer.length === 2 ? completer : function(v, cb) {
- cb(null, completer(v));
- };
+ this.completer = completer.length === 2 ?
+ completer :
+ function completerWrapper(v, cb) {
+ cb(null, completer(v));
+ };
}
this.setPrompt(prompt);
@@ -175,15 +177,23 @@ function Interface(input, output, completer, terminal) {
}
if (!this.terminal) {
- input.on('data', ondata);
- input.on('end', onend);
- self.once('close', function() {
+ function onSelfCloseWithoutTerminal() {
input.removeListener('data', ondata);
input.removeListener('end', onend);
- });
- this._decoder = new StringDecoder('utf8');
+ }
+ input.on('data', ondata);
+ input.on('end', onend);
+ self.once('close', onSelfCloseWithoutTerminal);
+ this._decoder = new StringDecoder('utf8');
} else {
+ function onSelfCloseWithTerminal() {
+ input.removeListener('keypress', onkeypress);
+ input.removeListener('end', ontermend);
+ if (output !== null && output !== undefined) {
+ output.removeListener('resize', onresize);
+ }
+ }
emitKeypressEvents(input, this);
@@ -206,13 +216,7 @@ function Interface(input, output, completer, terminal) {
if (output !== null && output !== undefined)
output.on('resize', onresize);
- self.once('close', function() {
- input.removeListener('keypress', onkeypress);
- input.removeListener('end', ontermend);
- if (output !== null && output !== undefined) {
- output.removeListener('resize', onresize);
- }
- });
+ self.once('close', onSelfCloseWithTerminal);
}
input.resume();
@@ -460,7 +464,7 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) {
var self = this;
self.pause();
- self.completer(self.line.slice(0, self.cursor), function(err, rv) {
+ self.completer(self.line.slice(0, self.cursor), function onComplete(err, rv) {
self.resume();
if (err) {
@@ -474,7 +478,7 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) {
// Apply/show completions.
if (lastKeypressWasTab) {
self._writeToOutput('\r\n');
- var width = completions.reduce(function(a, b) {
+ var width = completions.reduce(function completionReducer(a, b) {
return a.length > b.length ? a : b;
}).length + 2; // 2 space padding
var maxColumns = Math.floor(self.columns / width);
@@ -495,7 +499,9 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) {
}
// If there is a common prefix to all matches, then apply that portion.
- var f = completions.filter(function(e) { if (e) return e; });
+ var f = completions.filter(function completionFilter(e) {
+ if (e) return e;
+ });
var prefix = commonPrefix(f);
if (prefix.length > completeOn.length) {
self._insertString(prefix.slice(completeOn.length));