Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit baa8064

Browse filesBrowse files
rchouguledanielleadams
authored andcommitted
util: refactor inspect.js to use more primodials
PR-URL: #36730 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Pooja D P <Pooja.D.P@ibm.com>
1 parent b996e3b commit baa8064
Copy full SHA for baa8064

File tree

Expand file treeCollapse file tree

1 file changed

+10
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-8
lines changed
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+10-8Lines changed: 10 additions & 8 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.