From 9dca43e7093525d07db32ef6995f4e498da96006 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 28 Feb 2021 14:33:11 -0500 Subject: [PATCH 1/2] domain: show falsy names as anonymous for DEP0097 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Many anonymous functions use the empty string as their name. Since the DEP0097 logic was using nullish coalescing, these functions were not being displayed as anonymous. This commit updates the logic to use || instead of ??. PR-URL: https://github.com/nodejs/node/pull/37550 Reviewed-By: Anna Henningsen Reviewed-By: Antoine du Hamel Reviewed-By: Rich Trott Reviewed-By: Gerhard Stöbich Reviewed-By: James M Snell --- lib/domain.js | 2 +- test/parallel/test-domain-dep0097.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-domain-dep0097.js diff --git a/lib/domain.js b/lib/domain.js index 4a018c52f845f0..4e6cfcebc3aa51 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -130,7 +130,7 @@ function emitMakeCallbackDeprecation({ target, method }) { 'Using a domain property in MakeCallback is deprecated. Use the ' + 'async_context variant of MakeCallback or the AsyncResource class ' + 'instead. ' + - `(Triggered by calling ${method?.name ?? ''} ` + + `(Triggered by calling ${method?.name || ''} ` + `on ${target?.constructor?.name}.)`, 'DeprecationWarning', 'DEP0097'); sendMakeCallbackDeprecation = true; diff --git a/test/parallel/test-domain-dep0097.js b/test/parallel/test-domain-dep0097.js new file mode 100644 index 00000000000000..e877a4c47cc959 --- /dev/null +++ b/test/parallel/test-domain-dep0097.js @@ -0,0 +1,17 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const assert = require('assert'); +const domain = require('domain'); +const inspector = require('inspector'); + +process.on('warning', common.mustCall((warning) => { + assert.strictEqual(warning.code, 'DEP0097'); + assert.match(warning.message, /Triggered by calling on process/); +})); + +domain.create().run(() => { + inspector.open(); +}); From 152de34fb1fbf3803cee8d7dac2c37ad5061e331 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 28 Feb 2021 14:38:16 -0500 Subject: [PATCH 2/2] domain: add name to monkey-patched emit function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The domain module monkey patches EventEmitter.prototype.emit(), however the function's name was becoming the empty string. This commit forces the new emit function to have the proper name. PR-URL: https://github.com/nodejs/node/pull/37550 Reviewed-By: Anna Henningsen Reviewed-By: Antoine du Hamel Reviewed-By: Rich Trott Reviewed-By: Gerhard Stöbich Reviewed-By: James M Snell --- lib/domain.js | 2 +- test/parallel/test-domain-dep0097.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/domain.js b/lib/domain.js index 4e6cfcebc3aa51..acd5dc8221df31 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -456,7 +456,7 @@ EventEmitter.init = function() { }; const eventEmit = EventEmitter.prototype.emit; -EventEmitter.prototype.emit = function(...args) { +EventEmitter.prototype.emit = function emit(...args) { const domain = this.domain; const type = args[0]; diff --git a/test/parallel/test-domain-dep0097.js b/test/parallel/test-domain-dep0097.js index e877a4c47cc959..05b5c74b30d98e 100644 --- a/test/parallel/test-domain-dep0097.js +++ b/test/parallel/test-domain-dep0097.js @@ -9,7 +9,7 @@ const inspector = require('inspector'); process.on('warning', common.mustCall((warning) => { assert.strictEqual(warning.code, 'DEP0097'); - assert.match(warning.message, /Triggered by calling on process/); + assert.match(warning.message, /Triggered by calling emit on process/); })); domain.create().run(() => {