-
Notifications
You must be signed in to change notification settings - Fork 30k
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: change inspect depth default #17907
Changes from 3 commits
94b7b01
2d845cf
2721767
606f06c
3ca34ca
8ab8726
e220598
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
'use strict'; | ||
|
||
const { Buffer } = require('buffer'); | ||
const { customInspectSymbol } = require('internal/util'); | ||
|
||
function copyBuffer(src, target, offset) { | ||
Buffer.prototype.copy.call(src, target, offset); | ||
|
@@ -73,4 +74,8 @@ module.exports = class BufferList { | |
} | ||
return ret; | ||
} | ||
|
||
[customInspectSymbol]() { | ||
return `${this.constructor.name} { length: ${this.length} }`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ const { | |
|
||
const inspectDefaultOptions = Object.seal({ | ||
showHidden: false, | ||
depth: 2, | ||
depth: null, | ||
colors: false, | ||
customInspect: true, | ||
showProxy: false, | ||
|
@@ -317,7 +317,9 @@ Object.defineProperty(inspect, 'defaultOptions', { | |
if (options === null || typeof options !== 'object') { | ||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object'); | ||
} | ||
Object.assign(inspectDefaultOptions, options); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for not using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type check has to be done again in that case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt it will add a noticeable overhead but yes it makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the use _extend as it will still be faster than Object.assign There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About the performance - just recently I heard that |
||
const keys = Object.keys(options); | ||
for (var i = 0; i < keys.length; i++) | ||
inspectDefaultOptions[keys[i]] = options[keys[i]]; | ||
return inspectDefaultOptions; | ||
} | ||
}); | ||
|
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’d just use
util.inspect.custom
here, it saves people looking at this code one round-trip to another fileThere 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.
Done