Sitelet https://github.com/nodejs/node/issues/7536
Skip to content

Debugger misbehavior in function called via symbol property reference #7536

Description

@kkeri
  • Version: v4.4.7, v6.2.2
  • Platform: Windows7 64-bit
  • Subsystem: debugger
Steps to Reproduce
  1. Create the file test.js with the following code.
  2. Invoke node debug test.js.
    The debugger stops at line 1.
  3. Type the command 'c'
var S = Symbol();
var o = {
    [S]() {
        console.log("before");
        debugger;
        console.log("at breakpoint");
        console.log("after");
    }
}
o[S]();
Expected Behavior

"before" is printed then the debugger stops at debugger;.

Actual Behavior

"before" is printed and I get a debug> prompt without any code listing.
If I type 'bt' I get the message 'Can't request backtrace now'.
If I type 'list(5)' I get a list when the current line is marked at line 1.
If I type 'c' then "at breakpoint" and "after" is printed and
the program terminates without ever stopping at the breakpoint.

If I change the last line as follows, everything goes fine.

var S = Symbol();
var o = {
    [S]() {
        console.log("before");
        debugger;
        console.log("at breakpoint");
        console.log("after");
    }
}
var f = o[S];
f();

Node Inspector and VS 2015 Node.js tools also show weird behavior with the sample code. Effectively they are unable to stop at the breakpoint in o[S].

Activity

  1. bnoordhuis commented on Jul 5, 2016

    @bnoordhuis
    Member

    Confirmed. The debugger statement generates a v8::Break debug event without a JSON payload, tricking src/debug-agent.cc into thinking that the debug session has terminated. I'll put together a fix.

  2. bnoordhuis commented on Jul 5, 2016

    @bnoordhuis
    Member

    Turns out it's (also) a V8 bug. The JSON-ification of the event data fails with a "Cannot convert a Symbol value to a string" exception, that is why the payload is empty.

  3. bnoordhuis commented on Jul 5, 2016

    @bnoordhuis
    Member
  4. kkeri commented on Jul 6, 2016

    @kkeri
    Author

    @bnoordhuis: Good news. I'm ready to try out the fix as soon as it lands in node.

  5. bnoordhuis commented on Jul 8, 2016

    @bnoordhuis
    Member

    Tracking bug for back-porting the fix to the 5.2 and 5.3 branches: https://bugs.chromium.org/p/v8/issues/detail?id=5191

    I'll take care of back-porting it to older branches.

  6. kkeri commented on Jul 8, 2016

    @kkeri
    Author

    Trying to find a workaround, I ran into a more tricky scenario. It would be nice to see if the proposed fix repairs this one as well.

    This piece of code produces the same effect as my original sample. However if the breakpoint is moved into o.g, it works as expected.

    var S = Symbol();
    var o = {
        [S]() {
            debugger;
            console.log("in o[S]");
        },
        g() {
            console.log("in o.g");
        }
    }
    
    var f = o[S];
    var g = o.g;
    
    f.call(o);
    g.call(o);
  7. kkeri commented on Jul 9, 2016

    @kkeri
    Author

    One more exotic test case just to make sure that it is covered.

    var S = Symbol();
    var o = {
        [S]() {
            debugger;
            console.log("in o[S]");
        },
    }
    var f = o[S].bind(o);
    f();
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

    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