diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 1f7d0db2fdd840..241e2785cea59d 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -3,21 +3,14 @@ const { Array, ArrayIsArray, - BigInt64Array, BigIntPrototypeValueOf, - BigUint64Array, BooleanPrototypeValueOf, DatePrototypeGetTime, DatePrototypeToISOString, DatePrototypeToString, ErrorPrototypeToString, - Float32Array, - Float64Array, FunctionPrototypeCall, FunctionPrototypeToString, - Int8Array, - Int16Array, - Int32Array, JSONStringify, Map, MapPrototypeGetSize, @@ -59,10 +52,8 @@ const { SymbolIterator, SymbolToStringTag, TypedArrayPrototypeGetLength, - Uint16Array, - Uint32Array, + TypedArrayPrototypeGetSymbolToStringTag, Uint8Array, - Uint8ClampedArray, uncurryThis, } = primordials; @@ -120,17 +111,6 @@ const { isNumberObject, isBooleanObject, isBigIntObject, - isUint8Array, - isUint8ClampedArray, - isUint16Array, - isUint32Array, - isInt8Array, - isInt16Array, - isInt32Array, - isFloat32Array, - isFloat64Array, - isBigInt64Array, - isBigUint64Array } = require('internal/util/types'); const assert = require('internal/assert'); @@ -712,26 +692,6 @@ function formatProxy(ctx, proxy, recurseTimes) { ctx, res, '', ['Proxy [', ']'], kArrayExtrasType, recurseTimes); } -function findTypedConstructor(value) { - for (const [check, clazz] of [ - [isUint8Array, Uint8Array], - [isUint8ClampedArray, Uint8ClampedArray], - [isUint16Array, Uint16Array], - [isUint32Array, Uint32Array], - [isInt8Array, Int8Array], - [isInt16Array, Int16Array], - [isInt32Array, Int32Array], - [isFloat32Array, Float32Array], - [isFloat64Array, Float64Array], - [isBigInt64Array, BigInt64Array], - [isBigUint64Array, BigUint64Array] - ]) { - if (check(value)) { - return clazz; - } - } -} - // Note: using `formatValue` directly requires the indentation level to be // corrected by setting `ctx.indentationLvL += diff` and then to decrease the // value afterwards again. @@ -879,10 +839,9 @@ function formatRaw(ctx, value, recurseTimes, typedArray) { let bound = value; let fallback = ''; if (constructor === null) { - const constr = findTypedConstructor(value); - fallback = constr.name; + fallback = TypedArrayPrototypeGetSymbolToStringTag(value); // Reconstruct the array information. - bound = new constr(value); + bound = new primordials[fallback](value); } const size = TypedArrayPrototypeGetLength(value); const prefix = getPrefix(constructor, tag, fallback, `(${size})`);