Skip to content

Commit 637c1fa

Browse files
aduh95danielleadams
authored andcommitted
lib: refactor debuglog init
PR-URL: #38838 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Anto Aravinth <[email protected]>
1 parent c0d236f commit 637c1fa

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

‎lib/internal/util/debuglog.js‎

Lines 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
letdebugImpls;
19-
20-
letdebugEnvRegex=/^$/;
2118
lettestEnabled;
2219

20+
2321
// `debugEnv` is initial value of process.env.NODE_DEBUG
2422
functioninitializeDebugEnv(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=newRegExp(`^${debugEnv}$`,'i');
27+
.replaceAll('*','.*')
28+
.replaceAll(',','$|^');
29+
constdebugEnvRegex=newRegExp(`^${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)