diff options
author | Rich Trott <rtrott@gmail.com> | 2017-10-22 12:26:32 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2017-11-16 22:00:24 -0800 |
commit | 07d39a2262dac233b5f86b06ecc16484ab0f7858 (patch) | |
tree | 14c1c29089ebb87a792c114c42d7f12f2d0ec187 /lib/internal/util.js | |
parent | ccc87ebb3393a7a4738ed20d9378857633e74c76 (diff) | |
download | android-node-v8-07d39a2262dac233b5f86b06ecc16484ab0f7858.tar.gz android-node-v8-07d39a2262dac233b5f86b06ecc16484ab0f7858.tar.bz2 android-node-v8-07d39a2262dac233b5f86b06ecc16484ab0f7858.zip |
util: emit deprecation code only once
If another function has already emitted the deprecation warning with the
same code as the warning that is about to be emitted, do not emit the
warning.
This is a breaking change. Previously, different functions could emit
the same deprecation warning multiple times. This was a known bug rather
than a feature, but this change is being treated as a breaking change
out of caution. Identical deprecation warnings should not be emitted.
PR-URL: https://github.com/nodejs/node/pull/16393
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'lib/internal/util.js')
-rw-r--r-- | lib/internal/util.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/internal/util.js b/lib/internal/util.js index 138c811a54..c0050c930b 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -23,6 +23,10 @@ function objectToString(o) { return Object.prototype.toString.call(o); } +// Keep a list of deprecation codes that have been warned on so we only warn on +// each one once. +const codesWarned = {}; + // Mark that a method should not be used. // Returns a modified function which warns once by default. // If --no-deprecation is set, then it is a no-op. @@ -46,7 +50,10 @@ function deprecate(fn, msg, code) { if (!warned) { warned = true; if (code !== undefined) { - process.emitWarning(msg, 'DeprecationWarning', code, deprecated); + if (!codesWarned[code]) { + process.emitWarning(msg, 'DeprecationWarning', code, deprecated); + codesWarned[code] = true; + } } else { process.emitWarning(msg, 'DeprecationWarning', deprecated); } |