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

inspector: add inspector console support for native Console #7988

Closed
wants to merge 1 commit into from
Closed

inspector: add inspector console support for native Console #7988

wants to merge 1 commit into from

Conversation

alexkozy
Copy link
Member

@alexkozy alexkozy commented Aug 5, 2016

Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

console

Description of change

When node is running with --inspect flag, default console.log,
console.warn and other methods call inspector console methods in
addition to current behaviour (dump formatted message to stderr
and stdout). Inspector console methods forward message to DevTools and
show its in DevTools Console with DevTools formatters. Inspector console
methods not presented on Node console will be added into it.

Only own methods on global.console object will be changed while
debugging session. User still able to redefine it, use console.Console
or change original methods on Console.prototype.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. console Issues and PRs related to the console subsystem. lib / src Issues and PRs related to general changes in the lib or src directory. inspector Issues and PRs related to the V8 inspector protocol labels Aug 5, 2016
@alexkozy
Copy link
Member Author

alexkozy commented Aug 5, 2016

/cc @ofrobots @eugeneo

@jasnell
Copy link
Member

jasnell commented Aug 5, 2016

@bnoordhuis @ofrobots @trevnorris ...

@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Aug 5, 2016
@@ -3299,6 +3338,15 @@ void SetupProcessObject(Environment* env,
env->SetMethod(process, "_setupPromises", SetupPromises);
env->SetMethod(process, "_setupDomainUse", SetupDomainUse);

#if HAVE_INSPECTOR
// process.inspector
if (use_inspector) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to suggest moving this block (and 2 functions above) into inspector_agent.{h,cc} - this way there will be less conditional compilation to maintain.

@alexkozy
Copy link
Member Author

alexkozy commented Aug 5, 2016

/cc @dgozman

@mscdex
Copy link
Contributor

mscdex commented Aug 5, 2016

Wouldn't it be possible to instead store copies of the original console functions, which would allow us to avoid having to modify console.js at all? Having to make those console.js changes just for inspector makes me cringe.

@alexkozy
Copy link
Member Author

alexkozy commented Aug 6, 2016

I addressed your comments and moved all changes into inspector_agent.cc and bootstrap_node.js.
Please take another look!

}

