summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWeijia Wang <starkwang@126.com>2019-03-18 19:31:07 +0800
committerWeijia Wang <381152119@qq.com>2019-03-21 21:38:02 +0800
commitc8d3a73c8b673792e315759b70cf4822b64b3e45 (patch)
tree39f35c7327e82964acf66f63c3e9d1c919c3382b
parent1935625df4f56bd77c57ec100a9222c77e9d440c (diff)
downloadandroid-node-v8-c8d3a73c8b673792e315759b70cf4822b64b3e45.tar.gz
android-node-v8-c8d3a73c8b673792e315759b70cf4822b64b3e45.tar.bz2
android-node-v8-c8d3a73c8b673792e315759b70cf4822b64b3e45.zip
lib: use Array#includes instead of Array#indexOf
PR-URL: https://github.com/nodejs/node/pull/26732 Refs: https://github.com/nodejs/node/issues/26568 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
-rw-r--r--lib/_http_client.js2
-rw-r--r--lib/_stream_readable.js2
-rw-r--r--lib/assert.js2
-rw-r--r--lib/child_process.js2
-rw-r--r--lib/internal/cluster/shared_handle.js2
-rw-r--r--lib/internal/console/constructor.js2
-rw-r--r--lib/internal/fs/utils.js4
-rw-r--r--lib/internal/util/inspect.js8
-rw-r--r--lib/url.js6
9 files changed, 15 insertions, 15 deletions
diff --git a/lib/_http_client.js b/lib/_http_client.js
index 4e59126084..6436d22f6e 100644
--- a/lib/_http_client.js
+++ b/lib/_http_client.js
@@ -220,7 +220,7 @@ function ClientRequest(input, options, cb) {
// https://tools.ietf.org/html/rfc3986#section-3.2.2
var posColon = hostHeader.indexOf(':');
if (posColon !== -1 &&
- hostHeader.indexOf(':', posColon + 1) !== -1 &&
+ hostHeader.includes(':', posColon + 1) &&
hostHeader.charCodeAt(0) !== 91/* '[' */) {
hostHeader = `[${hostHeader}]`;
}
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index fe77c44186..ba948c6194 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -713,7 +713,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
// also returned false.
// => Check whether `dest` is still a piping destination.
if (((state.pipesCount === 1 && state.pipes === dest) ||
- (state.pipesCount > 1 && state.pipes.indexOf(dest) !== -1)) &&
+ (state.pipesCount > 1 && state.pipes.includes(dest))) &&
!cleanedUp) {
debug('false write response, pause', state.awaitDrain);
state.awaitDrain++;
diff --git a/lib/assert.js b/lib/assert.js
index 94e9406393..e32cae3cff 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -284,7 +284,7 @@ function getErrMessage(message, fn) {
// Flush unfinished multi byte characters.
decoder.end();
// Always normalize indentation, otherwise the message could look weird.
- if (message.indexOf('\n') !== -1) {
+ if (message.includes('\n')) {
if (EOL === '\r\n') {
message = message.replace(/\r\n/g, '\n');
}
diff --git a/lib/child_process.js b/lib/child_process.js
index 8060412b3f..805600820f 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -101,7 +101,7 @@ exports.fork = function fork(modulePath /* , args, options */) {
// and stderr from the parent if silent isn't set.
options.stdio = options.silent ? stdioStringToArray('pipe') :
stdioStringToArray('inherit');
- } else if (options.stdio.indexOf('ipc') === -1) {
+ } else if (!options.stdio.includes('ipc')) {
throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio');
}
diff --git a/lib/internal/cluster/shared_handle.js b/lib/internal/cluster/shared_handle.js
index 408657623b..0d0a805709 100644
--- a/lib/internal/cluster/shared_handle.js
+++ b/lib/internal/cluster/shared_handle.js
@@ -24,7 +24,7 @@ function SharedHandle(key, address, port, addressType, fd, flags) {
}
SharedHandle.prototype.add = function(worker, send) {
- assert(this.workers.indexOf(worker) === -1);
+ assert(!this.workers.includes(worker));
this.workers.push(worker);
send(this.errno, null, this.handle);
};
diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js
index 2fa812d9fe..b9af931d38 100644
--- a/lib/internal/console/constructor.js
+++ b/lib/internal/console/constructor.js
@@ -220,7 +220,7 @@ Console.prototype[kWriteToConsole] = function(streamSymbol, string) {
this._stdoutErrorHandler : this._stderrErrorHandler;
if (groupIndent.length !== 0) {
- if (string.indexOf('\n') !== -1) {
+ if (string.includes('\n')) {
string = string.replace(/\n/g, `\n${groupIndent}`);
}
string = groupIndent + string;
diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js
index 8a9d4d3572..0c5ce1ecb7 100644
--- a/lib/internal/fs/utils.js
+++ b/lib/internal/fs/utils.js
@@ -191,8 +191,8 @@ function nullCheck(path, propName, throwError = true) {
// We can only perform meaningful checks on strings and Uint8Arrays.
if (!pathIsString && !pathIsUint8Array ||
- pathIsString && path.indexOf('\u0000') === -1 ||
- pathIsUint8Array && path.indexOf(0) === -1) {
+ pathIsString && !path.includes('\u0000') ||
+ pathIsUint8Array && !path.includes(0)) {
return;
}
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index 4cee2d8b9f..dc97e6dceb 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -288,12 +288,12 @@ function strEscape(str) {
// instead wrap the text in double quotes. If double quotes exist, check for
// backticks. If they do not exist, use those as fallback instead of the
// double quotes.
- if (str.indexOf("'") !== -1) {
+ if (str.includes("'")) {
// This invalidates the charCode and therefore can not be matched for
// anymore.
- if (str.indexOf('"') === -1) {
+ if (!str.includes('"')) {
singleQuote = -1;
- } else if (str.indexOf('`') === -1 && str.indexOf('${') === -1) {
+ } else if (!str.includes('`') && !str.includes('${')) {
singleQuote = -2;
}
if (singleQuote !== 39) {
@@ -557,7 +557,7 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
// Using an array here is actually better for the average case than using
// a Set. `seen` will only check for the depth and will never grow too large.
- if (ctx.seen.indexOf(value) !== -1)
+ if (ctx.seen.includes(value))
return ctx.stylize('[Circular]', 'special');
return formatRaw(ctx, value, recurseTimes, typedArray);
diff --git a/lib/url.js b/lib/url.js
index ff54988f42..ade0007171 100644
--- a/lib/url.js
+++ b/lib/url.js
@@ -581,9 +581,9 @@ Url.prototype.format = function format() {
host = auth + this.host;
} else if (this.hostname) {
host = auth + (
- this.hostname.indexOf(':') === -1 ?
- this.hostname :
- '[' + this.hostname + ']'
+ this.hostname.includes(':') ?
+ '[' + this.hostname + ']' :
+ this.hostname
);
if (this.port) {
host += ':' + this.port;