-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Conversation
This removes the deprecated custom inspection function and fixes all tests accordingly. Refs: nodejs#15549
test/parallel/test-console.js
Outdated
@@ -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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/property/symbol/ ?
There was a problem hiding this comment.
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.
I think it is fine to not run the CI again for the changed comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I forgot to remove the docs. I just fixed that. |
`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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
@vsemozhetbyt would you be so kind and have a brief look at the changed docs before landing? :-) |
Or @Trott |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ;-) ).
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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. |
Doc changes LGTM) |
Thanks. Landed in 27df81c 🎉 |
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>
semver-major but no citgm run? |
@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. |
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
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
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), orvcbuild test
(Windows) passes