Skip to content

inspect objects with "Symbol" attributes #156

Description

@mmarchini

Inspect commands can't handle Symbol attributes (e.g. @@toStringTag and @@unscopable), resulting in <non-string> properties.

For example, the following code uses the @@toStringTag symbol:

class Bar {
  constructor() {
    this[Symbol.toStringTag] = "Bar";
  }
}

let bar = new Bar();

If we use llnode to find out the properties for bar, it will give the following output:

(lldb) v8 findjsinstances -v Bar
0x0000015078184729:<Object: Bar properties {
    .constructor=0x00000150781846e1:<function: Bar at index.js:17:14>}>
0x0000015078184949:<Object: Bar properties {
    .<non-string>=0x00002d2064acb1e1:<String: "Bar">}>

As you can see, there's a <non-string> property instead of our symbol.

I was looking at llnode and V8 code to try to find a solution, but I'm not sure how to implement it. Did anyone try this before?

Activity

  1. bnoordhuis commented on Dec 9, 2017

    @bnoordhuis
    Member

    Can you try this patch with node.js master? That should add the metadata for symbols although llnode still needs to be taught to use it.

    diff --git a/deps/v8/src/v8.gyp b/deps/v8/src/v8.gyp
    index 89eb271f61..38670c193d 100644
    --- a/deps/v8/src/v8.gyp
    +++ b/deps/v8/src/v8.gyp
    @@ -2452,6 +2452,8 @@
                 'objects-inl.h',
                 'objects/map.h',
                 'objects/map-inl.h',
    +            'objects/name.h',
    +            'objects/name-inl.h',
                 'objects/script.h',
                 'objects/script-inl.h',
                 'objects/shared-function-info.h',
    diff --git a/deps/v8/tools/gen-postmortem-metadata.py b/deps/v8/tools/gen-postmortem-metadata.py
    index 22f0afbef3..5f33fdebe9 100644
    --- a/deps/v8/tools/gen-postmortem-metadata.py
    +++ b/deps/v8/tools/gen-postmortem-metadata.py
    @@ -417,15 +417,10 @@ def load_objects_from_file(objfilename, checktypes):
             # way around.
             #
             for type in types:
    -                #
    -                # Symbols and Strings are implemented using the same classes.
    -                #
    -                usetype = re.sub('SYMBOL_', 'STRING_', type);
    -
                     #
                     # REGEXP behaves like REG_EXP, as in JS_REGEXP_TYPE => JSRegExp.
                     #
    -                usetype = re.sub('_REGEXP_', '_REG_EXP_', usetype);
    +                usetype = re.sub('_REGEXP_', '_REG_EXP_', type);
     
                     #
                     # Remove the "_TYPE" suffix and then convert to camel case,

    That gives you these:

    $ nm out/Release/node | grep -i v8dbg.*symbol
    0000000101596d58 D _v8dbg_class_Symbol__flags__SMI
    0000000101596d54 D _v8dbg_class_Symbol__name__Object
    000000010159ece4 S _v8dbg_parent_Symbol__Name
    0000000101596a50 D _v8dbg_type_Symbol__SYMBOL_TYPE
    
  2. mmarchini commented on Jul 12, 2018

    @mmarchini
    ContributorAuthor

    @bnoordhuis yes, this patch is enough on the V8 side. Will you submit a CL with these changes?

  3. mmarchini commented on Jul 23, 2018

    @mmarchini
    ContributorAuthor

    @bnoordhuis would you mind if I open a CL with these changes, or do you want to do it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions