Skip to content

Commit

Permalink
domain: show falsy names as anonymous for DEP0097
Browse files Browse the repository at this point in the history
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: #37550
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig authored and danielleadams committed Mar 16, 2021
1 parent 25a5f0b commit 1c09776
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '<anonymous>'} ` +
`(Triggered by calling ${method?.name || '<anonymous>'} ` +
`on ${target?.constructor?.name}.)`,
'DeprecationWarning', 'DEP0097');
sendMakeCallbackDeprecation = true;
Expand Down
17 changes: 17 additions & 0 deletions test/parallel/test-domain-dep0097.js
Original file line number Diff line number Diff line change
@@ -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 <anonymous> on process/);
}));

domain.create().run(() => {
inspector.open();
});

0 comments on commit 1c09776

Please sign in to comment.