Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2021-05-29 11:35:41 +0300
committerDanielle Adams <adamzdanielle@gmail.com>2021-06-13 05:39:38 +0300
commit637c1fa83c7267f0d0c3b375c06a61c86c4ebf05 (patch)
treefa59a1060389726b76adbe3359a9b19032f983a1 /lib
parentc0d236f5ea3afdf13255da6f31ed73fc4908295c (diff)
lib: refactor debuglog init
PR-URL: https://github.com/nodejs/node/pull/38838 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/util/debuglog.js22
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/internal/util/debuglog.js b/lib/internal/util/debuglog.js
index b1f82b957b1..93c741e7535 100644
--- a/lib/internal/util/debuglog.js
+++ b/lib/internal/util/debuglog.js
@@ -1,11 +1,10 @@
'use strict';
const {
- FunctionPrototypeBind,
ObjectCreate,
ObjectDefineProperty,
RegExp,
- RegExpPrototypeTest,
+ RegExpPrototypeExec,
SafeArrayIterator,
StringPrototypeToLowerCase,
StringPrototypeToUpperCase,
@@ -13,24 +12,25 @@ const {
const { inspect, format, formatWithOptions } = require('internal/util/inspect');
-// `debugs` is deliberately initialized to undefined so any call to
-// debuglog() before initializeDebugEnv() is called will throw.
+// `debugImpls` and `testEnabled` are deliberately not initialized so any call
+// to `debuglog()` before `initializeDebugEnv()` is called will throw.
let debugImpls;
-
-let debugEnvRegex = /^$/;
let testEnabled;
+
// `debugEnv` is initial value of process.env.NODE_DEBUG
function initializeDebugEnv(debugEnv) {
debugImpls = ObjectCreate(null);
if (debugEnv) {
+ // This is run before any user code, it's OK not to use primordials.
debugEnv = debugEnv.replace(/[|\\{}()[\]^$+?.]/g, '\\$&')
- .replace(/\*/g, '.*')
- .replace(/,/g, '$|^')
- .toUpperCase();
- debugEnvRegex = new RegExp(`^${debugEnv}$`, 'i');
+ .replaceAll('*', '.*')
+ .replaceAll(',', '$|^');
+ const debugEnvRegex = new RegExp(`^${debugEnv}$`, 'i');
+ testEnabled = (str) => RegExpPrototypeExec(debugEnvRegex, str) !== null;
+ } else {
+ testEnabled = () => false;
}
- testEnabled = FunctionPrototypeBind(RegExpPrototypeTest, null, debugEnvRegex);
}
// Emits warning when user sets