-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
console: add dirxml method #17152
console: add dirxml method #17152
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
This method was previously exposed by V8 (since Node v8.0.0) and not implemented in Node directly. Tests coming soon. Refs: #17128
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,6 +162,25 @@ Console.prototype.dir = function dir(object, options) { | |
}; | ||
|
||
|
||
Console.prototype.dirxml = function dirxml(...data) { | ||
const optionProps = ['showHidden', 'depth', 'colors'], | ||
maybeOptions = Object.getOwnPropertyNames(data.slice(-1)), | ||
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. These should be separate 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. Noted! |
||
isOption = maybeOptions.some((p) => optionProps.indexOf(p) !== -1); | ||
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. Is the last argument supposed to be an options object? The spec doesn't seem to call for that, and it makes for a slightly awkward UX, IMO. What if we want to display an object that has one of those magic props? 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 don't get why this is here. The spec doesn't allow to specify options for 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. That's kind of hard said like that. Anyway, I thought about the possibility of having the last object having precisely one of those options, but I thought that it would be better to allow passing options if need be, just like I'll remove it for now anyway, since it seems to be a bad idea, it's indeed akward. 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.
When working on features which have a spec, decisions should always be informed by the behaviour defined there. 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. Also, since the 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. BTW, the
-- not if we can help it anyway, which we couldn't with 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. Yep, definitely agree and good to have a bit of background on that! Thanks @TimothyGu. 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. Thanks for the background indeed! However, I don't know if Still dropping this while the standard is as its current state anyway, it does make sense, thank you all! 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 problem in this particular case is that There would need to either be a method to set general settings for all 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. Indeed that's a problem, that's what had me attempt (poorly) to parse the last object in the list. I don't mind attempting again if the standard does evolve though. If it evolves and if it's worth it. I don't know if it's the case though. |
||
let options = { customInspect: false }; | ||
|
||
if (isOption) { | ||
options = Object.assign(data.splice(-1), options); | ||
} | ||
for (const item of data) { | ||
write(this._ignoreErrors, | ||
this._stdout, | ||
util.inspect(item, options), | ||
this._stdoutErrorHandler, | ||
this[kGroupIndent]); | ||
} | ||
}; | ||
|
||
|
||
Console.prototype.time = function time(label = 'default') { | ||
// Coerces everything other than Symbol to a string | ||
label = `${label}`; | ||
|
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.
Nit: This can be simplified to
Console.prototype.dirxml = Console.prototype.log
as far as I can tell.