镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

@TimothyGu

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

Activity

  1. added
    utilIssues and PRs related to the built-in util module.
    on Mar 16, 2017
  2. hashseed commented on Mar 16, 2017

    @hashseed
    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.

  3. hashseed commented on Mar 16, 2017

    @hashseed
    Member

    @ofrobots already has an eye on this afaik.

  4. TimothyGu commented on Mar 16, 2017

    @TimothyGu
    MemberAuthor

    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.

  5. hashseed commented on Mar 16, 2017

    @hashseed
    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.

  6. ofrobots commented on Mar 16, 2017

    @ofrobots
    Contributor

    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.

  7. Trott commented on Jul 30, 2017

    @Trott
    Member

    This should remain open?

  8. bnoordhuis commented on Jul 30, 2017

    @bnoordhuis
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    utilIssues and PRs related to the built-in util module.v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions