Skip to content

Commit e113035

Browse files
Trotttargos
authored andcommitted
util: simplify constructor retrieval in inspect()
Instead of looping through a list of typed arrays, use TypedArrayPrototypeGetSymbolToStringTag. PR-URL: #36466 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent ba19313 commit e113035

1 file changed

Lines changed: 3 additions & 44 deletions

File tree

‎lib/internal/util/inspect.js‎

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,14 @@
33
const{
44
Array,
55
ArrayIsArray,
6-
BigInt64Array,
76
BigIntPrototypeValueOf,
8-
BigUint64Array,
97
BooleanPrototypeValueOf,
108
DatePrototypeGetTime,
119
DatePrototypeToISOString,
1210
DatePrototypeToString,
1311
ErrorPrototypeToString,
14-
Float32Array,
15-
Float64Array,
1612
FunctionPrototypeCall,
1713
FunctionPrototypeToString,
18-
Int8Array,
19-
Int16Array,
20-
Int32Array,
2114
JSONStringify,
2215
Map,
2316
MapPrototypeGetSize,
@@ -59,10 +52,8 @@ const {
5952
SymbolIterator,
6053
SymbolToStringTag,
6154
TypedArrayPrototypeGetLength,
62-
Uint16Array,
63-
Uint32Array,
55+
TypedArrayPrototypeGetSymbolToStringTag,
6456
Uint8Array,
65-
Uint8ClampedArray,
6657
uncurryThis,
6758
}=primordials;
6859

@@ -120,17 +111,6 @@ const {
120111
isNumberObject,
121112
isBooleanObject,
122113
isBigIntObject,
123-
isUint8Array,
124-
isUint8ClampedArray,
125-
isUint16Array,
126-
isUint32Array,
127-
isInt8Array,
128-
isInt16Array,
129-
isInt32Array,
130-
isFloat32Array,
131-
isFloat64Array,
132-
isBigInt64Array,
133-
isBigUint64Array
134114
}=require('internal/util/types');
135115

136116
constassert=require('internal/assert');
@@ -712,26 +692,6 @@ function formatProxy(ctx, proxy, recurseTimes) {
712692
ctx,res,'',['Proxy [',']'],kArrayExtrasType,recurseTimes);
713693
}
714694

715-
functionfindTypedConstructor(value){
716-
for(const[check,clazz]of[
717-
[isUint8Array,Uint8Array],
718-
[isUint8ClampedArray,Uint8ClampedArray],
719-
[isUint16Array,Uint16Array],
720-
[isUint32Array,Uint32Array],
721-
[isInt8Array,Int8Array],
722-
[isInt16Array,Int16Array],
723-
[isInt32Array,Int32Array],
724-
[isFloat32Array,Float32Array],
725-
[isFloat64Array,Float64Array],
726-
[isBigInt64Array,BigInt64Array],
727-
[isBigUint64Array,BigUint64Array]
728-
]){
729-
if(check(value)){
730-
returnclazz;
731-
}
732-
}
733-
}
734-
735695
// Note: using `formatValue` directly requires the indentation level to be
736696
// corrected by setting `ctx.indentationLvL += diff` and then to decrease the
737697
// value afterwards again.
@@ -879,10 +839,9 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
879839
letbound=value;
880840
letfallback='';
881841
if(constructor===null){
882-
constconstr=findTypedConstructor(value);
883-
fallback=constr.name;
842+
fallback=TypedArrayPrototypeGetSymbolToStringTag(value);
884843
// Reconstruct the array information.
885-
bound=newconstr(value);
844+
bound=newprimordials[fallback](value);
886845
}
887846
constsize=TypedArrayPrototypeGetLength(value);
888847
constprefix=getPrefix(constructor,tag,fallback,`(${size})`);

0 commit comments

Comments
 (0)