From 9dca43e7093525d07db32ef6995f4e498da96006 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 28 Feb 2021 14:33:11 -0500 Subject: [PATCH] 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 4a018c52f84..4e6cfcebc3a 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 00000000000..e877a4c47cc --- /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(); +});