Ignore:
Timestamp:
Aug 30, 2020, 6:26:30 PM (5 years ago)
Author:
[email protected]
Message:

[JSC] async function cannot appear in single-statement context
https://bugs.webkit.org/show_bug.cgi?id=215993

Reviewed by Darin Adler.

JSTests:

  • stress/async-function-lookahead.js: Added.

(testSyntax):
(testSyntaxError):
(testSyntax.false.async t):
(testSyntaxError.false.async t):

  • test262/expectations.yaml:

Source/JavaScriptCore:

The following code is syntax error[1] because ExpressionStatement has async [no LineTerminator here] function lookahead.

if (false)

async function t() { }

[1]: https://tc39.es/ecma262/#sec-expression-statement

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseStatement):
(JSC::Parser<LexerType>::maybeParseAsyncFunctionDeclarationStatement): Deleted.

  • parser/Parser.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r266327 r266340  
    19831983    case IDENT:
    19841984        if (UNLIKELY(*m_token.m_data.ident == m_vm.propertyNames->async && !m_token.m_data.escaped)) {
    1985             if (maybeParseAsyncFunctionDeclarationStatement(context, result, parentAllowsFunctionDeclarationAsStatement))
    1986                 break;
     1985            SavePoint savePoint = createSavePoint(context);
     1986            next();
     1987            failIfTrue(match(FUNCTION) && !m_lexer->hasLineTerminatorBeforeToken(), "Cannot use async function declaration in single-statement context");
     1988            restoreSavePoint(context, savePoint);
    19871989        }
    19881990        FALLTHROUGH;
     
    20662068    popScope(blockScope, TreeBuilder::NeedsFreeVariableInfo);
    20672069    return result;
    2068 }
    2069 
    2070 template <typename LexerType>
    2071 template <class TreeBuilder> bool Parser<LexerType>::maybeParseAsyncFunctionDeclarationStatement(TreeBuilder& context, TreeStatement& result, bool parentAllowsFunctionDeclarationAsStatement)
    2072 {
    2073     ASSERT(matchContextualKeyword(m_vm.propertyNames->async));
    2074     SavePoint savePoint = createSavePoint(context);
    2075     next();
    2076     if (match(FUNCTION) && !m_lexer->hasLineTerminatorBeforeToken()) {
    2077         const bool isAsync = true;
    2078         result = parseFunctionDeclarationStatement(context, isAsync, parentAllowsFunctionDeclarationAsStatement);
    2079         return true;
    2080     }
    2081     restoreSavePoint(context, savePoint);
    2082     return false;
    20832070}
    20842071
Note: See TracChangeset for help on using the changeset viewer.