New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 760225 link

Starred by 8 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: 2017-10-10
OS: ----
Pri: 2
Type: Bug



Sign in to add a comment

ES6: 'this' is undefined if constructor has arrow function and calls super()

Project Member Reported by allada@chromium.org, Aug 29 2017

Issue description

Run this as a snippet or file and then inspect 'this' when it breakpoints, it will be undefined.

Sample code:
(function() {
class foo {
    constructor() {
    }
}
class bar extends foo {
    constructor() {
        super();
        var b = () => this;
        this.c = 'b'; // <-- Inspect 'this' (it will be undefined)
        debugger;
    }
}

new bar();
})();
 

Comment 1 Deleted

Comment 2 Deleted

Sathya, please take a look!
Cc: adamk@chromium.org
Thanks. Looping in marja as well.
Cc: -adamk@chromium.org marja@chromium.org yangguo@chromium.org
(also actually looping in marja@)

Commenting out the arrow function makes this work.

Scope with the arrow function --
Inner function scope:
function constructor () { // (0x5614a6efb578) (79, 219)
  // strict mode scope
  // 4 heap slots
  // local vars:
  CONST .this_function;  // (0x5614a6efca50) never assigned
  CONST this;  // (0x5614a6efc9f0) forced context allocation, never assigned
  CONST .new.target;  // (0x5614a6efca20) never assigned

  arrow () { // (0x5614a6efd0e8) (117, 127)
    // strict mode scope
    // 4 heap slots
  }
}

Scope without the arrow function --
Inner function scope:
function constructor () { // (0x55b92fd48578) (79, 221)
  // strict mode scope
  // 4 heap slots
  // local vars:
  CONST this;  // (0x55b92fd499f0) never assigned
  CONST .this_function;  // (0x55b92fd49a50) never assigned
  CONST .new.target;  // (0x55b92fd49a20) never assigned
}

This seems counter intuitive to me that the context allocated variable isn't available. The scopes seem correct to me. I'm curious if there's a bug in the way inspector reads the context variables especially the special synthetic ones like 'this' var.


+yang, can you take a look please?
Cc: -yangguo@chromium.org kozyatinskiy@chromium.org
NextAction: 2017-10-10
Owner: yangguo@chromium.org
I will take a look as soon as I get back from Node Interactive (next week).

Does this issue show through inspecting scopes (scopes panel) or via debug-evaluate (console)? There is some mismatch between the two. The scopes panel doesn't correctly show 'this' for arrow functions afair, which also should be fixed.
Looks like this happen in both.
Screenshot from 2017-10-04 16:03:32.png
90.0 KB View Download
The NextAction date has arrived: 2017-10-10

Comment 9 by pledger@google.com, Jun 18 2018

Ping on this bug, as it is still active.

Sign in to add a comment