diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 410e6af6eecedb..f37452f9786057 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -813,7 +813,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) { return `${braces[0]}]`; // Special handle the value. The original value is required below. The // bound function is required to reconstruct missing information. - formatter = formatTypedArray.bind(null, bound); + formatter = formatTypedArray.bind(null, bound, size); extrasType = kArrayExtrasType; } else if (isMapIterator(value)) { keys = getKeys(value, ctx.showHidden); @@ -1389,8 +1389,8 @@ function formatArray(ctx, value, recurseTimes) { return output; } -function formatTypedArray(value, ctx, ignored, recurseTimes) { - const maxLength = MathMin(MathMax(0, ctx.maxArrayLength), value.length); +function formatTypedArray(value, length, ctx, ignored, recurseTimes) { + const maxLength = MathMin(MathMax(0, ctx.maxArrayLength), length); const remaining = value.length - maxLength; const output = new Array(maxLength); const elementFormatter = value.length > 0 && typeof value[0] === 'number' ? diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index b1cd48a6a83c03..346f0932179d57 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -311,6 +311,12 @@ assert(!/Object/.test( ); }); +{ + const brokenLength = new Float32Array(2); + Object.defineProperty(brokenLength, 'length', { value: -1 }); + assert.strictEqual(inspect(brokenLength), 'Float32Array(2) [ 0n, 0n ]'); +} + assert.strictEqual( util.inspect(Object.create({}, { visible: { value: 1, enumerable: true },