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

console,doc: add inspector console object #15579

Closed
wants to merge 1 commit into from

Conversation

bengl
Copy link
Member

@bengl bengl commented Sep 23, 2017

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: #12675

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
Affected core subsystem(s)

console, doc

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Sep 23, 2017
@bengl bengl added console Issues and PRs related to the console subsystem. and removed lib / src Issues and PRs related to general changes in the lib or src directory. labels Sep 23, 2017

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
Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@TimothyGu TimothyGu Sep 24, 2017

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.

Copy link
Member

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.

Copy link
Member

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"?

assert.notStrictEqual(console[name], console.inspector[name]);
}

// Everything in a v8 console object should be in console.inspector
Copy link
Contributor

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');
Copy link
Contributor

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?

const pristineConsole = vm.runInNewContext('this.console');
for (const name in console.inspector) {

// No functions on console that do nothing when no inspector is attached
Copy link
Contributor

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.

@refack
Copy link
Contributor

refack commented Sep 24, 2017

I like this approach. Only thing is this is "non standard", but I agree that this is the second best thing after require('inspector').console

@bengl
Copy link
Member Author

bengl commented Sep 24, 2017

/cc @jasnell since you opened the issue this refs.

@@ -417,6 +417,26 @@ added: v0.1.100

The `console.warn()` function is an alias for [`console.error()`][].

### console.inspector
<!-- YAML
added: XXXX
Copy link
Member

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

added: XXXX
-->

V8 contexts provide a `console` global object, but by default it's only useful
Copy link
Member

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

@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 25, 2017
@jasnell
Copy link
Member

jasnell commented Sep 25, 2017

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
Copy link
Member

@TimothyGu TimothyGu left a 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.

@daguej
Copy link
Contributor

daguej commented Nov 6, 2017

Given that these methods are already exposed (if undocumented) on the global console in a LTS release, why not keep and document them? IMO, it makes more sense than moving them to their own nonstandard object (console.inspector?) and breaking things in the process.

@BridgeAR
Copy link
Member

@bengl @TimothyGu what do you think about using require('inspector').console instead?
Because as it is right now, I do not see it landing and that might be a good alternative?

@TimothyGu
Copy link
Member

This will not be needed after #17128 is resolved. Since that ticket is pretty active, I recommend closing this PR.

@BridgeAR
Copy link
Member

Closing due the mentioned alternative.

@BridgeAR BridgeAR closed this Nov 22, 2017
@Trott Trott removed the tsc-review label Dec 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
console Issues and PRs related to the console subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

console: console exposing non-implemented methods
8 participants