Skip to content
/ node Public
forked from nodejs/node

Commit

Permalink
Merge branch 'master' of github.com:nodejs/node into inspector-whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Ostroukhov committed May 16, 2019
2 parents 2c7aef7 + cca375f commit 7e366b4
Show file tree
Hide file tree
Showing 26 changed files with 174 additions and 70 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ module.exports = {
line: {
// Ignore all lines that have less characters than 20 and all lines that
// start with something that looks like a variable name or code.
ignorePattern: '.{0,20}$|[a-z]+ ?[0-9A-Z_.(/=:[#-]|std',
// eslint-disable-next-line max-len
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].* ',
ignoreInlineComments: true,
ignoreConsecutiveComments: true,
},
Expand Down
22 changes: 6 additions & 16 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const {
ERR_CHILD_PROCESS_IPC_REQUIRED,
ERR_CHILD_PROCESS_STDIO_MAXBUFFER,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_OPT_VALUE,
ERR_OUT_OF_RANGE
} = require('internal/errors').codes;
const { clearTimeout, setTimeout } = require('timers');
Expand All @@ -46,24 +45,14 @@ const child_process = require('internal/child_process');
const {
getValidStdio,
setupChannel,
ChildProcess
ChildProcess,
stdioStringToArray
} = child_process;

const MAX_BUFFER = 1024 * 1024;

exports.ChildProcess = ChildProcess;

function stdioStringToArray(option) {
switch (option) {
case 'ignore':
case 'pipe':
case 'inherit':
return [option, option, option, 'ipc'];
default:
throw new ERR_INVALID_OPT_VALUE('stdio', option);
}
}

