From 62624aee43c30f03bc7f63e9d29223334675e89f Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 18 Aug 2016 14:00:59 -0700 Subject: [PATCH] process: fix handling of process.noDeprecation in emitWarning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cherry-picked from: PR-URL: https://github.com/nodejs/node/pull/8166 Reviewed-By: Сковорода Никита Андреевич Reviewed-By: Myles Borins --- lib/internal/process/warning.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 4087eb0d2847e7..74a74aa916dd91 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -1,9 +1,5 @@ '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}) `; exports.setup = setupProcessWarnings; @@ -13,8 +9,9 @@ function setupProcessWarnings() { process.on('warning', (warning) => { if (!(warning instanceof Error)) return; const isDeprecation = warning.name === 'DeprecationWarning'; - if (isDeprecation && noDeprecation) return; - const trace = traceWarnings || (isDeprecation && traceDeprecation); + if (isDeprecation && process.noDeprecation) return; + const trace = process.traceProcessWarnings || + (isDeprecation && process.traceDeprecation); if (trace && warning.stack) { console.error(`${prefix}${warning.stack}`); } else { @@ -41,9 +38,12 @@ function setupProcessWarnings() { if (!(warning instanceof Error)) { throw new TypeError('\'warning\' must be an Error object or string.'); } - if (throwDeprecation && warning.name === 'DeprecationWarning') - throw warning; - else - process.nextTick(() => process.emit('warning', warning)); + if (warning.name === 'DeprecationWarning') { + if (process.noDeprecation) + return; + if (process.throwDeprecation) + throw warning; + } + process.nextTick(() => process.emit('warning', warning)); }; }