process: fix handling of process.noDeprecation in emitWarning

PR-URL: https://github.com/nodejs/node/pull/8166
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
This commit is contained in:
James M Snell 2016-08-18 14:00:59 -07:00
parent 2d2a2d7c78
commit bf91035364

View File

@ -1,9 +1,5 @@
'use strict'; 'use strict';
const traceWarnings = process.traceProcessWarnings;
const noDeprecation = process.noDeprecation;
const traceDeprecation = process.traceDeprecation;
const throwDeprecation = process.throwDeprecation;
const prefix = `(${process.release.name}:${process.pid}) `; const prefix = `(${process.release.name}:${process.pid}) `;
exports.setup = setupProcessWarnings; exports.setup = setupProcessWarnings;
@ -13,8 +9,9 @@ function setupProcessWarnings() {
process.on('warning', (warning) => { process.on('warning', (warning) => {
if (!(warning instanceof Error)) return; if (!(warning instanceof Error)) return;
const isDeprecation = warning.name === 'DeprecationWarning'; const isDeprecation = warning.name === 'DeprecationWarning';
if (isDeprecation && noDeprecation) return; if (isDeprecation && process.noDeprecation) return;
const trace = traceWarnings || (isDeprecation && traceDeprecation); const trace = process.traceProcessWarnings ||
(isDeprecation && process.traceDeprecation);
if (trace && warning.stack) { if (trace && warning.stack) {
console.error(`${prefix}${warning.stack}`); console.error(`${prefix}${warning.stack}`);
} else { } else {
@ -41,9 +38,12 @@ function setupProcessWarnings() {
if (!(warning instanceof Error)) { if (!(warning instanceof Error)) {
throw new TypeError('\'warning\' must be an Error object or string.'); throw new TypeError('\'warning\' must be an Error object or string.');
} }
if (throwDeprecation && warning.name === 'DeprecationWarning') if (warning.name === 'DeprecationWarning') {
if (process.noDeprecation)
return;
if (process.throwDeprecation)
throw warning; throw warning;
else }
process.nextTick(() => process.emit('warning', warning)); process.nextTick(() => process.emit('warning', warning));
}; };
} }