Skip to content

Commit d7cc252

Browse files
committed
Checking label lists for labels
1 parent 19738b7 commit d7cc252

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/Parser/Parse.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10509,12 +10509,24 @@ ParseNodePtr Parser::ParseStatement()
1050910509
else
1051010510
{
1051110511
this->GetScanner()->Scan();
10512+
// Check if label is found within the current label id list.
10513+
for (LabelId* pLabelId = pLabelIdList; pLabelId; pLabelId = pLabelId->next)
10514+
{
10515+
if (pid == pLabelId->pid)
10516+
{
10517+
if (fnop == fnopContinue &&
10518+
!(ParseNode::Grfnop(m_pstmtCur->op) & fnop))
10519+
{
10520+
Error(ERRbadContinue);
10521+
}
10522+
goto LNeedTerminator;
10523+
}
10524+
}
1051210525
for (pstmt = m_pstmtCur; pstmt; pstmt = pstmt->pstmtOuter)
1051310526
{
1051410527
LabelId* pLabelId;
1051510528
for (pLabelId = pstmt->pLabelId; pLabelId; pLabelId = pLabelId->next)
1051610529
{
10517-
1051810530
if (pid == pLabelId->pid)
1051910531
{
1052010532
// Found the label. Make sure we can use it. We can

test/Basics/Labels.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,21 @@ testNoSyntaxErrorWithDanglingStaticAfterLabel=
338338
testRuntimeErrorWithDanglingStaticAfterLabel=
339339
`L: static
340340
x = 0`
341+
342+
testSyntaxErrorWithContinueAfterLabel=
343+
`function fn() {
344+
L:
345+
continue L;
346+
}
347+
fn1()`
348+
349+
testReferenceErrorWithBreakAfterLabel=
350+
`function fn() {
351+
L:
352+
break L;
353+
}
354+
fn1()`
355+
341356

342357
function testModuleScript(source, message, shouldFail = false) {
343358
let testfunc = () => testRunner.LoadModule(source, 'samethread', shouldFail);
@@ -467,6 +482,8 @@ var tests = [
467482
assert.throws(() => eval(testRuntimeErrorWithDanglingAwaitAfterLabel), ReferenceError, "Expected reference error from stranded await being used after label", "'await' is not defined")
468483
assert.throws(() => eval(testRuntimeErrorWithDanglingStaticAfterLabel), ReferenceError, "Expected reference error from stranded static being used after label", "'static' is not defined")
469484
assert.doesNotThrow(() => eval(testNoSyntaxErrorWithDanglingStaticAfterLabel), "Expected no issue parsing since static is viewed as an identifier")
485+
assert.throws(() => eval(testSyntaxErrorWithContinueAfterLabel), SyntaxError, "Expected syntax error from having continue outside of loop", "Can't have 'continue' outside of loop")
486+
assert.throws(() => eval(testReferenceErrorWithBreakAfterLabel), ReferenceError, "Expected reference error from fn1 not being defined", "'fn1' is not defined")
470487
}
471488
}
472489
];

0 commit comments

Comments
 (0)