<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:sbarati&#64;apple.com" title="Saam Barati &lt;sbarati&#64;apple.com&gt;"> <span class="fn">Saam Barati</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [ES6] Arrow function created before super() causes TDZ, should it?"
   href="https://bugs.webkit.org/show_bug.cgi?id=149338">bug 149338</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Attachment #262397 Flags</td>
           <td>review?
           </td>
           <td>review-
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [ES6] Arrow function created before super() causes TDZ, should it?"
   href="https://bugs.webkit.org/show_bug.cgi?id=149338#c8">Comment # 8</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [ES6] Arrow function created before super() causes TDZ, should it?"
   href="https://bugs.webkit.org/show_bug.cgi?id=149338">bug 149338</a>
              from <span class="vcard"><a class="email" href="mailto:sbarati&#64;apple.com" title="Saam Barati &lt;sbarati&#64;apple.com&gt;"> <span class="fn">Saam Barati</span></a>
</span></b>
        <pre>Comment on <span class=""><a href="attachment.cgi?id=262397&amp;action=diff" name="attach_262397" title="Patch">attachment 262397</a> <a href="attachment.cgi?id=262397&amp;action=edit" title="Patch">[details]</a></span>
Patch

View in context: <a href="https://bugs.webkit.org/attachment.cgi?id=262397&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=262397&amp;action=review</a>

<span class="quote">&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:485
&gt; +            RefPtr&lt;RegisterID&gt; parentScope = m_lexicalEnvironmentRegister</span >

We have a byte code variable m_topMostScope that does what you're doing here, but I think this logic is wrong.
Consider this program:
constructor() {
    if (c) {
         let x = 20;
         function captureX() { }
         if (c) {
            let x = 20;
            function captureX() { return x; }
            let arr = (blah) =&gt; blah;
         }
    }
}

The &quot;arr&quot; won't be created with the parent scope that contains the &quot;this&quot;.

I think you just want a resolveScope followed by a getFromScope.

<span class="quote">&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:2949
&gt; +        emitPutToScope(scopeRegister(), thisVar, thisRegister(), ThrowIfNotFound, NotInitialization);</span >

I think special casing &quot;this&quot; as a new thing both in terms of a resolve type
and in terms of a variable on JSScope is the wrong way to go about implementing this feature.

Here is one suggestion on how to solve this differently:
Anytime a function has an arrow function nested inside of it,
the parent function should create a lexical environment. Once this parent
function also creates the &quot;this&quot; variable, it should place it inside
the lexical environment it created. (This solves the problem in this code which keeps putting
the &quot;this&quot; into the activation every time an arrow function is created
even if &quot;this&quot; hasn't changed). Any time you make a call to super()
and you have a nested arrow function, you update the &quot;this&quot; inside
the lexical environment. Child functions that read from &quot;this&quot; can
just do so the normal way: resolveScope() then getFromScope().

The parent function that has the &quot;this&quot; inside the lexical environment
should just do what it normally does for lexical environments. The &quot;this&quot;
identifier should have a slot inside the symbol table, etc. I think this
would take away almost all this special case code for &quot;this&quot;. Then, the &quot;thisNode&quot;,
when inside an arrow function, should be smart and load the &quot;this&quot; from
the lexical environment using resolveScope() then getFromScope(). I believe
this suggested solution will cause &quot;this&quot; inside an environment to just work
for the most part.

<span class="quote">&gt; Source/JavaScriptCore/jit/JITOperations.cpp:1995
&gt; +    if (getPutInfo.resolveType() == LexicallyBoundVar) {</span >

I think special casing this is wrong. We should just be able to put the &quot;this&quot; identifier into an environment and have this code work.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>