Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: remove custom inspection function #20722

Closed
wants to merge 5 commits into from

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
@BridgeAR BridgeAR added the semver-major PRs that contain breaking changes and should be released in the next major version. label May 14, 2018
@BridgeAR BridgeAR requested review from Trott and a team May 14, 2018 16:57
@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label May 14, 2018
@BridgeAR
Copy link
Member Author

BridgeAR commented May 14, 2018

@@ -46,8 +47,8 @@ assert.throws(() => console.timeEnd(Symbol('test')),
TypeError);


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

@mscdex mscdex May 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
Member Author

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.

@@ -1162,8 +1110,11 @@ 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
Member Author

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.

@BridgeAR BridgeAR requested a review from a team May 15, 2018 11:20
@BridgeAR
Copy link
Member Author

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

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 17, 2018
@BridgeAR BridgeAR requested a review from a team May 17, 2018 15:04
@BridgeAR BridgeAR 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
Member Author

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

@BridgeAR BridgeAR 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
Member Author

Choose a reason for hiding this comment

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

Addressed.

@BridgeAR
Copy link
Member Author

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

@BridgeAR
Copy link
Member Author

Or @Trott

Copy link
Contributor

@vsemozhetbyt vsemozhetbyt 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

@vsemozhetbyt vsemozhetbyt May 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
Member Author

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
Member Author

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
@@ -426,6 +426,11 @@ passed that alter certain aspects of the formatted string.
`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
Member Author

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
@@ -426,6 +426,11 @@ passed that alter certain aspects of the formatted string.
`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
(`[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
@@ -426,6 +426,11 @@ passed that alter certain aspects of the formatted string.
`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
(`[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
Member Author

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
Member Author

BridgeAR commented May 19, 2018

Thanks.

Landed in 27df81c 🎉

@BridgeAR BridgeAR closed this May 19, 2018
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 <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@BridgeAR BridgeAR added the notable-change PRs with changes that should be highlighted in changelogs. label May 19, 2018
@Trott
Copy link
Member

Trott commented May 20, 2018

semver-major but no citgm run?

@BridgeAR
Copy link
Member Author

@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.

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
@targos targos removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 6, 2018
@BridgeAR BridgeAR deleted the remove-custom-inspect branch January 20, 2020 11:33
itu2n1i8w added a commit to itu2n1i8w/buffer that referenced this pull request Aug 5, 2024
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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notable-change PRs with changes that should be highlighted in changelogs. semver-major PRs that contain breaking changes and should be released in the next major version. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants