<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <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#c11">Comment # 11</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:gskachkov&#64;gmail.com" title="GSkachkov &lt;gskachkov&#64;gmail.com&gt;"> <span class="fn">GSkachkov</span></a>
</span></b>
        <pre>Comment on <span class="bz_obsolete"><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>

I've uploaded new patch. It is as previous just Draft, but it look more 'mature' for me. Patch covers only 'Function' case in BytecodeGenerator, because creating of lexical_env already implemented in it. If new patch more or less ok in approach to store 'this' I'll try to implement  lexical_env for 'Program' &amp; 'Eval' case

<span class="quote">&gt;&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:485
&gt;&gt; +            RefPtr&lt;RegisterID&gt; parentScope = m_lexicalEnvironmentRegister
&gt; 
&gt; We have a byte code variable m_topMostScope that does what you're doing here, but I think this logic is wrong.
&gt; Consider this program:
&gt; constructor() {
&gt;     if (c) {
&gt;          let x = 20;
&gt;          function captureX() { }
&gt;          if (c) {
&gt;             let x = 20;
&gt;             function captureX() { return x; }
&gt;             let arr = (blah) =&gt; blah;
&gt;          }
&gt;     }
&gt; }
&gt; 
&gt; The &quot;arr&quot; won't be created with the parent scope that contains the &quot;this&quot;.
&gt; 
&gt; I think you just want a resolveScope followed by a getFromScope.</span >

Done

<span class="quote">&gt;&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:2949
&gt;&gt; +        emitPutToScope(scopeRegister(), thisVar, thisRegister(), ThrowIfNotFound, NotInitialization);
&gt; 
&gt; I think special casing &quot;this&quot; as a new thing both in terms of a resolve type
&gt; and in terms of a variable on JSScope is the wrong way to go about implementing this feature.
&gt; 
&gt; Here is one suggestion on how to solve this differently:
&gt; Anytime a function has an arrow function nested inside of it,
&gt; the parent function should create a lexical environment. Once this parent
&gt; function also creates the &quot;this&quot; variable, it should place it inside
&gt; the lexical environment it created. (This solves the problem in this code which keeps putting
&gt; the &quot;this&quot; into the activation every time an arrow function is created
&gt; even if &quot;this&quot; hasn't changed). Any time you make a call to super()
&gt; and you have a nested arrow function, you update the &quot;this&quot; inside
&gt; the lexical environment. Child functions that read from &quot;this&quot; can
&gt; just do so the normal way: resolveScope() then getFromScope().
&gt; 
&gt; The parent function that has the &quot;this&quot; inside the lexical environment
&gt; should just do what it normally does for lexical environments. The &quot;this&quot;
&gt; identifier should have a slot inside the symbol table, etc. I think this
&gt; would take away almost all this special case code for &quot;this&quot;. Then, the &quot;thisNode&quot;,
&gt; when inside an arrow function, should be smart and load the &quot;this&quot; from
&gt; the lexical environment using resolveScope() then getFromScope(). I believe
&gt; this suggested solution will cause &quot;this&quot; inside an environment to just work
&gt; for the most part.</span >

Done. New patch is smaller than previous :-)</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>