From d3a2bce98ebbe253dfe093177d8d8a753e1ed7f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Louren=C3=A7o?= Date: Thu, 8 Aug 2024 19:07:15 -0300 Subject: [PATCH 1/5] lib: fix emit warning for debuglog.time when disabled --- lib/internal/util/debuglog.js | 15 +++++++-------- test/fixtures/GH-54265/dep1.js | 4 ++++ test/fixtures/GH-54265/dep2.js | 3 +++ test/fixtures/GH-54265/index.js | 10 ++++++++++ test/fixtures/GH-54265/require-hook.js | 9 +++++++++ test/parallel/test-module-print-timing.mjs | 17 +++++++++++++++++ 6 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 test/fixtures/GH-54265/dep1.js create mode 100644 test/fixtures/GH-54265/dep2.js create mode 100644 test/fixtures/GH-54265/index.js create mode 100644 test/fixtures/GH-54265/require-hook.js diff --git a/lib/internal/util/debuglog.js b/lib/internal/util/debuglog.js index 87d19dcc843170..0ffb79041641ac 100644 --- a/lib/internal/util/debuglog.js +++ b/lib/internal/util/debuglog.js @@ -133,6 +133,7 @@ function pad(value) { const kNone = 1 << 0; const kSkipLog = 1 << 1; const kSkipTrace = 1 << 2; +const kShouldSkipAll = kSkipLog | kSkipTrace; const kSecond = 1000; const kMinute = 60 * kSecond; @@ -377,8 +378,6 @@ function debugWithTimer(set, cb) { let debugLogCategoryEnabled = false; let timerFlags = kNone; - const skipAll = kSkipLog | kSkipTrace; - function ensureTimerFlagsAreUpdated() { timerFlags &= ~kSkipTrace; @@ -393,7 +392,7 @@ function debugWithTimer(set, cb) { function internalStartTimer(logLabel, traceLabel) { ensureTimerFlagsAreUpdated(); - if (timerFlags === skipAll) { + if ((timerFlags & kShouldSkipAll) === kShouldSkipAll) { return; } @@ -413,7 +412,7 @@ function debugWithTimer(set, cb) { function internalEndTimer(logLabel, traceLabel) { ensureTimerFlagsAreUpdated(); - if (timerFlags === skipAll) { + if ((timerFlags & kShouldSkipAll) === kShouldSkipAll) { return; } @@ -434,7 +433,7 @@ function debugWithTimer(set, cb) { function internalLogTimer(logLabel, traceLabel, args) { ensureTimerFlagsAreUpdated(); - if (timerFlags === skipAll) { + if ((timerFlags & kShouldSkipAll) === kShouldSkipAll) { return; } @@ -477,7 +476,7 @@ function debugWithTimer(set, cb) { const startTimer = (logLabel, traceLabel) => { init(); - if (timerFlags !== skipAll) + if ((timerFlags & kShouldSkipAll) !== kShouldSkipAll) internalStartTimer(logLabel, traceLabel); }; @@ -487,7 +486,7 @@ function debugWithTimer(set, cb) { const endTimer = (logLabel, traceLabel) => { init(); - if (timerFlags !== skipAll) + if ((timerFlags & kShouldSkipAll) !== kShouldSkipAll) internalEndTimer(logLabel, traceLabel); }; @@ -497,7 +496,7 @@ function debugWithTimer(set, cb) { const logTimer = (logLabel, traceLabel, args) => { init(); - if (timerFlags !== skipAll) + if ((timerFlags & kShouldSkipAll) !== kShouldSkipAll) internalLogTimer(logLabel, traceLabel, args); }; diff --git a/test/fixtures/GH-54265/dep1.js b/test/fixtures/GH-54265/dep1.js new file mode 100644 index 00000000000000..c194026fd3fded --- /dev/null +++ b/test/fixtures/GH-54265/dep1.js @@ -0,0 +1,4 @@ +// dep1.js +module.exports = function requireDep2() { + require("./dep2.js"); +}; \ No newline at end of file diff --git a/test/fixtures/GH-54265/dep2.js b/test/fixtures/GH-54265/dep2.js new file mode 100644 index 00000000000000..c40448661f656a --- /dev/null +++ b/test/fixtures/GH-54265/dep2.js @@ -0,0 +1,3 @@ +// dep2.js + +// (empty) \ No newline at end of file diff --git a/test/fixtures/GH-54265/index.js b/test/fixtures/GH-54265/index.js new file mode 100644 index 00000000000000..4a1bd232aa8e2e --- /dev/null +++ b/test/fixtures/GH-54265/index.js @@ -0,0 +1,10 @@ +// index.js +const Module = require("module"); +const requireDep2 = require("./dep1.js"); + +const globalCache = Module._cache; +Module._cache = Object.create(null); +require("./require-hook.js"); +Module._cache = globalCache; + +requireDep2(); \ No newline at end of file diff --git a/test/fixtures/GH-54265/require-hook.js b/test/fixtures/GH-54265/require-hook.js new file mode 100644 index 00000000000000..6a6d76d08aa0a2 --- /dev/null +++ b/test/fixtures/GH-54265/require-hook.js @@ -0,0 +1,9 @@ +// require-hook.js +const Module = require("module"); +const requireDep2 = require("./dep1.js"); + +const originalJSLoader = Module._extensions[".js"]; +Module._extensions[".js"] = function customJSLoader(module, filename) { + requireDep2(); + return originalJSLoader(module, filename); +}; \ No newline at end of file diff --git a/test/parallel/test-module-print-timing.mjs b/test/parallel/test-module-print-timing.mjs index 124ac5e2763e8c..01f715482e7ccd 100644 --- a/test/parallel/test-module-print-timing.mjs +++ b/test/parallel/test-module-print-timing.mjs @@ -4,6 +4,7 @@ import { readFile } from 'node:fs/promises'; import { it } from 'node:test'; import tmpdir from '../common/tmpdir.js'; import { spawnSyncAndAssert } from '../common/child_process.js'; +import fixtures from '../common/fixtures.js'; tmpdir.refresh(); @@ -153,3 +154,19 @@ it('should support enable tracing dynamically', async () => { const vmTraces = outputFileJson.filter((trace) => trace.name === "require('vm')"); assert.strictEqual(vmTraces.length, 0); }); + +it('should not print when is disabled and found duplicated labels (GH-54265)', () => { + const testFile = fixtures.path('GH-54265/index.js'); + + spawnSyncAndAssert(process.execPath, [ + testFile, + ], { + cwd: tmpdir.path, + env: { + ...process.env, + }, + }, { + stdout: '', + stderr: '', + }); +}); From 699e7278a1da1a0a36285a82311251c2758c33be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinicius=20Louren=C3=A7o?= <12551007+H4ad@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:35:18 -0300 Subject: [PATCH 2/5] Update test/fixtures/GH-54265/dep1.js Co-authored-by: James M Snell --- test/fixtures/GH-54265/dep1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/GH-54265/dep1.js b/test/fixtures/GH-54265/dep1.js index c194026fd3fded..42464d01ec18a1 100644 --- a/test/fixtures/GH-54265/dep1.js +++ b/test/fixtures/GH-54265/dep1.js @@ -1,4 +1,4 @@ // dep1.js module.exports = function requireDep2() { require("./dep2.js"); -}; \ No newline at end of file +}; From 9b0d97f88b96a4543bf23e1e1620de0d409ffda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinicius=20Louren=C3=A7o?= <12551007+H4ad@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:35:26 -0300 Subject: [PATCH 3/5] Update test/fixtures/GH-54265/dep2.js Co-authored-by: James M Snell --- test/fixtures/GH-54265/dep2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/GH-54265/dep2.js b/test/fixtures/GH-54265/dep2.js index c40448661f656a..59c017990f8999 100644 --- a/test/fixtures/GH-54265/dep2.js +++ b/test/fixtures/GH-54265/dep2.js @@ -1,3 +1,3 @@ // dep2.js -// (empty) \ No newline at end of file +// (empty) From 27e30eac22b89925723f41a4f332e0a7433fcdd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinicius=20Louren=C3=A7o?= <12551007+H4ad@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:35:32 -0300 Subject: [PATCH 4/5] Update test/fixtures/GH-54265/index.js Co-authored-by: James M Snell --- test/fixtures/GH-54265/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/GH-54265/index.js b/test/fixtures/GH-54265/index.js index 4a1bd232aa8e2e..9caef6b88cb9dc 100644 --- a/test/fixtures/GH-54265/index.js +++ b/test/fixtures/GH-54265/index.js @@ -7,4 +7,4 @@ Module._cache = Object.create(null); require("./require-hook.js"); Module._cache = globalCache; -requireDep2(); \ No newline at end of file +requireDep2(); From 44e8eb10db82ee9922e521c8bee15b0f76060750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinicius=20Louren=C3=A7o?= <12551007+H4ad@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:35:38 -0300 Subject: [PATCH 5/5] Update test/fixtures/GH-54265/require-hook.js Co-authored-by: James M Snell --- test/fixtures/GH-54265/require-hook.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/GH-54265/require-hook.js b/test/fixtures/GH-54265/require-hook.js index 6a6d76d08aa0a2..e94a2b6261dab0 100644 --- a/test/fixtures/GH-54265/require-hook.js +++ b/test/fixtures/GH-54265/require-hook.js @@ -6,4 +6,4 @@ const originalJSLoader = Module._extensions[".js"]; Module._extensions[".js"] = function customJSLoader(module, filename) { requireDep2(); return originalJSLoader(module, filename); -}; \ No newline at end of file +};