From 76af4f0d05e3e1eded391dd2f3db71bb4480429a Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 25 Apr 2019 00:46:40 +0200 Subject: [PATCH 001/106] tools: prohibit `assert.doesNotReject()` in Node.js core This makes sure we do not use `assert.doesNotReject()` anywhere in our code base. This is just a simple wrapper that catches the rejection and then rejects it again in case of an error. Thus, it is not useful to do that. The error message for `assert.doesNotThrow()` is also improved. PR-URL: https://github.com/nodejs/node/pull/27402 Reviewed-By: Rich Trott Reviewed-By: Benjamin Gruenbaum Reviewed-By: Beth Griggs Reviewed-By: James M Snell --- .eslintrc.js | 6 ++- doc/api/assert.md | 2 + test/parallel/test-assert-async.js | 68 +++++++++++++------------- test/parallel/test-fs-readdir-types.js | 5 +- 4 files changed, 43 insertions(+), 38 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 9aa90c6366232d..cfada1f65c181e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -184,7 +184,11 @@ module.exports = { }, { selector: "CallExpression[callee.property.name='doesNotThrow']", - message: 'Please replace `assert.doesNotThrow()` and add a comment next to the code instead.', + message: 'Do not use `assert.doesNotThrow()`. Write the code without the wrapper and add a comment instead.', + }, + { + selector: "CallExpression[callee.property.name='doesNotReject']", + message: 'Do not use `assert.doesNotReject()`. Write the code without the wrapper and add a comment instead.', }, { selector: "CallExpression[callee.property.name='rejects'][arguments.length<2]", diff --git a/doc/api/assert.md b/doc/api/assert.md index 9028d21f0d9df3..0a7d35f105e48e 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -454,6 +454,7 @@ function. See [`assert.throws()`][] for more details. Besides the async nature to await the completion behaves identically to [`assert.doesNotThrow()`][]. + ```js (async () => { await assert.doesNotReject( @@ -465,6 +466,7 @@ Besides the async nature to await the completion behaves identically to })(); ``` + ```js assert.doesNotReject(Promise.reject(new TypeError('Wrong value'))) .then(() => { diff --git a/test/parallel/test-assert-async.js b/test/parallel/test-assert-async.js index 140bd05d1a3c8f..8aad1d865c097e 100644 --- a/test/parallel/test-assert-async.js +++ b/test/parallel/test-assert-async.js @@ -114,11 +114,36 @@ promises.push(assert.rejects( } )); +{ + const handler = (generated, actual, err) => { + assert.strictEqual(err.generatedMessage, generated); + assert.strictEqual(err.code, 'ERR_ASSERTION'); + assert.strictEqual(err.actual, actual); + assert.strictEqual(err.operator, 'rejects'); + assert(/rejects/.test(err.stack)); + return true; + }; + const err = new Error(); + promises.push(assert.rejects( + assert.rejects(Promise.reject(null), { code: 'FOO' }), + handler.bind(null, true, null) + )); + promises.push(assert.rejects( + assert.rejects(Promise.reject(5), { code: 'FOO' }, 'AAAAA'), + handler.bind(null, false, 5) + )); + promises.push(assert.rejects( + assert.rejects(Promise.reject(err), { code: 'FOO' }, 'AAAAA'), + handler.bind(null, false, err) + )); +} + // Check `assert.doesNotReject`. { // `assert.doesNotReject` accepts a function or a promise // or a thenable as first argument. - const promise = assert.doesNotReject(() => new Map(), common.mustNotCall()); + /* eslint-disable no-restricted-syntax */ + let promise = assert.doesNotReject(() => new Map(), common.mustNotCall()); promises.push(assert.rejects(promise, { message: 'Expected instance of Promise to be returned ' + 'from the "promiseFn" function but got instance of Map.', @@ -149,9 +174,7 @@ promises.push(assert.rejects( code: 'ERR_INVALID_RETURN_VALUE' }) ); -} -{ const handler1 = (err) => { assert(err instanceof assert.AssertionError, `${err.name} is not instance of AssertionError`); @@ -173,7 +196,7 @@ promises.push(assert.rejects( const rejectingFn = async () => assert.fail(); - let promise = assert.doesNotReject(rejectingFn, common.mustCall(handler1)); + promise = assert.doesNotReject(rejectingFn, common.mustCall(handler1)); promises.push(assert.rejects(promise, common.mustCall(handler2))); promise = assert.doesNotReject(rejectingFn(), common.mustCall(handler1)); @@ -181,39 +204,16 @@ promises.push(assert.rejects( promise = assert.doesNotReject(() => assert.fail(), common.mustNotCall()); promises.push(assert.rejects(promise, common.mustCall(handler1))); -} -promises.push(assert.rejects( - assert.doesNotReject(123), - { - code: 'ERR_INVALID_ARG_TYPE', - message: 'The "promiseFn" argument must be one of type ' + - 'Function or Promise. Received type number' - } -)); - -{ - const handler = (generated, actual, err) => { - assert.strictEqual(err.generatedMessage, generated); - assert.strictEqual(err.code, 'ERR_ASSERTION'); - assert.strictEqual(err.actual, actual); - assert.strictEqual(err.operator, 'rejects'); - assert(/rejects/.test(err.stack)); - return true; - }; - const err = new Error(); promises.push(assert.rejects( - assert.rejects(Promise.reject(null), { code: 'FOO' }), - handler.bind(null, true, null) - )); - promises.push(assert.rejects( - assert.rejects(Promise.reject(5), { code: 'FOO' }, 'AAAAA'), - handler.bind(null, false, 5) - )); - promises.push(assert.rejects( - assert.rejects(Promise.reject(err), { code: 'FOO' }, 'AAAAA'), - handler.bind(null, false, err) + assert.doesNotReject(123), + { + code: 'ERR_INVALID_ARG_TYPE', + message: 'The "promiseFn" argument must be one of type ' + + 'Function or Promise. Received type number' + } )); + /* eslint-enable no-restricted-syntax */ } // Make sure all async code gets properly executed. diff --git a/test/parallel/test-fs-readdir-types.js b/test/parallel/test-fs-readdir-types.js index 96a3b73098728d..78f1b0d4e1b627 100644 --- a/test/parallel/test-fs-readdir-types.js +++ b/test/parallel/test-fs-readdir-types.js @@ -72,13 +72,12 @@ fs.readdir(readdirDir, { assertDirents(dirents); })); -// Check the promisified version -assert.doesNotReject(async () => { +(async () => { const dirents = await fs.promises.readdir(readdirDir, { withFileTypes: true }); assertDirents(dirents); -}); +})(); // Check for correct types when the binding returns unknowns const UNKNOWN = constants.UV_DIRENT_UNKNOWN; From c2a03d58c3b4f32a618b760e5165f9707af4d921 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 18 Apr 2019 12:25:57 +0800 Subject: [PATCH 002/106] lib: print to stdout/stderr directly instead of using console This patch adds an internal function that prints to stdout or stderr by directly writing to the known file descriptor, and uses it internally in common cases to avoid the overhead of the console implementation. PR-URL: https://github.com/nodejs/node/pull/27320 Reviewed-By: James M Snell --- lib/fs.js | 20 +-------- lib/internal/fs/utils.js | 22 +++++++++- lib/internal/main/repl.js | 10 ++--- lib/internal/process/execution.js | 18 ++++----- lib/internal/util/print.js | 67 +++++++++++++++++++++++++++++++ node.gyp | 1 + 6 files changed, 103 insertions(+), 35 deletions(-) create mode 100644 lib/internal/util/print.js diff --git a/lib/fs.js b/lib/fs.js index 38c13613cb352a..9effb93acb9b72 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -74,7 +74,8 @@ const { validateOffsetLengthRead, validateOffsetLengthWrite, validatePath, - warnOnNonPortableTemplate + warnOnNonPortableTemplate, + handleErrorFromBinding } = require('internal/fs/utils'); const { CHAR_FORWARD_SLASH, @@ -117,23 +118,6 @@ function showTruncateDeprecation() { } } -function handleErrorFromBinding(ctx) { - if (ctx.errno !== undefined) { // libuv error numbers - const err = uvException(ctx); - // eslint-disable-next-line no-restricted-syntax - Error.captureStackTrace(err, handleErrorFromBinding); - throw err; - } - if (ctx.error !== undefined) { // Errors created in C++ land. - // TODO(joyeecheung): currently, ctx.error are encoding errors - // usually caused by memory problems. We need to figure out proper error - // code(s) for this. - // eslint-disable-next-line no-restricted-syntax - Error.captureStackTrace(ctx.error, handleErrorFromBinding); - throw ctx.error; - } -} - function maybeCallback(cb) { if (typeof cb === 'function') return cb; diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index ca8328f553d283..dde78654e0f992 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -12,7 +12,8 @@ const { ERR_INVALID_OPT_VALUE_ENCODING, ERR_OUT_OF_RANGE }, - hideStackFrames + hideStackFrames, + uvException } = require('internal/errors'); const { isUint8Array, @@ -444,7 +445,26 @@ function warnOnNonPortableTemplate(template) { } } +// This handles errors following the convention of the fs binding. +function handleErrorFromBinding(ctx) { + if (ctx.errno !== undefined) { // libuv error numbers + const err = uvException(ctx); + // eslint-disable-next-line no-restricted-syntax + Error.captureStackTrace(err, handleErrorFromBinding); + throw err; + } + if (ctx.error !== undefined) { // Errors created in C++ land. + // TODO(joyeecheung): currently, ctx.error are encoding errors + // usually caused by memory problems. We need to figure out proper error + // code(s) for this. + // eslint-disable-next-line no-restricted-syntax + Error.captureStackTrace(ctx.error, handleErrorFromBinding); + throw ctx.error; + } +} + module.exports = { + handleErrorFromBinding, assertEncoding, copyObject, Dirent, diff --git a/lib/internal/main/repl.js b/lib/internal/main/repl.js index 980893f9c34e20..58afb2be9879fa 100644 --- a/lib/internal/main/repl.js +++ b/lib/internal/main/repl.js @@ -11,7 +11,7 @@ const { evalScript } = require('internal/process/execution'); -const console = require('internal/console/global'); +const { print, kStderr, kStdout } = require('internal/util/print'); const { getOptionValue } = require('internal/options'); @@ -21,14 +21,12 @@ markBootstrapComplete(); // --input-type flag not supported in REPL if (getOptionValue('--input-type')) { - // If we can't write to stderr, we'd like to make this a noop, - // so use console.error. - console.error('Cannot specify --input-type for REPL'); + print(kStderr, 'Cannot specify --input-type for REPL'); process.exit(1); } -console.log(`Welcome to Node.js ${process.version}.\n` + - 'Type ".help" for more information.'); +print(kStdout, `Welcome to Node.js ${process.version}.\n` + + 'Type ".help" for more information.'); const cliRepl = require('internal/repl'); cliRepl.createInternalRepl(process.env, (err, repl) => { diff --git a/lib/internal/process/execution.js b/lib/internal/process/execution.js index 19866d17226982..c95567c506237f 100644 --- a/lib/internal/process/execution.js +++ b/lib/internal/process/execution.js @@ -35,24 +35,22 @@ function tryGetCwd() { } } -function evalModule(source, print) { - const { log, error } = require('internal/console/global'); +function evalModule(source, printResult) { const { decorateErrorStack } = require('internal/util'); const asyncESM = require('internal/process/esm_loader'); + const { kStdout, kStderr, print } = require('internal/util/print'); asyncESM.loaderPromise.then(async (loader) => { const { result } = await loader.eval(source); - if (print) { - log(result); - } + if (printResult) { print(kStdout, result); } }) .catch((e) => { decorateErrorStack(e); - error(e); + print(kStderr, e); process.exit(1); }); } -function evalScript(name, body, breakFirstLine, print) { +function evalScript(name, body, breakFirstLine, printResult) { const CJSModule = require('internal/modules/cjs/loader'); const { kVmBreakFirstLineSymbol } = require('internal/util'); @@ -77,9 +75,9 @@ function evalScript(name, body, breakFirstLine, print) { [kVmBreakFirstLineSymbol]: ${!!breakFirstLine} });\n`; const result = module._compile(script, `${name}-wrapper`); - if (print) { - const { log } = require('internal/console/global'); - log(result); + if (printResult) { + const { kStdout, print } = require('internal/util/print'); + print(kStdout, result); } } diff --git a/lib/internal/util/print.js b/lib/internal/util/print.js new file mode 100644 index 00000000000000..4c9327502ebad2 --- /dev/null +++ b/lib/internal/util/print.js @@ -0,0 +1,67 @@ +'use strict'; + +// This implements a light-weight printer that writes to stdout/stderr +// directly to avoid the overhead in the console abstraction. + +const { formatWithOptions } = require('internal/util/inspect'); +const { writeString } = internalBinding('fs'); +const { handleErrorFromBinding } = require('internal/fs/utils'); +const { guessHandleType } = internalBinding('util'); +const { log } = require('internal/console/global'); + +const kStdout = 1; +const kStderr = 2; +const handleType = [undefined, undefined, undefined]; +function getFdType(fd) { + if (handleType[fd] === undefined) { + handleType[fd] = guessHandleType(fd); + } + return handleType[fd]; +} + +function formatAndWrite(fd, obj, ignoreErrors, colors = false) { + const str = `${formatWithOptions({ colors }, obj)}\n`; + const ctx = {}; + writeString(fd, str, null, undefined, undefined, ctx); + if (!ignoreErrors) { + handleErrorFromBinding(ctx); + } +} + +let colors; +function getColors() { + if (colors === undefined) { + colors = require('internal/tty').getColorDepth() > 2; + } + return colors; +} + +// TODO(joyeecheung): replace more internal process._rawDebug() +// and console.log() usage with this if possible. +function print(fd, obj, ignoreErrors = true) { + switch (getFdType(fd)) { + case 'TTY': + formatAndWrite(fd, obj, ignoreErrors, getColors()); + break; + case 'FILE': + formatAndWrite(fd, obj, ignoreErrors); + break; + case 'PIPE': + case 'TCP': + // Fallback to console.log to handle IPC. + if (process.channel && process.channel.fd === fd) { + log(obj); + } else { + formatAndWrite(fd, obj, ignoreErrors); + } + break; + default: + log(obj); + } +} + +module.exports = { + print, + kStderr, + kStdout +}; diff --git a/node.gyp b/node.gyp index 53bd954afb3e39..3cf47ffc255531 100644 --- a/node.gyp +++ b/node.gyp @@ -184,6 +184,7 @@ 'lib/internal/url.js', 'lib/internal/util.js', 'lib/internal/util/comparisons.js', + 'lib/internal/util/print.js', 'lib/internal/util/debuglog.js', 'lib/internal/util/inspect.js', 'lib/internal/util/inspector.js', From cfc7bdd3036953e27c366d2d2ed97ea382a70369 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 18 Apr 2019 12:33:58 +0800 Subject: [PATCH 003/106] benchmark: add benchmark for node -p PR-URL: https://github.com/nodejs/node/pull/27320 Reviewed-By: James M Snell --- benchmark/misc/print.js | 59 +++++++++++++++++++++++++++ test/benchmark/test-benchmark-misc.js | 1 + 2 files changed, 60 insertions(+) create mode 100644 benchmark/misc/print.js diff --git a/benchmark/misc/print.js b/benchmark/misc/print.js new file mode 100644 index 00000000000000..e048d22f7b76ab --- /dev/null +++ b/benchmark/misc/print.js @@ -0,0 +1,59 @@ +'use strict'; +const common = require('../common.js'); +const { spawn } = require('child_process'); + +const bench = common.createBenchmark(main, { + dur: [1], + code: ['1', '"string"', 'process.versions', 'process'] +}); + +function spawnProcess(code) { + const cmd = process.execPath || process.argv[0]; + const argv = ['-p', code]; + return spawn(cmd, argv); +} + +function start(state, code, bench, getNode) { + const node = getNode(code); + let stdout = ''; + let stderr = ''; + + node.stdout.on('data', (data) => { + stdout += data; + }); + + node.stderr.on('data', (data) => { + stderr += data; + }); + + node.on('exit', (code) => { + if (code !== 0) { + console.error('------ stdout ------'); + console.error(stdout); + console.error('------ stderr ------'); + console.error(stderr); + throw new Error(`Error during node startup, exit code ${code}`); + } + state.throughput++; + + if (state.go) { + start(state, code, bench, getNode); + } else { + bench.end(state.throughput); + } + }); +} + +function main({ dur, code }) { + const state = { + go: true, + throughput: 0 + }; + + setTimeout(() => { + state.go = false; + }, dur * 1000); + + bench.start(); + start(state, code, bench, spawnProcess); +} diff --git a/test/benchmark/test-benchmark-misc.js b/test/benchmark/test-benchmark-misc.js index b88415280833bc..13bd41e54016f5 100644 --- a/test/benchmark/test-benchmark-misc.js +++ b/test/benchmark/test-benchmark-misc.js @@ -10,6 +10,7 @@ runBenchmark('misc', [ 'method=', 'n=1', 'type=', + 'code=1', 'val=magyarország.icom.museum', 'script=test/fixtures/semicolon', 'mode=worker' From af29ae03449d5fc09c9bf4c6eb5804641a3cabb6 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Sun, 28 Apr 2019 16:39:49 +0800 Subject: [PATCH 004/106] test: add mustCall to net-connect-buffer test PR-URL: https://github.com/nodejs/node/pull/27446 Reviewed-By: Weijia Wang Reviewed-By: Gireesh Punathil Reviewed-By: Yongsheng Zhang Reviewed-By: Yorkie Liu Reviewed-By: Colin Ihrig --- test/parallel/test-net-connect-buffer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-net-connect-buffer.js b/test/parallel/test-net-connect-buffer.js index 81dd8f0c569c71..8c95400fb6a606 100644 --- a/test/parallel/test-net-connect-buffer.js +++ b/test/parallel/test-net-connect-buffer.js @@ -33,11 +33,11 @@ const tcp = net.Server(common.mustCall((s) => { buf += d; }); - s.on('end', function() { + s.on('end', common.mustCall(function() { console.error('SERVER: end', buf); assert.strictEqual(buf, "L'État, c'est moi"); s.end(); - }); + })); })); tcp.listen(0, common.mustCall(function() { From 7a35077197fc1b3bacbe057ffc6caaeb8199cd8a Mon Sep 17 00:00:00 2001 From: tonyhty Date: Sun, 28 Apr 2019 16:51:00 +0800 Subject: [PATCH 005/106] test: add mustCall to test-fs-readfile-pipe PR-URL: https://github.com/nodejs/node/pull/27450 Reviewed-By: Yorkie Liu Reviewed-By: Weijia Wang Reviewed-By: Gireesh Punathil Reviewed-By: Colin Ihrig --- test/parallel/test-fs-readfile-pipe.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-fs-readfile-pipe.js b/test/parallel/test-fs-readfile-pipe.js index 861ce20cfc798d..a21801e3890894 100644 --- a/test/parallel/test-fs-readfile-pipe.js +++ b/test/parallel/test-fs-readfile-pipe.js @@ -31,10 +31,10 @@ const assert = require('assert'); const fs = require('fs'); if (process.argv[2] === 'child') { - fs.readFile('/dev/stdin', function(er, data) { + fs.readFile('/dev/stdin', common.mustCall(function(er, data) { assert.ifError(er); process.stdout.write(data); - }); + })); return; } @@ -47,7 +47,7 @@ const exec = require('child_process').exec; const f = JSON.stringify(__filename); const node = JSON.stringify(process.execPath); const cmd = `cat ${filename} | ${node} ${f} child`; -exec(cmd, function(err, stdout, stderr) { +exec(cmd, common.mustCall(function(err, stdout, stderr) { assert.ifError(err); assert.strictEqual( stdout, @@ -58,4 +58,4 @@ exec(cmd, function(err, stdout, stderr) { '', `expected not to read anything from stderr but got: '${stderr}'`); console.log('ok'); -}); +})); From 6fd1384a4321c1acd817b65f0e3424f11913ca9a Mon Sep 17 00:00:00 2001 From: jyjunyz Date: Sun, 28 Apr 2019 16:58:20 +0800 Subject: [PATCH 006/106] test: add mustcall in test-dgram-connect-send-callback-buffer-length add mustcall() on client.bind callback PR-URL: https://github.com/nodejs/node/pull/27464 Reviewed-By: Weijia Wang Reviewed-By: Yorkie Liu Reviewed-By: Ouyang Yadong Reviewed-By: Gireesh Punathil Reviewed-By: Colin Ihrig --- .../test-dgram-connect-send-callback-buffer-length.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-dgram-connect-send-callback-buffer-length.js b/test/parallel/test-dgram-connect-send-callback-buffer-length.js index 3dc089e7386b5a..08c220682e79af 100644 --- a/test/parallel/test-dgram-connect-send-callback-buffer-length.js +++ b/test/parallel/test-dgram-connect-send-callback-buffer-length.js @@ -17,8 +17,8 @@ const messageSent = common.mustCall(function messageSent(err, bytes) { client.close(); }); -client.bind(0, () => { +client.bind(0, common.mustCall(() => { client.connect(client.address().port, common.mustCall(() => { client.send(buf, offset, len, messageSent); })); -}); +})); From d784ecb1ad2884ebdc345fcc1ed98cb97ad444c2 Mon Sep 17 00:00:00 2001 From: tongshouyu Date: Sun, 28 Apr 2019 16:50:27 +0800 Subject: [PATCH 007/106] test: add mustCall to test-net-eaddrinuse test PR-URL: https://github.com/nodejs/node/pull/27448 Reviewed-By: Yongsheng Zhang Reviewed-By: Weijia Wang Reviewed-By: Gireesh Punathil Reviewed-By: Colin Ihrig --- test/parallel/test-net-eaddrinuse.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-net-eaddrinuse.js b/test/parallel/test-net-eaddrinuse.js index 29508e4582852e..cfe004b6839e9b 100644 --- a/test/parallel/test-net-eaddrinuse.js +++ b/test/parallel/test-net-eaddrinuse.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const net = require('net'); @@ -28,10 +28,10 @@ const server1 = net.createServer(function(socket) { }); const server2 = net.createServer(function(socket) { }); -server1.listen(0, function() { +server1.listen(0, common.mustCall(function() { server2.on('error', function(error) { assert.strictEqual(error.message.includes('EADDRINUSE'), true); server1.close(); }); server2.listen(this.address().port); -}); +})); From e8d5b6226a047693f73a97680b93238a165f6bce Mon Sep 17 00:00:00 2001 From: "lixin.atom" Date: Sun, 28 Apr 2019 16:50:37 +0800 Subject: [PATCH 008/106] test: add "mustCall" for test-net-buffersize PR-URL: https://github.com/nodejs/node/pull/27451 Reviewed-By: Yongsheng Zhang Reviewed-By: Weijia Wang Reviewed-By: Gireesh Punathil Reviewed-By: Yorkie Liu Reviewed-By: Colin Ihrig Reviewed-By: Ouyang Yadong --- test/parallel/test-net-buffersize.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-net-buffersize.js b/test/parallel/test-net-buffersize.js index 1359a257440822..7225d70af318a0 100644 --- a/test/parallel/test-net-buffersize.js +++ b/test/parallel/test-net-buffersize.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const net = require('net'); @@ -36,12 +36,12 @@ const server = net.createServer(function(socket) { }); }); -server.listen(0, function() { +server.listen(0, common.mustCall(function() { const client = net.connect(this.address().port); - client.on('finish', function() { + client.on('finish', common.mustCall(() => { assert.strictEqual(client.bufferSize, 0); - }); + })); for (let i = 1; i < iter; i++) { client.write('a'); @@ -49,4 +49,4 @@ server.listen(0, function() { } client.end(); -}); +})); From 9fa5ba8b3c403dfebda62425fd43f18c6815f7b6 Mon Sep 17 00:00:00 2001 From: luoyu Date: Sun, 28 Apr 2019 16:56:57 +0800 Subject: [PATCH 009/106] test: add mustCall to test-fs-readfile-pipe-large PR-URL: https://github.com/nodejs/node/pull/27460 Reviewed-By: Weijia Wang Reviewed-By: Yorkie Liu Reviewed-By: Gireesh Punathil Reviewed-By: Colin Ihrig Reviewed-By: Ouyang Yadong --- test/parallel/test-fs-readfile-pipe-large.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-fs-readfile-pipe-large.js b/test/parallel/test-fs-readfile-pipe-large.js index b2b5192c789271..78c5feedb7210c 100644 --- a/test/parallel/test-fs-readfile-pipe-large.js +++ b/test/parallel/test-fs-readfile-pipe-large.js @@ -29,7 +29,7 @@ const exec = require('child_process').exec; const f = JSON.stringify(__filename); const node = JSON.stringify(process.execPath); const cmd = `cat ${filename} | ${node} ${f} child`; -exec(cmd, { maxBuffer: 1000000 }, function(err, stdout, stderr) { +exec(cmd, { maxBuffer: 1000000 }, common.mustCall((err, stdout, stderr) => { assert.ifError(err); assert.strictEqual( stdout, @@ -42,7 +42,7 @@ exec(cmd, { maxBuffer: 1000000 }, function(err, stdout, stderr) { `expect that it does not write to stderr, but got : ${stderr}` ); console.log('ok'); -}); +})); process.on('exit', function() { fs.unlinkSync(filename); From 7d80999454ba269078d74bac7086825e348dfc1b Mon Sep 17 00:00:00 2001 From: xinyulee Date: Sun, 28 Apr 2019 16:56:12 +0800 Subject: [PATCH 010/106] test: add mustCall to net-can-reset-timeout PR-URL: https://github.com/nodejs/node/pull/27462 Reviewed-By: Weijia Wang Reviewed-By: Yorkie Liu Reviewed-By: Gireesh Punathil Reviewed-By: Yongsheng Zhang Reviewed-By: Colin Ihrig --- test/parallel/test-net-can-reset-timeout.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-net-can-reset-timeout.js b/test/parallel/test-net-can-reset-timeout.js index 2fac07eab05e23..c72efb5f339c98 100644 --- a/test/parallel/test-net-can-reset-timeout.js +++ b/test/parallel/test-net-can-reset-timeout.js @@ -37,13 +37,13 @@ const server = net.createServer(common.mustCall(function(stream) { stream.write('WHAT.'); })); - stream.on('end', function() { + stream.on('end', common.mustCall(function() { console.log('server side end'); stream.end(); - }); + })); })); -server.listen(0, function() { +server.listen(0, common.mustCall(function() { const c = net.createConnection(this.address().port); c.on('data', function() { @@ -54,4 +54,4 @@ server.listen(0, function() { console.log('client side end'); server.close(); }); -}); +})); From 7c25dce7baaff8a37650f250a065fcbaa3f5c757 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 26 Apr 2019 19:28:16 +0800 Subject: [PATCH 011/106] deps: V8: cherry-pick 5d0cf6b MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: [snapshot] Use Handle to track name in `CodeSerializer::Deserialize` The `Script::InitLineEnds(Handle