-
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
console,doc: add inspector console object #15579
Conversation
doc/api/console.md
Outdated
|
||
V8 contexts provide a `console` global object, but by default it's only useful | ||
for sending console messages to attached inspectors. This is provided as a | ||
the `inspector` property of the global `console` object (but not of other |
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.
The a
is to much before the the
.
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.
Whoops! Will fix.
continue; | ||
wrappedConsole[key] = originalConsole[key]; | ||
} | ||
wrappedConsole.inspector = originalConsole; |
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 just completely ignore the dummy inspector methods, i.e. do not expose them at all.
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.
If the inspector methods are not provided, users don't have a way of sending any of the messages that aren't also provided by Console.prototype
to the inspector console.
I had originally thought of exposing something like require('inspector').console
, but I'm not sure that's something I can set up at bootstrap_node.js
time, so console.inspector
seemed to be a good second option.
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.
@bengl I understand that implication. However, I feel it's ugly from a user experience standpoint to require users to use console.inspector ? console.inspector.table : console.table
in polymorphic code: either it should work the way it does everywhere, or it shouldn't.
Also, these console methods only became exposed in 8.0.0, so there isn't much compatibility concern.
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.
For certain functions that inherently do not deal with stdio, like console.markTimeline
, console.profile
, console.profileEnd
, console.timeStamp
, console.timeline
, and console.timelineEnd
, I think we should just keep them as they are and maybe document them. There isn't any work needed by Node.js' Console to "support" those methods because they are no-ops in the console anyway.
That leaves console.debug
, console.dirxml
, and console.table
truly unimplemented Console methods.
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.
@TimothyGu Is that a "-1" opposition or more a "-0"?
test/parallel/test-console.js
Outdated
assert.notStrictEqual(console[name], console.inspector[name]); | ||
} | ||
|
||
// Everything in a v8 console object should be in console.inspector |
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.
Aren't you testing the other direction (i.e. that everything that's on console.inspector
also exsists on the pristineConsole
(i.e. the V8 native)?
So AFAICT the comment should be:
// Everything in `console.inspector` should also be in a v8 pristine console.
@@ -187,3 +188,15 @@ common.hijackStderr(common.mustCall(function(data) { | |||
assert.strictEqual(data.includes('no such label'), true); | |||
}); | |||
})); | |||
|
|||
const pristineConsole = vm.runInNewContext('this.console'); |
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.
Maybe you should skip if require('inspector').url() !== undefined
?
test/parallel/test-console.js
Outdated
const pristineConsole = vm.runInNewContext('this.console'); | ||
for (const name in console.inspector) { | ||
|
||
// No functions on console that do nothing when no inspector is attached |
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'm not sure I understand this comment.
I like this approach. Only thing is this is "non standard", but I agree that this is the second best thing after |
/cc @jasnell since you opened the issue this refs. |
0fa0ad1
to
d9fef0b
Compare
doc/api/console.md
Outdated
@@ -417,6 +417,26 @@ added: v0.1.100 | |||
|
|||
The `console.warn()` function is an alias for [`console.error()`][]. | |||
|
|||
### console.inspector | |||
<!-- YAML | |||
added: XXXX |
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: should be added: REPLACEME
doc/api/console.md
Outdated
added: XXXX | ||
--> | ||
|
||
V8 contexts provide a `console` global object, but by default it's only useful |
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/it's/it is
I'm generally good with this approach. I'd like review from other @nodejs/tsc, however. Left a couple of nit comments. |
Also, remove undocumented (and unusable without inspector) methods from the global console object. Rather than having the undocumented methods on the global console, these methods are now available on the console.inspector object. Fixes: nodejs#12675
d9fef0b
to
2a08479
Compare
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.
Making my -1 explicit.
Given that these methods are already exposed (if undocumented) on the global |
@bengl @TimothyGu what do you think about using |
This will not be needed after #17128 is resolved. Since that ticket is pretty active, I recommend closing this PR. |
Closing due the mentioned alternative. |
Remove undocumented (and unusable without inspector) methods from
the global
console
object.Rather than having the undocumented methods on the global
console
, thesemethods are now available on the
console.inspector
object.Fixes: #12675
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
console, doc