Browse Source

test: use eslint to fix var->const/let

Manually fix issues that eslint --fix couldn't do automatically.

Backport-PR-URL: https://github.com/nodejs/node/pull/11775
PR-URL: https://github.com/nodejs/node/pull/10685
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
v6.x
Gibson Fahnestock 8 years ago
committed by Myles Borins
parent
commit
db61c952de
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 2
      test/addons/async-hello-world/test.js
  2. 4
      test/addons/buffer-free-callback/test.js
  3. 2
      test/addons/hello-world-function-export/test.js
  4. 2
      test/addons/hello-world/test.js
  5. 8
      test/addons/load-long-path/test.js
  6. 2
      test/addons/make-callback-recurse/test.js
  7. 24
      test/addons/repl-domain-abort/test.js
  8. 3
      test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js
  9. 3
      test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js
  10. 3
      test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js
  11. 5
      test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js
  12. 3
      test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js
  13. 3
      test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js
  14. 3
      test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js
  15. 3
      test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js
  16. 2
      test/common.js
  17. 32
      test/debugger/helper-debugger-repl.js
  18. 70
      test/debugger/test-debugger-client.js
  19. 2
      test/debugger/test-debugger-repl-break-in-module.js
  20. 6
      test/debugger/test-debugger-repl-restart.js
  21. 4
      test/debugger/test-debugger-repl-term.js
  22. 4
      test/debugger/test-debugger-repl-utf8.js
  23. 6
      test/debugger/test-debugger-repl.js
  24. 8
      test/gc/test-http-client-connaborted.js
  25. 8
      test/gc/test-http-client-onerror.js
  26. 8
      test/gc/test-http-client-timeout.js
  27. 6
      test/gc/test-http-client.js
  28. 6
      test/gc/test-net-timeout.js
  29. 4
      test/inspector/inspector-helper.js
  30. 20
      test/internet/test-dgram-multicast-multi-process.js
  31. 14
      test/internet/test-dgram-send-cb-quelches-error.js
  32. 10
      test/internet/test-dns-cares-domains.js
  33. 4
      test/internet/test-dns-txt-sigsegv.js
  34. 84
      test/internet/test-dns.js
  35. 6
      test/internet/test-http-https-default-ports.js
  36. 12
      test/internet/test-net-connect-timeout.js
  37. 7
      test/internet/test-net-connect-unref.js
  38. 6
      test/internet/test-tls-connnect-melissadata.js
  39. 8
      test/known_issues/test-url-parse-conformance.js
  40. 2
      test/message/error_exit.js
  41. 10
      test/message/eval_messages.js
  42. 2
      test/message/max_tick_depth.js
  43. 10
      test/message/stdin_messages.js
  44. 2
      test/message/undefined_reference_in_new_context.js
  45. 2
      test/message/vm_display_runtime_error.js
  46. 2
      test/message/vm_display_syntax_error.js
  47. 2
      test/message/vm_dont_display_runtime_error.js
  48. 2
      test/message/vm_dont_display_syntax_error.js
  49. 2
      test/parallel/test-assert-typedarray-deepequal.js
  50. 35
      test/parallel/test-assert.js
  51. 2
      test/parallel/test-async-wrap-check-providers.js
  52. 6
      test/parallel/test-async-wrap-throw-from-callback.js
  53. 2
      test/parallel/test-async-wrap-uid.js
  54. 2
      test/parallel/test-beforeexit-event-exit.js
  55. 2
      test/parallel/test-buffer-ascii.js
  56. 26
      test/parallel/test-buffer-bytelength.js
  57. 2
      test/parallel/test-buffer-concat.js
  58. 2
      test/parallel/test-buffer-copy.js
  59. 6
      test/parallel/test-buffer-fill.js
  60. 10
      test/parallel/test-buffer-includes.js
  61. 39
      test/parallel/test-buffer-indexof.js
  62. 6
      test/parallel/test-buffer-inspect.js
  63. 4
      test/parallel/test-buffer-iterator.js
  64. 48
      test/parallel/test-buffer-swap.js
  65. 98
      test/parallel/test-buffer.js
  66. 8
      test/parallel/test-child-process-constructor.js
  67. 10
      test/parallel/test-child-process-default-options.js
  68. 4
      test/parallel/test-child-process-double-pipe.js
  69. 12
      test/parallel/test-child-process-env.js
  70. 2
      test/parallel/test-child-process-exec-cwd.js
  71. 4
      test/parallel/test-child-process-exec-stdout-stderr-data-string.js
  72. 18
      test/parallel/test-child-process-exit-code.js
  73. 2
      test/parallel/test-child-process-fork-close.js
  74. 4
      test/parallel/test-child-process-fork-dgram.js
  75. 16
      test/parallel/test-child-process-fork-exec-argv.js
  76. 16
      test/parallel/test-child-process-fork-exec-path.js
  77. 32
      test/parallel/test-child-process-fork-net.js
  78. 28
      test/parallel/test-child-process-fork-net2.js
  79. 9
      test/parallel/test-child-process-fork-ref.js
  80. 4
      test/parallel/test-child-process-fork-ref2.js
  81. 6
      test/parallel/test-child-process-fork-regr-gh-2847.js
  82. 8
      test/parallel/test-child-process-fork.js
  83. 4
      test/parallel/test-child-process-fork3.js
  84. 12
      test/parallel/test-child-process-internal.js
  85. 2
      test/parallel/test-child-process-send-returns-boolean.js
  86. 8
      test/parallel/test-child-process-set-blocking.js
  87. 16
      test/parallel/test-child-process-silent.js
  88. 2
      test/parallel/test-child-process-spawn-typeerror.js
  89. 8
      test/parallel/test-child-process-spawnsync-env.js
  90. 4
      test/parallel/test-child-process-spawnsync-input.js
  91. 6
      test/parallel/test-child-process-spawnsync-timeout.js
  92. 6
      test/parallel/test-child-process-stdin-ipc.js
  93. 3
      test/parallel/test-child-process-stdio-big-write-end.js
  94. 12
      test/parallel/test-child-process-stdio-inherit.js
  95. 4
      test/parallel/test-cli-eval.js
  96. 20
      test/parallel/test-cli-syntax.js
  97. 4
      test/parallel/test-cluster-basic.js
  98. 2
      test/parallel/test-cluster-bind-privileged-port.js
  99. 12
      test/parallel/test-cluster-dgram-1.js
  100. 6
      test/parallel/test-cluster-dgram-2.js

2
test/addons/async-hello-world/test.js

@ -1,6 +1,6 @@
'use strict';
const common = require('../../common');
var assert = require('assert');
const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
binding(5, common.mustCall(function(err, val) {

4
test/addons/buffer-free-callback/test.js

@ -5,8 +5,8 @@ const common = require('../../common');
const binding = require(`./build/${common.buildType}/binding`);
function check(size, alignment, offset) {
var buf = binding.alloc(size, alignment, offset);
var slice = buf.slice(size >>> 1);
let buf = binding.alloc(size, alignment, offset);
let slice = buf.slice(size >>> 1);
buf = null;
binding.check(slice);

2
test/addons/hello-world-function-export/test.js

@ -1,6 +1,6 @@
'use strict';
const common = require('../../common');
var assert = require('assert');
const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
assert.strictEqual(binding(), 'world');
console.log('binding.hello() =', binding());

2
test/addons/hello-world/test.js

@ -1,6 +1,6 @@
'use strict';
const common = require('../../common');
var assert = require('assert');
const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
assert.strictEqual(binding.hello(), 'world');
console.log('binding.hello() =', binding.hello());

8
test/addons/load-long-path/test.js

@ -14,9 +14,9 @@ common.refreshTmpDir();
// make a path that is more than 260 chars long.
// Any given folder cannot have a name longer than 260 characters,
// so create 10 nested folders each with 30 character long names.
var addonDestinationDir = path.resolve(common.tmpDir);
let addonDestinationDir = path.resolve(common.tmpDir);
for (var i = 0; i < 10; i++) {
for (let i = 0; i < 10; i++) {
addonDestinationDir = path.join(addonDestinationDir, 'x'.repeat(30));
fs.mkdirSync(addonDestinationDir);
}
@ -28,10 +28,10 @@ const addonPath = path.join(__dirname,
const addonDestinationPath = path.join(addonDestinationDir, 'binding.node');
// Copy binary to long path destination
var contents = fs.readFileSync(addonPath);
const contents = fs.readFileSync(addonPath);
fs.writeFileSync(addonDestinationPath, contents);
// Attempt to load at long path destination
var addon = require(addonDestinationPath);
const addon = require(addonDestinationPath);
assert.notEqual(addon, null);
assert.strictEqual(addon.hello(), 'world');

2
test/addons/make-callback-recurse/test.js

@ -65,7 +65,7 @@ assert.throws(function() {
results.push(2);
setImmediate(common.mustCall(function() {
for (var i = 0; i < results.length; i++) {
for (let i = 0; i < results.length; i++) {
assert.strictEqual(results[i], i,
`verifyExecutionOrder(${arg}) results: ${results}`);
}

24
test/addons/repl-domain-abort/test.js

@ -1,30 +1,30 @@
'use strict';
var common = require('../../common');
var assert = require('assert');
var repl = require('repl');
var stream = require('stream');
var path = require('path');
var buildType = process.config.target_defaults.default_configuration;
var buildPath = path.join(__dirname, 'build', buildType, 'binding');
const common = require('../../common');
const assert = require('assert');
const repl = require('repl');
const stream = require('stream');
const path = require('path');
const buildType = process.config.target_defaults.default_configuration;
let buildPath = path.join(__dirname, 'build', buildType, 'binding');
// On Windows, escape backslashes in the path before passing it to REPL.
if (common.isWindows)
buildPath = buildPath.replace(/\\/g, '/');
var cb_ran = false;
let cb_ran = false;
process.on('exit', function() {
assert(cb_ran);
console.log('ok');
});
var lines = [
const lines = [
// This line shouldn't cause an assertion error.
'require(\'' + buildPath + '\')' +
// Log output to double check callback ran.
'.method(function() { console.log(\'cb_ran\'); });',
];
var dInput = new stream.Readable();
var dOutput = new stream.Writable();
const dInput = new stream.Readable();
const dOutput = new stream.Writable();
dInput._read = function _read(size) {
while (lines.length > 0 && this.push(lines.shift()));
@ -38,7 +38,7 @@ dOutput._write = function _write(chunk, encoding, cb) {
cb();
};
var options = {
const options = {
input: dInput,
output: dOutput,
terminal: false,

3
test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js

@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
return;
}
let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength);
buf = Buffer.allocUnsafe(kStringMaxLength);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);

3
test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js

@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength + 1);
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);

3
test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js

@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength + 1);
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);

5
test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js

@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength + 1);
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
@ -33,7 +34,7 @@ assert.throws(function() {
buf.toString('latin1');
}, /"toString\(\)" failed/);
var maxString = buf.toString('latin1', 1);
let maxString = buf.toString('latin1', 1);
assert.strictEqual(maxString.length, kStringMaxLength);
// Free the memory early instead of at the end of the next assignment
maxString = undefined;

3
test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js

@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength + 1);
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);

3
test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js

@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength + 1);
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);

3
test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js

@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength + 2);
buf = Buffer.allocUnsafe(kStringMaxLength + 2);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);

3
test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js

@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength * 2 + 2);
buf = Buffer.allocUnsafe(kStringMaxLength * 2 + 2);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);

2
test/common.js

