| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3af9382 commit 1d6c17e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,9 +67,9 @@ exports.puts = util.deprecate(() => { | |||
| 67 | 67 | ||
| 68 | 68 | It returns a modified function which warns once by default. | |
| 69 | 69 | ||
| 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. | ||
| 73 | 73 | ||
| 74 | 74 | If `--trace-deprecation` is set, a warning and a stack trace are logged | |
| 75 | 75 | to the console the first time the deprecated API is used. Configurable | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,6 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const binding = process.binding('util'); | |
| 4 | 4 | const prefix = `(${process.release.name}:${process.pid}) `; | |
| 5 | - const noDeprecation = process.noDeprecation; | ||
| 6 | 5 | ||
| 7 | 6 | exports.getHiddenValue = binding.getHiddenValue; | |
| 8 | 7 | exports.setHiddenValue = binding.setHiddenValue; | |
@@ -16,7 +15,7 @@ exports.deprecate = function(fn, msg) { | |||
| 16 | 15 | // All the internal deprecations have to use this function only, as this will | |
| 17 | 16 | // prepend the prefix to the actual message. | |
| 18 | 17 | exports.printDeprecationMessage = function(msg, warned, ctor) { | |
| 19 | - if (warned || noDeprecation) | ||
| 18 | + if (warned || process.noDeprecation) | ||
| 20 | 19 | return true; | |
| 21 | 20 | process.emitWarning(msg, 'DeprecationWarning', | |
| 22 | 21 | ctor || exports.printDeprecationMessage); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 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 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments