<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [ES6] Implement ES6 arrow function syntax. Parser of arrow function with execution as common function"
   href="https://bugs.webkit.org/show_bug.cgi?id=144955#c80">Comment # 80</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [ES6] Implement ES6 arrow function syntax. Parser of arrow function with execution as common function"
   href="https://bugs.webkit.org/show_bug.cgi?id=144955">bug 144955</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=255426&amp;action=diff" name="attach_255426" title="Patch">attachment 255426</a> <a href="attachment.cgi?id=255426&amp;action=edit" title="Patch">[details]</a></span>
Patch

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

<span class="quote">&gt;&gt; Source/JavaScriptCore/parser/Parser.cpp:355
&gt;&gt; +    while (TreeStatement statement = parseStatement(context, directive, &amp;directiveLiteralLength, functionParseType)) {
&gt; 
&gt; I think using `parseStatement` for ArrowFunctionBodyExpression case is not good.
&gt; Now we have information about it as `functionParseType`.
&gt; so instead of using parseArrowFunctionSingleExpressionBody inside parseStatement, just separate path here and use parseArrowFunctionSingleExpressionBody directly.</span >

Done

<span class="quote">&gt;&gt; Source/JavaScriptCore/parser/Parser.cpp:593
&gt;&gt; +        failDueToUnexpectedToken();
&gt; 
&gt; Why this is needed?</span >

It is raise exception for following statement '=&gt;{a}' 
This function can be run in several cases:
1)  from parseFunctionBody - correct path
2)  during reparsing  - correct path
3)  from parseSourceElements, when js has nor correct statement  '=&gt;{ return a}'  - wrong path

<span class="quote">&gt;&gt; Source/JavaScriptCore/parser/Parser.cpp:615
&gt;&gt; +        next();
&gt; 
&gt; I think `parseType` is always ArrowFunctionParseType. So this is not necessary.</span >

In case of reparsing parseType there will be StandardFunctionParseType

<span class="quote">&gt;&gt; Source/JavaScriptCore/parser/Parser.cpp:1226
&gt;&gt; +#endif
&gt; 
&gt; Drop here.</span >

Done

<span class="quote">&gt;&gt; Source/JavaScriptCore/parser/Parser.cpp:1276
&gt;&gt; +#endif
&gt; 
&gt; Move this into parseSourceElements (at that time, do not loop.)
&gt; So, parseStatement's modification is dropped.</span >

Done

<span class="quote">&gt;&gt; Source/JavaScriptCore/parser/Parser.cpp:1505
&gt;&gt; +    if (const SourceProviderCacheItem* cachedInfo = TreeBuilder::CanUseFunctionCache ? findCachedFunctionInfo(info.startFunctionOffset) : 0) {
&gt; 
&gt; We lookup previously parsed function with info.startFunctionOffset key. But this value is later changed for ArrowFunctionBodyBlock case.
&gt; So when the type is ArrowFunctionBodyBlock, cachedInfo is never hit.
&gt; I've applied this patch to my workingcopy and log the searched `info.startFunctionOffset` and stored offset.
&gt; 
&gt; To test it, be carefull about the function's length. If the length is less than or equal to minimumFunctionLengthToCache, cachedInfo is not created.</span >

I've moved up logic of the checking type of arrow function and setting the info.startFunctionOffset.

<span class="quote">&gt;&gt; Source/JavaScriptCore/parser/Parser.cpp:1575
&gt;&gt; +            info.startFunctionOffset = m_token.m_data.offset;
&gt; 
&gt; Because of this change, ArrowFunctionBodyBlock cache is never hit.</span >

Moved before looking up to cache

<span class="quote">&gt;&gt; Source/JavaScriptCore/parser/Parser.cpp:1620
&gt;&gt; +    unsigned endFunctionOffset = location.startOffset;
&gt; 
&gt; Here, we just use location.startOffset. Is it OK for ArrowFunctionBodyExpression ended with line terminator? (we set info.endFunctionOffset = location.endOffset in the previous block).
&gt; I think dropping this is better to keep consistency with info.endFunctionOffset.</span >

There is no tocken line terminator. So I  end offset + 1 position of the tocken before line terminator.

<span class="quote">&gt;&gt; Source/JavaScriptCore/parser/Parser.cpp:1634
&gt;&gt; +        parameters.endFunctionStartOffset = endFunctionOffset;
&gt; 
&gt; Use info.endFunctionOffset.</span >

Done

<span class="quote">&gt;&gt; Source/JavaScriptCore/parser/Parser.cpp:2059
&gt;&gt; +        return parseArrowFunctionWrapper(context);
&gt; 
&gt; Now, PrimaryExpression part is removed. I think `parseArrowFunctionWrapper` can be renamed to `parseArrowFunctionExpression`.</span >

Done

<span class="quote">&gt;&gt; Source/JavaScriptCore/parser/Parser.cpp:2846
&gt;&gt; +    failIfFalse(match(IDENT) || match(OPENPAREN), &quot;Expected an arrow function input parameter&quot;);
&gt; 
&gt; This condition is guaranteed by `isArrowFunctionParameters()`. So this can be ASSERT.</span >

Done.

<span class="quote">&gt;&gt; Source/JavaScriptCore/parser/SourceCode.h:128
&gt;&gt; +        ASSERT(endArrowFunction &gt;= 1);
&gt; 
&gt; OK, now you updated `endArrowFunction`. So this assertion should be removed, correct?</span >

Correct. It always greater than startArrowFunction and 1. Done</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>