summaryrefslogtreecommitdiff
path: root/lib/internal
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-03-26 05:21:27 +0100
committerMichaël Zasso <targos@protonmail.com>2019-03-30 13:16:39 +0100
commitf86f5736da72ad4f3fb50692461222590e2f0258 (patch)
tree6fee263bfca24abbf76b7a3f1517b8184c29f077 /lib/internal
parentf0b3855a90bc5f68fe38ea5e7c69d30ae7d81a27 (diff)
downloadandroid-node-v8-f86f5736da72ad4f3fb50692461222590e2f0258.tar.gz
android-node-v8-f86f5736da72ad4f3fb50692461222590e2f0258.tar.bz2
android-node-v8-f86f5736da72ad4f3fb50692461222590e2f0258.zip
benchmark,lib: change var to const
Refs: https://github.com/nodejs/node/pull/26679 PR-URL: https://github.com/nodejs/node/pull/26915 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'lib/internal')
-rw-r--r--lib/internal/assert/assertion_error.js8
-rw-r--r--lib/internal/child_process.js40
-rw-r--r--lib/internal/console/constructor.js2
-rw-r--r--lib/internal/crypto/sig.js4
-rw-r--r--lib/internal/encoding.js8
-rw-r--r--lib/internal/modules/cjs/loader.js40
-rw-r--r--lib/internal/socket_list.js2
-rw-r--r--lib/internal/stream_base_commons.js8
-rw-r--r--lib/internal/streams/legacy.js2
-rw-r--r--lib/internal/url.js26
-rw-r--r--lib/internal/util.js2
11 files changed, 71 insertions, 71 deletions
diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js
index ea2a999a60..e12318ec54 100644
--- a/lib/internal/assert/assertion_error.js
+++ b/lib/internal/assert/assertion_error.js
@@ -292,13 +292,15 @@ class AssertionError extends Error {
if (typeof options !== 'object' || options === null) {
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
}
- var {
- actual,
- expected,
+ const {
message,
operator,
stackStartFn
} = options;
+ let {
+ actual,
+ expected
+ } = options;
const limit = Error.stackTraceLimit;
Error.stackTraceLimit = 0;
diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js
index 390feef96a..840a1f16e0 100644
--- a/lib/internal/child_process.js
+++ b/lib/internal/child_process.js
@@ -85,7 +85,7 @@ const handleConversion = {
},
got(message, handle, emit) {
- var server = new net.Server();
+ const server = new net.Server();
server.listen(handle, () => {
emit(server);
});
@@ -115,7 +115,7 @@ const handleConversion = {
socket.server._connections--;
}
- var handle = socket._handle;
+ const handle = socket._handle;
// Remove handle from socket object, it will be closed when the socket
// will be sent
@@ -160,7 +160,7 @@ const handleConversion = {
},
got(message, handle, emit) {
- var socket = new net.Socket({
+ const socket = new net.Socket({
handle: handle,
readable: true,
writable: true
@@ -202,7 +202,7 @@ const handleConversion = {
},
got(message, handle, emit) {
- var socket = new dgram.Socket(message.dgramType);
+ const socket = new dgram.Socket(message.dgramType);
socket.bind(handle, () => {
emit(socket);
@@ -304,21 +304,19 @@ function closePendingHandle(target) {
ChildProcess.prototype.spawn = function(options) {
- var ipc;
- var ipcFd;
- var i;
+ let i = 0;
if (options === null || typeof options !== 'object') {
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
}
// If no `stdio` option was given - use default
- var stdio = options.stdio || 'pipe';
+ let stdio = options.stdio || 'pipe';
stdio = getValidStdio(stdio, false);
- ipc = stdio.ipc;
- ipcFd = stdio.ipcFd;
+ const ipc = stdio.ipc;
+ const ipcFd = stdio.ipcFd;
stdio = options.stdio = stdio.stdio;
if (ipc !== undefined) {
@@ -344,7 +342,7 @@ ChildProcess.prototype.spawn = function(options) {
else
throw new ERR_INVALID_ARG_TYPE('options.args', 'Array', options.args);
- var err = this._handle.spawn(options);
+ const err = this._handle.spawn(options);
// Run-time errors should emit an error, not throw an exception.
if (err === UV_EACCES ||
@@ -505,7 +503,7 @@ function setupChannel(target, channel) {
if (StringDecoder === undefined)
StringDecoder = require('string_decoder').StringDecoder;
- var decoder = new StringDecoder('utf8');
+ const decoder = new StringDecoder('utf8');
var jsonBuffer = '';
var pendingHandle = null;
channel.buffering = false;
@@ -619,7 +617,7 @@ function setupChannel(target, channel) {
// a message.
target._send({ cmd: 'NODE_HANDLE_ACK' }, null, true);
- var obj = handleConversion[message.type];
+ const obj = handleConversion[message.type];
// Update simultaneous accepts on Windows
if (process.platform === 'win32') {
@@ -746,11 +744,11 @@ function setupChannel(target, channel) {
return this._handleQueue.length === 1;
}
- var req = new WriteWrap();
+ const req = new WriteWrap();
- var string = JSON.stringify(message) + '\n';
- var err = channel.writeUtf8String(req, string, handle);
- var wasAsyncWrite = streamBaseState[kLastWriteWasAsync];
+ const string = JSON.stringify(message) + '\n';
+ const err = channel.writeUtf8String(req, string, handle);
+ const wasAsyncWrite = streamBaseState[kLastWriteWasAsync];
if (err === 0) {
if (handle) {
@@ -853,7 +851,7 @@ function setupChannel(target, channel) {
if (!target.channel)
return;
- var eventName = (internal ? 'internalMessage' : 'message');
+ const eventName = (internal ? 'internalMessage' : 'message');
process.nextTick(emit, eventName, message, handle);
}
@@ -983,7 +981,7 @@ function getValidStdio(stdio, sync) {
function getSocketList(type, worker, key) {
- var sockets = worker.channel.sockets[type];
+ const sockets = worker.channel.sockets[type];
var socketList = sockets[key];
if (!socketList) {
var Construct = type === 'send' ? SocketListSend : SocketListReceive;
@@ -1002,8 +1000,8 @@ function maybeClose(subprocess) {
}
function spawnSync(opts) {
- var options = opts.options;
- var result = spawn_sync.spawn(options);
+ const options = opts.options;
+ const result = spawn_sync.spawn(options);
if (result.output && options.encoding && options.encoding !== 'buffer') {
for (var i = 0; i < result.output.length; i++) {
diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js
index 5041abfd4d..86ef83994e 100644
--- a/lib/internal/console/constructor.js
+++ b/lib/internal/console/constructor.js
@@ -106,7 +106,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
}
// Bind the prototype functions to this Console instance
- var keys = Object.keys(Console.prototype);
+ const keys = Object.keys(Console.prototype);
for (var v = 0; v < keys.length; v++) {
var k = keys[v];
// We have to bind the methods grabbed from the instance instead of from
diff --git a/lib/internal/crypto/sig.js b/lib/internal/crypto/sig.js
index 9eacfec8c0..6ecc64c3d4 100644
--- a/lib/internal/crypto/sig.js
+++ b/lib/internal/crypto/sig.js
@@ -155,9 +155,9 @@ Verify.prototype.verify = function verify(options, signature, sigEncoding) {
sigEncoding = sigEncoding || getDefaultEncoding();
// Options specific to RSA
- var rsaPadding = getPadding(options);
+ const rsaPadding = getPadding(options);
- var pssSaltLength = getSaltLength(options);
+ const pssSaltLength = getSaltLength(options);
signature = validateArrayBufferView(toBuf(signature, sigEncoding),
'signature');
diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js
index 578261427a..b45a074f38 100644
--- a/lib/internal/encoding.js
+++ b/lib/internal/encoding.js
@@ -321,8 +321,8 @@ class TextEncoder {
validateEncoder(this);
if (typeof depth === 'number' && depth < 0)
return this;
- var ctor = getConstructorOf(this);
- var obj = Object.create({
+ const ctor = getConstructorOf(this);
+ const obj = Object.create({
constructor: ctor === null ? TextEncoder : ctor
});
obj.encoding = this.encoding;
@@ -516,8 +516,8 @@ function makeTextDecoderJS() {
validateDecoder(this);
if (typeof depth === 'number' && depth < 0)
return this;
- var ctor = getConstructorOf(this);
- var obj = Object.create({
+ const ctor = getConstructorOf(this);
+ const obj = Object.create({
constructor: ctor === null ? TextDecoder : ctor
});
obj.encoding = this.encoding;
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index 3d68f8fc62..5b0a1cf3f5 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -98,7 +98,7 @@ function stat(filename) {
}
function updateChildren(parent, child, scan) {
- var children = parent && parent.children;
+ const children = parent && parent.children;
if (children && !(scan && children.includes(child)))
children.push(child);
}
@@ -321,9 +321,9 @@ Module._findPath = function(request, paths, isMain) {
return false;
}
- var cacheKey = request + '\x00' +
+ const cacheKey = request + '\x00' +
(paths.length === 1 ? paths[0] : paths.join('\x00'));
- var entry = Module._pathCache[cacheKey];
+ const entry = Module._pathCache[cacheKey];
if (entry)
return entry;
@@ -402,8 +402,8 @@ Module._findPath = function(request, paths, isMain) {
};
// 'node_modules' character codes reversed
-var nmChars = [ 115, 101, 108, 117, 100, 111, 109, 95, 101, 100, 111, 110 ];
-var nmLen = nmChars.length;
+const nmChars = [ 115, 101, 108, 117, 100, 111, 109, 95, 101, 100, 111, 110 ];
+const nmLen = nmChars.length;
if (isWindows) {
// 'from' is the __dirname of the module.
Module._nodeModulePaths = function(from) {
@@ -489,8 +489,8 @@ if (isWindows) {
// 'index.' character codes
-var indexChars = [ 105, 110, 100, 101, 120, 46 ];
-var indexLen = indexChars.length;
+const indexChars = [ 105, 110, 100, 101, 120, 46 ];
+const indexLen = indexChars.length;
Module._resolveLookupPaths = function(request, parent, newReturn) {
if (NativeModule.canBeRequiredByUsers(request)) {
debug('looking for %j in []', request);
@@ -584,7 +584,7 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
debug('RELATIVE: requested: %s set ID to: %s from %s', request, id,
parent.id);
- var parentDir = [path.dirname(parent.filename)];
+ const parentDir = [path.dirname(parent.filename)];
debug('looking for %j in %j', id, parentDir);
return (newReturn ? parentDir : [id, parentDir]);
};
@@ -601,9 +601,9 @@ Module._load = function(request, parent, isMain) {
debug('Module._load REQUEST %s parent: %s', request, parent.id);
}
- var filename = Module._resolveFilename(request, parent, isMain);
+ const filename = Module._resolveFilename(request, parent, isMain);
- var cachedModule = Module._cache[filename];
+ const cachedModule = Module._cache[filename];
if (cachedModule) {
updateChildren(parent, cachedModule, true);
return cachedModule.exports;
@@ -616,7 +616,7 @@ Module._load = function(request, parent, isMain) {
}
// Don't call updateChildren(), Module constructor already does.
- var module = new Module(filename, parent);
+ const module = new Module(filename, parent);
if (isMain) {
process.mainModule = module;
@@ -670,7 +670,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
}
// Look up the filename first, since that's the cache key.
- var filename = Module._findPath(request, paths, isMain);
+ const filename = Module._findPath(request, paths, isMain);
if (!filename) {
const requireStack = [];
for (var cursor = parent;
@@ -700,7 +700,7 @@ Module.prototype.load = function(filename) {
this.filename = filename;
this.paths = Module._nodeModulePaths(path.dirname(filename));
- var extension = findLongestRegisteredExtension(filename);
+ const extension = findLongestRegisteredExtension(filename);
Module._extensions[extension](this, filename);
this.loaded = true;
@@ -824,12 +824,12 @@ Module.prototype._compile = function(content, filename) {
inspectorWrapper = internalBinding('inspector').callAndPauseOnStart;
}
}
- var dirname = path.dirname(filename);
- var require = makeRequireFunction(this);
+ const dirname = path.dirname(filename);
+ const require = makeRequireFunction(this);
var result;
- var exports = this.exports;
- var thisValue = exports;
- var module = this;
+ const exports = this.exports;
+ const thisValue = exports;
+ const module = this;
if (inspectorWrapper) {
result = inspectorWrapper(compiledWrapper, thisValue, exports,
require, module, filename, dirname);
@@ -844,7 +844,7 @@ Module.prototype._compile = function(content, filename) {
// Native extension for .js
Module._extensions['.js'] = function(module, filename) {
- var content = fs.readFileSync(filename, 'utf8');
+ const content = fs.readFileSync(filename, 'utf8');
module._compile(stripBOM(content), filename);
};
@@ -958,7 +958,7 @@ Module._preloadModules = function(requests) {
// Preloaded modules have a dummy parent module which is deemed to exist
// in the current working directory. This seeds the search path for
// preloaded modules.
- var parent = new Module('internal/preload', null);
+ const parent = new Module('internal/preload', null);
try {
parent.paths = Module._nodeModulePaths(process.cwd());
} catch (e) {
diff --git a/lib/internal/socket_list.js b/lib/internal/socket_list.js
index 8cd7b1e0ed..e6b2a1d7c6 100644
--- a/lib/internal/socket_list.js
+++ b/lib/internal/socket_list.js
@@ -14,7 +14,7 @@ class SocketListSend extends EventEmitter {
}
_request(msg, cmd, swallowErrors, callback) {
- var self = this;
+ const self = this;
if (!this.child.connected) return onclose();
this.child._send(msg, undefined, swallowErrors);
diff --git a/lib/internal/stream_base_commons.js b/lib/internal/stream_base_commons.js
index 3f53e3903a..53ddc6336b 100644
--- a/lib/internal/stream_base_commons.js
+++ b/lib/internal/stream_base_commons.js
@@ -92,7 +92,7 @@ function onWriteComplete(status) {
}
function createWriteWrap(handle) {
- var req = new WriteWrap();
+ const req = new WriteWrap();
req.handle = handle;
req.oncomplete = onWriteComplete;
@@ -105,7 +105,7 @@ function createWriteWrap(handle) {
function writevGeneric(self, data, cb) {
const req = createWriteWrap(self[kHandle]);
- var allBuffers = data.allBuffers;
+ const allBuffers = data.allBuffers;
var chunks;
var i;
if (allBuffers) {
@@ -120,7 +120,7 @@ function writevGeneric(self, data, cb) {
chunks[i * 2 + 1] = entry.encoding;
}
}
- var err = req.handle.writev(req, chunks, allBuffers);
+ const err = req.handle.writev(req, chunks, allBuffers);
// Retain chunks
if (err === 0) req._chunks = chunks;
@@ -131,7 +131,7 @@ function writevGeneric(self, data, cb) {
function writeGeneric(self, data, encoding, cb) {
const req = createWriteWrap(self[kHandle]);
- var err = handleWriteReq(req, data, encoding);
+ const err = handleWriteReq(req, data, encoding);
afterWriteDispatched(self, req, err, cb);
return req;
diff --git a/lib/internal/streams/legacy.js b/lib/internal/streams/legacy.js
index 693987e9d1..44ebfc6bd9 100644
--- a/lib/internal/streams/legacy.js
+++ b/lib/internal/streams/legacy.js
@@ -9,7 +9,7 @@ Object.setPrototypeOf(Stream.prototype, EE.prototype);
Object.setPrototypeOf(Stream, EE);
Stream.prototype.pipe = function(dest, options) {
- var source = this;
+ const source = this;
function ondata(chunk) {
if (dest.writable && dest.write(chunk) === false && source.pause) {
diff --git a/lib/internal/url.js b/lib/internal/url.js
index 9bbd80148c..0771dab13a 100644
--- a/lib/internal/url.js
+++ b/lib/internal/url.js
@@ -192,19 +192,19 @@ class URLSearchParams {
if (typeof recurseTimes === 'number' && recurseTimes < 0)
return ctx.stylize('[Object]', 'special');
- var separator = ', ';
- var innerOpts = { ...ctx };
+ const separator = ', ';
+ const innerOpts = { ...ctx };
if (recurseTimes !== null) {
innerOpts.depth = recurseTimes - 1;
}
- var innerInspect = (v) => inspect(v, innerOpts);
+ const innerInspect = (v) => inspect(v, innerOpts);
- var list = this[searchParams];
- var output = [];
+ const list = this[searchParams];
+ const output = [];
for (var i = 0; i < list.length; i += 2)
output.push(`${innerInspect(list[i])} => ${innerInspect(list[i + 1])}`);
- var length = output.reduce(
+ const length = output.reduce(
(prev, cur) => prev + removeColors(cur).length + separator.length,
-separator.length
);
@@ -220,7 +220,7 @@ class URLSearchParams {
function onParseComplete(flags, protocol, username, password,
host, port, path, query, fragment) {
- var ctx = this[context];
+ const ctx = this[context];
ctx.flags = flags;
ctx.scheme = protocol;
ctx.username = (flags & URL_FLAGS_HAS_USERNAME) !== 0 ? username : '';
@@ -343,9 +343,9 @@ class URL {
if (typeof depth === 'number' && depth < 0)
return this;
- var ctor = getConstructorOf(this);
+ const ctor = getConstructorOf(this);
- var obj = Object.create({
+ const obj = Object.create({
constructor: ctor === null ? URL : ctor
});
@@ -1253,7 +1253,7 @@ function domainToUnicode(domain) {
// options object as expected by the http.request and https.request
// APIs.
function urlToOptions(url) {
- var options = {
+ const options = {
protocol: url.protocol,
hostname: typeof url.hostname === 'string' && url.hostname.startsWith('[') ?
url.hostname.slice(1, -1) :
@@ -1276,7 +1276,7 @@ function urlToOptions(url) {
const forwardSlashRegEx = /\//g;
function getPathFromURLWin32(url) {
- var hostname = url.hostname;
+ const hostname = url.hostname;
var pathname = url.pathname;
for (var n = 0; n < pathname.length; n++) {
if (pathname[n] === '%') {
@@ -1315,7 +1315,7 @@ function getPathFromURLPosix(url) {
if (url.hostname !== '') {
throw new ERR_INVALID_FILE_URL_HOST(platform);
}
- var pathname = url.pathname;
+ const pathname = url.pathname;
for (var n = 0; n < pathname.length; n++) {
if (pathname[n] === '%') {
var third = pathname.codePointAt(n + 2) | 0x20;
@@ -1389,7 +1389,7 @@ function toPathIfFileURL(fileURLOrPath) {
function constructUrl(flags, protocol, username, password,
host, port, path, query, fragment) {
- var ctx = new URLContext();
+ const ctx = new URLContext();
ctx.flags = flags;
ctx.scheme = protocol;
ctx.username = (flags & URL_FLAGS_HAS_USERNAME) !== 0 ? username : '';
diff --git a/lib/internal/util.js b/lib/internal/util.js
index f5b5fbedd4..2800f6122f 100644
--- a/lib/internal/util.js
+++ b/lib/internal/util.js
@@ -212,7 +212,7 @@ function getSignalsToNamesMapping() {
return signalsToNamesMapping;
signalsToNamesMapping = Object.create(null);
- for (var key in signals) {
+ for (const key in signals) {
signalsToNamesMapping[signals[key]] = key;
}