Browse Source

test,lib,doc: use function declarations

Replace function expressions with function declarations in preparation
for a lint rule requiring function declarations.

PR-URL: https://github.com/nodejs/node/pull/12711
Backport-PR-URL: https://github.com/nodejs/node/pull/13774
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
v6.x
Rich Trott 8 years ago
committed by Myles Borins
parent
commit
7e6a956a29
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 2
      doc/api/util.md
  2. 2
      lib/_http_client.js
  3. 4
      lib/_tls_legacy.js
  4. 4
      lib/crypto.js
  5. 4
      test/addons/make-callback/test.js
  6. 8
      test/inspector/inspector-helper.js
  7. 3
      test/parallel/test-assert.js
  8. 4
      test/parallel/test-child-process-fork-dgram.js
  9. 12
      test/parallel/test-child-process-fork-net.js
  10. 4
      test/parallel/test-child-process-fork-net2.js
  11. 2
      test/parallel/test-child-process-spawn-typeerror.js
  12. 8
      test/parallel/test-cluster-disconnect.js
  13. 2
      test/parallel/test-cluster-master-error.js
  14. 2
      test/parallel/test-cluster-master-kill.js
  15. 2
      test/parallel/test-cluster-message.js
  16. 2
      test/parallel/test-cluster-worker-exit.js
  17. 2
      test/parallel/test-console-not-call-toString.js
  18. 2
      test/parallel/test-debugger-pid.js
  19. 4
      test/parallel/test-event-emitter-add-listeners.js
  20. 4
      test/parallel/test-event-emitter-once.js
  21. 6
      test/parallel/test-fs-access.js
  22. 6
      test/parallel/test-fs-link.js
  23. 4
      test/parallel/test-fs-read-stream-fd-leak.js
  24. 94
      test/parallel/test-http-parser.js
  25. 4
      test/parallel/test-http-response-status-message.js
  26. 2
      test/parallel/test-https-simple.js
  27. 8
      test/parallel/test-net-server-max-connections-close-makes-more-available.js
  28. 4
      test/parallel/test-net-server-pause-on-connect.js
  29. 2
      test/parallel/test-net-socket-timeout.js
  30. 4
      test/parallel/test-os.js
  31. 6
      test/parallel/test-preload.js
  32. 2
      test/parallel/test-querystring.js
  33. 4
      test/parallel/test-readline-interface.js
  34. 8
      test/parallel/test-stream2-pipe-error-once-listener.js
  35. 4
      test/parallel/test-timers-ordering.js
  36. 12
      test/parallel/test-util-inspect.js
  37. 4
      test/pseudo-tty/test-tty-stdout-end.js
  38. 6
      test/pummel/test-dtrace-jsstack.js
  39. 6
      test/pummel/test-tls-session-timeout.js

2
doc/api/util.md

@ -557,7 +557,7 @@ Returns `true` if the given `object` is a `Function`. Otherwise, returns
const util = require('util'); const util = require('util');
function Foo() {} function Foo() {}
const Bar = function() {}; const Bar = () => {};
util.isFunction({}); util.isFunction({});
// Returns: false // Returns: false

2
lib/_http_client.js

