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 637c1fa

Browse filesBrowse files
aduh95danielleadams
authored andcommitted
lib: refactor debuglog init
PR-URL: #38838 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
1 parent c0d236f commit 637c1fa
Copy full SHA for 637c1fa

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

+11
-11
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
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
'use strict';
22

33
const {
4-
FunctionPrototypeBind,
54
ObjectCreate,
65
ObjectDefineProperty,
76
RegExp,
8-
RegExpPrototypeTest,
7+
RegExpPrototypeExec,
98
SafeArrayIterator,
109
StringPrototypeToLowerCase,
1110
StringPrototypeToUpperCase,
1211
} = primordials;
1312

1413
const { inspect, format, formatWithOptions } = require('internal/util/inspect');
1514

16-
// `debugs` is deliberately initialized to undefined so any call to
17-
// debuglog() before initializeDebugEnv() is called will throw.
15+
// `debugImpls` and `testEnabled` are deliberately not initialized so any call
16+
// to `debuglog()` before `initializeDebugEnv()` is called will throw.
1817
let debugImpls;
19-
20-
let debugEnvRegex = /^$/;
2118
let testEnabled;
2219

20+
2321
// `debugEnv` is initial value of process.env.NODE_DEBUG
2422
function initializeDebugEnv(debugEnv) {
2523
debugImpls = ObjectCreate(null);
2624
if (debugEnv) {
25+
// This is run before any user code, it's OK not to use primordials.
2726
debugEnv = debugEnv.replace(/[|\\{}()[\]^$+?.]/g, '\\$&')
28-
.replace(/\*/g, '.*')
29-
.replace(/,/g, '$|^')
30-
.toUpperCase();
31-
debugEnvRegex = new RegExp(`^${debugEnv}$`, 'i');
27+
.replaceAll('*', '.*')
28+
.replaceAll(',', '$|^');
29+
const debugEnvRegex = new RegExp(`^${debugEnv}$`, 'i');
30+
testEnabled = (str) => RegExpPrototypeExec(debugEnvRegex, str) !== null;
31+
} else {
32+
testEnabled = () => false;
3233
}
33-
testEnabled = FunctionPrototypeBind(RegExpPrototypeTest, null, debugEnvRegex);
3434
}
3535

3636
// Emits warning when user sets

0 commit comments

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