Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Unified Diff: test/cctest/test-parsing.cc

Issue 1062263002: [parser] report better errors for multiple ForBindings in ForIn/Of loops (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add tests for zero declarations Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/parser.cc ('K') | « src/preparser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index a086c3ec617142db00252cb462ba2a06506ac4e3..1f880c53ce4b285264679e073a8141bd8c9c27ad 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -4628,6 +4628,159 @@ TEST(ConstParsingInForInError) {
}
+TEST(InitializedDeclarationsInStrictForInError) {
+ const char* context_data[][2] = {{"'use strict';", ""},
+ {"function foo(){ 'use strict';", "}"},
+ {NULL, NULL}};
+
+ const char* data[] = {
+ "for (var i = 1 in {}) {}",
+ "for (var i = void 0 in [1, 2, 3]) {}",
+ "for (let i = 1 in {}) {}",
+ "for (let i = void 0 in [1, 2, 3]) {}",
+ "for (const i = 1 in {}) {}",
+ "for (const i = void 0 in [1, 2, 3]) {}",
+ NULL};
+ RunParserSyncTest(context_data, data, kError);
+}
+
+
+TEST(InitializedDeclarationsInStrictForOfError) {
+ const char* context_data[][2] = {{"'use strict';", ""},
+ {"function foo(){ 'use strict';", "}"},
+ {NULL, NULL}};
+
+ const char* data[] = {
+ "for (var i = 1 of {}) {}",
+ "for (var i = void 0 of [1, 2, 3]) {}",
+ "for (let i = 1 of {}) {}",
+ "for (let i = void 0 of [1, 2, 3]) {}",
+ "for (const i = 1 of {}) {}",
+ "for (const i = void 0 of [1, 2, 3]) {}",
+ NULL};
+ RunParserSyncTest(context_data, data, kError);
+}
+
+
+TEST(InitializedDeclarationsInSloppyForInError) {
+ const char* context_data[][2] = {{"", ""},
+ {"function foo(){", "}"},
+ {NULL, NULL}};
+
+ const char* data[] = {
+ "for (var i = 1 in {}) {}",
+ "for (var i = void 0 in [1, 2, 3]) {}",
+ NULL};
+ // TODO(caitp): This should be an error in sloppy mode.
+ RunParserSyncTest(context_data, data, kSuccess);
+}
+
+
+TEST(InitializedDeclarationsInSloppyForOfError) {
+ const char* context_data[][2] = {{"", ""},
+ {"function foo(){", "}"},
+ {NULL, NULL}};
+
+ const char* data[] = {
+ "for (var i = 1 of {}) {}",
+ "for (var i = void 0 of [1, 2, 3]) {}",
+ NULL};
+ RunParserSyncTest(context_data, data, kError);
+}
+
+
+TEST(ForInMultipleDeclarationsError) {
+ const char* context_data[][2] = {{"", ""},
+ {"function foo(){", "}"},
+ {"'use strict';", ""},
+ {"function foo(){ 'use strict';", "}"},
+ {NULL, NULL}};
+
+ const char* data[] = {
+ "for (var i, j in {}) {}",
+ "for (var i, j in [1, 2, 3]) {}",
+ "for (var i, j = 1 in {}) {}",
+ "for (var i, j = void 0 in [1, 2, 3]) {}",
+
+ "for (let i, j in {}) {}",
+ "for (let i, j in [1, 2, 3]) {}",
+ "for (let i, j = 1 in {}) {}",
+ "for (let i, j = void 0 in [1, 2, 3]) {}",
+
+ "for (const i, j in {}) {}",
+ "for (const i, j in [1, 2, 3]) {}",
+ "for (const i, j = 1 in {}) {}",
+ "for (const i, j = void 0 in [1, 2, 3]) {}",
+ NULL};
+ static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
+ RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
+TEST(ForOfMultipleDeclarationsError) {
+ const char* context_data[][2] = {{"", ""},
+ {"function foo(){", "}"},
+ {"'use strict';", ""},
+ {"function foo(){ 'use strict';", "}"},
+ {NULL, NULL}};
+
+ const char* data[] = {
+ "for (var i, j of {}) {}",
+ "for (var i, j of [1, 2, 3]) {}",
+ "for (var i, j = 1 of {}) {}",
+ "for (var i, j = void 0 of [1, 2, 3]) {}",
+
+ "for (let i, j of {}) {}",
+ "for (let i, j of [1, 2, 3]) {}",
+ "for (let i, j = 1 of {}) {}",
+ "for (let i, j = void 0 of [1, 2, 3]) {}",
+
+ "for (const i, j of {}) {}",
+ "for (const i, j of [1, 2, 3]) {}",
+ "for (const i, j = 1 of {}) {}",
+ "for (const i, j = void 0 of [1, 2, 3]) {}",
+ NULL};
+ static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
+ RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
+TEST(ForInNoDeclarationsError) {
+ const char* context_data[][2] = {{"", ""},
+ {"function foo(){", "}"},
+ {"'use strict';", ""},
+ {"function foo(){ 'use strict';", "}"},
+ {NULL, NULL}};
+
+ const char* data[] = {
+ "for (var in {}) {}",
+ "for (const in {}) {}",
+ NULL};
+ static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
+ RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
+TEST(ForOfNoDeclarationsError) {
+ const char* context_data[][2] = {{"", ""},
+ {"function foo(){", "}"},
+ {"'use strict';", ""},
+ {"function foo(){ 'use strict';", "}"},
+ {NULL, NULL}};
+
+ const char* data[] = {
+ "for (var of [1, 2, 3]) {}",
+ "for (const of [1, 2, 3]) {}",
+ NULL};
+ static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
+ RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
TEST(InvalidUnicodeEscapes) {
const char* context_data[][2] = {{"", ""},
{"'use strict';", ""},
« src/parser.cc ('K') | « src/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698