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

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

Issue 1602823003: [parser] Disallow Expression in for..of statements (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporating latest review feedback Created 4 years, 11 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
« no previous file with comments | « src/parsing/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 8573ce3391fa581fe60cfb5cf5e061027d93b3f5..80476dfc2e1eb2113f3a0388191753ca8e8a72a7 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -4909,6 +4909,23 @@ TEST(ConstParsingInForIn) {
}
+TEST(StatementParsingInForIn) {
+ const char* context_data[][2] = {{"", ""},
+ {"'use strict';", ""},
+ {"function foo(){ 'use strict';", "}"},
+ {NULL, NULL}};
+
+ const char* data[] = {"for(x in {}, {}) {}", "for(var x in {}, {}) {}",
+ "for(let x in {}, {}) {}", "for(const x in {}, {}) {}",
+ NULL};
+
+ static const ParserFlag always_flags[] = {
+ kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst};
+ RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
TEST(ConstParsingInForInError) {
const char* context_data[][2] = {{"'use strict';", ""},
{"function foo(){ 'use strict';", "}"},
@@ -5082,6 +5099,76 @@ TEST(ForOfNoDeclarationsError) {
}
+TEST(ForOfInOperator) {
+ const char* context_data[][2] = {{"", ""},
+ {"'use strict';", ""},
+ {"function foo(){ 'use strict';", "}"},
+ {NULL, NULL}};
+
+ const char* data[] = {
+ "for(x of 'foo' in {}) {}", "for(var x of 'foo' in {}) {}",
+ "for(let x of 'foo' in {}) {}", "for(const x of 'foo' in {}) {}", NULL};
+
+ static const ParserFlag always_flags[] = {
+ kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst};
+ RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
+TEST(ForOfYieldIdentifier) {
+ const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
+
+ const char* data[] = {"for(x of yield) {}", "for(var x of yield) {}",
+ "for(let x of yield) {}", "for(const x of yield) {}",
+ NULL};
+
+ static const ParserFlag always_flags[] = {
+ kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst};
+ RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
+TEST(ForOfYieldExpression) {
+ const char* context_data[][2] = {{"", ""},
+ {"'use strict';", ""},
+ {"function foo(){ 'use strict';", "}"},
+ {NULL, NULL}};
+
+ const char* data[] = {"function* g() { for(x of yield) {} }",
+ "function* g() { for(var x of yield) {} }",
+ "function* g() { for(let x of yield) {} }",
+ "function* g() { for(const x of yield) {} }", NULL};
+
+ static const ParserFlag always_flags[] = {
+ kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst};
+ RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
+TEST(ForOfExpressionError) {
+ const char* context_data[][2] = {{"", ""},
+ {"'use strict';", ""},
+ {"function foo(){ 'use strict';", "}"},
+ {NULL, NULL}};
+
+ const char* data[] = {
+ "for(x of [], []) {}", "for(var x of [], []) {}",
+ "for(let x of [], []) {}", "for(const x of [], []) {}",
+
+ // AssignmentExpression should be validated statically:
+ "for(x of { y = 23 }) {}", "for(var x of { y = 23 }) {}",
+ "for(let x of { y = 23 }) {}", "for(const x of { y = 23 }) {}", NULL};
+
+ static const ParserFlag always_flags[] = {
+ kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst};
+ RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
TEST(InvalidUnicodeEscapes) {
const char* context_data[][2] = {{"", ""},
{"'use strict';", ""},
« no previous file with comments | « src/parsing/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698