v8::Local<v8::Array> array = v8::Array::New(env->isolate());
for (int i = 0; i < args.Length(); ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check that arguments are functions here.

@alexkozy
Copy link
Member Author

alexkozy commented Aug 6, 2016

Addressed all comments, please take another look!

if (process.inspector) {
inspectorConsole = global.console;
wrapConsoleCall = process.inspector.wrapConsoleCall;
delete process.inspector.sequentally;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a s/sequentally/sequentially/ typo here.

Environment* env = Environment::GetCurrent(args);

if (args.Length() != 3 || !args[0]->IsFunction()
|| !args[1]->IsFunction() || !args[2]->IsObject()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: operator should go on previous line.

@alexkozy
Copy link
Member Author

alexkozy commented Aug 7, 2016

addressed comments, please take another look.

}

node_method.As<v8::Function>()->Call(context, info.Holder(), call_args.size(),
call_args.data());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: arguments should line up.

@bnoordhuis
Copy link
Member

LGTM with a suggestion and a nit. CI: https://ci.nodejs.org/job/node-test-pull-request/3559/

@alexkozy
Copy link
Member Author

alexkozy commented Aug 7, 2016

Thanks! All done. It looks like freebsd test failure doesn't relate to this pull request.

@jasnell
Copy link
Member

jasnell commented Aug 8, 2016

LGTM

if (process.inspector) {
inspectorConsole = global.console;
wrapConsoleCall = process.inspector.wrapConsoleCall;
delete process.inspector.wrapConsoleCall;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if inspector wasn't a public property on process (except during startup). Could you get away with deleting process.inspector here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove process.inspector here. Done.

@alexkozy
Copy link
Member Author

alexkozy commented Aug 8, 2016

All done. Please take another look!

@ofrobots
Copy link
Contributor

ofrobots commented Aug 8, 2016

if (!inspectorConsole.hasOwnProperty(key))
continue;
// If node console has the same method as inspector console,
// then wrap this two methods into one. Native wrapper will preserve
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grammar nit: "then wrap these two methods..."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, "will preserve the original stack"

@alexkozy
Copy link
Member Author

alexkozy commented Aug 9, 2016

Thanks for review.
Fixed grammar.


if (args.Length() != 3 || !args[0]->IsFunction() ||
!args[1]->IsFunction() || !args[2]->IsObject()) {
return env->ThrowError("Bad argument.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer the error message to be a bit more descriptive

@jasnell
Copy link
Member

jasnell commented Aug 9, 2016

LGTM with a nit

@alexkozy
Copy link
Member Author

alexkozy commented Aug 9, 2016

Done.

@ofrobots
Copy link
Contributor

@alexkozy
Copy link
Member Author

This time it was failed on https://ci.nodejs.org/job/node-compile-windows/3631/label=win-vs2015/console .
I compare output with previous successful build and it looks like difference at the end of output:
c:\workspace\node-compile-windows\label\win-vs2015>exit 0
FATAL: java.io.IOException: Connection aborted: org.jenkinsci.remoting.nio.NioChannelHub$MonoNioTransport@6034828e[name=test-rackspace-win2012r2-x64-6] ...

It looks like it doesn't relate to my change, does it?

@ofrobots
Copy link
Contributor

That seems to be infrastructure related. Windows did pass on the previous build. I think this is good to land. I will do so tomorrow.

When node is running with --inspect flag, default console.log,
console.warn and other methods call inspector console methods in
addition to current behaviour (dump formatted message to stderr
and stdout). Inspector console methods forward message to DevTools and
show its in DevTools Console with DevTools formatters. Inspector console
methods not presented on Node console will be added into it.

Only own methods on global.console object will be changed while
debugging session. User still able to redefine it, use console.Console
or change original methods on Console.prototype.
@alexkozy
Copy link
Member Author

I've rebased this pull request to resolve conflicts.

@ofrobots
Copy link
Contributor

Thanks, landed as f6070a1.

@ofrobots ofrobots closed this Aug 12, 2016
ofrobots pushed a commit that referenced this pull request Aug 12, 2016
When node is running with --inspect flag, default console.log,
console.warn and other methods call inspector console methods in
addition to current behaviour (dump formatted message to stderr and
stdout). Inspector console methods forward message to DevTools and
show up in DevTools Console with DevTools formatters. Inspector
console methods not present on Node console will be added into it.

Only own methods on global.console object will be changed while in a
debugging session. User are still able to redefine it, use
console.Console or change original methods on Console.prototype.

PR-URL: #7988
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
Reviewed-By: ofrobots - Ali Ijaz Sheikh <ofrobots@google.com>
@ofrobots
Copy link
Contributor

Looks great, btw:

// ...
http.get('http://www.google.com/index.html', (res) => {
  console.log(res);
  res.resume();
});

image

cjihrig pushed a commit that referenced this pull request Aug 15, 2016
When node is running with --inspect flag, default console.log,
console.warn and other methods call inspector console methods in
addition to current behaviour (dump formatted message to stderr and
stdout). Inspector console methods forward message to DevTools and
show up in DevTools Console with DevTools formatters. Inspector
console methods not present on Node console will be added into it.

Only own methods on global.console object will be changed while in a
debugging session. User are still able to redefine it, use
console.Console or change original methods on Console.prototype.

PR-URL: #7988
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
Reviewed-By: ofrobots - Ali Ijaz Sheikh <ofrobots@google.com>
@cjihrig cjihrig mentioned this pull request Aug 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. console Issues and PRs related to the console subsystem. inspector Issues and PRs related to the V8 inspector protocol lib / src Issues and PRs related to general changes in the lib or src directory. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants