Skip to content

Commit

Permalink
Bug 1713155 - Ensure correct handling of await in class static bloc…
Browse files Browse the repository at this point in the history
…k r=arai

This has been verified with the current version of
tc39/test262#2968, rev a502d69

Differential Revision: https://phabricator.services.mozilla.com/D119793
  • Loading branch information
mgaudet committed Jul 14, 2021
1 parent f782e6d commit 1f37508
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 6 additions & 3 deletions js/src/frontend/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3524,8 +3524,9 @@ bool GeneralParser<ParseHandler, Unit>::functionFormalParametersAndBody(
// function bodies are parsed with different yield/await settings.
{
AwaitHandling awaitHandling =
(funbox->isAsync() ||
(kind == FunctionSyntaxKind::Arrow && awaitIsKeyword()))
kind == FunctionSyntaxKind::StaticClassBlock ? AwaitIsDisallowed
: (funbox->isAsync() ||
(kind == FunctionSyntaxKind::Arrow && awaitIsKeyword()))
? AwaitIsKeyword
: AwaitIsName;
AutoAwaitIsKeyword<ParseHandler, Unit> awaitIsKeyword(this, awaitHandling);
Expand Down Expand Up @@ -8386,6 +8387,8 @@ GeneralParser<ParseHandler, Unit>::staticClassBlock(
FunctionFlags flags =
InitialFunctionFlags(syntaxKind, generatorKind, asyncKind, isSelfHosting);

AutoAwaitIsKeyword awaitIsKeyword(this, AwaitHandling::AwaitIsDisallowed);

// Create the function node for the static class body.
FunctionNodeType funNode = handler_.newFunction(syntaxKind, pos());
if (!funNode) {
Expand Down Expand Up @@ -10749,7 +10752,7 @@ bool GeneralParser<ParseHandler, Unit>::checkLabelOrIdentifierReference(
return true;
}
if (tt == TokenKind::Await) {
if (awaitIsKeyword()) {
if (awaitIsKeyword() || awaitIsDisallowed()) {
errorAt(offset, JSMSG_RESERVED_ID, "await");
return false;
}
Expand Down
10 changes: 8 additions & 2 deletions js/src/frontend/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ enum class PropertyType {
enum AwaitHandling : uint8_t {
AwaitIsName,
AwaitIsKeyword,
AwaitIsModuleKeyword
AwaitIsModuleKeyword,
AwaitIsDisallowed
};

template <class ParseHandler, typename Unit>
Expand Down Expand Up @@ -309,7 +310,11 @@ class MOZ_STACK_CLASS ParserBase : public ParserSharedBase,
bool inParametersOfAsyncFunction_ : 1;

public:
bool awaitIsKeyword() const { return awaitHandling_ != AwaitIsName; }
bool awaitIsKeyword() const {
return awaitHandling_ == AwaitIsKeyword ||
awaitHandling_ == AwaitIsModuleKeyword;
}
bool awaitIsDisallowed() const { return awaitHandling_ == AwaitIsDisallowed; }

bool inParametersOfAsyncFunction() const {
return inParametersOfAsyncFunction_;
Expand Down Expand Up @@ -698,6 +703,7 @@ class MOZ_STACK_CLASS GeneralParser : public PerHandlerParser<ParseHandler> {
using Base::PredictUninvoked;

using Base::alloc_;
using Base::awaitIsDisallowed;
using Base::awaitIsKeyword;
using Base::inParametersOfAsyncFunction;
using Base::parseGoal;
Expand Down

0 comments on commit 1f37508

Please sign in to comment.