FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

util: fix inspection of typed arrays with unusual length by BridgeAR · Pull Request #31458 · nodejs/node · GitHub

/ node Public
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 3 additions & 3 deletions lib/internal/util/inspect.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,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);
Expand Down Expand Up @@ -1401,8 +1401,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' ?
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-util-inspect.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,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 },
Expand Down

Back | FazBrowse Home | New Git URL