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

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: Correcting a typo 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
« src/parsing/parser.cc ('K') | « 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..20c82665354c3921a9b96119e20a3ed295c8111f 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -4909,6 +4909,18 @@ TEST(ConstParsingInForIn) {
}
+TEST(StatementParsingInForIn) {
+ const char* context_data[][2] = {{"'use strict';", ""},
adamk 2016/01/20 00:35:57 Can you add non-strict cases too? Seems like the m
mike3 2016/01/20 17:55:40 I've omitted strict mode because I was following t
adamk 2016/01/20 19:31:17 Outside strict mode, v8 will parse lexical declara
mike3 2016/01/20 19:54:08 Thanks for the pointer! (It's been a while since I
+ {"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};
+ RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, nullptr, 0);
adamk 2016/01/20 00:35:57 You can leave off the last 4 arguments here (they
mike3 2016/01/20 17:55:40 Acknowledged.
+}
+
+
TEST(ConstParsingInForInError) {
const char* context_data[][2] = {{"'use strict';", ""},
{"function foo(){ 'use strict';", "}"},
@@ -5082,6 +5094,57 @@ 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};
+ RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, nullptr, 0);
+}
+
+
+TEST(ForOfYieldIdentifier) {
+ const char* context_data[][2] = {{NULL, NULL}};
adamk 2016/01/20 00:35:57 This won't actually run any tests, since you haven
mike3 2016/01/20 17:55:40 Acknowledged.
+
+ const char* data[] = {"for(x of yield) {}", "for(var x of yield) {}",
adamk 2016/01/20 00:38:09 Also curious why you added tests for yield, that s
mike3 2016/01/20 17:55:40 I was thinking it would be good to be thorough, si
adamk 2016/01/20 19:31:17 It's fine to leave them in, thanks for the explana
+ "for(let x of yield) {}", "for(const x of yield) {}",
+ NULL};
+ RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, nullptr, 0);
+}
+
+
+TEST(ForOfYieldExpressionError) {
adamk 2016/01/20 00:35:57 This name seems wrong.
mike3 2016/01/20 17:55:40 Acknowledged.
+ const char* context_data[][2] = {{"'use strict';", ""},
adamk 2016/01/20 00:35:57 Again, non-strict versions would be good too, same
+ {"function foo(){ 'use strict';", "}"},
+ {NULL, NULL}};
+
+ const char* data[] = {"(function* g() { for(x of [], []) {} }",
+ "(function* g() { for(var x of [], []) {} }",
+ "(function* g() { for(let x of [], []) {} }",
+ "(function* g() { for(const x of [], []) {} }", NULL};
+ RunParserSyncTest(context_data, data, kError, nullptr, 0, nullptr, 0);
+}
+
+
+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};
+ RunParserSyncTest(context_data, data, kError, nullptr, 0, nullptr, 0);
+}
+
+
TEST(InvalidUnicodeEscapes) {
const char* context_data[][2] = {{"", ""},
{"'use strict';", ""},
« src/parsing/parser.cc ('K') | « src/parsing/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698