Skip to content

Commit 5ab0e22

Browse files
Kenji Fukudakfarnung
Kenji Fukuda
authored andcommitted
deps: update ChakraCore to chakra-core/ChakraCore@75ebad82b0
[MERGE #5482 @kfukuda2] Fixing labels, should throw syntax errors when labels are followed by lexical declarations Fixes nodejs#352 Merge pull request #5482 from kfukuda2:LabelsGrammarFix Fixes nodejs#352 Reviewed-By: chakrabot <[email protected]>
1 parent 49609c6 commit 5ab0e22

19 files changed

+439
-193
lines changed

deps/chakrashim/core/lib/Parser/Parse.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8442,6 +8442,10 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
84428442
}
84438443
}
84448444
}
8445+
else if (nop == knopAwait && m_token.tk == tkColon)
8446+
{
8447+
Error(ERRAwaitAsLabelInAsync);
8448+
}
84458449
else
84468450
{
84478451
// Disallow spread after a unary operator.
@@ -9573,6 +9577,7 @@ ParseNodePtr Parser::ParseStatement()
95739577
uint fnop;
95749578
bool expressionStmt = false;
95759579
bool isAsyncMethod = false;
9580+
bool labelledStatement = false;
95769581
tokens tok;
95779582
#if EXCEPTION_RECOVERY
95789583
ParseNodeTryCatch * pParentTryCatch = nullptr;
@@ -9625,6 +9630,10 @@ ParseNodePtr Parser::ParseStatement()
96259630
switch (tok)
96269631
{
96279632
case tkEOF:
9633+
if (labelledStatement)
9634+
{
9635+
Error(ERRLabelFollowedByEOF);
9636+
}
96289637
if (buildAST)
96299638
{
96309639
pnode = nullptr;
@@ -9646,6 +9655,25 @@ ParseNodePtr Parser::ParseStatement()
96469655
{
96479656
pnode = ParseFncDeclCheckScope<buildAST>(fFncDeclaration | (isAsyncMethod ? fFncAsync : fFncNoFlgs));
96489657
}
9658+
9659+
Assert(pnode != nullptr);
9660+
ParseNodeFnc* pNodeFnc = (ParseNodeFnc*)pnode;
9661+
if (labelledStatement)
9662+
{
9663+
if (IsStrictMode())
9664+
{
9665+
Error(ERRFunctionAfterLabelInStrict);
9666+
}
9667+
else if (pNodeFnc->IsAsync())
9668+
{
9669+
Error(ERRLabelBeforeAsyncFncDeclaration);
9670+
}
9671+
else if (pNodeFnc->IsGenerator())
9672+
{
9673+
Error(ERRLabelBeforeGeneratorDeclaration);
9674+
}
9675+
}
9676+
96499677
if (isAsyncMethod)
96509678
{
96519679
pnode->AsParseNodeFnc()->cbMin = iecpMin;
@@ -9655,7 +9683,11 @@ ParseNodePtr Parser::ParseStatement()
96559683
}
96569684

96579685
case tkCLASS:
9658-
if (m_scriptContext->GetConfig()->IsES6ClassAndExtendsEnabled())
9686+
if (labelledStatement)
9687+
{
9688+
Error(ERRLabelBeforeClassDeclaration);
9689+
}
9690+
else if (m_scriptContext->GetConfig()->IsES6ClassAndExtendsEnabled())
96599691
{
96609692
pnode = ParseClassDecl<buildAST>(TRUE, nullptr, nullptr, nullptr);
96619693
}
@@ -9668,6 +9700,10 @@ ParseNodePtr Parser::ParseStatement()
96689700
case tkID:
96699701
if (m_token.GetIdentifier(this->GetHashTbl()) == wellKnownPropertyPids.let)
96709702
{
9703+
if (labelledStatement)
9704+
{
9705+
Error(ERRLabelBeforeLexicalDeclaration);
9706+
}
96719707
// We see "let" at the start of a statement. This could either be a declaration or an identifier
96729708
// reference. The next token determines which.
96739709
RestorePoint parsedLet;
@@ -9701,6 +9737,10 @@ ParseNodePtr Parser::ParseStatement()
97019737

97029738
case tkCONST:
97039739
case tkLET:
9740+
if (labelledStatement)
9741+
{
9742+
Error(ERRLabelBeforeLexicalDeclaration);
9743+
}
97049744
ichMin = this->GetScanner()->IchMinTok();
97059745

97069746
this->GetScanner()->Scan();
@@ -10570,6 +10610,7 @@ ParseNodePtr Parser::ParseStatement()
1057010610
pLabelId->next = pLabelIdList;
1057110611
pLabelIdList = pLabelId;
1057210612
this->GetScanner()->Scan();
10613+
labelledStatement = true;
1057310614
goto LRestart;
1057410615
}
1057510616

deps/chakrashim/core/lib/Parser/perrors.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,10 @@ LSC_ERROR_MSG(1087, ERRInvalidExportName, "Unable to resolve module export name"
102102
LSC_ERROR_MSG(1088, ERRLetIDInLexicalDecl, "'let' is not an allowed identifier in lexical declarations")
103103

104104
LSC_ERROR_MSG(1089, ERRInvalidLHSInFor, "Invalid left-hand side in for loop")
105+
LSC_ERROR_MSG(1090, ERRLabelBeforeLexicalDeclaration, "Labels not allowed before lexical declaration")
106+
LSC_ERROR_MSG(1091, ERRLabelBeforeGeneratorDeclaration, "Labels not allowed before generator declaration")
107+
LSC_ERROR_MSG(1092, ERRLabelBeforeAsyncFncDeclaration, "Labels not allowed before async function declaration")
108+
LSC_ERROR_MSG(1093, ERRLabelBeforeClassDeclaration, "Labels not allowed before class declaration")
109+
LSC_ERROR_MSG(1094, ERRLabelFollowedByEOF, "Unexpected end of script after a label.")
110+
LSC_ERROR_MSG(1095, ERRFunctionAfterLabelInStrict, "Function declarations not allowed after a label in strict mode.")
111+
LSC_ERROR_MSG(1096, ERRAwaitAsLabelInAsync, "Use of 'await' as label in async function is not allowed.")

0 commit comments

Comments
 (0)