File tree Expand file tree Collapse file tree 3 files changed +37
-5
lines changed
Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -67,9 +67,9 @@ exports.puts = util.deprecate(() => {
6767
6868It returns a modified function which warns once by default.
6969
70- If ` --no-deprecation ` is set then this function is a NO-OP. Configurable
71- at run-time through the ` process.noDeprecation ` boolean (only effective
72- when set before a module is loaded.)
70+ This function does nothing if either the ` --no-deprecation ` command
71+ line flag is used, or the ` process.noDeprecation ` property is set to
72+ ` true ` * prior * to the first deprecation warning.
7373
7474If ` --trace-deprecation ` is set, a warning and a stack trace are logged
7575to the console the first time the deprecated API is used. Configurable
Original file line number Diff line number Diff line change 22
33const binding = process . binding ( 'util' ) ;
44const prefix = `(${ process . release . name } :${ process . pid } ) ` ;
5- const noDeprecation = process . noDeprecation ;
65
76exports . getHiddenValue = binding . getHiddenValue ;
87exports . setHiddenValue = binding . setHiddenValue ;
@@ -16,7 +15,7 @@ exports.deprecate = function(fn, msg) {
1615// All the internal deprecations have to use this function only, as this will
1716// prepend the prefix to the actual message.
1817exports . printDeprecationMessage = function ( msg , warned , ctor ) {
19- if ( warned || noDeprecation )
18+ if ( warned || process . noDeprecation )
2019 return true ;
2120 process . emitWarning ( msg , 'DeprecationWarning' ,
2221 ctor || exports . printDeprecationMessage ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ // Flags: --expose_internals --no-warnings
3+
4+ // The --no-warnings flag only supresses writing the warning to stderr, not the
5+ // emission of the corresponding event. This test file can be run without it.
6+
7+ process . noDeprecation = true ;
8+
9+ const common = require ( '../common' ) ;
10+ const assert = require ( 'assert' ) ;
11+
12+ function listener ( ) {
13+ common . fail ( 'received unexpected warning' ) ;
14+ }
15+
16+ process . addListener ( 'warning' , listener ) ;
17+
18+ const internalUtil = require ( 'internal/util' ) ;
19+ internalUtil . printDeprecationMessage ( 'Something is deprecated.' ) ;
20+
21+ // The warning would be emitted in the next tick, so continue after that.
22+ process . nextTick ( common . mustCall ( ( ) => {
23+ // Check that deprecations can be re-enabled.
24+ process . noDeprecation = false ;
25+ process . removeListener ( 'warning' , listener ) ;
26+
27+ process . addListener ( 'warning' , common . mustCall ( ( warning ) => {
28+ assert . strictEqual ( warning . name , 'DeprecationWarning' ) ;
29+ assert . strictEqual ( warning . message , 'Something else is deprecated.' ) ;
30+ } ) ) ;
31+
32+ internalUtil . printDeprecationMessage ( 'Something else is deprecated.' ) ;
33+ } ) ) ;
You can’t perform that action at this time.
0 commit comments