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 <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

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎lib/internal/util/inspect.js‎

Lines 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-
}elseif(!str.includes('`')&&!str.includes('${')){
471+
}elseif(!StringPrototypeIncludes(str,'`')&&
472+
!StringPrototypeIncludes(str,'${')){
471473
singleQuote=-2;
472474
}
473475
if(singleQuote!==39){
@@ -488,7 +490,7 @@ function strEscape(str) {
488490
letlast=0;
489491
constlastIndex=str.length;
490492
for(leti=0;i<lastIndex;i++){
491-
constpoint=str.charCodeAt(i);
493+
constpoint=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=newSafeSet();
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
constsymbols=ObjectGetOwnPropertySymbols(obj);
617619
if(symbols.length!==0){
618-
keys.push(...symbols);
620+
ArrayPrototypePush(keys,...symbols);
619621
}
620622
for(constkeyofkeys){
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)