Skip to content

Commit

Permalink
fixup: use RegExpPrototypeSymbolReplace instead of StringPrototypeRep…
Browse files Browse the repository at this point in the history
…lace
  • Loading branch information
ljharb committed Dec 16, 2021
1 parent 3e95189 commit 96f3f53
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/internal/util/inspect.js
Expand Up @@ -49,6 +49,7 @@ const {
ObjectSetPrototypeOf,
ReflectOwnKeys,
RegExp,
RegExpPrototypeSymbolReplace,
RegExpPrototypeTest,
RegExpPrototypeToString,
SafeStringIterator,
Expand All @@ -64,7 +65,6 @@ const {
StringPrototypePadEnd,
StringPrototypePadStart,
StringPrototypeRepeat,
StringPrototypeReplace,
StringPrototypeSlice,
StringPrototypeSplit,
StringPrototypeToLowerCase,
Expand Down Expand Up @@ -498,7 +498,7 @@ function strEscape(str) {
if (str.length < 5000 && !RegExpPrototypeTest(escapeTest, str))
return addQuotes(str, singleQuote);
if (str.length > 100) {
str = StringPrototypeReplace(str, escapeReplace, escapeFn);
str = RegExpPrototypeSymbolReplace(escapeReplace, str, escapeFn);
return addQuotes(str, singleQuote);
}

Expand Down Expand Up @@ -1458,9 +1458,9 @@ function handleMaxCallStackSize(ctx, err, constructorName, indentationLvl) {
}

function addNumericSeparator(integerString) {
return StringPrototypeReplace(
integerString,
return RegExpPrototypeSymbolReplace(
/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g,
integerString,
'$&_'
);
}
Expand Down Expand Up @@ -1618,9 +1618,11 @@ function formatArrayBuffer(ctx, value) {
}
if (hexSlice === undefined)
hexSlice = uncurryThis(require('buffer').Buffer.prototype.hexSlice);
let str = StringPrototypeTrim(StringPrototypeReplace(
let str = StringPrototypeTrim(RegExpPrototypeSymbolReplace(
/(.{2})/g,
hexSlice(buffer, 0, MathMin(ctx.maxArrayLength, buffer.length)),
/(.{2})/g, '$1 '));
'$1 '
));
const remaining = buffer.length - ctx.maxArrayLength;
if (remaining > 0)
str += ` ... ${remaining} more byte${remaining > 1 ? 's' : ''}`;
Expand Down Expand Up @@ -1852,16 +1854,20 @@ function formatProperty(ctx, value, recurseTimes, key, type, desc,
return str;
}
if (typeof key === 'symbol') {
const tmp = StringPrototypeReplace(
const tmp = RegExpPrototypeSymbolReplace(
strEscapeSequencesReplacer,
SymbolPrototypeToString(key),
strEscapeSequencesReplacer, escapeFn
escapeFn
);
name = `[${ctx.stylize(tmp, 'symbol')}]`;
} else if (key === '__proto__') {
name = "['__proto__']";
} else if (desc.enumerable === false) {
const tmp = StringPrototypeReplace(key,
strEscapeSequencesReplacer, escapeFn);
const tmp = RegExpPrototypeSymbolReplace(
strEscapeSequencesReplacer,
key,
escapeFn
);
name = `[${tmp}]`;
} else if (RegExpPrototypeTest(keyStrRegExp, key)) {
name = ctx.stylize(key, 'name');
Expand Down

0 comments on commit 96f3f53

Please sign in to comment.