@ -606,7 +606,7 @@ ClientRequest.prototype._deferToConnect = function(method, arguments_, cb) {
cb(); cb();
} }
var onSocket = function() { var onSocket = () => {
if (self.socket.writable) { if (self.socket.writable) {
callSocketMethod(); callSocketMethod();
} else { } else {

4
lib/_tls_legacy.js

@ -425,9 +425,9 @@ CryptoStream.prototype.destroySoon = function(err) {
// was written on this side was read from the other side. // was written on this side was read from the other side.
var self = this; var self = this;
var waiting = 1; var waiting = 1;
var finish = function() { function finish() {
if (--waiting === 0) self.destroy(); if (--waiting === 0) self.destroy();
}; }
this._opposite.once('end', finish); this._opposite.once('end', finish);
if (!this._finished) { if (!this._finished) {
this.once('finish', finish); this.once('finish', finish);

4
lib/crypto.js

@ -581,11 +581,11 @@ function pbkdf2(password, salt, iterations, keylen, digest, callback) {
// at this point, we need to handle encodings. // at this point, we need to handle encodings.
var encoding = exports.DEFAULT_ENCODING; var encoding = exports.DEFAULT_ENCODING;
if (callback) { if (callback) {
var next = function(er, ret) { function next(er, ret) {
if (ret) if (ret)
ret = ret.toString(encoding); ret = ret.toString(encoding);
callback(er, ret); callback(er, ret);
}; }
binding.PBKDF2(password, salt, iterations, keylen, digest, next); binding.PBKDF2(password, salt, iterations, keylen, digest, next);
} else { } else {
var ret = binding.PBKDF2(password, salt, iterations, keylen, digest); var ret = binding.PBKDF2(password, salt, iterations, keylen, digest);

4
test/addons/make-callback/test.js

@ -57,9 +57,9 @@ const forward = vm.runInNewContext(`
}) })
`); `);
// Runs in outer context. // Runs in outer context.
const endpoint = function($Object) { function endpoint($Object) {
if (Object === $Object) if (Object === $Object)
throw new Error('bad'); throw new Error('bad');
return Object; return Object;
}; }
assert.strictEqual(Object, makeCallback(process, forward, endpoint)); assert.strictEqual(Object, makeCallback(process, forward, endpoint));

8
test/inspector/inspector-helper.js

@ -120,7 +120,7 @@ function timeout(message, multiplicator) {
TIMEOUT * (multiplicator || 1)); TIMEOUT * (multiplicator || 1));
} }
const TestSession = function(socket, harness) { function TestSession(socket, harness) {
this.mainScriptPath = harness.mainScriptPath; this.mainScriptPath = harness.mainScriptPath;
this.mainScriptId = null; this.mainScriptId = null;
@ -145,7 +145,7 @@ const TestSession = function(socket, harness) {
buffer = buffer.slice(consumed); buffer = buffer.slice(consumed);
} while (consumed); } while (consumed);
}).on('close', () => assert(this.expectClose_, 'Socket closed prematurely')); }).on('close', () => assert(this.expectClose_, 'Socket closed prematurely'));
}; }
TestSession.prototype.scriptUrlForId = function(id) { TestSession.prototype.scriptUrlForId = function(id) {
return this.scripts_[id]; return this.scripts_[id];
@ -302,7 +302,7 @@ TestSession.prototype.testHttpResponse = function(path, check) {
}; };
const Harness = function(port, childProcess) { function Harness(port, childProcess) {
this.port = port; this.port = port;
this.mainScriptPath = mainScript; this.mainScriptPath = mainScript;
this.stderrFilters_ = []; this.stderrFilters_ = [];
@ -327,7 +327,7 @@ const Harness = function(port, childProcess) {
this.returnCode_ = code; this.returnCode_ = code;
this.running_ = false; this.running_ = false;
}); });
}; }
Harness.prototype.addStderrFilter = function(regexp, callback) { Harness.prototype.addStderrFilter = function(regexp, callback) {
this.stderrFilters_.push((message) => { this.stderrFilters_.push((message) => {

3
test/parallel/test-assert.js

@ -428,7 +428,7 @@ try {
AnotherErrorType = class extends Error {}; AnotherErrorType = class extends Error {};
const functionThatThrows = function() { const functionThatThrows = () => {
throw new AnotherErrorType('foo'); throw new AnotherErrorType('foo');
}; };
@ -471,6 +471,7 @@ a.throws(makeBlock(a.deepEqual, args, []));
// more checking that arguments objects are handled correctly // more checking that arguments objects are handled correctly
{ {
// eslint-disable-next-line func-style
const returnArguments = function() { return arguments; }; const returnArguments = function() { return arguments; };
const someArgs = returnArguments('a'); const someArgs = returnArguments('a');

4
test/parallel/test-child-process-fork-dgram.js

@ -57,7 +57,7 @@ if (process.argv[2] === 'child') {
}); });
}); });
const sendMessages = function() { function sendMessages() {
const serverPort = parentServer.address().port; const serverPort = parentServer.address().port;
const timer = setInterval(function() { const timer = setInterval(function() {
@ -81,7 +81,7 @@ if (process.argv[2] === 'child') {
); );
} }
}, 1); }, 1);
}; }
parentServer.bind(0, '127.0.0.1'); parentServer.bind(0, '127.0.0.1');

12
test/parallel/test-child-process-fork-net.js

@ -66,7 +66,7 @@ if (process.argv[2] === 'child') {
})); }));
// send net.Server to child and test by connecting // send net.Server to child and test by connecting
const testServer = function(callback) { function testServer(callback) {
// destroy server execute callback when done // destroy server execute callback when done
const progress = new ProgressTracker(2, function() { const progress = new ProgressTracker(2, function() {
@ -95,7 +95,7 @@ if (process.argv[2] === 'child') {
server.listen(0); server.listen(0);
// handle client messages // handle client messages
const messageHandlers = function(msg) { function messageHandlers(msg) {
if (msg.what === 'listening') { if (msg.what === 'listening') {
// make connections // make connections
@ -117,13 +117,13 @@ if (process.argv[2] === 'child') {
child.removeListener('message', messageHandlers); child.removeListener('message', messageHandlers);
callback(); callback();
} }
}; }
child.on('message', messageHandlers); child.on('message', messageHandlers);
}; }
// send net.Socket to child // send net.Socket to child
const testSocket = function(callback) { function testSocket(callback) {
// create a new server and connect to it, // create a new server and connect to it,
// but the socket will be handled by the child // but the socket will be handled by the child
@ -158,7 +158,7 @@ if (process.argv[2] === 'child') {
server.close(); server.close();
}); });
}); });
}; }
// create server and send it to child // create server and send it to child
let serverSuccess = false; let serverSuccess = false;

4
test/parallel/test-child-process-fork-net2.js

@ -123,7 +123,7 @@ if (process.argv[2] === 'child') {
server.listen(0, '127.0.0.1'); server.listen(0, '127.0.0.1');
let closeServer = function() { function closeServer() {
server.close(); server.close();
setTimeout(function() { setTimeout(function() {
@ -132,7 +132,7 @@ if (process.argv[2] === 'child') {
child2.send('close'); child2.send('close');
child3.disconnect(); child3.disconnect();
}, 200); }, 200);
}; }
process.on('exit', function() { process.on('exit', function() {
assert.strictEqual(disconnected, count); assert.strictEqual(disconnected, count);

2
test/parallel/test-child-process-spawn-typeerror.js

@ -57,7 +57,7 @@ assert.throws(function() {
// Argument types for combinatorics // Argument types for combinatorics
const a = []; const a = [];
const o = {}; const o = {};
const c = function c() {}; function c() {}
const s = 'string'; const s = 'string';
const u = undefined; const u = undefined;
const n = null; const n = null;

8
test/parallel/test-cluster-disconnect.js

@ -17,7 +17,7 @@ if (cluster.isWorker) {
const servers = 2; const servers = 2;
// test a single TCP server // test a single TCP server
const testConnection = function(port, cb) { const testConnection = (port, cb) => {
const socket = net.connect(port, '127.0.0.1', () => { const socket = net.connect(port, '127.0.0.1', () => {
// buffer result // buffer result
let result = ''; let result = '';
@ -31,7 +31,7 @@ if (cluster.isWorker) {
}; };
// test both servers created in the cluster // test both servers created in the cluster
const testCluster = function(cb) { const testCluster = (cb) => {
let done = 0; let done = 0;
for (let i = 0; i < servers; i++) { for (let i = 0; i < servers; i++) {
@ -46,7 +46,7 @@ if (cluster.isWorker) {
}; };
// start two workers and execute callback when both is listening // start two workers and execute callback when both is listening
const startCluster = function(cb) { const startCluster = (cb) => {
const workers = 8; const workers = 8;
let online = 0; let online = 0;
@ -60,7 +60,7 @@ if (cluster.isWorker) {
} }
}; };
const test = function(again) { const test = (again) => {
//1. start cluster //1. start cluster
startCluster(common.mustCall(() => { startCluster(common.mustCall(() => {
//2. test cluster //2. test cluster

2
test/parallel/test-cluster-master-error.js

@ -80,7 +80,7 @@ if (cluster.isWorker) {
// Check that the cluster died accidentally (non-zero exit code) // Check that the cluster died accidentally (non-zero exit code)
masterExited = !!code; masterExited = !!code;
const pollWorkers = function() { const pollWorkers = () => {
// When master is dead all workers should be dead too // When master is dead all workers should be dead too
let alive = false; let alive = false;
workers.forEach((pid) => alive = common.isAlive(pid)); workers.forEach((pid) => alive = common.isAlive(pid));

2
test/parallel/test-cluster-master-kill.js

@ -47,7 +47,7 @@ if (cluster.isWorker) {
assert.strictEqual(code, 0); assert.strictEqual(code, 0);
// check worker process status // check worker process status
const pollWorker = function() { const pollWorker = () => {
alive = common.isAlive(pid); alive = common.isAlive(pid);
if (alive) { if (alive) {
setTimeout(pollWorker, 50); setTimeout(pollWorker, 50);

2
test/parallel/test-cluster-message.js

@ -59,7 +59,7 @@ if (cluster.isWorker) {
let client; let client;
const check = function(type, result) { const check = (type, result) => {
checks[type].receive = true; checks[type].receive = true;
checks[type].correct = result; checks[type].correct = result;
console.error('check', checks); console.error('check', checks);

2
test/parallel/test-cluster-worker-exit.js

@ -82,7 +82,7 @@ if (cluster.isWorker) {
} }
})); }));
const finish_test = function() { const finish_test = () => {
try { try {
checkResults(expected_results, results); checkResults(expected_results, results);
} catch (exc) { } catch (exc) {

2
test/parallel/test-console-not-call-toString.js

@ -2,7 +2,7 @@
require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const func = function() {}; function func() {}
let toStringCalled = false; let toStringCalled = false;
func.toString = function() { func.toString = function() {
toStringCalled = true; toStringCalled = true;

2
test/parallel/test-debugger-pid.js

@ -11,7 +11,7 @@ const interfacer = spawn(process.execPath, ['debug', '-p', '655555']);
console.error(process.execPath, 'debug', '-p', '655555'); console.error(process.execPath, 'debug', '-p', '655555');
interfacer.stdout.setEncoding('utf-8'); interfacer.stdout.setEncoding('utf-8');
interfacer.stderr.setEncoding('utf-8'); interfacer.stderr.setEncoding('utf-8');
const onData = function(data) { const onData = (data) => {
data = (buffer + data).split('\n'); data = (buffer + data).split('\n');
buffer = data.pop(); buffer = data.pop();
data.forEach(function(line) { data.forEach(function(line) {

4
test/parallel/test-event-emitter-add-listeners.js

@ -47,8 +47,8 @@ const EventEmitter = require('events');
} }
{ {
const listen1 = function listen1() {}; const listen1 = () => {};
const listen2 = function listen2() {}; const listen2 = () => {};
const ee = new EventEmitter(); const ee = new EventEmitter();
ee.once('newListener', function() { ee.once('newListener', function() {

4
test/parallel/test-event-emitter-once.js

@ -12,9 +12,9 @@ e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b'); e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b'); e.emit('hello', 'a', 'b');
const remove = function() { function remove() {
common.fail('once->foo should not be emitted'); common.fail('once->foo should not be emitted');
}; }
e.once('foo', remove); e.once('foo', remove);
e.removeListener('foo', remove); e.removeListener('foo', remove);

6
test/parallel/test-fs-access.js

@ -7,7 +7,7 @@ const doesNotExist = path.join(common.tmpDir, '__this_should_not_exist');
const readOnlyFile = path.join(common.tmpDir, 'read_only_file'); const readOnlyFile = path.join(common.tmpDir, 'read_only_file');
const readWriteFile = path.join(common.tmpDir, 'read_write_file'); const readWriteFile = path.join(common.tmpDir, 'read_write_file');
const removeFile = function(file) { const removeFile = (file) => {
try { try {
fs.unlinkSync(file); fs.unlinkSync(file);
} catch (err) { } catch (err) {
@ -15,11 +15,11 @@ const removeFile = function(file) {
} }
}; };
const createFileWithPerms = function(file, mode) { function createFileWithPerms(file, mode) {
removeFile(file); removeFile(file);
fs.writeFileSync(file, ''); fs.writeFileSync(file, '');
fs.chmodSync(file, mode); fs.chmodSync(file, mode);
}; }
common.refreshTmpDir(); common.refreshTmpDir();
createFileWithPerms(readOnlyFile, 0o444); createFileWithPerms(readOnlyFile, 0o444);

6
test/parallel/test-fs-link.js

@ -11,11 +11,11 @@ const srcPath = path.join(common.tmpDir, 'hardlink-target.txt');
const dstPath = path.join(common.tmpDir, 'link1.js'); const dstPath = path.join(common.tmpDir, 'link1.js');
fs.writeFileSync(srcPath, 'hello world'); fs.writeFileSync(srcPath, 'hello world');
const callback = function(err) { function callback(err) {
if (err) throw err; assert.ifError(err);
const dstContent = fs.readFileSync(dstPath, 'utf8'); const dstContent = fs.readFileSync(dstPath, 'utf8');
assert.strictEqual('hello world', dstContent); assert.strictEqual('hello world', dstContent);
}; }
fs.link(srcPath, dstPath, common.mustCall(callback)); fs.link(srcPath, dstPath, common.mustCall(callback));

4
test/parallel/test-fs-read-stream-fd-leak.js

@ -29,7 +29,7 @@ function testLeak(endFn, callback) {
let i = 0; let i = 0;
let check = 0; let check = 0;
const checkFunction = function() { function checkFunction() {
if (openCount !== 0 && check < totalCheck) { if (openCount !== 0 && check < totalCheck) {
check++; check++;
setTimeout(checkFunction, 100); setTimeout(checkFunction, 100);
@ -44,7 +44,7 @@ function testLeak(endFn, callback) {
openCount = 0; openCount = 0;
callback && setTimeout(callback, 100); callback && setTimeout(callback, 100);
}; }
setInterval(function() { setInterval(function() {
const s = fs.createReadStream(emptyTxt); const s = fs.createReadStream(emptyTxt);

94
test/parallel/test-http-parser.js

@ -77,9 +77,9 @@ function expectBody(expected) {
'GET /hello HTTP/1.1' + CRLF + 'GET /hello HTTP/1.1' + CRLF +
CRLF); CRLF);
const onHeadersComplete = function(versionMajor, versionMinor, headers, const onHeadersComplete = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage, method, url, statusCode, statusMessage,
upgrade, shouldKeepAlive) { upgrade, shouldKeepAlive) => {
assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMajor, 1);
assert.strictEqual(versionMinor, 1); assert.strictEqual(versionMinor, 1);
assert.strictEqual(method, methods.indexOf('GET')); assert.strictEqual(method, methods.indexOf('GET'));
@ -118,9 +118,9 @@ function expectBody(expected) {
CRLF + CRLF +
'pong'); 'pong');
const onHeadersComplete = function(versionMajor, versionMinor, headers, const onHeadersComplete = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage, method, url, statusCode, statusMessage,
upgrade, shouldKeepAlive) { upgrade, shouldKeepAlive) => {
assert.strictEqual(method, undefined); assert.strictEqual(method, undefined);
assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMajor, 1);
assert.strictEqual(versionMinor, 1); assert.strictEqual(versionMinor, 1);
@ -128,7 +128,7 @@ function expectBody(expected) {
assert.strictEqual(statusMessage, 'OK'); assert.strictEqual(statusMessage, 'OK');
}; };
const onBody = function(buf, start, len) { const onBody = (buf, start, len) => {
const body = '' + buf.slice(start, start + len); const body = '' + buf.slice(start, start + len);
assert.strictEqual(body, 'pong'); assert.strictEqual(body, 'pong');
}; };
@ -148,9 +148,9 @@ function expectBody(expected) {
'HTTP/1.0 200 Connection established' + CRLF + 'HTTP/1.0 200 Connection established' + CRLF +
CRLF); CRLF);
const onHeadersComplete = function(versionMajor, versionMinor, headers, const onHeadersComplete = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage, method, url, statusCode, statusMessage,
upgrade, shouldKeepAlive) { upgrade, shouldKeepAlive) => {
assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMajor, 1);
assert.strictEqual(versionMinor, 0); assert.strictEqual(versionMinor, 0);
assert.strictEqual(method, undefined); assert.strictEqual(method, undefined);
@ -182,15 +182,15 @@ function expectBody(expected) {
let seen_body = false; let seen_body = false;
const onHeaders = function(headers, url) { const onHeaders = (headers, url) => {
assert.ok(seen_body); // trailers should come after the body assert.ok(seen_body); // trailers should come after the body
assert.deepStrictEqual(headers, assert.deepStrictEqual(headers,
['Vary', '*', 'Content-Type', 'text/plain']); ['Vary', '*', 'Content-Type', 'text/plain']);
}; };
const onHeadersComplete = function(versionMajor, versionMinor, headers, const onHeadersComplete = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage, method, url, statusCode, statusMessage,
upgrade, shouldKeepAlive) { upgrade, shouldKeepAlive) => {
assert.strictEqual(method, methods.indexOf('POST')); assert.strictEqual(method, methods.indexOf('POST'));
assert.strictEqual(url || parser.url, '/it'); assert.strictEqual(url || parser.url, '/it');
assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMajor, 1);
@ -199,7 +199,7 @@ function expectBody(expected) {
parser[kOnHeaders] = mustCall(onHeaders); parser[kOnHeaders] = mustCall(onHeaders);
}; };
const onBody = function(buf, start, len) { const onBody = (buf, start, len) => {
const body = '' + buf.slice(start, start + len); const body = '' + buf.slice(start, start + len);
assert.strictEqual(body, 'ping'); assert.strictEqual(body, 'ping');
seen_body = true; seen_body = true;
@ -223,9 +223,9 @@ function expectBody(expected) {
'X-Filler2: 42' + CRLF + 'X-Filler2: 42' + CRLF +
CRLF); CRLF);
const onHeadersComplete = function(versionMajor, versionMinor, headers, const onHeadersComplete = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage, method, url, statusCode, statusMessage,
upgrade, shouldKeepAlive) { upgrade, shouldKeepAlive) => {
assert.strictEqual(method, methods.indexOf('GET')); assert.strictEqual(method, methods.indexOf('GET'));
assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMajor, 1);
assert.strictEqual(versionMinor, 0); assert.strictEqual(versionMinor, 0);
@ -253,9 +253,9 @@ function expectBody(expected) {
lots_of_headers + lots_of_headers +
CRLF); CRLF);
const onHeadersComplete = function(versionMajor, versionMinor, headers, const onHeadersComplete = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage, method, url, statusCode, statusMessage,
upgrade, shouldKeepAlive) { upgrade, shouldKeepAlive) => {
assert.strictEqual(method, methods.indexOf('GET')); assert.strictEqual(method, methods.indexOf('GET'));
assert.strictEqual(url || parser.url, '/foo/bar/baz?quux=42#1337'); assert.strictEqual(url || parser.url, '/foo/bar/baz?quux=42#1337');
assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMajor, 1);
@ -287,16 +287,16 @@ function expectBody(expected) {
CRLF + CRLF +
'foo=42&bar=1337'); 'foo=42&bar=1337');
const onHeadersComplete = function(versionMajor, versionMinor, headers, const onHeadersComplete = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage, method, url, statusCode, statusMessage,
upgrade, shouldKeepAlive) { upgrade, shouldKeepAlive) => {
assert.strictEqual(method, methods.indexOf('POST')); assert.strictEqual(method, methods.indexOf('POST'));
assert.strictEqual(url || parser.url, '/it'); assert.strictEqual(url || parser.url, '/it');
assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMajor, 1);
assert.strictEqual(versionMinor, 1); assert.strictEqual(versionMinor, 1);
}; };
const onBody = function(buf, start, len) { const onBody = (buf, start, len) => {
const body = '' + buf.slice(start, start + len); const body = '' + buf.slice(start, start + len);
assert.strictEqual(body, 'foo=42&bar=1337'); assert.strictEqual(body, 'foo=42&bar=1337');
}; };
@ -325,9 +325,9 @@ function expectBody(expected) {
'1234567890' + CRLF + '1234567890' + CRLF +
'0' + CRLF); '0' + CRLF);
const onHeadersComplete = function(versionMajor, versionMinor, headers, const onHeadersComplete = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage, method, url, statusCode, statusMessage,
upgrade, shouldKeepAlive) { upgrade, shouldKeepAlive) => {
assert.strictEqual(method, methods.indexOf('POST')); assert.strictEqual(method, methods.indexOf('POST'));
assert.strictEqual(url || parser.url, '/it'); assert.strictEqual(url || parser.url, '/it');
assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMajor, 1);
@ -337,7 +337,7 @@ function expectBody(expected) {
let body_part = 0; let body_part = 0;
const body_parts = ['123', '123456', '1234567890']; const body_parts = ['123', '123456', '1234567890'];
const onBody = function(buf, start, len) { const onBody = (buf, start, len) => {
const body = '' + buf.slice(start, start + len); const body = '' + buf.slice(start, start + len);
assert.strictEqual(body, body_parts[body_part++]); assert.strictEqual(body, body_parts[body_part++]);
}; };
@ -363,9 +363,9 @@ function expectBody(expected) {
'6' + CRLF + '6' + CRLF +
'123456' + CRLF); '123456' + CRLF);
const onHeadersComplete = function(versionMajor, versionMinor, headers, const onHeadersComplete = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage, method, url, statusCode, statusMessage,
upgrade, shouldKeepAlive) { upgrade, shouldKeepAlive) => {
assert.strictEqual(method, methods.indexOf('POST')); assert.strictEqual(method, methods.indexOf('POST'));
assert.strictEqual(url || parser.url, '/it'); assert.strictEqual(url || parser.url, '/it');
assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMajor, 1);
@ -376,7 +376,7 @@ function expectBody(expected) {
const body_parts = const body_parts =
['123', '123456', '123456789', '123456789ABC', '123456789ABCDEF']; ['123', '123456', '123456789', '123456789ABC', '123456789ABCDEF'];
const onBody = function(buf, start, len) { const onBody = (buf, start, len) => {
const body = '' + buf.slice(start, start + len); const body = '' + buf.slice(start, start + len);
assert.strictEqual(body, body_parts[body_part++]); assert.strictEqual(body, body_parts[body_part++]);
}; };
@ -421,9 +421,9 @@ function expectBody(expected) {
'0' + CRLF); '0' + CRLF);
function test(a, b) { function test(a, b) {
const onHeadersComplete = function(versionMajor, versionMinor, headers, const onHeadersComplete = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage, method, url, statusCode, statusMessage,
upgrade, shouldKeepAlive) { upgrade, shouldKeepAlive) => {
assert.strictEqual(method, methods.indexOf('POST')); assert.strictEqual(method, methods.indexOf('POST'));
assert.strictEqual(url || parser.url, '/helpme'); assert.strictEqual(url || parser.url, '/helpme');
assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMajor, 1);
@ -432,7 +432,7 @@ function expectBody(expected) {
let expected_body = '123123456123456789123456789ABC123456789ABCDEF'; let expected_body = '123123456123456789123456789ABC123456789ABCDEF';
const onBody = function(buf, start, len) { const onBody = (buf, start, len) => {
const chunk = '' + buf.slice(start, start + len); const chunk = '' + buf.slice(start, start + len);
assert.strictEqual(expected_body.indexOf(chunk), 0); assert.strictEqual(expected_body.indexOf(chunk), 0);
expected_body = expected_body.slice(chunk.length); expected_body = expected_body.slice(chunk.length);
@ -480,9 +480,9 @@ function expectBody(expected) {
'123456789ABCDEF' + CRLF + '123456789ABCDEF' + CRLF +
'0' + CRLF); '0' + CRLF);
const onHeadersComplete = function(versionMajor, versionMinor, headers, const onHeadersComplete = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage, method, url, statusCode, statusMessage,
upgrade, shouldKeepAlive) { upgrade, shouldKeepAlive) => {
assert.strictEqual(method, methods.indexOf('POST')); assert.strictEqual(method, methods.indexOf('POST'));
assert.strictEqual(url || parser.url, '/it'); assert.strictEqual(url || parser.url, '/it');
assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMajor, 1);
@ -494,7 +494,7 @@ function expectBody(expected) {
let expected_body = '123123456123456789123456789ABC123456789ABCDEF'; let expected_body = '123123456123456789123456789ABC123456789ABCDEF';
const onBody = function(buf, start, len) { const onBody = (buf, start, len) => {
const chunk = '' + buf.slice(start, start + len); const chunk = '' + buf.slice(start, start + len);
assert.strictEqual(expected_body.indexOf(chunk), 0); assert.strictEqual(expected_body.indexOf(chunk), 0);
expected_body = expected_body.slice(chunk.length); expected_body = expected_body.slice(chunk.length);
@ -532,9 +532,9 @@ function expectBody(expected) {
CRLF + CRLF +
'pong'); 'pong');
const onHeadersComplete1 = function(versionMajor, versionMinor, headers, const onHeadersComplete1 = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage, method, url, statusCode, statusMessage,
upgrade, shouldKeepAlive) { upgrade, shouldKeepAlive) => {
assert.strictEqual(method, methods.indexOf('PUT')); assert.strictEqual(method, methods.indexOf('PUT'));
assert.strictEqual(url, '/this'); assert.strictEqual(url, '/this');
assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMajor, 1);
@ -544,9 +544,9 @@ function expectBody(expected) {
['Content-Type', 'text/plain', 'Transfer-Encoding', 'chunked']); ['Content-Type', 'text/plain', 'Transfer-Encoding', 'chunked']);
}; };
const onHeadersComplete2 = function(versionMajor, versionMinor, headers, const onHeadersComplete2 = (versionMajor, versionMinor, headers,
method, url, statusCode, statusMessage, method, url, statusCode, statusMessage,
upgrade, shouldKeepAlive) { upgrade, shouldKeepAlive) => {
assert.strictEqual(method, methods.indexOf('POST')); assert.strictEqual(method, methods.indexOf('POST'));
assert.strictEqual(url, '/that'); assert.strictEqual(url, '/that');
assert.strictEqual(versionMajor, 1); assert.strictEqual(versionMajor, 1);

4
test/parallel/test-http-response-status-message.js

@ -38,7 +38,7 @@ const server = net.createServer(function(connection) {
}); });
}); });
const runTest = function(testCaseIndex) { function runTest(testCaseIndex) {
const testCase = testCases[testCaseIndex]; const testCase = testCases[testCaseIndex];
http.get({ http.get({
@ -61,7 +61,7 @@ const runTest = function(testCaseIndex) {
response.resume(); response.resume();
}); });
}; }
server.listen(0, function() { runTest(0); }); server.listen(0, function() { runTest(0); });

2
test/parallel/test-https-simple.js

@ -18,7 +18,7 @@ const options = {
const tests = 2; const tests = 2;
let successful = 0; let successful = 0;
const testSucceeded = function() { const testSucceeded = () => {
successful = successful + 1; successful = successful + 1;
if (successful === tests) { if (successful === tests) {
server.close(); server.close();

8
test/parallel/test-net-server-max-connections-close-makes-more-available.js

@ -17,7 +17,7 @@ const connections = [];
const received = []; const received = [];
const sent = []; const sent = [];
const createConnection = function(index) { function createConnection(index) {
console.error('creating connection ' + index); console.error('creating connection ' + index);
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
@ -45,9 +45,9 @@ const createConnection = function(index) {
connections[index] = connection; connections[index] = connection;
}); });
}; }
const closeConnection = function(index) { function closeConnection(index) {
console.error('closing connection ' + index); console.error('closing connection ' + index);
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
connections[index].on('end', function() { connections[index].on('end', function() {
@ -55,7 +55,7 @@ const closeConnection = function(index) {
}); });
connections[index].end(); connections[index].end();
}); });
}; }
let server = net.createServer(function(socket) { let server = net.createServer(function(socket) {
socket.on('data', function(data) { socket.on('data', function(data) {

4
test/parallel/test-net-server-pause-on-connect.js

@ -7,7 +7,7 @@ let stopped = true;
let server1Sock; let server1Sock;
const server1ConnHandler = function(socket) { const server1ConnHandler = (socket) => {
socket.on('data', function(data) { socket.on('data', function(data) {
if (stopped) { if (stopped) {
common.fail('data event should not have happened yet'); common.fail('data event should not have happened yet');
@ -23,7 +23,7 @@ const server1ConnHandler = function(socket) {
const server1 = net.createServer({pauseOnConnect: true}, server1ConnHandler); const server1 = net.createServer({pauseOnConnect: true}, server1ConnHandler);
const server2ConnHandler = function(socket) { const server2ConnHandler = (socket) => {
socket.on('data', function(data) { socket.on('data', function(data) {
assert.strictEqual(data.toString(), msg, 'invalid data received'); assert.strictEqual(data.toString(), msg, 'invalid data received');
socket.end(); socket.end();

2
test/parallel/test-net-socket-timeout.js

@ -4,7 +4,7 @@ const net = require('net');
const assert = require('assert'); const assert = require('assert');
// Verify that invalid delays throw // Verify that invalid delays throw
const noop = function() {}; const noop = () => {};
const s = new net.Socket(); const s = new net.Socket();
const nonNumericDelays = [ const nonNumericDelays = [
'100', true, false, undefined, null, '', {}, noop, [] '100', true, false, undefined, null, '', {}, noop, []

4
test/parallel/test-os.js

@ -104,7 +104,7 @@ console.error(interfaces);
switch (platform) { switch (platform) {
case 'linux': case 'linux':
{ {
const filter = function(e) { return e.address === '127.0.0.1'; }; const filter = (e) => e.address === '127.0.0.1';
const actual = interfaces.lo.filter(filter); const actual = interfaces.lo.filter(filter);
const expected = [{ address: '127.0.0.1', netmask: '255.0.0.0', const expected = [{ address: '127.0.0.1', netmask: '255.0.0.0',
mac: '00:00:00:00:00:00', family: 'IPv4', mac: '00:00:00:00:00:00', family: 'IPv4',
@ -114,7 +114,7 @@ switch (platform) {
} }
case 'win32': case 'win32':
{ {
const filter = function(e) { return e.address === '127.0.0.1'; }; const filter = (e) => e.address === '127.0.0.1';
const actual = interfaces['Loopback Pseudo-Interface 1'].filter(filter); const actual = interfaces['Loopback Pseudo-Interface 1'].filter(filter);
const expected = [{ address: '127.0.0.1', netmask: '255.0.0.0', const expected = [{ address: '127.0.0.1', netmask: '255.0.0.0',
mac: '00:00:00:00:00:00', family: 'IPv4', mac: '00:00:00:00:00:00', family: 'IPv4',

6
test/parallel/test-preload.js

@ -13,7 +13,7 @@ if (common.isSunOS) {
const nodeBinary = process.argv[0]; const nodeBinary = process.argv[0];
const preloadOption = function(preloads) { const preloadOption = (preloads) => {
let option = ''; let option = '';
preloads.forEach(function(preload, index) { preloads.forEach(function(preload, index) {
option += '-r ' + preload + ' '; option += '-r ' + preload + ' ';
@ -21,9 +21,7 @@ const preloadOption = function(preloads) {
return option; return option;
}; };
const fixture = function(name) { const fixture = (name) => path.join(common.fixturesDir, name);
return path.join(common.fixturesDir, name);
};
const fixtureA = fixture('printA.js'); const fixtureA = fixture('printA.js');
const fixtureB = fixture('printB.js'); const fixtureB = fixture('printB.js');

2
test/parallel/test-querystring.js

@ -67,7 +67,7 @@ const qsColonTestCases = [
]; ];
// [wonkyObj, qs, canonicalObj] // [wonkyObj, qs, canonicalObj]
const extendedFunction = function() {}; function extendedFunction() {}
extendedFunction.prototype = {a: 'b'}; extendedFunction.prototype = {a: 'b'};
const qsWeirdObjects = [ const qsWeirdObjects = [
[{regexp: /./g}, 'regexp=', {'regexp': ''}], [{regexp: /./g}, 'regexp=', {'regexp': ''}],

4
test/parallel/test-readline-interface.js

@ -265,9 +265,7 @@ function isWarned(emitter) {
// \t does not become part of the input when there is a completer function // \t does not become part of the input when there is a completer function
fi = new FakeInput(); fi = new FakeInput();
const completer = function(line) { const completer = (line) => [[], line];
return [[], line];
};
rli = new readline.Interface({ rli = new readline.Interface({
input: fi, input: fi,
output: fi, output: fi,

8
test/parallel/test-stream2-pipe-error-once-listener.js

@ -5,9 +5,9 @@ const util = require('util');
const stream = require('stream'); const stream = require('stream');
const Read = function() { function Read() {
stream.Readable.call(this); stream.Readable.call(this);
}; }
util.inherits(Read, stream.Readable); util.inherits(Read, stream.Readable);
Read.prototype._read = function(size) { Read.prototype._read = function(size) {
@ -16,9 +16,9 @@ Read.prototype._read = function(size) {
}; };
const Write = function() { function Write() {
stream.Writable.call(this); stream.Writable.call(this);
}; }
util.inherits(Write, stream.Writable); util.inherits(Write, stream.Writable);
Write.prototype._write = function(buffer, encoding, cb) { Write.prototype._write = function(buffer, encoding, cb) {

4
test/parallel/test-timers-ordering.js

@ -8,7 +8,7 @@ const N = 30;
let last_i = 0; let last_i = 0;
let last_ts = 0; let last_ts = 0;
const f = function(i) { function f(i) {
if (i <= N) { if (i <= N) {
// check order // check order
assert.strictEqual(i, last_i + 1, 'order is broken: ' + i + ' != ' + assert.strictEqual(i, last_i + 1, 'order is broken: ' + i + ' != ' +
@ -25,5 +25,5 @@ const f = function(i) {
// schedule next iteration // schedule next iteration
setTimeout(f, 1, i + 1); setTimeout(f, 1, i + 1);
} }
}; }
f(1); f(1);

12
test/parallel/test-util-inspect.js

@ -252,9 +252,11 @@ Object.defineProperty(
assert.strictEqual(util.inspect(value), '[ 1, 2, 3, growingLength: [Getter] ]'); assert.strictEqual(util.inspect(value), '[ 1, 2, 3, growingLength: [Getter] ]');
// Function with properties // Function with properties
value = function() {}; {
value.aprop = 42; const value = () => {};
assert.strictEqual(util.inspect(value), '{ [Function: value] aprop: 42 }'); value.aprop = 42;
assert.strictEqual(util.inspect(value), '{ [Function: value] aprop: 42 }');
}
// Anonymous function with properties // Anonymous function with properties
value = (() => function() {})(); value = (() => function() {})();
@ -595,9 +597,7 @@ assert.doesNotThrow(function() {
// util.inspect with "colors" option should produce as many lines as without it // util.inspect with "colors" option should produce as many lines as without it
function test_lines(input) { function test_lines(input) {
const count_lines = function(str) { const count_lines = (str) => (str.match(/\n/g) || []).length;
return (str.match(/\n/g) || []).length;
};
const without_color = util.inspect(input); const without_color = util.inspect(input);
const with_color = util.inspect(input, {colors: true}); const with_color = util.inspect(input, {colors: true});

4
test/pseudo-tty/test-tty-stdout-end.js

@ -2,11 +2,11 @@
require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
const shouldThrow = function() { const shouldThrow = () => {
process.stdout.end(); process.stdout.end();
}; };
const validateError = function(e) { const validateError = (e) => {
return e instanceof Error && return e instanceof Error &&
e.message === 'process.stdout cannot be closed.'; e.message === 'process.stdout cannot be closed.';
}; };

6
test/pummel/test-dtrace-jsstack.js

@ -13,18 +13,18 @@ if (!common.isSunOS) {
*/ */
const frames = [ 'stalloogle', 'bagnoogle', 'doogle' ]; const frames = [ 'stalloogle', 'bagnoogle', 'doogle' ];
const stalloogle = function(str) { const stalloogle = (str) => {
global.expected = str; global.expected = str;
os.loadavg(); os.loadavg();
}; };
const bagnoogle = function(arg0, arg1) { const bagnoogle = (arg0, arg1) => {
stalloogle(arg0 + ' is ' + arg1 + ' except that it is read-only'); stalloogle(arg0 + ' is ' + arg1 + ' except that it is read-only');
}; };
let done = false; let done = false;
const doogle = function() { const doogle = () => {
if (!done) if (!done)
setTimeout(doogle, 10); setTimeout(doogle, 10);

6
test/pummel/test-tls-session-timeout.js

@ -57,7 +57,7 @@ function doTest() {
// Expects a callback -- cb(connectionType : enum ['New'|'Reused']) // Expects a callback -- cb(connectionType : enum ['New'|'Reused'])
const Client = function(cb) { function Client(cb) {
const flags = [ const flags = [
's_client', 's_client',
'-connect', 'localhost:' + common.PORT, '-connect', 'localhost:' + common.PORT,
@ -74,7 +74,7 @@ function doTest() {
}); });
client.on('exit', function(code) { client.on('exit', function(code) {
let connectionType; let connectionType;
const grepConnectionType = function(line) { const grepConnectionType = (line) => {
const matches = line.match(/(New|Reused), /); const matches = line.match(/(New|Reused), /);
if (matches) { if (matches) {
connectionType = matches[1]; connectionType = matches[1];
@ -87,7 +87,7 @@ function doTest() {
} }
cb(connectionType); cb(connectionType);
}); });
}; }
const server = tls.createServer(options, function(cleartext) { const server = tls.createServer(options, function(cleartext) {
cleartext.on('error', function(er) { cleartext.on('error', function(er) {

Loading…
Cancel
Save