exports.fork = function fork(modulePath /* , args, options */) {
validateString(modulePath, 'modulePath');

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

if (typeof options.stdio === 'string') {
options.stdio = stdioStringToArray(options.stdio);
options.stdio = stdioStringToArray(options.stdio, 'ipc');
} else if (!Array.isArray(options.stdio)) {
// Use a separate fd=3 for the IPC channel. Inherit stdin, stdout,
// and stderr from the parent if silent isn't set.
options.stdio = options.silent ? stdioStringToArray('pipe') :
stdioStringToArray('inherit');
options.stdio = stdioStringToArray(
options.silent ? 'pipe' : 'inherit',
'ipc');
} else if (!options.stdio.includes('ipc')) {
throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio');
}
Expand Down
11 changes: 6 additions & 5 deletions lib/internal/assert/assertion_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ class AssertionError extends Error {
const {
message,
operator,
stackStartFn
stackStartFn,
// Compatibility with older versions.
stackStartFunction
} = options;
let {
actual,
Expand Down Expand Up @@ -373,8 +375,7 @@ class AssertionError extends Error {
let res = inspectValue(actual);
let other = inspectValue(expected);
const knownOperators = kReadableOperator[operator];
if ((operator === 'notDeepEqual' || operator === 'notEqual') &&
res === other) {
if (operator === 'notDeepEqual' && res === other) {
res = `${knownOperators}\n\n${res}`;
if (res.length > 1024) {
res = `${res.slice(0, 1021)}...`;
Expand All @@ -387,7 +388,7 @@ class AssertionError extends Error {
if (other.length > 512) {
other = `${other.slice(0, 509)}...`;
}
if (operator === 'deepEqual' || operator === 'equal') {
if (operator === 'deepEqual') {
const eq = operator === 'deepEqual' ? 'deep-equal' : 'equal';
res = `${knownOperators}\n\n${res}\n\nshould loosely ${eq}\n\n`;
} else {
Expand Down Expand Up @@ -418,7 +419,7 @@ class AssertionError extends Error {
this.expected = expected;
this.operator = operator;
// eslint-disable-next-line no-restricted-syntax
Error.captureStackTrace(this, stackStartFn);
Error.captureStackTrace(this, stackStartFn || stackStartFunction);
// Create error message including the error code in the name.
this.stack;
// Reset the name.
Expand Down
24 changes: 17 additions & 7 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,21 @@ const handleConversion = {
}
};

function stdioStringToArray(stdio, channel) {
const options = [];

switch (stdio) {
case 'ignore':
case 'pipe': options.push(stdio, stdio, stdio); break;
case 'inherit': options.push(0, 1, 2); break;
default:
throw new ERR_INVALID_OPT_VALUE('stdio', stdio);
}

if (channel) options.push(channel);

return options;
}

function ChildProcess() {
EventEmitter.call(this);
Expand Down Expand Up @@ -892,13 +907,7 @@ function getValidStdio(stdio, sync) {

// Replace shortcut with an array
if (typeof stdio === 'string') {
switch (stdio) {
case 'ignore': stdio = ['ignore', 'ignore', 'ignore']; break;
case 'pipe': stdio = ['pipe', 'pipe', 'pipe']; break;
case 'inherit': stdio = [0, 1, 2]; break;
default:
throw new ERR_INVALID_OPT_VALUE('stdio', stdio);
}
stdio = stdioStringToArray(stdio);
} else if (!Array.isArray(stdio)) {
throw new ERR_INVALID_OPT_VALUE('stdio', inspect(stdio));
}
Expand Down Expand Up @@ -1042,5 +1051,6 @@ module.exports = {
ChildProcess,
setupChannel,
getValidStdio,
stdioStringToArray,
spawnSync
};
3 changes: 2 additions & 1 deletion lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ Console.prototype[kWriteToConsole] = function(streamSymbol, string) {
// handle both situations.
try {
// Add and later remove a noop error handler to catch synchronous errors.
stream.once('error', noop);
if (stream.listenerCount('error') === 0)
stream.once('error', noop);

stream.write(string, errorHandler);
} catch (e) {
Expand Down
7 changes: 6 additions & 1 deletion lib/internal/process/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,12 @@ function createFatalException() {
if (exceptionHandlerState.captureFn !== null) {
exceptionHandlerState.captureFn(er);
} else if (!process.emit('uncaughtException', er, type)) {
// If someone handled it, then great. otherwise, die in C++ land
// If someone handled it, then great. Otherwise, die in C++ land
// since that means that we'll exit the process, emit the 'exit' event.
const { inspect } = require('internal/util/inspect');
const colors = internalBinding('util').guessHandleType(2) === 'TTY' &&
require('internal/tty').hasColors() ||
inspect.defaultOptions.colors;
try {
if (!process._exiting) {
process._exiting = true;
Expand All @@ -157,6 +161,7 @@ function createFatalException() {
const { kExpandStackSymbol } = require('internal/util');
if (typeof er[kExpandStackSymbol] === 'function')
er[kExpandStackSymbol]();
er.stack = inspect(er, { colors });
} catch {
// Nothing to be done about it at this point.
}
Expand Down
18 changes: 13 additions & 5 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,12 +727,20 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
braces = getIteratorBraces('Set', tag);
formatter = formatIterator;
// Handle other regular objects again.
} else if (keys.length === 0) {
if (isExternal(value))
return ctx.stylize('[External]', 'special');
return `${getPrefix(constructor, tag, 'Object')}{}`;
} else {
braces[0] = `${getPrefix(constructor, tag, 'Object')}{`;
let fallback = '';
if (constructor === null) {
fallback = internalGetConstructorName(value);
if (fallback === tag) {
fallback = 'Object';
}
}
if (keys.length === 0) {
if (isExternal(value))
return ctx.stylize('[External]', 'special');
return `${getPrefix(constructor, tag, fallback)}{}`;
}
braces[0] = `${getPrefix(constructor, tag, fallback)}{`;
}
}
}
Expand Down
18 changes: 17 additions & 1 deletion test/message/assert_throws_stack.out
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,20 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
at *
at *
at *
at *
at * {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: Error: foo
at assert.throws.bar (*assert_throws_stack.js:*)
at getActual (assert.js:*)
at Function.throws (assert.js:*)
at Object.<anonymous> (*assert_throws_stack.js:*:*)
at *
at *
at *
at *
at *
at *,
expected: [Object],
operator: 'throws'
}
8 changes: 7 additions & 1 deletion test/message/error_exit.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
at Module.load (internal/modules/cjs/loader.js:*:*)
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
at internal/main/run_main_module.js:*:*
at internal/main/run_main_module.js:*:* {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: 1,
expected: 2,
operator: 'strictEqual'
}
18 changes: 17 additions & 1 deletion test/message/if-error-has-good-stack.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,20 @@ AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
at Module.load (internal/modules/cjs/loader.js:*:*)
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
at internal/main/run_main_module.js:*:*
at internal/main/run_main_module.js:*:* {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: Error: test error
at c (*if-error-has-good-stack.js:*:*)
at b (*if-error-has-good-stack.js:*:*)
at a (*if-error-has-good-stack.js:*:*)
at Object.<anonymous> (*if-error-has-good-stack.js:*:*)
at Module._compile (internal/modules/cjs/loader.js:*:*)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:*:*)
at Module.load (internal/modules/cjs/loader.js:*:*)
at Function.Module._load (internal/modules/cjs/loader.js:*:*)
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
at internal/main/run_main_module.js:*:*
expected: null,
operator: 'ifError'
}
2 changes: 1 addition & 1 deletion test/message/stack_overflow.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ before
JSON.stringify(array);
^

RangeError: Maximum call stack size exceeded
[RangeError: Maximum call stack size exceeded]
2 changes: 1 addition & 1 deletion test/message/throw_custom_error.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*test*message*throw_custom_error.js:*
throw ({ name: 'MyCustomError', message: 'This is a custom message' });
^
MyCustomError: This is a custom message
{ name: 'MyCustomError', message: 'This is a custom message' }
2 changes: 1 addition & 1 deletion test/message/throw_in_line_with_tabs.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ before
*test*message*throw_in_line_with_tabs.js:*
throw ({ foo: 'bar' });
^
[object Object]
{ foo: 'bar' }
2 changes: 1 addition & 1 deletion test/message/throw_non_error.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*test*message*throw_non_error.js:*
throw ({ foo: 'bar' });
^
[object Object]
{ foo: 'bar' }
18 changes: 18 additions & 0 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1203,3 +1203,21 @@ assert.throws(
() => a.deepStrictEqual(),
{ code: 'ERR_MISSING_ARGS' }
);

// Verify that `stackStartFunction` works as alternative to `stackStartFn`.
{
(function hidden() {
const err = new assert.AssertionError({
actual: 'foo',
operator: 'strictEqual',
stackStartFunction: hidden
});
const err2 = new assert.AssertionError({
actual: 'foo',
operator: 'strictEqual',
stackStartFn: hidden
});
assert(!err.stack.includes('hidden'));
assert(!err2.stack.includes('hidden'));
})();
}
2 changes: 1 addition & 1 deletion test/parallel/test-error-reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ errExec('throws_error6.js', common.mustCall((err, stdout, stderr) => {

// Object that throws in toString() doesn't print garbage
errExec('throws_error7.js', common.mustCall((err, stdout, stderr) => {
assert.ok(/<toString\(\) threw exception/.test(stderr));
assert.ok(/throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n$/.test(stderr));
}));
4 changes: 4 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,10 @@ if (typeof Symbol !== 'undefined') {
util.inspect({ a: { b: new ArraySubclass([1, [2], 3]) } }, { depth: 1 }),
'{ a: { b: [ArraySubclass] } }'
);
assert.strictEqual(
util.inspect(Object.setPrototypeOf(x, null)),
'[ObjectSubclass: null prototype] { foo: 42 }'
);
}

// Empty and circular before depth.
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-worker-console-listeners.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
const common = require('../common');
const { Worker, isMainThread } = require('worker_threads');
const EventEmitter = require('events');

if (isMainThread) {
process.on('warning', common.mustNotCall('unexpected warning'));

for (let i = 0; i < EventEmitter.defaultMaxListeners; ++i) {
const worker = new Worker(__filename);

worker.on('exit', common.mustCall(() => {
console.log('a'); // This console.log() is part of the test.
}));
}
}
10 changes: 10 additions & 0 deletions test/pseudo-tty/test-fatal-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
require('../common');

const { inspect } = require('util');

inspect.defaultOptions.colors = true;

const err = new TypeError('foobar');
err.bla = true;
throw err;
14 changes: 14 additions & 0 deletions test/pseudo-tty/test-fatal-error.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*test-fatal-error.js:*
throw err;
^

TypeError: foobar
at Object.<anonymous> (*test-fatal-error.js:*)
*[90m at *(internal*loader.js:*:*)*[39m
*[90m at *(internal*loader.js:*:*)*[39m
*[90m at *(internal*loader.js:*:*)*[39m
*[90m at *(internal*loader.js:*:*)*[39m
*[90m at *[39m
*[90m at *[39m {
bla: *[33mtrue*[39m
}
6 changes: 2 additions & 4 deletions tools/eslint-rules/no-duplicate-requires.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
'use strict';

const { isRequireCall } = require('./rules-utils.js');

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
Expand All @@ -13,10 +15,6 @@ function isString(node) {
return node && node.type === 'Literal' && typeof node.value === 'string';
}

function isRequireCall(node) {
return node.callee.type === 'Identifier' && node.callee.name === 'require';
}

function isTopLevel(node) {
do {
if (node.type === 'FunctionDeclaration' ||
Expand Down
Loading

0 comments on commit 7e366b4

Please sign in to comment.