Skip to content

Conversation

@BridgeAR
Copy link
Member

This removes the deprecated custom inspection function and fixes
all tests accordingly.

Refs: #15549

I guess we could merge #20525 first and land this one right afterwards.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

This removes the deprecated custom inspection function and fixes all tests accordingly. Refs: nodejs#15549
@BridgeARBridgeAR added the semver-major PRs that contain breaking changes and should be released in the next major version. label May 14, 2018
@BridgeARBridgeAR requested review from a team and TrottMay 14, 2018 16:57
@nodejs-github-botnodejs-github-bot added the util Issues and PRs related to the built-in util module. label May 14, 2018
@BridgeAR
Copy link
MemberAuthor

BridgeAR commented May 14, 2018


// an Object with a custom .inspect() function
constcustom_inspect={foo: 'bar',inspect: ()=>'inspect'};
// An Object with a custom .inspect() function.
Copy link
Contributor

@mscdexmscdexMay 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should be slightly re-worded to instead say "custom inspect function" or "custom inspect symbol" or similar now, to avoid confusion.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say it is still a custom inspect function but it might be best to just write .inspect() without dot and brackets.


util.inspect(process);

// Setting custom inspect property to a non-function should do nothing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/property/symbol/ ?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it is still a property. It is just accessed with a symbol.

@BridgeARBridgeAR requested a review from a teamMay 15, 2018 11:20
@BridgeAR
Copy link
MemberAuthor

I think it is fine to not run the CI again for the changed comment.

Copy link
Member

@mcollinamcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@BridgeARBridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 17, 2018
@BridgeARBridgeAR requested a review from a teamMay 17, 2018 15:04
@BridgeARBridgeAR removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 17, 2018
@BridgeAR
Copy link
MemberAuthor

I forgot to remove the docs. I just fixed that.

@BridgeARBridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 17, 2018
`util.inspect()` will invoke and use the result of when inspecting the object:
Objects may also define their own `[util.inspect.custom](depth, opts)` function
that `util.inspect()` will invoke and use the result of when inspecting the
object:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s also the customInspect option description which references inspect(){… }, fwiw

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

@BridgeAR
Copy link
MemberAuthor

@vsemozhetbyt would you be so kind and have a brief look at the changed docs before landing? :-)

@BridgeAR
Copy link
MemberAuthor

Or @Trott

Copy link
Contributor

@vsemozhetbytvsemozhetbyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs LGTM with possible nits)

*`customInspect`{boolean} If `false`, then custom `inspect(depth, opts)`
functions will not be called. **Default:**`true`.
*`customInspect`{boolean} If `false`, then
`[util.inspect.custom](depth, opts)` functions will not be called.
Copy link
Contributor

@vsemozhetbytvsemozhetbytMay 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can many functions be called during the inspection? Does this mean nested objects with own custom functions?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it is the same function (if it does not replace itself during custom inspection ;-) ).

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again: functions do seem to be correct as it is not about a specific custom inspect function but about custom inspect functions in general.

doc/api/util.md Outdated
`util.inspect()` will use the constructor's name and/or `@@toStringTag` to make
an identifiable tag for an inspected value.

Values may supply their own custom inspection function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the next code example does not contain any mention of this, maybe we should link inspection function here to #util_util_inspect_custom or #util_custom_inspection_functions_on_objects?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was also wrapping my head around this. I moved it because when looking at the current documentation it is confusing as it seems to be about something else than it really is. So +1 on that.

doc/api/util.md Outdated
an identifiable tag for an inspected value.

Values may supply their own custom inspection function
(`[util.inspect.custom](depth, opts)`), when called these receive the current
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function -> functions or these receive -> this receives?

doc/api/util.md Outdated

Values may supply their own custom inspection function
(`[util.inspect.custom](depth, opts)`), when called these receive the current
`depth` in the recursive inspection, as well as the options object passed to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options -> `options`?

This is already sufficiently covered in the docs.
@BridgeAR
Copy link
MemberAuthor

BridgeAR commented May 19, 2018

Comments addressed (I actually removed the whole paragraph as it is already sufficiently covered in the docs and the current docs are more confusing than helpful).

PTAL

I would like to land this some time soon.

@vsemozhetbyt
Copy link
Contributor

Doc changes LGTM)

@BridgeAR
Copy link
MemberAuthor

BridgeAR commented May 19, 2018

Thanks.

Landed in 27df81c 🎉

BridgeAR added a commit to BridgeAR/node that referenced this pull request May 19, 2018
This removes the deprecated custom inspection function and fixes all tests accordingly. Refs: nodejs#15549 PR-URL: nodejs#20722 Refs: nodejs#15549 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
@BridgeARBridgeAR added the notable-change PRs with changes that should be highlighted in changelogs. label May 19, 2018
@Trott
Copy link
Member

semver-major but no citgm run?

@BridgeAR
Copy link
MemberAuthor

@Trott sorry, I missed that. However, later CITGM runs did not show up any result. I did find usage of it though and I am going to fix those in the next days.

@jdaltonjdalton mentioned this pull request Jun 5, 2018
goto-bus-stop added a commit to goto-bus-stop/buffer that referenced this pull request Jun 20, 2018
Ports the `buffer-inspect` test from Node core. Adds a `Buffer.prototype[util.inspect.custom]` method, which is an alias to `Buffer.prototype.inspect`. Node already doesn't have an `.inspect` method on Buffers anymore, but since this module has to work in browsers that do not have Symbols, it seems better to keep it around. In Node, this will use the builtin `util.inspect.custom` symbol. In the browser, it will use `Symbol.for('util.inspect.custom')`. The browser version of `util` will also use the `inspect-custom-symbol` module in the near future. If nodejs/node#20857 gets merged, `Symbol.for('util.inspect.custom')` will be used everywhere and the dependency on `inspect-custom-symbol` could probably be dropped. The motivation for this is API parity and the fact that Node is removing support for the old `.inspect` method: nodejs/node#20722
@targostargos removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 6, 2018
@BridgeARBridgeAR deleted the remove-custom-inspect branch January 20, 2020 11:33
totorokop pushed a commit to totorokop/react-native-buffer that referenced this pull request Aug 25, 2025
Ports the `buffer-inspect` test from Node core. Adds a `Buffer.prototype[util.inspect.custom]` method, which is an alias to `Buffer.prototype.inspect`. Node already doesn't have an `.inspect` method on Buffers anymore, but since this module has to work in browsers that do not have Symbols, it seems better to keep it around. In Node, this will use the builtin `util.inspect.custom` symbol. In the browser, it will use `Symbol.for('util.inspect.custom')`. The browser version of `util` will also use the `inspect-custom-symbol` module in the near future. If nodejs/node#20857 gets merged, `Symbol.for('util.inspect.custom')` will be used everywhere and the dependency on `inspect-custom-symbol` could probably be dropped. The motivation for this is API parity and the fact that Node is removing support for the old `.inspect` method: nodejs/node#20722
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notable-changePRs with changes that should be highlighted in changelogs.semver-majorPRs that contain breaking changes and should be released in the next major version.utilIssues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@BridgeAR@vsemozhetbyt@Trott@mcollina@mscdex@jasnell@addaleax@targos@nodejs-github-bot