Skip to content

Commit a9ce2b6

Browse files
H4adRafaelGSS
authored andcommitted
lib: fix emit warning for debuglog.time when disabled
PR-URL: #54275 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent fc57bea commit a9ce2b6

File tree

6 files changed

+50
-8
lines changed

6 files changed

+50
-8
lines changed

lib/internal/util/debuglog.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ function pad(value) {
133133
const kNone = 1 << 0;
134134
const kSkipLog = 1 << 1;
135135
const kSkipTrace = 1 << 2;
136+
const kShouldSkipAll = kSkipLog | kSkipTrace;
136137

137138
const kSecond = 1000;
138139
const kMinute = 60 * kSecond;
@@ -377,8 +378,6 @@ function debugWithTimer(set, cb) {
377378
let debugLogCategoryEnabled = false;
378379
let timerFlags = kNone;
379380

380-
const skipAll = kSkipLog | kSkipTrace;
381-
382381
function ensureTimerFlagsAreUpdated() {
383382
timerFlags &= ~kSkipTrace;
384383

@@ -393,7 +392,7 @@ function debugWithTimer(set, cb) {
393392
function internalStartTimer(logLabel, traceLabel) {
394393
ensureTimerFlagsAreUpdated();
395394

396-
if (timerFlags === skipAll) {
395+
if ((timerFlags & kShouldSkipAll) === kShouldSkipAll) {
397396
return;
398397
}
399398

@@ -413,7 +412,7 @@ function debugWithTimer(set, cb) {
413412
function internalEndTimer(logLabel, traceLabel) {
414413
ensureTimerFlagsAreUpdated();
415414

416-
if (timerFlags === skipAll) {
415+
if ((timerFlags & kShouldSkipAll) === kShouldSkipAll) {
417416
return;
418417
}
419418

@@ -434,7 +433,7 @@ function debugWithTimer(set, cb) {
434433
function internalLogTimer(logLabel, traceLabel, args) {
435434
ensureTimerFlagsAreUpdated();
436435

437-
if (timerFlags === skipAll) {
436+
if ((timerFlags & kShouldSkipAll) === kShouldSkipAll) {
438437
return;
439438
}
440439

@@ -477,7 +476,7 @@ function debugWithTimer(set, cb) {
477476
const startTimer = (logLabel, traceLabel) => {
478477
init();
479478

480-
if (timerFlags !== skipAll)
479+
if ((timerFlags & kShouldSkipAll) !== kShouldSkipAll)
481480
internalStartTimer(logLabel, traceLabel);
482481
};
483482

@@ -487,7 +486,7 @@ function debugWithTimer(set, cb) {
487486
const endTimer = (logLabel, traceLabel) => {
488487
init();
489488

490-
if (timerFlags !== skipAll)
489+
if ((timerFlags & kShouldSkipAll) !== kShouldSkipAll)
491490
internalEndTimer(logLabel, traceLabel);
492491
};
493492

@@ -497,7 +496,7 @@ function debugWithTimer(set, cb) {
497496
const logTimer = (logLabel, traceLabel, args) => {
498497
init();
499498

500-
if (timerFlags !== skipAll)
499+
if ((timerFlags & kShouldSkipAll) !== kShouldSkipAll)
501500
internalLogTimer(logLabel, traceLabel, args);
502501
};
503502

test/fixtures/GH-54265/dep1.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// dep1.js
2+
module.exports = function requireDep2() {
3+
require("./dep2.js");
4+
};

test/fixtures/GH-54265/dep2.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// dep2.js
2+
3+
// (empty)

test/fixtures/GH-54265/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// index.js
2+
const Module = require("module");
3+
const requireDep2 = require("./dep1.js");
4+
5+
const globalCache = Module._cache;
6+
Module._cache = Object.create(null);
7+
require("./require-hook.js");
8+
Module._cache = globalCache;
9+
10+
requireDep2();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// require-hook.js
2+
const Module = require("module");
3+
const requireDep2 = require("./dep1.js");
4+
5+
const originalJSLoader = Module._extensions[".js"];
6+
Module._extensions[".js"] = function customJSLoader(module, filename) {
7+
requireDep2();
8+
return originalJSLoader(module, filename);
9+
};

test/parallel/test-module-print-timing.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { readFile } from 'node:fs/promises';
44
import { it } from 'node:test';
55
import tmpdir from '../common/tmpdir.js';
66
import { spawnSyncAndAssert } from '../common/child_process.js';
7+
import fixtures from '../common/fixtures.js';
78

89
tmpdir.refresh();
910

@@ -153,3 +154,19 @@ it('should support enable tracing dynamically', async () => {
153154
const vmTraces = outputFileJson.filter((trace) => trace.name === "require('vm')");
154155
assert.strictEqual(vmTraces.length, 0);
155156
});
157+
158+
it('should not print when is disabled and found duplicated labels (GH-54265)', () => {
159+
const testFile = fixtures.path('GH-54265/index.js');
160+
161+
spawnSyncAndAssert(process.execPath, [
162+
testFile,
163+
], {
164+
cwd: tmpdir.path,
165+
env: {
166+
...process.env,
167+
},
168+
}, {
169+
stdout: '',
170+
stderr: '',
171+
});
172+
});

0 commit comments

Comments
 (0)