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

Find an alternative to V8's Debug Mirror API for util.inspect #11875

Closed
TimothyGu opened this issue Mar 16, 2017 · 7 comments
Closed

Find an alternative to V8's Debug Mirror API for util.inspect #11875

TimothyGu opened this issue Mar 16, 2017 · 7 comments
Labels
util Issues and PRs related to the built-in util module. v8 engine Issues and PRs related to the V8 dependency.

Comments

@TimothyGu
Copy link
Member

Currently we are able to display certain hidden properties of objects from util.inspect through the V8 debug context's MakeMirror:

  • Promise status and value:

    node/lib/util.js

    Lines 287 to 288 in e296ffb

    const mirror = Debug.MakeMirror(p, true);
    return {status: mirror.status(), value: mirror.promiseValue().value_};
  • Collection iterator:

    node/lib/util.js

    Lines 739 to 741 in e296ffb

    const mirror = Debug.MakeMirror(value, true);
    var nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1;
    var vals = mirror.preview();

While it works just fine currently, the V8 debugger API will be deprecated in V8 5.9 in favor of the v8 inspector API. We'll need to find a way to use the inspector API for this purpose.

/cc @nodejs/v8

@TimothyGu TimothyGu added the v8 engine Issues and PRs related to the V8 dependency. label Mar 16, 2017
@mscdex mscdex added the util Issues and PRs related to the built-in util module. label Mar 16, 2017
@hashseed
Copy link
Member

The functionality you are looking for are exposed directly in the V8 API. Take a look at v8::Map, v8::Set, and v8::Promise. No need to go through the inspector.

@hashseed
Copy link
Member

@ofrobots already has an eye on this afaik.

@TimothyGu
Copy link
Member Author

Ahh I was only looking at the v8.h in the current Node.js tree which doesn't have v8::Promise::Result() etc. However, I'm still not sure how one would be able to inspect an iterator object. While there is v8::Value::IsMapIterator() there isn't a corresponding v8::MapIterator class to provide information about the current index of the iterator.

Either way I'm glad there's someone on top of this already.

@hashseed
Copy link
Member

I guess we could consider adding an API for Map- and SetIterators. Then again, the inspector actually also offers the set of functionality you are looking for.

Take a look at this inspector test and its expected result.

@ofrobots
Copy link
Contributor

ofrobots commented Mar 16, 2017

Yes, I have been tracking the migration of the Debug context. The idea that either we can start using bona fide V8 apis (e.g. to inspect promises) or use the inspector in-process. The latter depends on the inspector being available in-process to JavaScript, which is dependent on a few changes, the first of which is #11431, which is currently blocked on reviews.

TimothyGu added a commit to TimothyGu/node that referenced this issue Apr 8, 2017
PR-URL: nodejs#12254
Refs: nodejs#11875
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Josh Gavant <josh.gavant@outlook.com>
@Trott
Copy link
Member

Trott commented Jul 30, 2017

This should remain open?

@bnoordhuis
Copy link
Member

An alternative to Debug.MakeMirror() is in #13295.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
util Issues and PRs related to the built-in util module. v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

6 participants