Skip to content

Commit baa8064

Browse files
rchouguledanielleadams
authored andcommitted
util: refactor inspect.js to use more primodials
PR-URL: #36730 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Pooja D P <[email protected]>
1 parent b996e3b commit baa8064

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/internal/util/inspect.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
Array,
55
ArrayIsArray,
66
ArrayPrototypeFilter,
7+
ArrayPrototypeForEach,
78
ArrayPrototypePush,
89
ArrayPrototypeSort,
910
ArrayPrototypeUnshift,
@@ -462,12 +463,13 @@ function strEscape(str) {
462463
// instead wrap the text in double quotes. If double quotes exist, check for
463464
// backticks. If they do not exist, use those as fallback instead of the
464465
// double quotes.
465-
if (str.includes("'")) {
466+
if (StringPrototypeIncludes(str, "'")) {
466467
// This invalidates the charCode and therefore can not be matched for
467468
// anymore.
468-
if (!str.includes('"')) {
469+
if (!StringPrototypeIncludes(str, '"')) {
469470
singleQuote = -1;
470-
} else if (!str.includes('`') && !str.includes('${')) {
471+
} else if (!StringPrototypeIncludes(str, '`') &&
472+
!StringPrototypeIncludes(str, '${')) {
471473
singleQuote = -2;
472474
}
473475
if (singleQuote !== 39) {
@@ -488,7 +490,7 @@ function strEscape(str) {
488490
let last = 0;
489491
const lastIndex = str.length;
490492
for (let i = 0; i < lastIndex; i++) {
491-
const point = str.charCodeAt(i);
493+
const point = StringPrototypeCharCodeAt(str, i);
492494
if (point === singleQuote ||
493495
point === 92 ||
494496
point < 32 ||
@@ -609,13 +611,13 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) {
609611
if (depth === 0) {
610612
keySet = new SafeSet();
611613
} else {
612-
keys.forEach((key) => keySet.add(key));
614+
ArrayPrototypeForEach(keys, (key) => keySet.add(key));
613615
}
614616
// Get all own property names and symbols.
615617
keys = ObjectGetOwnPropertyNames(obj);
616618
const symbols = ObjectGetOwnPropertySymbols(obj);
617619
if (symbols.length !== 0) {
618-
keys.push(...symbols);
620+
ArrayPrototypePush(keys, ...symbols);
619621
}
620622
for (const key of keys) {
621623
// Ignore the `constructor` property and keys that exist on layers above.
@@ -632,9 +634,9 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) {
632634
ctx, obj, recurseTimes, key, kObjectType, desc, main);
633635
if (ctx.colors) {
634636
// Faint!
635-
output.push(`\u001b[2m${value}\u001b[22m`);
637+
ArrayPrototypePush(output, `\u001b[2m${value}\u001b[22m`);
636638
} else {
637-
output.push(value);
639+
ArrayPrototypePush(output, value);
638640
}
639641
}
640642
// Limit the inspection to up to three prototype layers. Using `recurseTimes`

0 commit comments

Comments
 (0)