|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | const { |
4 | | - FunctionPrototypeBind, |
5 | 4 | ObjectCreate, |
6 | 5 | ObjectDefineProperty, |
7 | 6 | RegExp, |
8 | | - RegExpPrototypeTest, |
| 7 | + RegExpPrototypeExec, |
9 | 8 | SafeArrayIterator, |
10 | 9 | StringPrototypeToLowerCase, |
11 | 10 | StringPrototypeToUpperCase, |
12 | 11 | } = primordials; |
13 | 12 |
|
14 | 13 | const { inspect, format, formatWithOptions } = require('internal/util/inspect'); |
15 | 14 |
|
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. |
18 | 17 | let debugImpls; |
19 | | - |
20 | | -let debugEnvRegex = /^$/; |
21 | 18 | let testEnabled; |
22 | 19 |
|
| 20 | + |
23 | 21 | // `debugEnv` is initial value of process.env.NODE_DEBUG |
24 | 22 | function initializeDebugEnv(debugEnv) { |
25 | 23 | debugImpls = ObjectCreate(null); |
26 | 24 | if (debugEnv) { |
| 25 | + // This is run before any user code, it's OK not to use primordials. |
27 | 26 | 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; |
32 | 33 | } |
33 | | - testEnabled = FunctionPrototypeBind(RegExpPrototypeTest, null, debugEnvRegex); |
34 | 34 | } |
35 | 35 |
|
36 | 36 | // Emits warning when user sets |
|
0 commit comments