<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [JSC] implement async functions proposal"
   href="https://bugs.webkit.org/show_bug.cgi?id=156147#c73">Comment # 73</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [JSC] implement async functions proposal"
   href="https://bugs.webkit.org/show_bug.cgi?id=156147">bug 156147</a>
              from <span class="vcard"><a class="email" href="mailto:utatane.tea&#64;gmail.com" title="Yusuke Suzuki &lt;utatane.tea&#64;gmail.com&gt;"> <span class="fn">Yusuke Suzuki</span></a>
</span></b>
        <pre>Comment on <span class=""><a href="attachment.cgi?id=277938&amp;action=diff" name="attach_277938" title="Patch">attachment 277938</a> <a href="attachment.cgi?id=277938&amp;action=edit" title="Patch">[details]</a></span>
Patch

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

Nice.

Seeing the code, it seems that AsyncArrowFunctionMode / AsyncArrowFunctionBodyMode cases are sometimes missing.
Can AsyncArrowFunctionBodyMode become an arrow function?

<span class="quote">&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:245
&gt; +    bool containsArrowOrEvalButNotInArrowBlock = ((functionNode-&gt;usesArrowFunction() &amp;&amp; functionNode-&gt;doAnyInnerArrowFunctionsUseAnyFeature()) || functionNode-&gt;usesEval()) &amp;&amp; (!m_codeBlock-&gt;isArrowFunction() &amp;&amp; !m_codeBlock-&gt;isAsyncArrowFunction());</span >

Can we change this to the new `isArrowFunction()` including ArrowFunction / AsyncArrowFunction?
Or is there any obstacles?

<span class="quote">&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:624
&gt; +        emitLabel(didNotThrow.get());</span >

This phase is used when we encounter `async function (param = throwError()) { }`, right?
Looks correct.

<span class="quote">&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:630
&gt; +    if (SourceParseMode::ArrowFunctionMode == parseMode || SourceParseMode::AsyncArrowFunctionBodyMode == parseMode || SourceParseMode::AsyncArrowFunctionMode == parseMode || SourceParseMode::AsyncArrowFunctionMode == parseMode) {</span >

AsyncArrowFunctionMode is duplicated.

<span class="quote">&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:631
&gt; +        if (functionNode-&gt;usesThis() || functionNode-&gt;usesSuperProperty() || isSuperUsedInInnerArrowFunction())</span >

Nice.

<span class="quote">&gt; Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:2906
&gt; +    ASSERT(func-&gt;metadata()-&gt;parseMode() == SourceParseMode::ArrowFunctionMode || func-&gt;metadata()-&gt;parseMode() == SourceParseMode::AsyncArrowFunctionMode);</span >

Is it safe for AsyncArrowFunctionBodyMode with single line expression?

<span class="quote">&gt; Source/JavaScriptCore/parser/Parser.cpp:255
&gt; +    bool isArrowFunctionBodyExpression = parseMode == SourceParseMode::AsyncArrowFunctionBodyMode &amp;&amp; !match(OPENBRACE);</span >

Can we move this `parseMode == SourceParseMode::AsyncArrowFunctionBodyMode` to L263?

<span class="quote">&gt; Source/JavaScriptCore/parser/Parser.cpp:552
&gt; +        asyncFunctionBodyScope-&gt;setSourceParseMode(innerParseMode);</span >

This part is changed in the latest trunk, so rebasing. :)

<span class="quote">&gt; Source/JavaScriptCore/parser/Parser.cpp:619
&gt; +            // Eagerly parse as AsyncFUnctionDeclaration. This is the uncommon case,</span >

Typo: AsyncFUnctionDeclaration =&gt; AsyncFunctionDeclaration

<span class="quote">&gt; Source/JavaScriptCore/parser/Parser.cpp:625
&gt; +                result = parseAsyncFunctionDeclaration(context);</span >

Let's break here, call restoreSavePoint(savePoint); and fall through to the await / field path.

<span class="quote">&gt; Source/JavaScriptCore/parser/Parser.cpp:1796
&gt; +                    result = parseAsyncFunctionDeclaration(context);</span >

These code is largely the same to the FUNCTION case. So extracting this to some function is recommended.

<span class="quote">&gt; Source/JavaScriptCore/parser/Parser.cpp:1797
&gt; +                }</span >

Nit: breaking here may clean up the following code :)

