| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2d64947 commit 4807499
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -124,20 +124,23 @@ process.setUncaughtExceptionCaptureCallback = function(fn) { | |||
| 124 | 124 | ||
| 125 | 125 | ||
| 126 | 126 | let sendMakeCallbackDeprecation = false; | |
| 127 | - function emitMakeCallbackDeprecation() { | ||
| 127 | + function emitMakeCallbackDeprecation({ target, method }) { | ||
| 128 | 128 | if (!sendMakeCallbackDeprecation) { | |
| 129 | 129 | process.emitWarning( | |
| 130 | 130 | 'Using a domain property in MakeCallback is deprecated. Use the ' + | |
| 131 | 131 | 'async_context variant of MakeCallback or the AsyncResource class ' + | |
| 132 | - 'instead.', 'DeprecationWarning', 'DEP0097'); | ||
| 132 | + 'instead. ' + | ||
| 133 | + `(Triggered by calling ${method?.name ?? '<anonymous>'} ` + | ||
| 134 | + `on ${target?.constructor?.name}.)`, | ||
| 135 | + 'DeprecationWarning', 'DEP0097'); | ||
| 133 | 136 | sendMakeCallbackDeprecation = true; | |
| 134 | 137 | } | |
| 135 | 138 | } | |
| 136 | 139 | ||
| 137 | 140 | function topLevelDomainCallback(cb, ...args) { | |
| 138 | 141 | const domain = this.domain; | |
| 139 | 142 | if (exports.active && domain) | |
| 140 | - emitMakeCallbackDeprecation(); | ||
| 143 | + emitMakeCallbackDeprecation({ target: this, method: cb }); | ||
| 141 | 144 | ||
| 142 | 145 | if (domain) | |
| 143 | 146 | domain.enter(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ const domain = require('domain'); | |||
| 6 | 6 | const binding = require(`./build/${common.buildType}/binding`); | |
| 7 | 7 | ||
| 8 | 8 | function makeCallback(object, cb) { | |
| 9 | - binding.makeCallback(object, () => setImmediate(cb)); | ||
| 9 | + binding.makeCallback(object, function someMethod() { setImmediate(cb); }); | ||
| 10 | 10 | } | |
| 11 | 11 | ||
| 12 | 12 | let latestWarning = null; | |
@@ -16,8 +16,14 @@ process.on('warning', (warning) => { | |||
| 16 | 16 | ||
| 17 | 17 | const d = domain.create(); | |
| 18 | 18 | ||
| 19 | + class Resource { | ||
| 20 | + constructor(domain) { | ||
| 21 | + this.domain = domain; | ||
| 22 | + } | ||
| 23 | + } | ||
| 24 | + | ||
| 19 | 25 | // When domain is disabled, no warning will be emitted | |
| 20 | - makeCallback({ domain: d }, common.mustCall(() => { | ||
| 26 | + makeCallback(new Resource(d), common.mustCall(() => { | ||
| 21 | 27 | assert.strictEqual(latestWarning, null); | |
| 22 | 28 | ||
| 23 | 29 | d.run(common.mustCall(() => { | |
@@ -26,7 +32,9 @@ makeCallback({ domain: d }, common.mustCall(() => { | |||
| 26 | 32 | assert.strictEqual(latestWarning, null); | |
| 27 | 33 | ||
| 28 | 34 | // Warning is emitted when domain property is used and domain is enabled | |
| 29 | - makeCallback({ domain: d }, common.mustCall(() => { | ||
| 35 | + makeCallback(new Resource(d), common.mustCall(() => { | ||
| 36 | + assert.match(latestWarning.message, | ||
| 37 | + /Triggered by calling someMethod on Resource\./); | ||
| 30 | 38 | assert.strictEqual(latestWarning.name, 'DeprecationWarning'); | |
| 31 | 39 | assert.strictEqual(latestWarning.code, 'DEP0097'); | |
| 32 | 40 | })); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments