Bug 1302692 - Fix error messages for labeled continue statements, remove some dead code. r=jwalden

--HG--
extra : rebase_source : 9f21e417a9598bb8786e52d84fa5a6ac145d2b6d
This commit is contained in:
Jan de Mooij 2016-09-30 12:04:34 +02:00
Родитель 53c63f69db
Коммит c6919b5db5
2 изменённых файлов: 28 добавлений и 7 удалений

Просмотреть файл

@ -5546,17 +5546,21 @@ Parser<ParseHandler>::continueStatement(YieldHandling yieldHandling)
};
if (label) {
bool foundTarget = false;
ParseContext::Statement* stmt = pc->innermostStatement();
bool foundLoop = false;
for (;;) {
stmt = ParseContext::Statement::findNearest(stmt, isLoop);
if (!stmt) {
report(ParseError, false, null(), JSMSG_BAD_CONTINUE);
report(ParseError, false, null(),
foundLoop ? JSMSG_LABEL_NOT_FOUND : JSMSG_BAD_CONTINUE);
return null();
}
foundLoop = true;
// Is it labeled by our label?
bool foundTarget = false;
stmt = stmt->enclosing();
while (stmt && stmt->is<ParseContext::LabelStatement>()) {
if (stmt->as<ParseContext::LabelStatement>().label() == label) {
@ -5568,11 +5572,6 @@ Parser<ParseHandler>::continueStatement(YieldHandling yieldHandling)
if (foundTarget)
break;
}
if (!foundTarget) {
report(ParseError, false, null(), JSMSG_LABEL_NOT_FOUND);
return null();
}
} else if (!pc->findInnermostStatement(isLoop)) {
report(ParseError, false, null(), JSMSG_BAD_CONTINUE);
return null();

Просмотреть файл

@ -0,0 +1,22 @@
load(libdir + "asserts.js");
function test(s, expected) {
assertErrorMessage(() => Function(s), SyntaxError, expected);
}
test("A: continue;", "continue must be inside loop");
test("A: continue B;", "continue must be inside loop");
test("A: if (false) { continue; }", "continue must be inside loop");
test("A: if (false) { continue B; }", "continue must be inside loop");
test("while (false) { (() => { continue B; })(); }", "continue must be inside loop");
test("B: while (false) { (() => { continue B; })(); }", "continue must be inside loop");
test("do { continue B; } while (false);", "label not found");
test("A: for (;;) { continue B; }", "label not found");
test("A: while (false) { if (x) { continue B; } }", "label not found");
test("A: while (false) { B: if (x) { continue B; } }", "label not found");
test("A: if (false) { break B; }", "label not found");
test("A: while (false) { break B; }", "label not found");
test("A: while (true) { if (x) { break B; } }", "label not found");
test("B: while (false) { (() => { break B; })(); }", "label not found");