<span class="quote">&gt; Source/JavaScriptCore/parser/Parser.cpp:2268
&gt; +        if (mode != SourceParseMode::AsyncArrowFunctionMode) {
&gt; +            semanticFailIfTrue(generatorBodyScope-&gt;hasDirectSuper(), &quot;super is not valid in this context&quot;);
&gt; +            if (generatorBodyScope-&gt;needsSuperBinding())
&gt; +                semanticFailIfTrue(expectedSuperBinding == SuperBinding::NotNeeded, &quot;super can only be used in a method of a derived class&quot;);
&gt; +        } else {
&gt; +            if (generatorBodyScope-&gt;hasDirectSuper())
&gt; +                functionScope-&gt;setHasDirectSuper();
&gt; +            if (generatorBodyScope-&gt;needsSuperBinding())
&gt; +                functionScope-&gt;setNeedsSuperBinding();
&gt; +        }</span >

These checks are now done in parsing location. Let's remove this.
When removing this, maybe, we need to recheck that closestParentOrdinaryFunctionNonLexicalScope works correctly with async arrow wrapper / body functions.

<span class="quote">&gt; Source/JavaScriptCore/parser/Parser.cpp:3197
&gt; +                next();</span >

Is it necessary to create a save point here? Can we just call `semanticFailIfFalse(match(FUNCTION) &amp;&amp; !m_lexer-&gt;prevTerminator(), &quot;...&quot;)` ?

<span class="quote">&gt; Source/JavaScriptCore/parser/Parser.cpp:3318
&gt;      }</span >

Handling async arrow function here seems natural :)

<span class="quote">&gt; Source/JavaScriptCore/parser/Parser.cpp:3602
&gt; +        }</span >

Is this safe for `async get value() { }`?

<span class="quote">&gt; Source/JavaScriptCore/parser/Parser.cpp:4014
&gt; +        }</span >

Which tests need this?

<span class="quote">&gt; Source/JavaScriptCore/parser/Parser.cpp:4221
&gt; +                failIfFalse(base, &quot;Failed to parse async function expression&quot;);</span >

Why is this handled here? Can we handle `async function` case in parsePrimaryExpression?
And can we parse async arrow function in parseAssignmentExpression? (At that case, we check `async IDENT =&gt;` in parsePrimaryExpression similar to the current arrow function parsing).

<a href="https://tc39.github.io/ecmascript-asyncawait/#prod-UnaryExpression">https://tc39.github.io/ecmascript-asyncawait/#prod-UnaryExpression</a>

<span class="quote">&gt; Source/JavaScriptCore/runtime/CodeCache.cpp:226
&gt; +    ConstructAbility constructAbility;
&gt; +    switch (metadata-&gt;parseMode()) {
&gt; +    case SourceParseMode::NormalFunctionMode:
&gt; +        // let allocKind be &quot;constructor&quot;.
&gt; +        constructAbility = ConstructAbility::CanConstruct;
&gt; +        break;
&gt; +
&gt; +    case SourceParseMode::GeneratorBodyMode:
&gt; +    case SourceParseMode::GeneratorWrapperFunctionMode:
&gt; +    case SourceParseMode::GetterMode:
&gt; +    case SourceParseMode::SetterMode:
&gt; +    case SourceParseMode::MethodMode:
&gt; +    case SourceParseMode::ArrowFunctionMode:
&gt; +    case SourceParseMode::AsyncFunctionBodyMode:
&gt; +    case SourceParseMode::AsyncArrowFunctionBodyMode:
&gt; +    case SourceParseMode::AsyncFunctionMode:
&gt; +    case SourceParseMode::AsyncMethodMode:
&gt; +    case SourceParseMode::AsyncArrowFunctionMode:
&gt; +        // let allocKind be &quot;non-constructor&quot;.
&gt; +        constructAbility = ConstructAbility::CannotConstruct;
&gt; +        break;
&gt; +
&gt; +    case SourceParseMode::ProgramMode:
&gt; +    case SourceParseMode::ModuleAnalyzeMode:
&gt; +    case SourceParseMode::ModuleEvaluateMode:
&gt; +        RELEASE_ASSERT_NOT_REACHED();
&gt; +        break;</span >

Could you extract this to static function?

<span class="quote">&gt; Source/JavaScriptCore/runtime/CommonIdentifiers.h:36
&gt; +    macro(AsyncFunction) \</span >

Let's remove this.</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>