@ -208,7 +208,7 @@ exports.hasIPv6 = Object.keys(ifaces).some(function(name) {
* the process aborts.
*/
exports.childShouldThrowAndAbort = function() {
var testCmd = '';
let testCmd = '';
if (!exports.isWindows) {
// Do not create core files, as it can take a lot of disk space on
// continuous testing and developers' machines

32
test/debugger/helper-debugger-repl.js

@ -1,15 +1,15 @@
'use strict';
const common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
const assert = require('assert');
const spawn = require('child_process').spawn;
process.env.NODE_DEBUGGER_TIMEOUT = 2000;
var port = common.PORT;
const port = common.PORT;
var child;
var buffer = '';
var expected = [];
var quit;
let child;
let buffer = '';
const expected = [];
let quit;
function startDebugger(scriptToDebug) {
scriptToDebug = process.env.NODE_DEBUGGER_TEST_SCRIPT ||
@ -34,23 +34,23 @@ function startDebugger(scriptToDebug) {
console.log(line);
assert.ok(expected.length > 0, 'Got unexpected line: ' + line);
var expectedLine = expected[0].lines.shift();
const expectedLine = expected[0].lines.shift();
assert.ok(line.match(expectedLine) !== null, line + ' != ' + expectedLine);
if (expected[0].lines.length === 0) {
var callback = expected[0].callback;
const callback = expected[0].callback;
expected.shift();
callback && callback();
}
});
var childClosed = false;
let childClosed = false;
child.on('close', function(code) {
assert(!code);
childClosed = true;
});
var quitCalled = false;
let quitCalled = false;
quit = function() {
if (quitCalled || childClosed) return;
quitCalled = true;
@ -60,7 +60,7 @@ function startDebugger(scriptToDebug) {
setTimeout(function() {
console.error('dying badly buffer=%j', buffer);
var err = 'Timeout';
let err = 'Timeout';
if (expected.length > 0 && expected[0].lines) {
err = err + '. Expected: ' + expected[0].lines.shift();
}
@ -95,7 +95,7 @@ function addTest(input, output) {
child.stdin.write(expected[0].input + '\n');
if (!expected[0].lines) {
var callback = expected[0].callback;
const callback = expected[0].callback;
expected.shift();
callback && callback();
@ -107,17 +107,17 @@ function addTest(input, output) {
expected.push({input: input, lines: output, callback: next});
}
var handshakeLines = [
const handshakeLines = [
/listening on /,
/connecting.* ok/
];
var initialBreakLines = [
const initialBreakLines = [
/break in .*:1/,
/1/, /2/, /3/
];
var initialLines = handshakeLines.concat(initialBreakLines);
const initialLines = handshakeLines.concat(initialBreakLines);
// Process initial lines
addTest(null, initialLines);

70
test/debugger/test-debugger-client.js

@ -1,12 +1,12 @@
'use strict';
const common = require('../common');
var assert = require('assert');
var debug = require('_debugger');
const assert = require('assert');
const debug = require('_debugger');
process.env.NODE_DEBUGGER_TIMEOUT = 2000;
var debugPort = common.PORT;
const debugPort = common.PORT;
debug.port = debugPort;
var spawn = require('child_process').spawn;
const spawn = require('child_process').spawn;
setTimeout(function() {
if (nodeProcess) nodeProcess.kill('SIGTERM');
@ -14,8 +14,8 @@ setTimeout(function() {
}, 10000).unref();
var resCount = 0;
var p = new debug.Protocol();
let resCount = 0;
const p = new debug.Protocol();
p.onResponse = function() {
resCount++;
};
@ -29,12 +29,12 @@ assert.strictEqual(resCount, 1);
// Make sure split messages go in.
var parts = [];
const parts = [];
parts.push('Content-Length: 336\r\n');
assert.strictEqual(parts[0].length, 21);
parts.push('\r\n');
assert.strictEqual(parts[1].length, 2);
var bodyLength = 0;
let bodyLength = 0;
parts.push('{"seq":12,"type":"event","event":"break","body":' +
'{"invocationText":"#<a Server>');
@ -55,7 +55,7 @@ bodyLength += parts[4].length;
assert.strictEqual(bodyLength, 336);
for (var i = 0; i < parts.length; i++) {
for (let i = 0; i < parts.length; i++) {
p.execute(parts[i]);
}
assert.strictEqual(resCount, 2);
@ -63,24 +63,24 @@ assert.strictEqual(resCount, 2);
// Make sure that if we get backed up, we still manage to get all the
// messages
var d = 'Content-Length: 466\r\n\r\n' +
'{"seq":10,"type":"event","event":"afterCompile","success":true,' +
'"body":{"script":{"handle":1,"type":"script","name":"dns.js",' +
'"id":34,"lineOffset":0,"columnOffset":0,"lineCount":241,' +
'"sourceStart":"(function(module, exports, require) {' +
'var dns = process.binding(\'cares\')' +
';\\nvar ne","sourceLength":6137,"scriptType":2,"compilationType":0,' +
'"context":{"ref":0},"text":"dns.js (lines: 241)"}},"refs":' +
'[{"handle":0' +
',"type":"context","text":"#<a ContextMirror>"}],"running":true}' +
'\r\n\r\nContent-Length: 119\r\n\r\n' +
'{"seq":11,"type":"event","event":"scriptCollected","success":true,' +
'"body":{"script":{"id":26}},"refs":[],"running":true}';
const d = 'Content-Length: 466\r\n\r\n' +
'{"seq":10,"type":"event","event":"afterCompile","success":true,' +
'"body":{"script":{"handle":1,"type":"script","name":"dns.js",' +
'"id":34,"lineOffset":0,"columnOffset":0,"lineCount":241,' +
'"sourceStart":"(function(module, exports, require) {' +
'let dns = process.binding(\'cares\')' +
';\\nlet ne","sourceLength":6137,"scriptType":2,"compilationType":0' +
',"context":{"ref":0},"text":"dns.js (lines: 241)"}},"refs":' +
'[{"handle":0' +
',"type":"context","text":"#<a ContextMirror>"}],"running":true}' +
'\r\n\r\nContent-Length: 119\r\n\r\n' +
'{"seq":11,"type":"event","event":"scriptCollected","success":true,' +
'"body":{"script":{"id":26}},"refs":[],"running":true}';
p.execute(d);
assert.strictEqual(resCount, 4);
var expectedConnections = 0;
var tests = [];
let expectedConnections = 0;
const tests = [];
function addTest(cb) {
expectedConnections++;
tests.push(cb);
@ -102,9 +102,9 @@ addTest(function(client, done) {
assert.ifError(err);
console.error('got %d scripts', Object.keys(client.scripts).length);
var foundMainScript = false;
for (var k in client.scripts) {
var script = client.scripts[k];
let foundMainScript = false;
for (const k in client.scripts) {
const script = client.scripts[k];
if (script && script.name === 'bootstrap_node.js') {
foundMainScript = true;
break;
@ -127,19 +127,19 @@ addTest(function(client, done) {
});
var connectCount = 0;
var script = 'setTimeout(function() { console.log("blah"); });' +
'setInterval(function() {}, 1000000);';
let connectCount = 0;
const script = 'setTimeout(function() { console.log("blah"); });' +
'setInterval(function() {}, 1000000);';
var nodeProcess;
let nodeProcess;
function doTest(cb, done) {
var args = ['--debug=' + debugPort, '-e', script];
const args = ['--debug=' + debugPort, '-e', script];
nodeProcess = spawn(process.execPath, args);
nodeProcess.stdout.once('data', function() {
console.log('>>> new node process: %d', nodeProcess.pid);
var failed = true;
let failed = true;
try {
process._debugProcess(nodeProcess.pid);
failed = false;
@ -151,9 +151,9 @@ function doTest(cb, done) {
console.log('>>> starting debugger session');
});
var didTryConnect = false;
let didTryConnect = false;
nodeProcess.stderr.setEncoding('utf8');
var b = '';
let b = '';
nodeProcess.stderr.on('data', function(data) {
console.error('got stderr data %j', data);
nodeProcess.stderr.resume();

2
test/debugger/test-debugger-repl-break-in-module.js

@ -1,6 +1,6 @@
'use strict';
require('../common');
var repl = require('./helper-debugger-repl.js');
const repl = require('./helper-debugger-repl.js');
repl.startDebugger('break-in-module/main.js');

6
test/debugger/test-debugger-repl-restart.js

@ -1,15 +1,15 @@
'use strict';
require('../common');
var repl = require('./helper-debugger-repl.js');
const repl = require('./helper-debugger-repl.js');
repl.startDebugger('breakpoints.js');
var linesWithBreakpoint = [
const linesWithBreakpoint = [
/1/, /2/, /3/, /4/, /5/, /\* 6/
];
// We slice here, because addTest will change the given array.
repl.addTest('sb(6)', linesWithBreakpoint.slice());
var initialLines = repl.initialLines.slice();
const initialLines = repl.initialLines.slice();
initialLines.splice(2, 0, /Restoring/, /Warning/);
// Restart the debugged script

4
test/debugger/test-debugger-repl-term.js

@ -2,11 +2,11 @@
require('../common');
process.env.NODE_FORCE_READLINE = 1;
var repl = require('./helper-debugger-repl.js');
const repl = require('./helper-debugger-repl.js');
repl.startDebugger('breakpoints.js');
var addTest = repl.addTest;
const addTest = repl.addTest;
// next
addTest('n', [

4
test/debugger/test-debugger-repl-utf8.js

@ -1,6 +1,6 @@
'use strict';
var common = require('../common');
var script = common.fixturesDir + '/breakpoints_utf8.js';
const common = require('../common');
const script = common.fixturesDir + '/breakpoints_utf8.js';
process.env.NODE_DEBUGGER_TEST_SCRIPT = script;
require('./test-debugger-repl.js');

6
test/debugger/test-debugger-repl.js

@ -1,10 +1,10 @@
'use strict';
var common = require('../common');
var repl = require('./helper-debugger-repl.js');
const common = require('../common');
const repl = require('./helper-debugger-repl.js');
repl.startDebugger('breakpoints.js');
var addTest = repl.addTest;
const addTest = repl.addTest;
// Next
addTest('n', [

8
test/gc/test-http-client-connaborted.js

@ -18,7 +18,7 @@ let countGC = 0;
console.log('We should do ' + todo + ' requests');
var server = http.createServer(serverHandler);
const server = http.createServer(serverHandler);
server.listen(0, getall);
function getall() {
@ -31,7 +31,7 @@ function getall() {
statusLater();
}
var req = http.get({
const req = http.get({
hostname: 'localhost',
pathname: '/',
port: server.address().port
@ -44,14 +44,14 @@ function getall() {
setImmediate(getall);
}
for (var i = 0; i < 10; i++)
for (let i = 0; i < 10; i++)
getall();
function afterGC() {
countGC++;
}
var timer;
let timer;
function statusLater() {
global.gc();
if (timer) clearTimeout(timer);

8
test/gc/test-http-client-onerror.js

@ -20,7 +20,7 @@ let countGC = 0;
console.log('We should do ' + todo + ' requests');
var server = http.createServer(serverHandler);
const server = http.createServer(serverHandler);
server.listen(0, runTest);
function getall() {
@ -37,7 +37,7 @@ function getall() {
throw er;
}
var req = http.get({
const req = http.get({
hostname: 'localhost',
pathname: '/',
port: server.address().port
@ -51,7 +51,7 @@ function getall() {
}
function runTest() {
for (var i = 0; i < 10; i++)
for (let i = 0; i < 10; i++)
getall();
}
@ -59,7 +59,7 @@ function afterGC() {
countGC++;
}
var timer;
let timer;
function statusLater() {
global.gc();
if (timer) clearTimeout(timer);

8
test/gc/test-http-client-timeout.js

@ -22,7 +22,7 @@ let countGC = 0;
console.log('We should do ' + todo + ' requests');
var server = http.createServer(serverHandler);
const server = http.createServer(serverHandler);
server.listen(0, getall);
function getall() {
@ -36,7 +36,7 @@ function getall() {
statusLater();
}
var req = http.get({
const req = http.get({
hostname: 'localhost',
pathname: '/',
port: server.address().port
@ -53,14 +53,14 @@ function getall() {
setImmediate(getall);
}
for (var i = 0; i < 10; i++)
for (let i = 0; i < 10; i++)
getall();
function afterGC() {
countGC++;
}
var timer;
let timer;
function statusLater() {
global.gc();
if (timer) clearTimeout(timer);

6
test/gc/test-http-client.js

@ -18,7 +18,7 @@ let countGC = 0;
console.log('We should do ' + todo + ' requests');
var server = http.createServer(serverHandler);
const server = http.createServer(serverHandler);
server.listen(0, getall);
@ -34,7 +34,7 @@ function getall() {
res.on('end', global.gc);
}
var req = http.get({
const req = http.get({
hostname: 'localhost',
pathname: '/',
port: server.address().port
@ -47,7 +47,7 @@ function getall() {
setImmediate(getall);
}
for (var i = 0; i < 10; i++)
for (let i = 0; i < 10; i++)
getall();
function afterGC() {

6
test/gc/test-net-timeout.js

@ -7,7 +7,7 @@ require('../common');
function serverHandler(sock) {
sock.setTimeout(120000);
sock.resume();
var timer;
let timer;
sock.on('close', function() {
clearTimeout(timer);
});
@ -29,7 +29,7 @@ let countGC = 0;
console.log('We should do ' + todo + ' requests');
var server = net.createServer(serverHandler);
const server = net.createServer(serverHandler);
server.listen(0, getall);
function getall() {
@ -50,7 +50,7 @@ function getall() {
setImmediate(getall);
}
for (var i = 0; i < 10; i++)
for (let i = 0; i < 10; i++)
getall();
function afterGC() {

4
test/inspector/inspector-helper.js

@ -110,7 +110,7 @@ function makeBufferingDataCallback(dataCallback) {
buffer = Buffer.alloc(0);
else
buffer = Buffer.from(lines.pop(), 'utf8');
for (var line of lines)
for (const line of lines)
dataCallback(line);
};
}
@ -222,7 +222,7 @@ TestSession.prototype.sendInspectorCommands = function(commands) {
};
TestSession.prototype.createCallbackWithTimeout_ = function(message) {
var promise = new Promise((resolve) => {
const promise = new Promise((resolve) => {
this.enqueue((callback) => {
const timeoutId = timeout(message);
resolve(() => {

20
test/internet/test-dgram-multicast-multi-process.js

@ -13,7 +13,7 @@ const messages = [
];
const workers = {};
const listeners = 3;
let dead, listening, sendSocket, done, timer;
// Skip test in FreeBSD jails.
if (common.inFreeBSDJail) {
@ -76,10 +76,10 @@ function launchChildProcess() {
Object.keys(workers).forEach(function(pid) {
const worker = workers[pid];
var count = 0;
let count = 0;
worker.messagesReceived.forEach(function(buf) {
for (var i = 0; i < messages.length; ++i) {
for (let i = 0; i < messages.length; ++i) {
if (buf.toString() === messages[i].toString()) {
count++;
break;
@ -110,13 +110,13 @@ function killChildren(children) {
}
if (process.argv[2] !== 'child') {
var listening = 0;
var dead = 0;
var i = 0;
var done = 0;
listening = 0;
dead = 0;
let i = 0;
done = 0;
// Exit the test if it doesn't succeed within TIMEOUT.
var timer = setTimeout(function() {
timer = setTimeout(function() {
console.error('[PARENT] Responses were not received within %d ms.',
TIMEOUT);
console.error('[PARENT] Fail');
@ -127,11 +127,11 @@ if (process.argv[2] !== 'child') {
}, TIMEOUT);
// Launch child processes.
for (var x = 0; x < listeners; x++) {
for (let x = 0; x < listeners; x++) {
launchChildProcess(x);
}
var sendSocket = dgram.createSocket('udp4');
sendSocket = dgram.createSocket('udp4');
// The socket is actually created async now.
sendSocket.on('listening', function() {

14
test/internet/test-dgram-send-cb-quelches-error.js

@ -1,12 +1,12 @@
'use strict';
var common = require('../common');
var mustCall = common.mustCall;
var assert = require('assert');
var dgram = require('dgram');
var dns = require('dns');
const common = require('../common');
const mustCall = common.mustCall;
const assert = require('assert');
const dgram = require('dgram');
const dns = require('dns');
var socket = dgram.createSocket('udp4');
var buffer = Buffer.from('gary busey');
const socket = dgram.createSocket('udp4');
const buffer = Buffer.from('gary busey');
dns.setServers([]);

10
test/internet/test-dns-cares-domains.js

@ -1,10 +1,10 @@
'use strict';
require('../common');
var assert = require('assert');
var dns = require('dns');
var domain = require('domain');
const assert = require('assert');
const dns = require('dns');
const domain = require('domain');
var methods = [
const methods = [
'resolve4',
'resolve6',
'resolveCname',
@ -18,7 +18,7 @@ var methods = [
];
methods.forEach(function(method) {
var d = domain.create();
const d = domain.create();
d.run(function() {
dns[method]('google.com', function() {
assert.strictEqual(process.domain, d, method + ' retains domain');

4
test/internet/test-dns-txt-sigsegv.js

@ -1,7 +1,7 @@
'use strict';
require('../common');
var assert = require('assert');
var dns = require('dns');
const assert = require('assert');
const dns = require('dns');
dns.resolveTxt('www.microsoft.com', function(err, records) {
assert.equal(err, null);

84
test/internet/test-dns.js

@ -15,7 +15,7 @@ const queue = [];
function TEST(f) {
function next() {
var f = queue.shift();
const f = queue.shift();
if (f) {
running = true;
console.log(f.name);
@ -44,7 +44,7 @@ function checkWrap(req) {
TEST(function test_reverse_bogus(done) {
var error;
let error;
try {
dns.reverse('bogus ip', function() {
@ -62,13 +62,13 @@ TEST(function test_reverse_bogus(done) {
TEST(function test_resolveMx(done) {
var req = dns.resolveMx('gmail.com', function(err, result) {
const req = dns.resolveMx('gmail.com', function(err, result) {
if (err) throw err;
assert.ok(result.length > 0);
for (var i = 0; i < result.length; i++) {
var item = result[i];
for (let i = 0; i < result.length; i++) {
const item = result[i];
assert.ok(item);
assert.strictEqual(typeof item, 'object');
@ -85,7 +85,7 @@ TEST(function test_resolveMx(done) {
});
TEST(function test_resolveMx_failure(done) {
var req = dns.resolveMx('something.invalid', function(err, result) {
const req = dns.resolveMx('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');
@ -98,13 +98,13 @@ TEST(function test_resolveMx_failure(done) {
});
TEST(function test_resolveNs(done) {
var req = dns.resolveNs('rackspace.com', function(err, names) {
const req = dns.resolveNs('rackspace.com', function(err, names) {
if (err) throw err;
assert.ok(names.length > 0);
for (var i = 0; i < names.length; i++) {
var name = names[i];
for (let i = 0; i < names.length; i++) {
const name = names[i];
assert.ok(name);
assert.strictEqual(typeof name, 'string');
}
@ -116,7 +116,7 @@ TEST(function test_resolveNs(done) {
});
TEST(function test_resolveNs_failure(done) {
var req = dns.resolveNs('something.invalid', function(err, result) {
const req = dns.resolveNs('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');
@ -129,13 +129,13 @@ TEST(function test_resolveNs_failure(done) {
});
TEST(function test_resolveSrv(done) {
var req = dns.resolveSrv('_jabber._tcp.google.com', function(err, result) {
const req = dns.resolveSrv('_jabber._tcp.google.com', function(err, result) {
if (err) throw err;
assert.ok(result.length > 0);
for (var i = 0; i < result.length; i++) {
var item = result[i];
for (let i = 0; i < result.length; i++) {
const item = result[i];
assert.ok(item);
assert.strictEqual(typeof item, 'object');
@ -154,7 +154,7 @@ TEST(function test_resolveSrv(done) {
});
TEST(function test_resolveSrv_failure(done) {
var req = dns.resolveSrv('something.invalid', function(err, result) {
const req = dns.resolveSrv('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');
@ -167,13 +167,13 @@ TEST(function test_resolveSrv_failure(done) {
});
TEST(function test_resolvePtr(done) {
var req = dns.resolvePtr('8.8.8.8.in-addr.arpa', function(err, result) {
const req = dns.resolvePtr('8.8.8.8.in-addr.arpa', function(err, result) {
if (err) throw err;
assert.ok(result.length > 0);
for (var i = 0; i < result.length; i++) {
var item = result[i];
for (let i = 0; i < result.length; i++) {
const item = result[i];
assert.ok(item);
assert.strictEqual(typeof item, 'string');
}
@ -185,7 +185,7 @@ TEST(function test_resolvePtr(done) {
});
TEST(function test_resolvePtr_failure(done) {
var req = dns.resolvePtr('something.invalid', function(err, result) {
const req = dns.resolvePtr('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');
@ -198,13 +198,13 @@ TEST(function test_resolvePtr_failure(done) {
});
TEST(function test_resolveNaptr(done) {
var req = dns.resolveNaptr('sip2sip.info', function(err, result) {
const req = dns.resolveNaptr('sip2sip.info', function(err, result) {
if (err) throw err;
assert.ok(result.length > 0);
for (var i = 0; i < result.length; i++) {
var item = result[i];
for (let i = 0; i < result.length; i++) {
const item = result[i];
assert.ok(item);
assert.strictEqual(typeof item, 'object');
@ -223,7 +223,7 @@ TEST(function test_resolveNaptr(done) {
});
TEST(function test_resolveNaptr_failure(done) {
var req = dns.resolveNaptr('something.invalid', function(err, result) {
const req = dns.resolveNaptr('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');
@ -236,7 +236,7 @@ TEST(function test_resolveNaptr_failure(done) {
});
TEST(function test_resolveSoa(done) {
var req = dns.resolveSoa('nodejs.org', function(err, result) {
const req = dns.resolveSoa('nodejs.org', function(err, result) {
if (err) throw err;
assert.ok(result);
@ -270,7 +270,7 @@ TEST(function test_resolveSoa(done) {
});
TEST(function test_resolveSoa_failure(done) {
var req = dns.resolveSoa('something.invalid', function(err, result) {
const req = dns.resolveSoa('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');
@ -283,13 +283,13 @@ TEST(function test_resolveSoa_failure(done) {
});
TEST(function test_resolveCname(done) {
var req = dns.resolveCname('www.microsoft.com', function(err, names) {
const req = dns.resolveCname('www.microsoft.com', function(err, names) {
if (err) throw err;
assert.ok(names.length > 0);
for (var i = 0; i < names.length; i++) {
var name = names[i];
for (let i = 0; i < names.length; i++) {
const name = names[i];
assert.ok(name);
assert.strictEqual(typeof name, 'string');
}
@ -301,7 +301,7 @@ TEST(function test_resolveCname(done) {
});
TEST(function test_resolveCname_failure(done) {
var req = dns.resolveCname('something.invalid', function(err, result) {
const req = dns.resolveCname('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');
@ -315,7 +315,7 @@ TEST(function test_resolveCname_failure(done) {
TEST(function test_resolveTxt(done) {
var req = dns.resolveTxt('google.com', function(err, records) {
const req = dns.resolveTxt('google.com', function(err, records) {
if (err) throw err;
assert.strictEqual(records.length, 1);
assert.ok(util.isArray(records[0]));
@ -327,7 +327,7 @@ TEST(function test_resolveTxt(done) {
});
TEST(function test_resolveTxt_failure(done) {
var req = dns.resolveTxt('something.invalid', function(err, result) {
const req = dns.resolveTxt('something.invalid', function(err, result) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, 'ENOTFOUND');
@ -341,7 +341,7 @@ TEST(function test_resolveTxt_failure(done) {
TEST(function test_lookup_failure(done) {
var req = dns.lookup('does.not.exist', 4, function(err, ip, family) {
const req = dns.lookup('does.not.exist', 4, function(err, ip, family) {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, dns.NOTFOUND);
assert.strictEqual(err.errno, 'ENOTFOUND');
@ -356,7 +356,7 @@ TEST(function test_lookup_failure(done) {
TEST(function test_lookup_null(done) {
var req = dns.lookup(null, function(err, ip, family) {
const req = dns.lookup(null, function(err, ip, family) {
if (err) throw err;
assert.strictEqual(ip, null);
assert.strictEqual(family, 4);
@ -369,7 +369,7 @@ TEST(function test_lookup_null(done) {
TEST(function test_lookup_ip_all(done) {
var req = dns.lookup('127.0.0.1', {all: true}, function(err, ips, family) {
const req = dns.lookup('127.0.0.1', {all: true}, function(err, ips, family) {
if (err) throw err;
assert.ok(Array.isArray(ips));
assert.ok(ips.length > 0);
@ -384,7 +384,7 @@ TEST(function test_lookup_ip_all(done) {
TEST(function test_lookup_null_all(done) {
var req = dns.lookup(null, {all: true}, function(err, ips, family) {
const req = dns.lookup(null, {all: true}, function(err, ips, family) {
if (err) throw err;
assert.ok(Array.isArray(ips));
assert.strictEqual(ips.length, 0);
@ -397,7 +397,7 @@ TEST(function test_lookup_null_all(done) {
TEST(function test_lookup_all_mixed(done) {
var req = dns.lookup('www.google.com', {all: true}, function(err, ips) {
const req = dns.lookup('www.google.com', {all: true}, function(err, ips) {
if (err) throw err;
assert.ok(Array.isArray(ips));
assert.ok(ips.length > 0);
@ -419,7 +419,7 @@ TEST(function test_lookup_all_mixed(done) {
TEST(function test_lookupservice_invalid(done) {
var req = dns.lookupService('1.2.3.4', 80, function(err, host, service) {
const req = dns.lookupService('1.2.3.4', 80, function(err, host, service) {
assert(err instanceof Error);
assert.strictEqual(err.code, 'ENOTFOUND');
assert.ok(/1\.2\.3\.4/.test(err.message));
@ -432,7 +432,7 @@ TEST(function test_lookupservice_invalid(done) {
TEST(function test_reverse_failure(done) {
var req = dns.reverse('0.0.0.0', function(err) {
const req = dns.reverse('0.0.0.0', function(err) {
assert(err instanceof Error);
assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
assert.strictEqual(err.hostname, '0.0.0.0');
@ -446,7 +446,7 @@ TEST(function test_reverse_failure(done) {
TEST(function test_lookup_failure(done) {
var req = dns.lookup('nosuchhostimsure', function(err) {
const req = dns.lookup('nosuchhostimsure', function(err) {
assert(err instanceof Error);
assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
assert.strictEqual(err.hostname, 'nosuchhostimsure');
@ -460,7 +460,7 @@ TEST(function test_lookup_failure(done) {
TEST(function test_resolve_failure(done) {
var req = dns.resolve4('nosuchhostimsure', function(err) {
const req = dns.resolve4('nosuchhostimsure', function(err) {
assert(err instanceof Error);
switch (err.code) {
@ -482,12 +482,12 @@ TEST(function test_resolve_failure(done) {
});
var getaddrinfoCallbackCalled = false;
let getaddrinfoCallbackCalled = false;
console.log('looking up nodejs.org...');
var cares = process.binding('cares_wrap');
var req = new cares.GetAddrInfoReqWrap();
const cares = process.binding('cares_wrap');
const req = new cares.GetAddrInfoReqWrap();
cares.getaddrinfo(req, 'nodejs.org', 4);
req.oncomplete = function(err, domains) {

6
test/internet/test-http-https-default-ports.js

@ -1,13 +1,13 @@
'use strict';
var common = require('../common');
const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
var https = require('https');
const https = require('https');
var http = require('http');
const http = require('http');
https.get('https://www.google.com/', common.mustCall(function(res) {
res.resume();

12
test/internet/test-net-connect-timeout.js

@ -4,24 +4,24 @@
// https://groups.google.com/forum/#!topic/nodejs-dev/jR7-5UDqXkw
const common = require('../common');
var net = require('net');
var assert = require('assert');
const net = require('net');
const assert = require('assert');
var start = new Date();
const start = new Date();
var T = 100;
const T = 100;
// 192.0.2.1 is part of subnet assigned as "TEST-NET" in RFC 5737.
// For use solely in documentation and example source code.
// In short, it should be unreachable.
// In practice, it's a network black hole.
var socket = net.createConnection(9999, '192.0.2.1');
const socket = net.createConnection(9999, '192.0.2.1');
socket.setTimeout(T);
socket.on('timeout', common.mustCall(function() {
console.error('timeout');
var now = new Date();
const now = new Date();
assert.ok(now - start < T + 500);
socket.destroy();
}));

7
test/internet/test-net-connect-unref.js

@ -1,11 +1,10 @@
'use strict';
const common = require('../common');
var net = require('net');
const net = require('net');
var client;
var TIMEOUT = 10 * 1000;
const TIMEOUT = 10 * 1000;
client = net.createConnection(53, '8.8.8.8', function() {
const client = net.createConnection(53, '8.8.8.8', function() {
client.unref();
});

6
test/internet/test-tls-connnect-melissadata.js

@ -2,14 +2,14 @@
// Test for authorized access to the server which has a cross root
// certification between Starfield Class 2 and ValiCert Class 2
var common = require('../common');
const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
var tls = require('tls');
var socket = tls.connect(443, 'address.melissadata.net', function() {
const tls = require('tls');
const socket = tls.connect(443, 'address.melissadata.net', function() {
socket.resume();
socket.destroy();
});

8
test/known_issues/test-url-parse-conformance.js

@ -9,14 +9,14 @@ const path = require('path');
const tests = require(path.join(common.fixturesDir, 'url-tests.json'));
var failed = 0;
var attempted = 0;
let failed = 0;
let attempted = 0;
tests.forEach((test) => {
attempted++;
// Skip comments
if (typeof test === 'string') return;
var parsed;
let parsed;
try {
// Attempt to parse
@ -28,7 +28,7 @@ tests.forEach((test) => {
} else {
// Test was not supposed to fail, so we're good so far. Now
// check the results of the parse.
var username, password;
let username, password;
try {
assert.strictEqual(test.href, parsed.href);
assert.strictEqual(test.protocol, parsed.protocol);

2
test/message/error_exit.js

@ -1,6 +1,6 @@
'use strict';
require('../common');
var assert = require('assert');
const assert = require('assert');
process.on('exit', function(code) {
console.error('Exiting with code=%d', code);

10
test/message/eval_messages.js

@ -2,19 +2,19 @@
require('../common');
var spawn = require('child_process').spawn;
const spawn = require('child_process').spawn;
function run(cmd, strict, cb) {
var args = [];
const args = [];
if (strict) args.push('--use_strict');
args.push('-pe', cmd);
var child = spawn(process.execPath, args);
const child = spawn(process.execPath, args);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stdout);
child.on('close', cb);
}
var queue =
const queue =
[ 'with(this){__filename}',
'42',
'throw new Error("hello")',
@ -22,7 +22,7 @@ var queue =
'var ______________________________________________; throw 10' ];
function go() {
var c = queue.shift();
const c = queue.shift();
if (!c) return console.log('done');
run(c, false, function() {
run(c, true, go);

2
test/message/max_tick_depth.js

@ -2,7 +2,7 @@
require('../common');
process.maxTickDepth = 10;
var i = 20;
let i = 20;
process.nextTick(function f() {
console.error('tick %d', i);
if (i-- > 0)

10
test/message/stdin_messages.js

@ -2,20 +2,20 @@
require('../common');
var spawn = require('child_process').spawn;
const spawn = require('child_process').spawn;
function run(cmd, strict, cb) {
var args = [];
const args = [];
if (strict) args.push('--use_strict');
args.push('-p');
var child = spawn(process.execPath, args);
const child = spawn(process.execPath, args);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stdout);
child.stdin.end(cmd);
child.on('close', cb);
}
var queue =
const queue =
[ 'with(this){__filename}',
'42',
'throw new Error("hello")',
@ -23,7 +23,7 @@ var queue =
'var ______________________________________________; throw 10' ];
function go() {
var c = queue.shift();
const c = queue.shift();
if (!c) return console.log('done');
run(c, false, function() {
run(c, true, go);

2
test/message/undefined_reference_in_new_context.js

@ -1,6 +1,6 @@
'use strict';
require('../common');
var vm = require('vm');
const vm = require('vm');
console.error('before');

2
test/message/vm_display_runtime_error.js

@ -1,6 +1,6 @@
'use strict';
require('../common');
var vm = require('vm');
const vm = require('vm');
console.error('beginning');

2
test/message/vm_display_syntax_error.js

@ -1,6 +1,6 @@
'use strict';
require('../common');
var vm = require('vm');
const vm = require('vm');
console.error('beginning');

2
test/message/vm_dont_display_runtime_error.js

@ -1,6 +1,6 @@
'use strict';
require('../common');
var vm = require('vm');
const vm = require('vm');
console.error('beginning');

2
test/message/vm_dont_display_syntax_error.js

@ -1,6 +1,6 @@
'use strict';
require('../common');
var vm = require('vm');
const vm = require('vm');
console.error('beginning');

2
test/parallel/test-assert-typedarray-deepequal.js

@ -5,7 +5,7 @@ const assert = require('assert');
const a = require('assert');
function makeBlock(f) {
var args = Array.prototype.slice.call(arguments, 1);
const args = Array.prototype.slice.call(arguments, 1);
return function() {
return f.apply(this, args);
};

35
test/parallel/test-assert.js

@ -1,10 +1,10 @@
'use strict';
require('../common');
var assert = require('assert');
var a = require('assert');
const assert = require('assert');
const a = require('assert');
function makeBlock(f) {
var args = Array.prototype.slice.call(arguments, 1);
const args = Array.prototype.slice.call(arguments, 1);
return function() {
return f.apply(this, args);
};
@ -127,8 +127,8 @@ assert.throws(makeBlock(a.deepEqual, {a: 4}, {a: 4, b: true}),
assert.doesNotThrow(makeBlock(a.deepEqual, ['a'], {0: 'a'}));
//(although not necessarily the same order),
assert.doesNotThrow(makeBlock(a.deepEqual, {a: 4, b: '1'}, {b: '1', a: 4}));
var a1 = [1, 2, 3];
var a2 = [1, 2, 3];
const a1 = [1, 2, 3];
const a2 = [1, 2, 3];
a1.a = 'test';
a1.b = true;
a2.b = true;
@ -138,7 +138,7 @@ assert.throws(makeBlock(a.deepEqual, Object.keys(a1), Object.keys(a2)),
assert.doesNotThrow(makeBlock(a.deepEqual, a1, a2));
// having an identical prototype property
var nbRoot = {
const nbRoot = {
toString: function() { return this.first + ' ' + this.last; }
};
@ -156,8 +156,8 @@ function nameBuilder2(first, last) {
}
nameBuilder2.prototype = nbRoot;
var nb1 = new nameBuilder('Ryan', 'Dahl');
var nb2 = new nameBuilder2('Ryan', 'Dahl');
const nb1 = new nameBuilder('Ryan', 'Dahl');
let nb2 = new nameBuilder2('Ryan', 'Dahl');
assert.doesNotThrow(makeBlock(a.deepEqual, nb1, nb2));
@ -289,8 +289,8 @@ function Constructor2(first, last) {
this.last = last;
}
var obj1 = new Constructor1('Ryan', 'Dahl');
var obj2 = new Constructor2('Ryan', 'Dahl');
const obj1 = new Constructor1('Ryan', 'Dahl');
let obj2 = new Constructor2('Ryan', 'Dahl');
assert.throws(makeBlock(a.deepStrictEqual, obj1, obj2), a.AssertionError);
@ -307,7 +307,7 @@ assert.throws(makeBlock(assert.deepStrictEqual, true, 1),
assert.throws(makeBlock(assert.deepStrictEqual, Symbol(), Symbol()),
a.AssertionError);
var s = Symbol();
const s = Symbol();
assert.doesNotThrow(makeBlock(assert.deepStrictEqual, s, s));
@ -348,7 +348,7 @@ assert.throws(makeBlock(thrower, a.AssertionError));
assert.throws(makeBlock(thrower, TypeError));
// when passing a type, only catch errors of the appropriate type
var threw = false;
let threw = false;
try {
a.throws(makeBlock(thrower, TypeError), a.AssertionError);
} catch (e) {
@ -417,10 +417,11 @@ a.throws(makeBlock(thrower, TypeError), function(err) {
// https://github.com/nodejs/node/issues/3188
threw = false;
let AnotherErrorType;
try {
var ES6Error = class extends Error {};
const ES6Error = class extends Error {};
var AnotherErrorType = class extends Error {};
AnotherErrorType = class extends Error {};
const functionThatThrows = function() {
throw new AnotherErrorType('foo');
@ -459,7 +460,7 @@ assert.ok(threw);
a.throws(makeBlock(a.deepStrictEqual, d, e), /AssertionError/);
}
// GH-7178. Ensure reflexivity of deepEqual with `arguments` objects.
var args = (function() { return arguments; })();
const args = (function() { return arguments; })();
a.throws(makeBlock(a.deepEqual, [], args));
a.throws(makeBlock(a.deepEqual, args, []));
@ -478,7 +479,7 @@ a.throws(makeBlock(a.deepEqual, args, []));
a.doesNotThrow(makeBlock(a.deepEqual, someArgs, sameArgs));
}
var circular = {y: 1};
const circular = {y: 1};
circular.x = circular;
function testAssertionMessage(actual, expected) {
@ -543,7 +544,7 @@ try {
// Verify that throws() and doesNotThrow() throw on non-function block
function testBlockTypeError(method, block) {
var threw = true;
let threw = true;
try {
method(block);

2
test/parallel/test-async-wrap-check-providers.js

@ -23,7 +23,7 @@ keyList.splice(0, 1);
// want to improve under https://github.com/nodejs/node/issues/5085.
// strip out fs watch related parts for now
if (common.isAix) {
for (var i = 0; i < keyList.length; i++) {
for (let i = 0; i < keyList.length; i++) {
if ((keyList[i] === 'FSEVENTWRAP') || (keyList[i] === 'STATWATCHER')) {
keyList.splice(i, 1);
}

6
test/parallel/test-async-wrap-throw-from-callback.js

@ -8,8 +8,8 @@ const domain = require('domain');
const spawn = require('child_process').spawn;
const callbacks = [ 'init', 'pre', 'post' ];
const toCall = process.argv[2];
var msgCalled = 0;
var msgReceived = 0;
let msgCalled = 0;
let msgReceived = 0;
function init() {
if (toCall === 'init')
@ -48,7 +48,7 @@ if (typeof process.argv[2] === 'string') {
msgCalled++;
const child = spawn(process.execPath, [__filename, item]);
var errstring = '';
let errstring = '';
child.stderr.on('data', (data) => {
errstring += data.toString();

2
test/parallel/test-async-wrap-uid.js

@ -6,7 +6,7 @@ const assert = require('assert');
const async_wrap = process.binding('async_wrap');
// Give the event loop time to clear out the final uv_close().
var si_cntr = 3;
let si_cntr = 3;
process.on('beforeExit', () => {
if (--si_cntr > 0) setImmediate(() => {});
});

2
test/parallel/test-beforeexit-event-exit.js

@ -1,6 +1,6 @@
'use strict';
require('../common');
var assert = require('assert');
const assert = require('assert');
process.on('beforeExit', function() {
assert(false, 'exit should not allow this to occur');

2
test/parallel/test-buffer-ascii.js

@ -16,7 +16,7 @@ const expected = 'Cb\u0000\u0019est, graphiquement, la rC)union ' +
const buf = Buffer.from(input);
for (var i = 0; i < expected.length; ++i) {
for (let i = 0; i < expected.length; ++i) {
assert.strictEqual(buf.slice(i).toString('ascii'), expected.slice(i));
// Skip remainder of multi-byte sequence.

26
test/parallel/test-buffer-bytelength.js

@ -20,37 +20,37 @@ assert(ArrayBuffer.isView(Buffer.allocUnsafeSlow(10)));
assert(ArrayBuffer.isView(Buffer.from('')));
// buffer
var incomplete = Buffer.from([0xe4, 0xb8, 0xad, 0xe6, 0x96]);
const incomplete = Buffer.from([0xe4, 0xb8, 0xad, 0xe6, 0x96]);
assert.strictEqual(Buffer.byteLength(incomplete), 5);
var ascii = Buffer.from('abc');
const ascii = Buffer.from('abc');
assert.strictEqual(Buffer.byteLength(ascii), 3);
// ArrayBuffer
var buffer = new ArrayBuffer(8);
const buffer = new ArrayBuffer(8);
assert.strictEqual(Buffer.byteLength(buffer), 8);
// TypedArray
var int8 = new Int8Array(8);
const int8 = new Int8Array(8);
assert.strictEqual(Buffer.byteLength(int8), 8);
var uint8 = new Uint8Array(8);
const uint8 = new Uint8Array(8);
assert.strictEqual(Buffer.byteLength(uint8), 8);
var uintc8 = new Uint8ClampedArray(2);
const uintc8 = new Uint8ClampedArray(2);
assert.strictEqual(Buffer.byteLength(uintc8), 2);
var int16 = new Int16Array(8);
const int16 = new Int16Array(8);
assert.strictEqual(Buffer.byteLength(int16), 16);
var uint16 = new Uint16Array(8);
const uint16 = new Uint16Array(8);
assert.strictEqual(Buffer.byteLength(uint16), 16);
var int32 = new Int32Array(8);
const int32 = new Int32Array(8);
assert.strictEqual(Buffer.byteLength(int32), 32);
var uint32 = new Uint32Array(8);
const uint32 = new Uint32Array(8);
assert.strictEqual(Buffer.byteLength(uint32), 32);
var float32 = new Float32Array(8);
const float32 = new Float32Array(8);
assert.strictEqual(Buffer.byteLength(float32), 32);
var float64 = new Float64Array(8);
const float64 = new Float64Array(8);
assert.strictEqual(Buffer.byteLength(float64), 64);
// DataView
var dv = new DataView(new ArrayBuffer(2));
const dv = new DataView(new ArrayBuffer(2));
assert.strictEqual(Buffer.byteLength(dv), 2);
// special case: zero length string

2
test/parallel/test-buffer-concat.js

@ -5,7 +5,7 @@ const assert = require('assert');
const zero = [];
const one = [ Buffer.from('asdf') ];
const long = [];
for (var i = 0; i < 10; i++) long.push(Buffer.from('asdf'));
for (let i = 0; i < 10; i++) long.push(Buffer.from('asdf'));
const flatZero = Buffer.concat(zero);
const flatOne = Buffer.concat(one);

2
test/parallel/test-buffer-copy.js

@ -5,7 +5,7 @@ const assert = require('assert');
const b = Buffer.allocUnsafe(1024);
const c = Buffer.allocUnsafe(512);
var cntr = 0;
let cntr = 0;
{
// copy 512 bytes, from 0 to 512.

6
test/parallel/test-buffer-fill.js

@ -243,7 +243,7 @@ function writeToFill(string, offset, end, encoding) {
// Convert "end" to "length" (which write understands).
const length = end - offset < 0 ? 0 : end - offset;
var wasZero = false;
let wasZero = false;
do {
const written = buf2.write(string, offset, length, encoding);
offset += written;
@ -324,7 +324,7 @@ Buffer.alloc(8, '');
{
let elseWasLast = false;
assert.throws(() => {
var ctr = 0;
let ctr = 0;
const start = {
[Symbol.toPrimitive]() {
// We use this condition to get around the check in lib/buffer.js
@ -357,7 +357,7 @@ assert.throws(() => {
{
let elseWasLast = false;
assert.throws(() => {
var ctr = 0;
let ctr = 0;
const end = {
[Symbol.toPrimitive]() {
// We use this condition to get around the check in lib/buffer.js

10
test/parallel/test-buffer-includes.js

@ -140,7 +140,7 @@ assert.strictEqual(
// test usc2 encoding
var twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
let twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
assert(twoByteString.includes('\u0395', 4, 'ucs2'));
assert(twoByteString.includes('\u03a3', -4, 'ucs2'));
@ -190,7 +190,7 @@ assert(!mixedByteStringUtf8.includes('\u0396'));
// Test complex string includes algorithms. Only trigger for long strings.
// Long string that isn't a simple repeat of a shorter string.
var longString = 'A';
let longString = 'A';
for (let i = 66; i < 76; i++) { // from 'B' to 'K'
longString = longString + String.fromCharCode(i) + longString;
}
@ -198,7 +198,7 @@ for (let i = 66; i < 76; i++) { // from 'B' to 'K'
const longBufferString = Buffer.from(longString);
// pattern of 15 chars, repeated every 16 chars in long
var pattern = 'ABACABADABACABA';
let pattern = 'ABACABADABACABA';
for (let i = 0; i < longBufferString.length - pattern.length; i += 7) {
const includes = longBufferString.includes(pattern, i);
assert(includes, 'Long ABACABA...-string at index ' + i);
@ -229,8 +229,8 @@ assert(!allCharsBufferUtf8.includes('notfound'));
assert(!allCharsBufferUcs2.includes('notfound'));
// Find substrings in Utf8.
var lengths = [1, 3, 15]; // Single char, simple and complex.
var indices = [0x5, 0x60, 0x400, 0x680, 0x7ee, 0xFF02, 0x16610, 0x2f77b];
let lengths = [1, 3, 15]; // Single char, simple and complex.
let indices = [0x5, 0x60, 0x400, 0x680, 0x7ee, 0xFF02, 0x16610, 0x2f77b];
for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
for (let i = 0; i < indices.length; i++) {
const index = indices[i];

39
test/parallel/test-buffer-indexof.js

@ -193,7 +193,7 @@ assert.equal(Buffer.from('aaaa00a').indexOf('3030', 'hex'), 4);
assert.equal(-1, twoByteString.indexOf('\u03a3', -2, 'ucs2'));
}
var mixedByteStringUcs2 =
const mixedByteStringUcs2 =
Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395', 'ucs2');
assert.equal(6, mixedByteStringUcs2.indexOf('bc', 0, 'ucs2'));
assert.equal(10, mixedByteStringUcs2.indexOf('\u03a3', 0, 'ucs2'));
@ -228,7 +228,7 @@ assert.equal(
6, twoByteString.indexOf('\u03a3\u0395', 0, 'ucs2'), 'Sigma Epsilon');
}
var mixedByteStringUtf8 = Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395');
const mixedByteStringUtf8 = Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395');
assert.equal(5, mixedByteStringUtf8.indexOf('bc'));
assert.equal(5, mixedByteStringUtf8.indexOf('bc', 5));
assert.equal(5, mixedByteStringUtf8.indexOf('bc', -8));
@ -238,15 +238,15 @@ assert.equal(-1, mixedByteStringUtf8.indexOf('\u0396'));
// Test complex string indexOf algorithms. Only trigger for long strings.
// Long string that isn't a simple repeat of a shorter string.
var longString = 'A';
let longString = 'A';
for (let i = 66; i < 76; i++) { // from 'B' to 'K'
longString = longString + String.fromCharCode(i) + longString;
}
var longBufferString = Buffer.from(longString);
const longBufferString = Buffer.from(longString);
// pattern of 15 chars, repeated every 16 chars in long
var pattern = 'ABACABADABACABA';
let pattern = 'ABACABADABACABA';
for (let i = 0; i < longBufferString.length - pattern.length; i += 7) {
const index = longBufferString.indexOf(pattern, i);
assert.equal((i + 15) & ~0xf, index, 'Long ABACABA...-string at index ' + i);
@ -262,17 +262,17 @@ assert.equal(
1535, longBufferString.indexOf(pattern, 512), 'Long JABACABA..., Second J');
// Search for a non-ASCII string in a pure ASCII string.
var asciiString = Buffer.from(
const asciiString = Buffer.from(
'arglebargleglopglyfarglebargleglopglyfarglebargleglopglyf');
assert.equal(-1, asciiString.indexOf('\x2061'));
assert.equal(3, asciiString.indexOf('leb', 0));
// Search in string containing many non-ASCII chars.
var allCodePoints = [];
const allCodePoints = [];
for (let i = 0; i < 65536; i++) allCodePoints[i] = i;
var allCharsString = String.fromCharCode.apply(String, allCodePoints);
var allCharsBufferUtf8 = Buffer.from(allCharsString);
var allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2');
const allCharsString = String.fromCharCode.apply(String, allCodePoints);
const allCharsBufferUtf8 = Buffer.from(allCharsString);
const allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2');
// Search for string long enough to trigger complex search with ASCII pattern
// and UC16 subject.
@ -309,10 +309,10 @@ assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1);
length = 4 * length;
}
var patternBufferUtf8 = allCharsBufferUtf8.slice(index, index + length);
const patternBufferUtf8 = allCharsBufferUtf8.slice(index, index + length);
assert.equal(index, allCharsBufferUtf8.indexOf(patternBufferUtf8));
var patternStringUtf8 = patternBufferUtf8.toString();
const patternStringUtf8 = patternBufferUtf8.toString();
assert.equal(index, allCharsBufferUtf8.indexOf(patternStringUtf8));
}
}
@ -327,12 +327,12 @@ assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1);
const index = indices[i] * 2;
const length = lengths[lengthIndex];
var patternBufferUcs2 =
const patternBufferUcs2 =
allCharsBufferUcs2.slice(index, index + length);
assert.equal(
index, allCharsBufferUcs2.indexOf(patternBufferUcs2, 0, 'ucs2'));
var patternStringUcs2 = patternBufferUcs2.toString('ucs2');
const patternStringUcs2 = patternBufferUcs2.toString('ucs2');
assert.equal(
index, allCharsBufferUcs2.indexOf(patternStringUcs2, 0, 'ucs2'));
}
@ -491,7 +491,7 @@ assert.strictEqual(buf_bc.lastIndexOf('你好', 5, 'binary'), -1);
assert.strictEqual(buf_bc.lastIndexOf(Buffer.from('你好'), 7), -1);
// Test lastIndexOf on a longer buffer:
var bufferString = new Buffer('a man a plan a canal panama');
const bufferString = new Buffer('a man a plan a canal panama');
assert.equal(15, bufferString.lastIndexOf('canal'));
assert.equal(21, bufferString.lastIndexOf('panama'));
assert.equal(0, bufferString.lastIndexOf('a man a plan a canal panama'));
@ -542,16 +542,17 @@ assert.equal(511, longBufferString.lastIndexOf(pattern, 1534));
// countBits returns the number of bits in the binary reprsentation of n.
function countBits(n) {
for (var count = 0; n > 0; count++) {
let count;
for (count = 0; n > 0; count++) {
n = n & (n - 1); // remove top bit
}
return count;
}
var parts = [];
for (var i = 0; i < 1000000; i++) {
const parts = [];
for (let i = 0; i < 1000000; i++) {
parts.push((countBits(i) % 2 === 0) ? 'yolo' : 'swag');
}
var reallyLong = new Buffer(parts.join(' '));
const reallyLong = new Buffer(parts.join(' '));
assert.equal('yolo swag swag yolo', reallyLong.slice(0, 19).toString());
// Expensive reverse searches. Stress test lastIndexOf:

6
test/parallel/test-buffer-inspect.js

@ -6,13 +6,13 @@ const buffer = require('buffer');
buffer.INSPECT_MAX_BYTES = 2;
var b = Buffer.allocUnsafe(4);
let b = Buffer.allocUnsafe(4);
b.fill('1234');
var s = buffer.SlowBuffer(4);
let s = buffer.SlowBuffer(4);
s.fill('1234');
var expected = '<Buffer 31 32 ... >';
let expected = '<Buffer 31 32 ... >';
assert.strictEqual(util.inspect(b), expected);
assert.strictEqual(util.inspect(s), expected);

4
test/parallel/test-buffer-iterator.js

@ -3,8 +3,8 @@ require('../common');
const assert = require('assert');
const buffer = Buffer.from([1, 2, 3, 4, 5]);
var arr;
var b;
let arr;
let b;
// buffers should be iterable

48
test/parallel/test-buffer-swap.js

@ -45,80 +45,80 @@ assert.deepStrictEqual(buf3_64, Buffer.from([0x01, 0x02, 0x0a, 0x09, 0x08, 0x07,
0x0f, 0x10]));
// Force use of native code (Buffer size above threshold limit for js impl)
var buf4A = new Uint32Array(256).fill(0x04030201);
var buf4 = Buffer.from(buf4A.buffer, buf4A.byteOffset);
var buf5A = new Uint32Array(256).fill(0x03040102);
var buf5 = Buffer.from(buf5A.buffer, buf5A.byteOffset);
const buf4A = new Uint32Array(256).fill(0x04030201);
const buf4 = Buffer.from(buf4A.buffer, buf4A.byteOffset);
const buf5A = new Uint32Array(256).fill(0x03040102);
const buf5 = Buffer.from(buf5A.buffer, buf5A.byteOffset);
buf4.swap16();
assert.deepStrictEqual(buf4, buf5);
var buf6A = new Uint32Array(256).fill(0x04030201);
var buf6 = Buffer.from(buf6A.buffer);
var bu7A = new Uint32Array(256).fill(0x01020304);
var buf7 = Buffer.from(bu7A.buffer, bu7A.byteOffset);
const buf6A = new Uint32Array(256).fill(0x04030201);
const buf6 = Buffer.from(buf6A.buffer);
const bu7A = new Uint32Array(256).fill(0x01020304);
const buf7 = Buffer.from(bu7A.buffer, bu7A.byteOffset);
buf6.swap32();
assert.deepStrictEqual(buf6, buf7);
var buf8A = new Uint8Array(256 * 8);
var buf9A = new Uint8Array(256 * 8);
const buf8A = new Uint8Array(256 * 8);
const buf9A = new Uint8Array(256 * 8);
for (let i = 0; i < buf8A.length; i++) {
buf8A[i] = i % 8;
buf9A[buf9A.length - i - 1] = i % 8;
}
var buf8 = Buffer.from(buf8A.buffer, buf8A.byteOffset);
var buf9 = Buffer.from(buf9A.buffer, buf9A.byteOffset);
const buf8 = Buffer.from(buf8A.buffer, buf8A.byteOffset);
const buf9 = Buffer.from(buf9A.buffer, buf9A.byteOffset);
buf8.swap64();
assert.deepStrictEqual(buf8, buf9);
// Test native code with buffers that are not memory-aligned
var buf10A = new Uint8Array(256 * 8);
var buf11A = new Uint8Array(256 * 8 - 2);
const buf10A = new Uint8Array(256 * 8);
const buf11A = new Uint8Array(256 * 8 - 2);
for (let i = 0; i < buf10A.length; i++) {
buf10A[i] = i % 2;
}
for (let i = 1; i < buf11A.length; i++) {
buf11A[buf11A.length - i] = (i + 1) % 2;
}
var buf10 = Buffer.from(buf10A.buffer, buf10A.byteOffset);
const buf10 = Buffer.from(buf10A.buffer, buf10A.byteOffset);
// 0|1 0|1 0|1...
var buf11 = Buffer.from(buf11A.buffer, buf11A.byteOffset);
const buf11 = Buffer.from(buf11A.buffer, buf11A.byteOffset);
// 0|0 1|0 1|0...
buf10.slice(1, buf10.length - 1).swap16();
assert.deepStrictEqual(buf10.slice(0, buf11.length), buf11);
var buf12A = new Uint8Array(256 * 8);
var buf13A = new Uint8Array(256 * 8 - 4);
const buf12A = new Uint8Array(256 * 8);
const buf13A = new Uint8Array(256 * 8 - 4);
for (let i = 0; i < buf12A.length; i++) {
buf12A[i] = i % 4;
}
for (let i = 1; i < buf13A.length; i++) {
buf13A[buf13A.length - i] = (i + 1) % 4;
}
var buf12 = Buffer.from(buf12A.buffer, buf12A.byteOffset);
const buf12 = Buffer.from(buf12A.buffer, buf12A.byteOffset);
// 0|1 2 3 0|1 2 3...
var buf13 = Buffer.from(buf13A.buffer, buf13A.byteOffset);
const buf13 = Buffer.from(buf13A.buffer, buf13A.byteOffset);
// 0|0 3 2 1|0 3 2...
buf12.slice(1, buf12.length - 3).swap32();
assert.deepStrictEqual(buf12.slice(0, buf13.length), buf13);
var buf14A = new Uint8Array(256 * 8);
var buf15A = new Uint8Array(256 * 8 - 8);
const buf14A = new Uint8Array(256 * 8);
const buf15A = new Uint8Array(256 * 8 - 8);
for (let i = 0; i < buf14A.length; i++) {
buf14A[i] = i % 8;
}
for (let i = 1; i < buf15A.length; i++) {
buf15A[buf15A.length - i] = (i + 1) % 8;
}
var buf14 = Buffer.from(buf14A.buffer, buf14A.byteOffset);
const buf14 = Buffer.from(buf14A.buffer, buf14A.byteOffset);
// 0|1 2 3 4 5 6 7 0|1 2 3 4...
var buf15 = Buffer.from(buf15A.buffer, buf15A.byteOffset);
const buf15 = Buffer.from(buf15A.buffer, buf15A.byteOffset);
// 0|0 7 6 5 4 3 2 1|0 7 6 5...
buf14.slice(1, buf14.length - 7).swap64();

98
test/parallel/test-buffer.js

@ -1,14 +1,14 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');
const assert = require('assert');
var Buffer = require('buffer').Buffer;
var SlowBuffer = require('buffer').SlowBuffer;
const Buffer = require('buffer').Buffer;
const SlowBuffer = require('buffer').SlowBuffer;
// counter to ensure unique value is always copied
var cntr = 0;
let cntr = 0;
var b = Buffer(1024); // safe constructor
const b = Buffer(1024); // safe constructor
console.log('b.length == %d', b.length);
assert.strictEqual(1024, b.length);
@ -24,15 +24,15 @@ for (let i = 0; i < 1024; i++) {
assert.strictEqual(i % 256, b[i]);
}
var c = Buffer(512);
const c = Buffer(512);
console.log('c.length == %d', c.length);
assert.strictEqual(512, c.length);
var d = new Buffer([]);
const d = new Buffer([]);
assert.strictEqual(0, d.length);
var ui32 = new Uint32Array(4).fill(42);
var e = Buffer(ui32);
const ui32 = new Uint32Array(4).fill(42);
const e = Buffer(ui32);
for (const [key, value] of e.entries()) {
assert.deepStrictEqual(value, ui32[key]);
}
@ -179,7 +179,7 @@ Buffer(8).fill('');
}
// copy string longer than buffer length (failure will segfault)
var bb = Buffer(10);
const bb = Buffer(10);
bb.fill('hello crazy world');
@ -214,7 +214,7 @@ assert.equal(b.copy(c, 0, 100, 10), 0);
// when targetStart > targetLength, zero copied
assert.equal(b.copy(c, 512, 0, 10), 0);
var caught_error;
let caught_error;
// invalid encoding for Buffer.toString
caught_error = null;
@ -352,7 +352,7 @@ assert.equal(rangeBuffer.toString({toString: function() {
}}), 'abc');
// testing for smart defaults and ability to pass string values as offset
var writeTest = new Buffer('abcdes');
const writeTest = new Buffer('abcdes');
writeTest.write('n', 'ascii');
writeTest.write('o', '1', 'ascii');
writeTest.write('d', '2', 'ascii');
@ -394,20 +394,20 @@ assert.equal(writeTest.toString(), 'nodejs');
// UTF-8 slice test
var utf8String = '¡hέlló wôrld!';
var offset = 100;
const utf8String = '¡hέlló wôrld!';
const offset = 100;
b.write(utf8String, 0, Buffer.byteLength(utf8String), 'utf8');
var utf8Slice = b.toString('utf8', 0, Buffer.byteLength(utf8String));
let utf8Slice = b.toString('utf8', 0, Buffer.byteLength(utf8String));
assert.equal(utf8String, utf8Slice);
var written = b.write(utf8String, offset, 'utf8');
let written = b.write(utf8String, offset, 'utf8');
assert.equal(Buffer.byteLength(utf8String), written);
utf8Slice = b.toString('utf8', offset, offset + Buffer.byteLength(utf8String));
assert.equal(utf8String, utf8Slice);
var sliceA = b.slice(offset, offset + Buffer.byteLength(utf8String));
var sliceB = b.slice(offset, offset + Buffer.byteLength(utf8String));
const sliceA = b.slice(offset, offset + Buffer.byteLength(utf8String));
const sliceB = b.slice(offset, offset + Buffer.byteLength(utf8String));
for (let i = 0; i < Buffer.byteLength(utf8String); i++) {
assert.equal(sliceA[i], sliceB[i]);
}
@ -514,10 +514,10 @@ for (let i = 0; i < Buffer.byteLength(utf8String); i++) {
}
var arrayIsh = {0: 0, 1: 1, 2: 2, 3: 3, length: 4};
var g = new Buffer(arrayIsh);
const arrayIsh = {0: 0, 1: 1, 2: 2, 3: 3, length: 4};
let g = new Buffer(arrayIsh);
assert.deepStrictEqual(g, new Buffer([0, 1, 2, 3]));
var strArrayIsh = {0: '0', 1: '1', 2: '2', 3: '3', length: 4};
const strArrayIsh = {0: '0', 1: '1', 2: '2', 3: '3', length: 4};
g = new Buffer(strArrayIsh);
assert.deepStrictEqual(g, new Buffer([0, 1, 2, 3]));
@ -670,7 +670,7 @@ assert.equal(
);
// This string encodes single '.' character in UTF-16
var dot = new Buffer('//4uAA==', 'base64');
const dot = new Buffer('//4uAA==', 'base64');
assert.equal(dot[0], 0xff);
assert.equal(dot[1], 0xfe);
assert.equal(dot[2], 0x2e);
@ -722,11 +722,11 @@ assert.equal(0, Buffer('hello').slice(0, 0).length);
// test hex toString
console.log('Create hex string from buffer');
var hexb = new Buffer(256);
const hexb = new Buffer(256);
for (let i = 0; i < 256; i++) {
hexb[i] = i;
}
var hexStr = hexb.toString('hex');
const hexStr = hexb.toString('hex');
assert.equal(hexStr,
'000102030405060708090a0b0c0d0e0f' +
'101112131415161718191a1b1c1d1e1f' +
@ -746,7 +746,7 @@ assert.equal(hexStr,
'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff');
console.log('Create buffer from hex string');
var hexb2 = new Buffer(hexStr, 'hex');
const hexb2 = new Buffer(hexStr, 'hex');
for (let i = 0; i < 256; i++) {
assert.equal(hexb2[i], hexb[i]);
}
@ -773,7 +773,7 @@ assert.strictEqual(Buffer.from('A', 'base64').length, 0);
function buildBuffer(data) {
if (Array.isArray(data)) {
var buffer = Buffer(data.length);
const buffer = Buffer(data.length);
data.forEach(function(v, k) {
buffer[k] = v;
});
@ -782,7 +782,7 @@ function buildBuffer(data) {
return null;
}
var x = buildBuffer([0x81, 0xa3, 0x66, 0x6f, 0x6f, 0xa3, 0x62, 0x61, 0x72]);
const x = buildBuffer([0x81, 0xa3, 0x66, 0x6f, 0x6f, 0xa3, 0x62, 0x61, 0x72]);
console.log(x.inspect());
assert.equal('<Buffer 81 a3 66 6f 6f a3 62 61 72>', x.inspect());
@ -991,7 +991,7 @@ assert.equal(0, Buffer('hello').slice(0, 0).length);
{
// test for buffer overrun
const buf = new Buffer([0, 0, 0, 0, 0]); // length: 5
var sub = buf.slice(0, 4); // length: 4
const sub = buf.slice(0, 4); // length: 4
written = sub.write('12345', 'latin1');
assert.equal(written, 4);
assert.equal(buf[4], 0);
@ -1087,55 +1087,55 @@ assert.throws(function() {
// issue GH-5587
assert.throws(function() {
var buf = new Buffer(8);
const buf = new Buffer(8);
buf.writeFloatLE(0, 5);
}, RangeError);
assert.throws(function() {
var buf = new Buffer(16);
const buf = new Buffer(16);
buf.writeDoubleLE(0, 9);
}, RangeError);
// attempt to overflow buffers, similar to previous bug in array buffers
assert.throws(function() {
var buf = Buffer(8);
const buf = Buffer(8);
buf.readFloatLE(0xffffffff);
}, RangeError);
assert.throws(function() {
var buf = Buffer(8);
const buf = Buffer(8);
buf.writeFloatLE(0.0, 0xffffffff);
}, RangeError);
assert.throws(function() {
var buf = Buffer(8);
const buf = Buffer(8);
buf.readFloatLE(0xffffffff);
}, RangeError);
assert.throws(function() {
var buf = Buffer(8);
const buf = Buffer(8);
buf.writeFloatLE(0.0, 0xffffffff);
}, RangeError);
// ensure negative values can't get past offset
assert.throws(function() {
var buf = Buffer(8);
const buf = Buffer(8);
buf.readFloatLE(-1);
}, RangeError);
assert.throws(function() {
var buf = Buffer(8);
const buf = Buffer(8);
buf.writeFloatLE(0.0, -1);
}, RangeError);
assert.throws(function() {
var buf = Buffer(8);
const buf = Buffer(8);
buf.readFloatLE(-1);
}, RangeError);
assert.throws(function() {
var buf = Buffer(8);
const buf = Buffer(8);
buf.writeFloatLE(0.0, -1);
}, RangeError);
@ -1155,7 +1155,7 @@ assert.throws(function() {
}
[16, 32].forEach(function(bits) {
var buf = new Buffer(bits / 8 - 1);
const buf = new Buffer(bits / 8 - 1);
assert.throws(function() { buf['readUInt' + bits + 'BE'](0); },
RangeError,
@ -1175,7 +1175,7 @@ assert.throws(function() {
});
[16, 32].forEach(function(bits) {
var buf = new Buffer([0xFF, 0xFF, 0xFF, 0xFF]);
const buf = new Buffer([0xFF, 0xFF, 0xFF, 0xFF]);
assert.equal(buf['readUInt' + bits + 'BE'](0),
(0xFFFFFFFF >>> (32 - bits)));
@ -1389,10 +1389,10 @@ assert.throws(function() {
if (common.hasCrypto) {
// Test truncation after decode
var crypto = require('crypto');
const crypto = require('crypto');
var b1 = new Buffer('YW55=======', 'base64');
var b2 = new Buffer('YW55', 'base64');
const b1 = new Buffer('YW55=======', 'base64');
const b2 = new Buffer('YW55', 'base64');
assert.equal(
crypto.createHash('sha1').update(b1).digest('hex'),
@ -1426,17 +1426,17 @@ if (common.hasCrypto) {
}
assert.throws(function() {
var b = Buffer(1);
const b = Buffer(1);
Buffer.compare(b, 'abc');
});
assert.throws(function() {
var b = Buffer(1);
const b = Buffer(1);
Buffer.compare('abc', b);
});
assert.throws(function() {
var b = Buffer(1);
const b = Buffer(1);
b.compare('abc');
});
@ -1454,14 +1454,14 @@ assert.throws(function() {
}
assert.throws(function() {
var b = Buffer(1);
const b = Buffer(1);
b.equals('abc');
});
// Regression test for https://github.com/nodejs/node/issues/649.
assert.throws(function() { Buffer(1422561062959).toString('utf8'); });
var ps = Buffer.poolSize;
const ps = Buffer.poolSize;
Buffer.poolSize = 0;
assert.equal(Buffer(1).parent, undefined);
Buffer.poolSize = ps;

8
test/parallel/test-child-process-constructor.js

@ -1,13 +1,13 @@
'use strict';
require('../common');
var assert = require('assert');
var child_process = require('child_process');
var ChildProcess = child_process.ChildProcess;
const assert = require('assert');
const child_process = require('child_process');
const ChildProcess = child_process.ChildProcess;
assert.strictEqual(typeof ChildProcess, 'function');
// test that we can call spawn
var child = new ChildProcess();
const child = new ChildProcess();
child.spawn({
file: process.execPath,
args: ['--interactive'],

10
test/parallel/test-child-process-default-options.js

@ -1,19 +1,19 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');
const assert = require('assert');
var spawn = require('child_process').spawn;
const spawn = require('child_process').spawn;
process.env.HELLO = 'WORLD';
var child;
let child;
if (common.isWindows) {
child = spawn('cmd.exe', ['/c', 'set'], {});
} else {
child = spawn('/usr/bin/env', [], {});
}
var response = '';
let response = '';
child.stdout.setEncoding('utf8');

4
test/parallel/test-child-process-double-pipe.js

@ -8,7 +8,7 @@ const spawn = require('child_process').spawn;
// We're trying to reproduce:
// $ echo "hello\nnode\nand\nworld" | grep o | sed s/o/a/
var grep, sed, echo;
let grep, sed, echo;
if (common.isWindows) {
grep = spawn('grep', ['--binary', 'o']),
@ -82,7 +82,7 @@ grep.stdout.on('end', function(code) {
});
var result = '';
let result = '';
// print sed's output
sed.stdout.on('data', function(data) {

12
test/parallel/test-child-process-env.js

@ -1,17 +1,17 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');
const assert = require('assert');
var spawn = require('child_process').spawn;
const spawn = require('child_process').spawn;
var env = {
const env = {
'HELLO': 'WORLD'
};
Object.setPrototypeOf(env, {
'FOO': 'BAR'
});
var child;
let child;
if (common.isWindows) {
child = spawn('cmd.exe', ['/c', 'set'], {env: env});
} else {
@ -19,7 +19,7 @@ if (common.isWindows) {
}
var response = '';
let response = '';
child.stdout.setEncoding('utf8');

2
test/parallel/test-child-process-exec-cwd.js

@ -3,7 +3,7 @@ const common = require('../common');
const assert = require('assert');
const exec = require('child_process').exec;
var pwdcommand, dir;
let pwdcommand, dir;
if (common.isWindows) {
pwdcommand = 'echo %cd%';

4
test/parallel/test-child-process-exec-stdout-stderr-data-string.js

@ -4,8 +4,8 @@ const common = require('../common');
const assert = require('assert');
const exec = require('child_process').exec;
var stdoutCalls = 0;
var stderrCalls = 0;
let stdoutCalls = 0;
let stderrCalls = 0;
const command = common.isWindows ? 'dir' : 'ls';
exec(command).stdout.on('data', (data) => {

18
test/parallel/test-child-process-exit-code.js

@ -1,20 +1,20 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
var path = require('path');
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
const path = require('path');
var exitScript = path.join(common.fixturesDir, 'exit.js');
var exitChild = spawn(process.argv[0], [exitScript, 23]);
const exitScript = path.join(common.fixturesDir, 'exit.js');
const exitChild = spawn(process.argv[0], [exitScript, 23]);
exitChild.on('exit', common.mustCall(function(code, signal) {
assert.strictEqual(code, 23);
assert.strictEqual(signal, null);
}));
var errorScript = path.join(common.fixturesDir,
'child_process_should_emit_error.js');
var errorChild = spawn(process.argv[0], [errorScript]);
const errorScript = path.join(common.fixturesDir,
'child_process_should_emit_error.js');
const errorChild = spawn(process.argv[0], [errorScript]);
errorChild.on('exit', common.mustCall(function(code, signal) {
assert.ok(code !== 0);
assert.strictEqual(signal, null);

2
test/parallel/test-child-process-fork-close.js

@ -3,7 +3,7 @@ const common = require('../common');
const assert = require('assert');
const fork = require('child_process').fork;
var cp = fork(common.fixturesDir + '/child-process-message-and-exit.js');
const cp = fork(common.fixturesDir + '/child-process-message-and-exit.js');
let gotMessage = false;
let gotExit = false;

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

@ -37,8 +37,8 @@ if (process.argv[2] === 'child') {
const msg = Buffer.from('Some bytes');
var childGotMessage = false;
var parentGotMessage = false;
let childGotMessage = false;
let parentGotMessage = false;
parentServer.once('message', function(msg, rinfo) {
parentGotMessage = true;

16
test/parallel/test-child-process-fork-exec-argv.js

@ -1,9 +1,9 @@
'use strict';
require('../common');
var assert = require('assert');
var child_process = require('child_process');
var spawn = child_process.spawn;
var fork = child_process.fork;
const assert = require('assert');
const child_process = require('child_process');
const spawn = child_process.spawn;
const fork = child_process.fork;
if (process.argv[2] === 'fork') {
process.stdout.write(JSON.stringify(process.execArgv), function() {
@ -12,11 +12,11 @@ if (process.argv[2] === 'fork') {
} else if (process.argv[2] === 'child') {
fork(__filename, ['fork']);
} else {
var execArgv = ['--stack-size=256'];
var args = [__filename, 'child', 'arg0'];
const execArgv = ['--stack-size=256'];
const args = [__filename, 'child', 'arg0'];
var child = spawn(process.execPath, execArgv.concat(args));
var out = '';
const child = spawn(process.execPath, execArgv.concat(args));
let out = '';
child.stdout.on('data', function(chunk) {
out += chunk;

16
test/parallel/test-child-process-fork-exec-path.js

@ -1,11 +1,11 @@
'use strict';
const common = require('../common');
var assert = require('assert');
var fs = require('fs');
var path = require('path');
var msg = {test: 'this'};
var nodePath = process.execPath;
var copyPath = path.join(common.tmpDir, 'node-copy.exe');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const msg = {test: 'this'};
const nodePath = process.execPath;
const copyPath = path.join(common.tmpDir, 'node-copy.exe');
if (process.env.FORK) {
assert(process.send);
@ -23,9 +23,9 @@ if (process.env.FORK) {
fs.chmodSync(copyPath, '0755');
// slow but simple
var envCopy = JSON.parse(JSON.stringify(process.env));
const envCopy = JSON.parse(JSON.stringify(process.env));
envCopy.FORK = 'true';
var child = require('child_process').fork(__filename, {
const child = require('child_process').fork(__filename, {
execPath: copyPath,
env: envCopy
});

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

@ -19,7 +19,7 @@ ProgressTracker.prototype.check = function() {
if (process.argv[2] === 'child') {
var serverScope;
let serverScope;
process.on('message', function onServer(msg, server) {
if (msg.what !== 'server') return;
@ -58,17 +58,17 @@ if (process.argv[2] === 'child') {
process.send({what: 'ready'});
} else {
var child = fork(process.argv[1], ['child']);
const child = fork(process.argv[1], ['child']);
child.on('exit', function() {
console.log('CHILD: died');
});
// send net.Server to child and test by connecting
var testServer = function(callback) {
const testServer = function(callback) {
// destroy server execute callback when done
var progress = new ProgressTracker(2, function() {
const progress = new ProgressTracker(2, function() {
server.on('close', function() {
console.log('PARENT: server closed');
child.send({what: 'close'});
@ -77,11 +77,11 @@ if (process.argv[2] === 'child') {
});
// we expect 4 connections and close events
var connections = new ProgressTracker(4, progress.done.bind(progress));
var closed = new ProgressTracker(4, progress.done.bind(progress));
const connections = new ProgressTracker(4, progress.done.bind(progress));
const closed = new ProgressTracker(4, progress.done.bind(progress));
// create server and send it to child
var server = net.createServer();
let server = net.createServer();
server.on('connection', function(socket) {
console.log('PARENT: got connection');
socket.destroy();
@ -94,12 +94,12 @@ if (process.argv[2] === 'child') {
server.listen(0);
// handle client messages
var messageHandlers = function(msg) {
const messageHandlers = function(msg) {
if (msg.what === 'listening') {
// make connections
var socket;
for (var i = 0; i < 4; i++) {
let socket;
for (let i = 0; i < 4; i++) {
socket = net.connect(server.address().port, function() {
console.log('CLIENT: connected');
});
@ -122,11 +122,11 @@ if (process.argv[2] === 'child') {
};
// send net.Socket to child
var testSocket = function(callback) {
const testSocket = function(callback) {
// create a new server and connect to it,
// but the socket will be handled by the child
var server = net.createServer();
const server = net.createServer();
server.on('connection', function(socket) {
socket.on('close', function() {
console.log('CLIENT: socket closed');
@ -145,8 +145,8 @@ if (process.argv[2] === 'child') {
// will have to do.
server.listen(0, function() {
console.error('testSocket, listening');
var connect = net.connect(server.address().port);
var store = '';
const connect = net.connect(server.address().port);
let store = '';
connect.on('data', function(chunk) {
store += chunk;
console.log('CLIENT: got data');
@ -160,8 +160,8 @@ if (process.argv[2] === 'child') {
};
// create server and send it to child
var serverSuccess = false;
var socketSuccess = false;
let serverSuccess = false;
let socketSuccess = false;
child.on('message', function onReady(msg) {
if (msg.what !== 'ready') return;
child.removeListener('message', onReady);

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

@ -1,13 +1,13 @@
'use strict';
const common = require('../common');
var assert = require('assert');
var fork = require('child_process').fork;
var net = require('net');
var count = 12;
const assert = require('assert');
const fork = require('child_process').fork;
const net = require('net');
const count = 12;
if (process.argv[2] === 'child') {
var needEnd = [];
var id = process.argv[3];
const needEnd = [];
const id = process.argv[3];
process.on('message', function(m, socket) {
if (!socket) return;
@ -60,11 +60,11 @@ if (process.argv[2] === 'child') {
} else {
var child1 = fork(process.argv[1], ['child', '1']);
var child2 = fork(process.argv[1], ['child', '2']);
var child3 = fork(process.argv[1], ['child', '3']);
const child1 = fork(process.argv[1], ['child', '1']);
const child2 = fork(process.argv[1], ['child', '2']);
const child3 = fork(process.argv[1], ['child', '3']);
var server = net.createServer();
const server = net.createServer();
let connected = 0;
let closed = 0;
@ -94,10 +94,10 @@ if (process.argv[2] === 'child') {
}
});
var disconnected = 0;
let disconnected = 0;
server.on('listening', function() {
var j = count, client;
let j = count, client;
while (j--) {
client = net.connect(this.address().port, '127.0.0.1');
client.on('error', function() {
@ -112,7 +112,7 @@ if (process.argv[2] === 'child') {
}
});
var closeEmitted = false;
let closeEmitted = false;
server.on('close', common.mustCall(function() {
closeEmitted = true;
@ -123,7 +123,7 @@ if (process.argv[2] === 'child') {
server.listen(0, '127.0.0.1');
var closeServer = function() {
let closeServer = function() {
server.close();
setTimeout(function() {

9
test/parallel/test-child-process-fork-ref.js

@ -1,7 +1,7 @@
'use strict';
require('../common');
var assert = require('assert');
var fork = require('child_process').fork;
const assert = require('assert');
const fork = require('child_process').fork;
if (process.argv[2] === 'child') {
process.send('1');
@ -16,9 +16,10 @@ if (process.argv[2] === 'child') {
});
} else {
var child = fork(__filename, ['child'], {silent: true});
const child = fork(__filename, ['child'], {silent: true});
var ipc = [], stdout = '';
const ipc = [];
let stdout = '';
child.on('message', function(msg) {
ipc.push(msg);

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

@ -1,6 +1,6 @@
'use strict';
require('../common');
var fork = require('child_process').fork;
const fork = require('child_process').fork;
if (process.argv[2] === 'child') {
console.log('child -> call disconnect');
@ -12,7 +12,7 @@ if (process.argv[2] === 'child') {
}, 400);
} else {
var child = fork(__filename, ['child']);
const child = fork(__filename, ['child']);
child.on('disconnect', function() {
console.log('parent -> disconnect');

6
test/parallel/test-child-process-fork-regr-gh-2847.js

@ -14,7 +14,7 @@ if (!cluster.isMaster) {
return;
}
var server = net.createServer(function(s) {
const server = net.createServer(function(s) {
if (common.isWindows) {
s.on('error', function(err) {
// Prevent possible ECONNRESET errors from popping up
@ -26,10 +26,10 @@ var server = net.createServer(function(s) {
s.destroy();
}, 100);
}).listen(0, function() {
var worker = cluster.fork();
const worker = cluster.fork();
function send(callback) {
var s = net.connect(server.address().port, function() {
const s = net.connect(server.address().port, function() {
worker.send({}, s, callback);
});

8
test/parallel/test-child-process-fork.js

@ -1,10 +1,10 @@
'use strict';
const common = require('../common');
var assert = require('assert');
var fork = require('child_process').fork;
var args = ['foo', 'bar'];
const assert = require('assert');
const fork = require('child_process').fork;
const args = ['foo', 'bar'];
var n = fork(common.fixturesDir + '/child-process-spawn-node.js', args);
const n = fork(common.fixturesDir + '/child-process-spawn-node.js', args);
assert.deepStrictEqual(args, ['foo', 'bar']);
n.on('message', function(m) {

4
test/parallel/test-child-process-fork3.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
var child_process = require('child_process');
const common = require('../common');
const child_process = require('child_process');
child_process.fork(common.fixturesDir + '/empty.js'); // should not hang

12
test/parallel/test-child-process-internal.js

@ -1,11 +1,11 @@
'use strict';
const common = require('../common');
var assert = require('assert');
const assert = require('assert');
//messages
var PREFIX = 'NODE_';
var normal = {cmd: 'foo' + PREFIX};
var internal = {cmd: PREFIX + 'bar'};
const PREFIX = 'NODE_';
const normal = {cmd: 'foo' + PREFIX};
const internal = {cmd: PREFIX + 'bar'};
if (process.argv[2] === 'child') {
//send non-internal message containing PREFIX at a non prefix position
@ -18,8 +18,8 @@ if (process.argv[2] === 'child') {
} else {
var fork = require('child_process').fork;
var child = fork(process.argv[1], ['child']);
const fork = require('child_process').fork;
const child = fork(process.argv[1], ['child']);
child.once('message', common.mustCall(function(data) {
assert.deepStrictEqual(data, normal);

2
test/parallel/test-child-process-send-returns-boolean.js

@ -15,7 +15,7 @@ assert.strictEqual(rv, true);
const spawnOptions = { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] };
const s = spawn(process.execPath, [emptyFile], spawnOptions);
var handle = null;
let handle = null;
s.on('exit', function() {
handle.close();
});

8
test/parallel/test-child-process-set-blocking.js

@ -1,11 +1,11 @@
'use strict';
const common = require('../common');
var assert = require('assert');
var ch = require('child_process');
const assert = require('assert');
const ch = require('child_process');
var SIZE = 100000;
const SIZE = 100000;
var cp = ch.spawn('python', ['-c', 'print ' + SIZE + ' * "C"'], {
const cp = ch.spawn('python', ['-c', 'print ' + SIZE + ' * "C"'], {
stdio: 'inherit'
});

16
test/parallel/test-child-process-silent.js

@ -1,7 +1,7 @@
'use strict';
require('../common');
var assert = require('assert');
var childProcess = require('child_process');
const assert = require('assert');
const childProcess = require('child_process');
// Child pipe test
if (process.argv[2] === 'pipe') {
@ -32,15 +32,15 @@ if (process.argv[2] === 'pipe') {
// testcase | start parent && child IPC test
// testing: is stderr and stdout piped to parent
var args = [process.argv[1], 'parent'];
var parent = childProcess.spawn(process.execPath, args);
const args = [process.argv[1], 'parent'];
const parent = childProcess.spawn(process.execPath, args);
//got any stderr or std data
var stdoutData = false;
let stdoutData = false;
parent.stdout.on('data', function() {
stdoutData = true;
});
var stderrData = false;
let stderrData = false;
parent.stdout.on('data', function() {
stderrData = true;
});
@ -52,8 +52,8 @@ if (process.argv[2] === 'pipe') {
child.stderr.pipe(process.stderr, {end: false});
child.stdout.pipe(process.stdout, {end: false});
var childSending = false;
var childReciveing = false;
let childSending = false;
let childReciveing = false;
child.on('message', function(message) {
if (childSending === false) {
childSending = (message === 'message from child');

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

@ -12,7 +12,7 @@ const invalidOptionsMsg = /"options" argument must be an object/;
const empty = common.fixturesDir + '/empty.js';
assert.throws(function() {
var child = spawn(invalidcmd, 'this is not an array');
const child = spawn(invalidcmd, 'this is not an array');
child.on('error', common.fail);
}, TypeError);

8
test/parallel/test-child-process-spawnsync-env.js

@ -1,13 +1,13 @@
'use strict';
require('../common');
var assert = require('assert');
var cp = require('child_process');
const assert = require('assert');
const cp = require('child_process');
if (process.argv[2] === 'child') {
console.log(process.env.foo);
} else {
var expected = 'bar';
var child = cp.spawnSync(process.execPath, [__filename, 'child'], {
const expected = 'bar';
const child = cp.spawnSync(process.execPath, [__filename, 'child'], {
env: Object.assign(process.env, { foo: expected })
});

4
test/parallel/test-child-process-spawnsync-input.js

@ -17,7 +17,7 @@ const args = [
`console.log("${msgOut}"); console.error("${msgErr}");`
];
var ret;
let ret;
function checkSpawnSyncRet(ret) {
@ -51,7 +51,7 @@ if (process.argv.indexOf('spawnchild') !== -1) {
verifyBufOutput(spawnSync(process.execPath, [__filename, 'spawnchild', 1]));
verifyBufOutput(spawnSync(process.execPath, [__filename, 'spawnchild', 2]));
var options = {
let options = {
input: 1234
};

6
test/parallel/test-child-process-spawnsync-timeout.js

@ -2,7 +2,7 @@
const common = require('../common');
const assert = require('assert');
var spawnSync = require('child_process').spawnSync;
const spawnSync = require('child_process').spawnSync;
const TIMER = 200;
const SLEEP = common.platformTimeout(5000);
@ -15,8 +15,8 @@ switch (process.argv[2]) {
}, SLEEP);
break;
default:
var start = Date.now();
var ret = spawnSync(process.execPath, [__filename, 'child'],
const start = Date.now();
const ret = spawnSync(process.execPath, [__filename, 'child'],
{timeout: TIMER});
assert.strictEqual(ret.error.errno, 'ETIMEDOUT');
const end = Date.now() - start;

6
test/parallel/test-child-process-stdin-ipc.js

@ -1,8 +1,8 @@
'use strict';
const common = require('../common');
var assert = require('assert');
const assert = require('assert');
var spawn = require('child_process').spawn;
const spawn = require('child_process').spawn;
if (process.argv[2] === 'child') {
// Just reference stdin, it should start it
@ -10,7 +10,7 @@ if (process.argv[2] === 'child') {
return;
}
var proc = spawn(process.execPath, [__filename, 'child'], {
const proc = spawn(process.execPath, [__filename, 'child'], {
stdio: ['ipc', 'inherit', 'inherit']
});

3
test/parallel/test-child-process-stdio-big-write-end.js

@ -28,8 +28,9 @@ function parent() {
});
// Write until the buffer fills up.
let buf;
do {
var buf = Buffer.alloc(BUFSIZE, '.');
buf = Buffer.alloc(BUFSIZE, '.');
sent += BUFSIZE;
} while (child.stdin.write(buf));

12
test/parallel/test-child-process-stdio-inherit.js

@ -1,7 +1,7 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
if (process.argv[2] === 'parent')
parent();
@ -9,10 +9,10 @@ else
grandparent();
function grandparent() {
var child = spawn(process.execPath, [__filename, 'parent']);
const child = spawn(process.execPath, [__filename, 'parent']);
child.stderr.pipe(process.stderr);
var output = '';
var input = 'asdfasdf';
let output = '';
const input = 'asdfasdf';
child.stdout.on('data', function(chunk) {
output += chunk;

4
test/parallel/test-cli-eval.js

@ -14,7 +14,7 @@ const nodejs = '"' + process.execPath + '"';
// replace \ by / because windows uses backslashes in paths, but they're still
// interpreted as the escape character when put between quotes.
var filename = __filename.replace(/\\/g, '/');
const filename = __filename.replace(/\\/g, '/');
// assert that nothing is written to stdout
child.exec(nodejs + ' --eval 42',
@ -32,7 +32,7 @@ child.exec(nodejs + ' --eval "console.error(42)"',
// assert that the expected output is written to stdout
['--print', '-p -e', '-pe', '-p'].forEach(function(s) {
var cmd = nodejs + ' ' + s + ' ';
const cmd = nodejs + ' ' + s + ' ';
child.exec(cmd + '42',
function(err, stdout, stderr) {

20
test/parallel/test-cli-syntax.js

@ -5,10 +5,10 @@ const assert = require('assert');
const spawnSync = require('child_process').spawnSync;
const path = require('path');
var node = process.execPath;
const node = process.execPath;
// test both sets of arguments that check syntax
var syntaxArgs = [
const syntaxArgs = [
['-c'],
['--check']
];
@ -25,8 +25,8 @@ var syntaxArgs = [
// loop each possible option, `-c` or `--check`
syntaxArgs.forEach(function(args) {
var _args = args.concat(file);
var c = spawnSync(node, _args, {encoding: 'utf8'});
const _args = args.concat(file);
const c = spawnSync(node, _args, {encoding: 'utf8'});
// no output should be produced
assert.strictEqual(c.stdout, '', 'stdout produced');
@ -46,14 +46,14 @@ var syntaxArgs = [
// loop each possible option, `-c` or `--check`
syntaxArgs.forEach(function(args) {
var _args = args.concat(file);
var c = spawnSync(node, _args, {encoding: 'utf8'});
const _args = args.concat(file);
const c = spawnSync(node, _args, {encoding: 'utf8'});
// no stdout should be produced
assert.strictEqual(c.stdout, '', 'stdout produced');
// stderr should have a syntax error message
var match = c.stderr.match(/^SyntaxError: Unexpected identifier$/m);
const match = c.stderr.match(/^SyntaxError: Unexpected identifier$/m);
assert(match, 'stderr incorrect');
assert.strictEqual(c.status, 1, 'code == ' + c.status);
@ -69,14 +69,14 @@ var syntaxArgs = [
// loop each possible option, `-c` or `--check`
syntaxArgs.forEach(function(args) {
var _args = args.concat(file);
var c = spawnSync(node, _args, {encoding: 'utf8'});
const _args = args.concat(file);
const c = spawnSync(node, _args, {encoding: 'utf8'});
// no stdout should be produced
assert.strictEqual(c.stdout, '', 'stdout produced');
// stderr should have a module not found error message
var match = c.stderr.match(/^Error: Cannot find module/m);
const match = c.stderr.match(/^Error: Cannot find module/m);
assert(match, 'stderr incorrect');
assert.strictEqual(c.status, 1, 'code == ' + c.status);

4
test/parallel/test-cluster-basic.js

@ -56,7 +56,7 @@ if (cluster.isWorker) {
}
};
var worker;
let worker;
const stateNames = Object.keys(checks.worker.states);
//Check events, states, and emit arguments
@ -72,7 +72,7 @@ if (cluster.isWorker) {
checks.cluster.equal[name] = worker === arguments[0];
//Check state
var state = stateNames[index];
const state = stateNames[index];
checks.worker.states[state] = (state === worker.state);
}));
});

2
test/parallel/test-cluster-bind-privileged-port.js

@ -19,7 +19,7 @@ if (cluster.isMaster) {
assert.strictEqual(exitCode, 0);
}));
} else {
var s = net.createServer(common.fail);
const s = net.createServer(common.fail);
s.listen(42, common.fail.bind(null, 'listen should have failed'));
s.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'EACCES');

12
test/parallel/test-cluster-dgram-1.js

@ -21,10 +21,10 @@ else
function master() {
var listening = 0;
let listening = 0;
// Fork 4 workers.
for (var i = 0; i < NUM_WORKERS; i++)
for (let i = 0; i < NUM_WORKERS; i++)
cluster.fork();
// Wait until all workers are listening.
@ -35,7 +35,7 @@ function master() {
// Start sending messages.
const buf = Buffer.from('hello world');
const socket = dgram.createSocket('udp4');
var sent = 0;
let sent = 0;
doSend();
function doSend() {
@ -60,7 +60,7 @@ function master() {
}
function setupWorker(worker) {
var received = 0;
let received = 0;
worker.on('message', common.mustCall((msg) => {
received = msg.received;
@ -75,10 +75,10 @@ function master() {
function worker() {
var received = 0;
let received = 0;
// Create udp socket and start listening.
var socket = dgram.createSocket('udp4');
const socket = dgram.createSocket('udp4');
socket.on('message', common.mustCall((data, info) => {
received++;

6
test/parallel/test-cluster-dgram-2.js

@ -20,10 +20,10 @@ else
function master() {
var received = 0;
let received = 0;
// Start listening on a socket.
var socket = dgram.createSocket('udp4');
const socket = dgram.createSocket('udp4');
socket.bind(common.PORT);
// Disconnect workers when the expected number of messages have been
@ -42,7 +42,7 @@ function master() {
}, NUM_WORKERS * PACKETS_PER_WORKER));
// Fork workers.
for (var i = 0; i < NUM_WORKERS; i++)
for (let i = 0; i < NUM_WORKERS; i++)
cluster.fork();
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save