<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#c45">Comment # 45</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=""><a href="attachment.cgi?id=264022&amp;action=diff" name="attach_264022" title="Patch">attachment 264022</a> <a href="attachment.cgi?id=264022&amp;action=edit" title="Patch">[details]</a></span>
Patch

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

<span class="quote">&gt;&gt; Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.h:163
&gt;&gt; +    unsigned m_isDerivedConstructorContext: 1;
&gt; 
&gt; style: &quot;m_isDerivedConstructorContext:&quot; =&gt; &quot;m_isDerivedConstructorContext :&quot;</span >

Done

<span class="quote">&gt;&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:807
&gt;&gt; +void BytecodeGenerator::initializeEmptyVarLexicalEnvironmentIfNeeded(SymbolTable* systemTable)
&gt; 
&gt; &quot;systemTable&quot; =&gt; &quot;symbolTable&quot;
&gt; I also don't like the name &quot;initializeEmptyVarLexicalEnvironmentIfNeeded&quot;. It doesn't really mean what you're doing here.
&gt; I think a better name would be something along the lines of: &quot;initializeArrowFunctionContextScopeIfNeeded&quot;.</span >

Done

<span class="quote">&gt;&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:821
&gt;&gt; +            if (m_codeType == FunctionCode) {
&gt; 
&gt; Aren't there more specific situations where we need this? Like if we're in a derived constructor context?</span >

I've decided to include into this patch the implementation of lexically binding of new.target for all cases, because it is required small changes in comparison to patch without it( current condition + condition to load new.target into function context + tests)  
new.target is always exist for function and lexically bound to the arrow function

<span class="quote">&gt;&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:849
&gt;&gt; +    m_arrowFunctionVarLexicalEnvRegister = emitMove(newRegister(), m_scopeRegister);
&gt; 
&gt; I think you want &quot;newBlockScopeVariable&quot; instead of &quot;newRegister&quot;</span >

fixed

<span class="quote">&gt;&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:2981
&gt;&gt; +void BytecodeGenerator::emitUpdateScopeIfNeeded()
&gt; 
&gt; I think a better name for this would be something like:
&gt; &quot;emitUpdateArrowFunctionContextScope&quot;.
&gt; This names seems to general. It would be good to pin it down to being arrowfunction-related.</span >

OK. I think  emitUpdateVariablesInArrowFunctionContextScope will be better, because we change values of the variables in arrow function scope?

<span class="quote">&gt;&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:2996
&gt;&gt; +void BytecodeGenerator::emitPutThisToScope()
&gt; 
&gt; Again, I would signify in the name that this is related to arrow functions.</span >

Renamed to emitPutThisToArrowFunctionContextScope

<span class="quote">&gt;&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:3897
&gt;&gt; +void BytecodeGenerator::emitGetNewTargeFromArrowFunctionLexicalEnvironment()
&gt; 
&gt; typo: &quot;emitGetNewTarge...&quot; =&gt; &quot;emitGetNewTarget...&quot;</span >

fixed

<span class="quote">&gt;&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h:827
&gt;&gt; +        RegisterID* m_arrowFunctionVarLexicalEnvRegister { nullptr };
&gt; 
&gt; nit: I would call this something like: &quot;m_arrowFunctionContextLexicalEnvironmentRegister&quot;.
&gt; I think &quot;var&quot; is the wrong word here.</span >

renamed

<span class="quote">&gt;&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h:828
&gt;&gt; +        RegisterID* m_arrowFunctionResolvedLexicalEnvRegister { nullptr };
&gt; 
&gt; style: I would spell out &quot;Environment&quot; in this name, even though it's verbose.</span >

Done

<span class="quote">&gt;&gt; Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:699
&gt;&gt; +// We need try to load 'this' before call eval, because it can created by 'super' in some of the arrow function
&gt; 
&gt; style: Indent this.
&gt; Also, I'm a bit confused about this. Do we get the current function's &quot;this&quot; when making a function call?</span >

I think it has to rewritten -&gt; // We need try to load 'this' before call eval in constructor, because 'this' can created by 'super' in some of the arrow function
It is necessary to cover following case :
     var A = class A {
       constructor () { this.id = 'A'; }
     }

     var B = class B extend A {
        constructor () {
           var arrow = () =&gt; super();
           arrow();
           eval(&quot;this.id = 'B'&quot;);
        }
     }
    new B();

<span class="quote">&gt;&gt; Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:738
&gt;&gt; +                &amp;&amp; (generator.usesArrowFunction() || generator.usesEval())))
&gt; 
&gt; style: I'd move this to the above line.
&gt; WebKit style says that this should be 4 spaces from the indentation of the &quot;if&quot;, which would look bad here. I would just move it one line up.</span >

I've changed, now it has two variable and condition in one line:
    bool isConstructorKindDerived = generator.constructorKind() == ConstructorKind::Derived;
    bool usesArrowFunctionOrEval  = generator.usesArrowFunction() || generator.usesEval();
    if (generator.isDerivedConstructorContext() || (isConstructorKindDerived &amp;&amp; usesArrowFunctionOrEval))</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>