Skip to content

Commit 7e366b4

Browse files
author
Eugene Ostroukhov
committed
Merge branch 'master' of github.com:nodejs/node into inspector-whitelist
2 parents 2c7aef7 + cca375f commit 7e366b4

26 files changed

+174
-70
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ module.exports = {
6666
line: {
6767
// Ignore all lines that have less characters than 20 and all lines that
6868
// start with something that looks like a variable name or code.
69-
ignorePattern: '.{0,20}$|[a-z]+ ?[0-9A-Z_.(/=:[#-]|std',
69+
// eslint-disable-next-line max-len
70+
ignorePattern: '.{0,20}$|[a-z]+ ?[0-9A-Z_.(/=:[#-]|std|http|ssh|ftp|(let|var|const) [a-z_A-Z0-9]+ =|[b-z] |[a-z]*[0-9].* ',
7071
ignoreInlineComments: true,
7172
ignoreConsecutiveComments: true,
7273
},

lib/child_process.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const {
3737
ERR_CHILD_PROCESS_IPC_REQUIRED,
3838
ERR_CHILD_PROCESS_STDIO_MAXBUFFER,
3939
ERR_INVALID_ARG_TYPE,
40-
ERR_INVALID_OPT_VALUE,
4140
ERR_OUT_OF_RANGE
4241
} = require('internal/errors').codes;
4342
const { clearTimeout, setTimeout } = require('timers');
@@ -46,24 +45,14 @@ const child_process = require('internal/child_process');
4645
const {
4746
getValidStdio,
4847
setupChannel,
49-
ChildProcess
48+
ChildProcess,
49+
stdioStringToArray
5050
} = child_process;
5151

5252
const MAX_BUFFER = 1024 * 1024;
5353

5454
exports.ChildProcess = ChildProcess;
5555

56-
function stdioStringToArray(option) {
57-
switch (option) {
58-
case 'ignore':
59-
case 'pipe':
60-
case 'inherit':
61-
return [option, option, option, 'ipc'];
62-
default:
63-
throw new ERR_INVALID_OPT_VALUE('stdio', option);
64-
}
65-
}
66-
6756
exports.fork = function fork(modulePath /* , args, options */) {
6857
validateString(modulePath, 'modulePath');
6958

@@ -104,12 +93,13 @@ exports.fork = function fork(modulePath /* , args, options */) {
10493
args = execArgv.concat([modulePath], args);
10594

10695
if (typeof options.stdio === 'string') {
107-
options.stdio = stdioStringToArray(options.stdio);
96+
options.stdio = stdioStringToArray(options.stdio, 'ipc');
10897
} else if (!Array.isArray(options.stdio)) {
10998
// Use a separate fd=3 for the IPC channel. Inherit stdin, stdout,
11099
// and stderr from the parent if silent isn't set.
111-
options.stdio = options.silent ? stdioStringToArray('pipe') :
112-
stdioStringToArray('inherit');
100+
options.stdio = stdioStringToArray(
101+
options.silent ? 'pipe' : 'inherit',
102+
'ipc');
113103
} else if (!options.stdio.includes('ipc')) {
114104
throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio');
115105
}

lib/internal/assert/assertion_error.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ class AssertionError extends Error {
298298
const {
299299
message,
300300
operator,
301-
stackStartFn
301+
stackStartFn,
302+
// Compatibility with older versions.
303+
stackStartFunction
302304
} = options;
303305
let {
304306
actual,
@@ -373,8 +375,7 @@ class AssertionError extends Error {
373375
let res = inspectValue(actual);
374376
let other = inspectValue(expected);
375377
const knownOperators = kReadableOperator[operator];
376-
if ((operator === 'notDeepEqual' || operator === 'notEqual') &&
377-
res === other) {
378+
if (operator === 'notDeepEqual' && res === other) {
378379
res = `${knownOperators}\n\n${res}`;
379380
if (res.length > 1024) {
380381
res = `${res.slice(0, 1021)}...`;
@@ -387,7 +388,7 @@ class AssertionError extends Error {
387388
if (other.length > 512) {
388389
other = `${other.slice(0, 509)}...`;
389390
}
390-
if (operator === 'deepEqual' || operator === 'equal') {
391+
if (operator === 'deepEqual') {
391392
const eq = operator === 'deepEqual' ? 'deep-equal' : 'equal';
392393
res = `${knownOperators}\n\n${res}\n\nshould loosely ${eq}\n\n`;
393394
} else {
@@ -418,7 +419,7 @@ class AssertionError extends Error {
418419
this.expected = expected;
419420
this.operator = operator;
420421
// eslint-disable-next-line no-restricted-syntax
421-
Error.captureStackTrace(this, stackStartFn);
422+
Error.captureStackTrace(this, stackStartFn || stackStartFunction);
422423
// Create error message including the error code in the name.
423424
this.stack;
424425
// Reset the name.

lib/internal/child_process.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,21 @@ const handleConversion = {
214214
}
215215
};
216216

217+
function stdioStringToArray(stdio, channel) {
218+
const options = [];
219+
220+
switch (stdio) {
221+
case 'ignore':
222+
case 'pipe': options.push(stdio, stdio, stdio); break;
223+
case 'inherit': options.push(0, 1, 2); break;
224+
default:
225+
throw new ERR_INVALID_OPT_VALUE('stdio', stdio);
226+
}
227+
228+
if (channel) options.push(channel);
229+
230+
return options;
231+
}
217232

218233
function ChildProcess() {
219234
EventEmitter.call(this);
@@ -892,13 +907,7 @@ function getValidStdio(stdio, sync) {
892907

893908
// Replace shortcut with an array
894909
if (typeof stdio === 'string') {
895-
switch (stdio) {
896-
case 'ignore': stdio = ['ignore', 'ignore', 'ignore']; break;
897-
case 'pipe': stdio = ['pipe', 'pipe', 'pipe']; break;
898-
case 'inherit': stdio = [0, 1, 2]; break;
899-
default:
900-
throw new ERR_INVALID_OPT_VALUE('stdio', stdio);
901-
}
910+
stdio = stdioStringToArray(stdio);
902911
} else if (!Array.isArray(stdio)) {
903912
throw new ERR_INVALID_OPT_VALUE('stdio', inspect(stdio));
904913
}
@@ -1042,5 +1051,6 @@ module.exports = {
10421051
ChildProcess,
10431052
setupChannel,
10441053
getValidStdio,
1054+
stdioStringToArray,
10451055
spawnSync
10461056
};

lib/internal/console/constructor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ Console.prototype[kWriteToConsole] = function(streamSymbol, string) {
231231
// handle both situations.
232232
try {
233233
// Add and later remove a noop error handler to catch synchronous errors.
234-
stream.once('error', noop);
234+
if (stream.listenerCount('error') === 0)
235+
stream.once('error', noop);
235236

236237
stream.write(string, errorHandler);
237238
} catch (e) {

lib/internal/process/execution.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,12 @@ function createFatalException() {
142142
if (exceptionHandlerState.captureFn !== null) {
143143
exceptionHandlerState.captureFn(er);
144144
} else if (!process.emit('uncaughtException', er, type)) {
145-
// If someone handled it, then great. otherwise, die in C++ land
145+
// If someone handled it, then great. Otherwise, die in C++ land
146146
// since that means that we'll exit the process, emit the 'exit' event.
147+
const { inspect } = require('internal/util/inspect');
148+
const colors = internalBinding('util').guessHandleType(2) === 'TTY' &&
149+
require('internal/tty').hasColors() ||
150+
inspect.defaultOptions.colors;
147151
try {
148152
if (!process._exiting) {
149153
process._exiting = true;
@@ -157,6 +161,7 @@ function createFatalException() {
157161
const { kExpandStackSymbol } = require('internal/util');
158162
if (typeof er[kExpandStackSymbol] === 'function')
159163
er[kExpandStackSymbol]();
164+
er.stack = inspect(er, { colors });
160165
} catch {
161166
// Nothing to be done about it at this point.
162167
}

lib/internal/util/inspect.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -727,12 +727,20 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
727727
braces = getIteratorBraces('Set', tag);
728728
formatter = formatIterator;
729729
// Handle other regular objects again.
730-
} else if (keys.length === 0) {
731-
if (isExternal(value))
732-
return ctx.stylize('[External]', 'special');
733-
return `${getPrefix(constructor, tag, 'Object')}{}`;
734730
} else {
735-
braces[0] = `${getPrefix(constructor, tag, 'Object')}{`;
731+
let fallback = '';
732+
if (constructor === null) {
733+
fallback = internalGetConstructorName(value);
734+
if (fallback === tag) {
735+
fallback = 'Object';
736+
}
737+
}
738+
if (keys.length === 0) {
739+
if (isExternal(value))
740+
return ctx.stylize('[External]', 'special');
741+
return `${getPrefix(constructor, tag, fallback)}{}`;
742+
}
743+
braces[0] = `${getPrefix(constructor, tag, fallback)}{`;
736744
}
737745
}
738746
}

test/message/assert_throws_stack.out

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,20 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
1515
at *
1616
at *
1717
at *
18-
at *
18+
at * {
19+
generatedMessage: true,
20+
code: 'ERR_ASSERTION',
21+
actual: Error: foo
22+
at assert.throws.bar (*assert_throws_stack.js:*)
23+
at getActual (assert.js:*)
24+
at Function.throws (assert.js:*)
25+
at Object.<anonymous> (*assert_throws_stack.js:*:*)
26+
at *
27+
at *
28+
at *
29+
at *
30+
at *
31+
at *,
32+
expected: [Object],
33+
operator: 'throws'
34+
}

test/message/error_exit.out

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
1313
at Module.load (internal/modules/cjs/loader.js:*:*)
1414
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
1515
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
16-
at internal/main/run_main_module.js:*:*
16+
at internal/main/run_main_module.js:*:* {
17+
generatedMessage: true,
18+
code: 'ERR_ASSERTION',
19+
actual: 1,
20+
expected: 2,
21+
operator: 'strictEqual'
22+
}

test/message/if-error-has-good-stack.out

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,20 @@ AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
1616
at Module.load (internal/modules/cjs/loader.js:*:*)
1717
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
1818
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
19-
at internal/main/run_main_module.js:*:*
19+
at internal/main/run_main_module.js:*:* {
20+
generatedMessage: false,
21+
code: 'ERR_ASSERTION',
22+
actual: Error: test error
23+
at c (*if-error-has-good-stack.js:*:*)
24+
at b (*if-error-has-good-stack.js:*:*)
25+
at a (*if-error-has-good-stack.js:*:*)
26+
at Object.<anonymous> (*if-error-has-good-stack.js:*:*)
27+
at Module._compile (internal/modules/cjs/loader.js:*:*)
28+
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
29+
at Module.load (internal/modules/cjs/loader.js:*:*)
30+
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
31+
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
32+
at internal/main/run_main_module.js:*:*
33+
expected: null,
34+
operator: 'ifError'
35+
}

test/message/stack_overflow.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ before
33
JSON.stringify(array);
44
^
55

6-
RangeError: Maximum call stack size exceeded
6+
[RangeError: Maximum call stack size exceeded]

test/message/throw_custom_error.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
*test*message*throw_custom_error.js:*
22
throw ({ name: 'MyCustomError', message: 'This is a custom message' });
33
^
4-
MyCustomError: This is a custom message
4+
{ name: 'MyCustomError', message: 'This is a custom message' }

test/message/throw_in_line_with_tabs.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ before
22
*test*message*throw_in_line_with_tabs.js:*
33
throw ({ foo: 'bar' });
44
^
5-
[object Object]
5+
{ foo: 'bar' }

test/message/throw_non_error.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
*test*message*throw_non_error.js:*
22
throw ({ foo: 'bar' });
33
^
4-
[object Object]
4+
{ foo: 'bar' }

test/parallel/test-assert.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,3 +1203,21 @@ assert.throws(
12031203
() => a.deepStrictEqual(),
12041204
{ code: 'ERR_MISSING_ARGS' }
12051205
);
1206+
1207+
// Verify that `stackStartFunction` works as alternative to `stackStartFn`.
1208+
{
1209+
(function hidden() {
1210+
const err = new assert.AssertionError({
1211+
actual: 'foo',
1212+
operator: 'strictEqual',
1213+
stackStartFunction: hidden
1214+
});
1215+
const err2 = new assert.AssertionError({
1216+
actual: 'foo',
1217+
operator: 'strictEqual',
1218+
stackStartFn: hidden
1219+
});
1220+
assert(!err.stack.includes('hidden'));
1221+
assert(!err2.stack.includes('hidden'));
1222+
})();
1223+
}

test/parallel/test-error-reporting.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ errExec('throws_error6.js', common.mustCall((err, stdout, stderr) => {
7777

7878
// Object that throws in toString() doesn't print garbage
7979
errExec('throws_error7.js', common.mustCall((err, stdout, stderr) => {
80-
assert.ok(/<toString\(\) threw exception/.test(stderr));
80+
assert.ok(/throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n$/.test(stderr));
8181
}));

test/parallel/test-util-inspect.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,10 @@ if (typeof Symbol !== 'undefined') {
11561156
util.inspect({ a: { b: new ArraySubclass([1, [2], 3]) } }, { depth: 1 }),
11571157
'{ a: { b: [ArraySubclass] } }'
11581158
);
1159+
assert.strictEqual(
1160+
util.inspect(Object.setPrototypeOf(x, null)),
1161+
'[ObjectSubclass: null prototype] { foo: 42 }'
1162+
);
11591163
}
11601164

11611165
// Empty and circular before depth.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
const common = require('../common');
3+
const { Worker, isMainThread } = require('worker_threads');
4+
const EventEmitter = require('events');
5+
6+
if (isMainThread) {
7+
process.on('warning', common.mustNotCall('unexpected warning'));
8+
9+
for (let i = 0; i < EventEmitter.defaultMaxListeners; ++i) {
10+
const worker = new Worker(__filename);
11+
12+
worker.on('exit', common.mustCall(() => {
13+
console.log('a'); // This console.log() is part of the test.
14+
}));
15+
}
16+
}

test/pseudo-tty/test-fatal-error.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
require('../common');
3+
4+
const { inspect } = require('util');
5+
6+
inspect.defaultOptions.colors = true;
7+
8+
const err = new TypeError('foobar');
9+
err.bla = true;
10+
throw err;

test/pseudo-tty/test-fatal-error.out

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*test-fatal-error.js:*
2+
throw err;
3+
^
4+
5+
TypeError: foobar
6+
at Object.<anonymous> (*test-fatal-error.js:*)
7+
*[90m at *(internal*loader.js:*:*)*[39m
8+
*[90m at *(internal*loader.js:*:*)*[39m
9+
*[90m at *(internal*loader.js:*:*)*[39m
10+
*[90m at *(internal*loader.js:*:*)*[39m
11+
*[90m at *[39m
12+
*[90m at *[39m {
13+
bla: *[33mtrue*[39m
14+
}

tools/eslint-rules/no-duplicate-requires.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
'use strict';
66

7+
const { isRequireCall } = require('./rules-utils.js');
8+
79
//------------------------------------------------------------------------------
810
// Rule Definition
911
//------------------------------------------------------------------------------
@@ -13,10 +15,6 @@ function isString(node) {
1315
return node && node.type === 'Literal' && typeof node.value === 'string';
1416
}
1517

16-
function isRequireCall(node) {
17-
return node.callee.type === 'Identifier' && node.callee.name === 'require';
18-
}
19-
2018
function isTopLevel(node) {
2119
do {
2220
if (node.type === 'FunctionDeclaration' ||

0 commit comments

Comments
 (0)