Skip to content

Commit fb6af9a

Browse files
committed
fixup: use RegExpPrototypeSymbolReplace instead of StringPrototypeReplace
1 parent 49a76f7 commit fb6af9a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

lib/internal/util/inspect.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const {
4949
ObjectSetPrototypeOf,
5050
ReflectOwnKeys,
5151
RegExp,
52+
RegExpPrototypeSymbolReplace,
5253
RegExpPrototypeTest,
5354
RegExpPrototypeToString,
5455
SafeStringIterator,
@@ -64,7 +65,6 @@ const {
6465
StringPrototypePadEnd,
6566
StringPrototypePadStart,
6667
StringPrototypeRepeat,
67-
StringPrototypeReplace,
6868
StringPrototypeSlice,
6969
StringPrototypeSplit,
7070
StringPrototypeToLowerCase,
@@ -498,7 +498,7 @@ function strEscape(str) {
498498
if (str.length < 5000 && !RegExpPrototypeTest(escapeTest, str))
499499
return addQuotes(str, singleQuote);
500500
if (str.length > 100) {
501-
str = StringPrototypeReplace(str, escapeReplace, escapeFn);
501+
str = RegExpPrototypeSymbolReplace(escapeReplace, str, escapeFn);
502502
return addQuotes(str, singleQuote);
503503
}
504504

@@ -1458,9 +1458,9 @@ function handleMaxCallStackSize(ctx, err, constructorName, indentationLvl) {
14581458
}
14591459

14601460
function addNumericSeparator(integerString) {
1461-
return StringPrototypeReplace(
1462-
integerString,
1461+
return RegExpPrototypeSymbolReplace(
14631462
/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g,
1463+
integerString,
14641464
'$&_'
14651465
);
14661466
}
@@ -1619,9 +1619,11 @@ function formatArrayBuffer(ctx, value) {
16191619
}
16201620
if (hexSlice === undefined)
16211621
hexSlice = uncurryThis(require('buffer').Buffer.prototype.hexSlice);
1622-
let str = StringPrototypeTrim(StringPrototypeReplace(
1622+
let str = StringPrototypeTrim(RegExpPrototypeSymbolReplace(
1623+
/(.{2})/g,
16231624
hexSlice(buffer, 0, MathMin(ctx.maxArrayLength, buffer.length)),
1624-
/(.{2})/g, '$1 '));
1625+
'$1 '
1626+
));
16251627
const remaining = buffer.length - ctx.maxArrayLength;
16261628
if (remaining > 0)
16271629
str += ` ... ${remaining} more byte${remaining > 1 ? 's' : ''}`;
@@ -1853,16 +1855,20 @@ function formatProperty(ctx, value, recurseTimes, key, type, desc,
18531855
return str;
18541856
}
18551857
if (typeof key === 'symbol') {
1856-
const tmp = StringPrototypeReplace(
1858+
const tmp = RegExpPrototypeSymbolReplace(
1859+
strEscapeSequencesReplacer,
18571860
SymbolPrototypeToString(key),
1858-
strEscapeSequencesReplacer, escapeFn
1861+
escapeFn
18591862
);
18601863
name = `[${ctx.stylize(tmp, 'symbol')}]`;
18611864
} else if (key === '__proto__') {
18621865
name = "['__proto__']";
18631866
} else if (desc.enumerable === false) {
1864-
const tmp = StringPrototypeReplace(key,
1865-
strEscapeSequencesReplacer, escapeFn);
1867+
const tmp = RegExpPrototypeSymbolReplace(
1868+
strEscapeSequencesReplacer,
1869+
key,
1870+
escapeFn
1871+
);
18661872
name = `[${tmp}]`;
18671873
} else if (RegExpPrototypeTest(keyStrRegExp, key)) {
18681874
name = ctx.stylize(key, 'name');

0 commit comments

Comments
 (0)