[parser] Use better error message to continue a non IterationStatement

BUG=v8:6142

Change-Id: Ia9dff3814fa9d802d94f1769d0f4b5db709a96df
Reviewed-on: https://chromium-review.googlesource.com/459436
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44133}
This commit is contained in:
Sathya Gunasekaran 2017-03-25 13:45:54 -07:00 committed by Commit Bot
parent 1bf8becc63
commit cd868618ea
5 changed files with 48 additions and 14 deletions

View File

@ -556,7 +556,10 @@ class ErrorUtils : public AllStatic {
T(GeneratorInLegacyContext, \
"Generator declarations are not allowed in legacy contexts.") \
T(IllegalBreak, "Illegal break statement") \
T(IllegalContinue, "Illegal continue statement") \
T(NoIterationStatement, \
"Illegal continue statement: no surrounding iteration statement") \
T(IllegalContinue, \
"Illegal continue statement: '%' does not denote an iteration statement") \
T(IllegalLanguageModeDirective, \
"Illegal '%' directive in function with non-simple parameter list") \
T(IllegalReturn, "Illegal return statement") \

View File

@ -5068,7 +5068,11 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseContinueStatement(
if (impl()->IsNullStatement(target)) {
// Illegal continue statement.
MessageTemplate::Template message = MessageTemplate::kIllegalContinue;
if (!impl()->IsEmptyIdentifier(label)) {
typename Types::BreakableStatement breakable_target =
impl()->LookupBreakTarget(label, CHECK_OK);
if (impl()->IsEmptyIdentifier(label)) {
message = MessageTemplate::kNoIterationStatement;
} else if (impl()->IsNullStatement(breakable_target)) {
message = MessageTemplate::kUnknownLabel;
}
ReportMessage(message, label);

View File

@ -0,0 +1,27 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
try {
eval('a: { continue a; }');
assertUnreachable();
} catch(e) {
assertTrue(e instanceof SyntaxError);
assertEquals('Illegal continue statement: \'a\' does not denote an iteration statement', e.message);
}
try {
eval('continue;');
assertUnreachable();
} catch(e) {
assertTrue(e instanceof SyntaxError);
assertEquals('Illegal continue statement: no surrounding iteration statement', e.message);
}
try {
eval('a: { continue b;}');
assertUnreachable();
} catch(e) {
assertTrue(e instanceof SyntaxError);
assertEquals("Undefined label 'b'", e.message);
}

View File

@ -110,8 +110,8 @@ PASS (function (){'misc directive'; 'use strict'; with({}){}}) threw exception S
PASS 'use strict'; return threw exception SyntaxError: Illegal return statement.
PASS 'use strict'; break threw exception SyntaxError: Illegal break statement.
PASS (function (){'use strict'; break}) threw exception SyntaxError: Illegal break statement.
PASS 'use strict'; continue threw exception SyntaxError: Illegal continue statement.
PASS (function (){'use strict'; continue}) threw exception SyntaxError: Illegal continue statement.
PASS 'use strict'; continue threw exception SyntaxError: Illegal continue statement: no surrounding iteration statement.
PASS (function (){'use strict'; continue}) threw exception SyntaxError: Illegal continue statement: no surrounding iteration statement.
PASS 'use strict'; for(;;)return threw exception SyntaxError: Illegal return statement.
PASS 'use strict'; for(;;)break missingLabel threw exception SyntaxError: Undefined label 'missingLabel'.
PASS (function (){'use strict'; for(;;)break missingLabel}) threw exception SyntaxError: Undefined label 'missingLabel'.

View File

@ -28,31 +28,31 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS L:{true;break L;false} is true
PASS if (0) { L:{ break; } } threw exception SyntaxError: Illegal break statement.
PASS if (0) { L:{ continue L; } } threw exception SyntaxError: Undefined label 'L'.
PASS if (0) { L:{ continue; } } threw exception SyntaxError: Illegal continue statement.
PASS if (0) { switch (1) { case 1: continue; } } threw exception SyntaxError: Illegal continue statement.
PASS if (0) { L:{ continue L; } } threw exception SyntaxError: Illegal continue statement: 'L' does not denote an iteration statement.
PASS if (0) { L:{ continue; } } threw exception SyntaxError: Illegal continue statement: no surrounding iteration statement.
PASS if (0) { switch (1) { case 1: continue; } } threw exception SyntaxError: Illegal continue statement: no surrounding iteration statement.
PASS A:L:{true;break L;false} is true
PASS if (0) { A:L:{ break; } } threw exception SyntaxError: Illegal break statement.
PASS if (0) { A:L:{ continue L; } } threw exception SyntaxError: Undefined label 'L'.
PASS if (0) { A:L:{ continue; } } threw exception SyntaxError: Illegal continue statement.
PASS if (0) { A:L:{ continue L; } } threw exception SyntaxError: Illegal continue statement: 'L' does not denote an iteration statement.
PASS if (0) { A:L:{ continue; } } threw exception SyntaxError: Illegal continue statement: no surrounding iteration statement.
PASS L:A:{true;break L;false} is true
PASS if (0) { L:A:{ break; } } threw exception SyntaxError: Illegal break statement.
PASS if (0) { L:A:{ continue L; } } threw exception SyntaxError: Undefined label 'L'.
PASS if (0) { L:A:{ continue; } } threw exception SyntaxError: Illegal continue statement.
PASS if (0) { L:A:{ continue L; } } threw exception SyntaxError: Illegal continue statement: 'L' does not denote an iteration statement.
PASS if (0) { L:A:{ continue; } } threw exception SyntaxError: Illegal continue statement: no surrounding iteration statement.
PASS if(0){ L:for(;;) continue L; } is undefined.
PASS if(0){ L:A:for(;;) continue L; } is undefined.
PASS if(0){ A:L:for(;;) continue L; } is undefined.
PASS if(0){ A:for(;;) L:continue L; } threw exception SyntaxError: Undefined label 'L'.
PASS if(0){ A:for(;;) L:continue L; } threw exception SyntaxError: Illegal continue statement: 'L' does not denote an iteration statement.
PASS if(0){ L:for(;;) A:continue L; } is undefined.
PASS if(0){ L:do continue L; while(0); } is undefined.
PASS if(0){ L:A:do continue L; while(0); } is undefined.
PASS if(0){ A:L:do continue L; while(0);} is undefined.
PASS if(0){ A:do L:continue L; while(0); } threw exception SyntaxError: Undefined label 'L'.
PASS if(0){ A:do L:continue L; while(0); } threw exception SyntaxError: Illegal continue statement: 'L' does not denote an iteration statement.
PASS if(0){ L:do A:continue L; while(0); } is undefined.
PASS if(0){ L:while(0) continue L; } is undefined.
PASS if(0){ L:A:while(0) continue L; } is undefined.
PASS if(0){ A:L:while(0) continue L; } is undefined.
PASS if(0){ A:while(0) L:continue L; } threw exception SyntaxError: Undefined label 'L'.
PASS if(0){ A:while(0) L:continue L; } threw exception SyntaxError: Illegal continue statement: 'L' does not denote an iteration statement.
PASS if(0){ L:while(0) A:continue L; } is undefined.
PASS successfullyParsed is true