Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f2fbcc5

Browse filesBrowse files
BridgeARaduh95
authored andcommitted
util: fix debuglog.enabled not being present with callback logger
The method returned by the callback is missing the .enabled property. This is added in a consistent way that it also verifies that it's a getter. Fixes: #56676 PR-URL: #59858 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e790eb6 commit f2fbcc5
Copy full SHA for f2fbcc5

File tree

Expand file treeCollapse file tree

2 files changed

+19
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-3
lines changed
Open diff view settings
Collapse file

‎lib/internal/util/debuglog.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/debuglog.js
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,17 @@ function debuglog(set, cb) {
9494
// Only invokes debuglogImpl() when the debug function is
9595
// called for the first time.
9696
debug = debuglogImpl(enabled, set);
97-
if (typeof cb === 'function')
97+
if (typeof cb === 'function') {
98+
ObjectDefineProperty(debug, 'enabled', {
99+
__proto__: null,
100+
get() {
101+
return enabled;
102+
},
103+
configurable: true,
104+
enumerable: true,
105+
});
98106
cb(debug);
107+
}
99108
switch (args.length) {
100109
case 1: return debug(args[0]);
101110
case 2: return debug(args[0], args[1]);
Collapse file

‎test/sequential/test-util-debug.js‎

Copy file name to clipboardExpand all lines: test/sequential/test-util-debug.js
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function parent() {
5757

5858
function test(environ, shouldWrite, section, forceColors = false) {
5959
let expectErr = '';
60-
const expectOut = shouldWrite ? 'enabled\n' : 'disabled\n';
60+
const expectOut = shouldWrite ? 'outer enabled\ninner enabled\n' : 'outer disabled\ninner disabled\n';
6161

6262
const spawn = require('child_process').spawn;
6363
const child = spawn(process.execPath, [__filename, 'child', section], {
@@ -117,11 +117,18 @@ function child(section) {
117117
Object.defineProperty(process.stderr, 'hasColors', {
118118
value: tty.WriteStream.prototype.hasColors
119119
});
120+
121+
let innerDebug = null;
120122
// eslint-disable-next-line no-restricted-syntax
121123
const debug = util.debuglog(section, common.mustCall((cb) => {
122124
assert.strictEqual(typeof cb, 'function');
125+
innerDebug = cb;
123126
}));
124127
debug('this', { is: 'a' }, /debugging/);
125128
debug('num=%d str=%s obj=%j', 1, 'a', { foo: 'bar' });
126-
console.log(debug.enabled ? 'enabled' : 'disabled');
129+
console.log(debug.enabled ? 'outer enabled' : 'outer disabled');
130+
console.log(innerDebug.enabled ? 'inner enabled' : 'inner disabled');
131+
132+
assert.strictEqual(typeof Object.getOwnPropertyDescriptor(debug, 'enabled').get, 'function');
133+
assert.strictEqual(typeof Object.getOwnPropertyDescriptor(innerDebug, 'enabled').get, 'function');
127134
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.