From 324f6a0ea30ff1b8fc1ada50abc9e0bad986958b Mon Sep 17 00:00:00 2001 From: Martok Date: Fri, 17 Jun 2022 21:12:01 +0200 Subject: Issue #1918 - m-c 1353693: Correct parsing of async generator methods --- js/src/frontend/Parser.cpp | 19 ++++++++++++++----- js/src/frontend/Parser.h | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index f2d87f52be..cb84a939f6 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -7085,6 +7085,7 @@ JSOpFromPropertyType(PropertyType propType) case PropertyType::Method: case PropertyType::GeneratorMethod: case PropertyType::AsyncMethod: + case PropertyType::AsyncGeneratorMethod: case PropertyType::Constructor: case PropertyType::DerivedConstructor: return JSOP_INITPROP; @@ -7208,7 +7209,7 @@ Parser::classDefinition(YieldHandling yieldHandling, if (propType != PropertyType::Getter && propType != PropertyType::Setter && propType != PropertyType::Method && propType != PropertyType::GeneratorMethod && - propType != PropertyType::AsyncMethod && + propType != PropertyType::AsyncMethod && propType != PropertyType::AsyncGeneratorMethod && propType != PropertyType::Constructor && propType != PropertyType::DerivedConstructor) { errorAt(nameOffset, JSMSG_BAD_METHOD_DEF); @@ -9736,6 +9737,9 @@ Parser::propertyName(YieldHandling yieldHandling, // AsyncMethod[Yield, Await]: // async [no LineTerminator here] PropertyName[?Yield, ?Await] ... // + // AsyncGeneratorMethod[Yield, Await]: + // async [no LineTerminator here] * PropertyName[?Yield, ?Await] ... + // // PropertyName: // LiteralPropertyName // ComputedPropertyName[?Yield, ?Await] @@ -9751,7 +9755,7 @@ Parser::propertyName(YieldHandling yieldHandling, if (!tokenStream.peekTokenSameLine(&tt)) return null(); if (tt == TOK_STRING || tt == TOK_NUMBER || tt == TOK_LB || - TokenKindIsPossibleIdentifierName(tt)) + TokenKindIsPossibleIdentifierName(tt) || tt == TOK_MUL) { isAsync = true; tokenStream.consumeKnownToken(tt); @@ -9891,7 +9895,9 @@ Parser::propertyName(YieldHandling yieldHandling, if (tt == TOK_LP) { tokenStream.ungetToken(); - if (isGenerator) + if (isGenerator && isAsync) + *propType = PropertyType::AsyncGeneratorMethod; + else if (isGenerator) *propType = PropertyType::GeneratorMethod; else if (isAsync) *propType = PropertyType::AsyncMethod; @@ -10169,6 +10175,7 @@ Parser::methodDefinition(uint32_t toStringStart, PropertyType prop case PropertyType::Method: case PropertyType::GeneratorMethod: case PropertyType::AsyncMethod: + case PropertyType::AsyncGeneratorMethod: kind = Method; break; @@ -10184,11 +10191,13 @@ Parser::methodDefinition(uint32_t toStringStart, PropertyType prop MOZ_CRASH("Parser: methodDefinition: unexpected property type"); } - GeneratorKind generatorKind = propType == PropertyType::GeneratorMethod + GeneratorKind generatorKind = (propType == PropertyType::GeneratorMethod || + propType == PropertyType::AsyncGeneratorMethod) ? StarGenerator : NotGenerator; - FunctionAsyncKind asyncKind = (propType == PropertyType::AsyncMethod) + FunctionAsyncKind asyncKind = (propType == PropertyType::AsyncMethod || + propType == PropertyType::AsyncGeneratorMethod) ? AsyncFunction : SyncFunction; diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index 97f6917bd6..1e9028cbee 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -579,6 +579,7 @@ enum class PropertyType { Method, GeneratorMethod, AsyncMethod, + AsyncGeneratorMethod, Constructor, DerivedConstructor }; -- cgit v1.2.3