Skip to content

Commit 10cdaa7

Browse files
committed
Throw a syntax error when the statement of a with statement is a labeled function.
1 parent 3ee8aca commit 10cdaa7

File tree

5 files changed

+551
-512
lines changed

5 files changed

+551
-512
lines changed

lib/Parser/Parse.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10037,14 +10037,38 @@ ParseNodePtr Parser::ParseStatement()
1003710037
}
1003810038

1003910039
Assert(pnode != nullptr);
10040-
ParseNodeFnc* pNodeFnc = (ParseNodeFnc*)pnode;
10040+
1004110041
if (labelledStatement)
1004210042
{
1004310043
if (IsStrictMode())
1004410044
{
1004510045
Error(ERRFunctionAfterLabelInStrict);
1004610046
}
10047-
else if (pNodeFnc->IsAsync())
10047+
// #sec-with-statement-static-semantics-early-errors states that the Statement of
10048+
// a WithStatement throws a Syntax Error if the Statement is a LabelledFunction.
10049+
else if (m_pstmtCur && m_pstmtCur->pnodeStmt && m_pstmtCur->pnodeStmt->nop == knopWith)
10050+
{
10051+
Error(ERRStmtOfWithIsLabelledFunc);
10052+
}
10053+
10054+
ParseNodeFnc* pNodeFnc = nullptr;
10055+
10056+
// pnode can be a knopBlock due to ParseFncDeclCheckScope, which
10057+
// can return a ParseNodeBlock that contains a ParseNodeFnc.
10058+
if (pnode->nop == knopBlock)
10059+
{
10060+
ParseNodeBlock* pNodeBlock = pnode->AsParseNodeBlock();
10061+
if (pNodeBlock->pnodeStmt && pNodeBlock->pnodeStmt->nop == knopFncDecl)
10062+
{
10063+
pNodeFnc = pNodeBlock->pnodeStmt->AsParseNodeFnc();
10064+
}
10065+
}
10066+
if (pNodeFnc == nullptr)
10067+
{
10068+
pNodeFnc = pnode->AsParseNodeFnc();
10069+
}
10070+
10071+
if (pNodeFnc->IsAsync())
1004810072
{
1004910073
Error(ERRLabelBeforeAsyncFncDeclaration);
1005010074
}

lib/Parser/perrors.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ LSC_ERROR_MSG(1095, ERRFunctionAfterLabelInStrict, "Function declarations not al
111111
LSC_ERROR_MSG(1096, ERRAwaitAsLabelInAsync, "Use of 'await' as label in async function is not allowed.")
112112
LSC_ERROR_MSG(1097, ERRExperimental, "Use of disabled experimental feature")
113113
LSC_ERROR_MSG(1098, ERRDuplicateExport, "Duplicate export of name '%s'")
114-
//1098-1199 available for future use
114+
LSC_ERROR_MSG(1099, ERRStmtOfWithIsLabelledFunc, "The statement of a 'with' statement cannot be a labelled function.")
115+
//1100-1199 available for future use
115116

116117
// Generic errors intended to be re-usable
117118
LSC_ERROR_MSG(1200, ERRKeywordAfter, "Unexpected keyword '%s' after '%s'")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SyntaxError: The statement of a 'with' statement cannot be a labelled function.
2+
at code (LabelFuncAsWithStmt.js:7:1)

test/Function/LabelFuncAsWithStmt.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
with ({}) L: function f() { }

0 commit comments

Comments
 (0)