util: add maxObjectProperties option to inspect - #65242
Open
watson wants to merge 1 commit into
Open
Conversation
Collaborator
|
Review requested:
|
watson
force-pushed
the
support-max-props-in-util-inspect
branch
from
August 12, 2026 12:09
90f87b9 to
0282eb8
Compare
Add a maxObjectProperties option to util.inspect that caps the number of named properties included in formatted output. The limit applies independently from maxArrayLength and defaults to Infinity, preserving existing behavior. Own string and symbol properties are included before user-defined prototype properties. Array, Map, Set, and WeakSet entries governed by maxArrayLength, as well as built-in metadata entries such as [byteLength], [buffer], and [BYTES_PER_ELEMENT], do not consume the property budget. The limit is applied before sorted, and omitted properties are not evaluated (including getters and [util.inspect.custom]). Prototype property collection is deferred so truncated properties are discarded before their values are formatted. Assertion errors pass maxObjectProperties: Infinity explicitly so changes to inspect.defaultOptions do not affect diff output. Signed-off-by: Thomas Watson <w@tson.dk>
watson
force-pushed
the
support-max-props-in-util-inspect
branch
from
August 12, 2026 12:16
0282eb8 to
c01faf8
Compare
watson
marked this pull request as ready for review
August 12, 2026 12:22
BridgeAR
self-requested a review
August 12, 2026 13:06
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
maxObjectPropertiestoutil.inspectso callers can cap how many named properties are formatted per inspected value, independently frommaxArrayLength.The default is
Infinity, so existing output is unchanged unless the option is set. Own string and symbol properties are shown before user-defined prototype properties. Entries governed bymaxArrayLengthand built-in metadata such as[byteLength],[buffer], and[BYTES_PER_ELEMENT]do not count toward the limit. Omitted properties are not evaluated, so getters and[util.inspect.custom]on truncated keys are skipped. The limit is applied beforesorted. Assertion errors passmaxObjectProperties: Infinityexplicitly so changes toinspect.defaultOptionsdo not affect assertion diffs.Examples
Regular object
Array with custom properties
Array indices are governed by
maxArrayLength; named properties on the array usemaxObjectProperties:Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.