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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/parsing/preparser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 4891 matching lines...) Expand 10 before | Expand all | Expand 10 after
4902 const char* data[] = { 4902 const char* data[] = {
4903 "for(const x = 1; ; ) {}", 4903 "for(const x = 1; ; ) {}",
4904 "for(const x = 1, y = 2;;){}", 4904 "for(const x = 1, y = 2;;){}",
4905 "for(const x in [1,2,3]) {}", 4905 "for(const x in [1,2,3]) {}",
4906 "for(const x of [1,2,3]) {}", 4906 "for(const x of [1,2,3]) {}",
4907 NULL}; 4907 NULL};
4908 RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, nullptr, 0); 4908 RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, nullptr, 0);
4909 } 4909 }
4910 4910
4911 4911
4912 TEST(StatementParsingInForIn) {
4913 const char* context_data[][2] = {{"", ""},
4914 {"'use strict';", ""},
4915 {"function foo(){ 'use strict';", "}"},
4916 {NULL, NULL}};
4917
4918 const char* data[] = {"for(x in {}, {}) {}", "for(var x in {}, {}) {}",
4919 "for(let x in {}, {}) {}", "for(const x in {}, {}) {}",
4920 NULL};
4921
4922 static const ParserFlag always_flags[] = {
4923 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst};
4924 RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, always_flags,
4925 arraysize(always_flags));
4926 }
4927
4928
4912 TEST(ConstParsingInForInError) { 4929 TEST(ConstParsingInForInError) {
4913 const char* context_data[][2] = {{"'use strict';", ""}, 4930 const char* context_data[][2] = {{"'use strict';", ""},
4914 {"function foo(){ 'use strict';", "}"}, 4931 {"function foo(){ 'use strict';", "}"},
4915 {NULL, NULL}}; 4932 {NULL, NULL}};
4916 4933
4917 const char* data[] = { 4934 const char* data[] = {
4918 "for(const x,y = 1; ; ) {}", 4935 "for(const x,y = 1; ; ) {}",
4919 "for(const x = 4 in [1,2,3]) {}", 4936 "for(const x = 4 in [1,2,3]) {}",
4920 "for(const x = 4, y in [1,2,3]) {}", 4937 "for(const x = 4, y in [1,2,3]) {}",
4921 "for(const x = 4 of [1,2,3]) {}", 4938 "for(const x = 4 of [1,2,3]) {}",
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
5075 const char* data[] = { 5092 const char* data[] = {
5076 "for (var of [1, 2, 3]) {}", 5093 "for (var of [1, 2, 3]) {}",
5077 "for (const of [1, 2, 3]) {}", 5094 "for (const of [1, 2, 3]) {}",
5078 NULL}; 5095 NULL};
5079 static const ParserFlag always_flags[] = {kAllowHarmonySloppy}; 5096 static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
5080 RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags, 5097 RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags,
5081 arraysize(always_flags)); 5098 arraysize(always_flags));
5082 } 5099 }
5083 5100
5084 5101
5102 TEST(ForOfInOperator) {
5103 const char* context_data[][2] = {{"", ""},
5104 {"'use strict';", ""},
5105 {"function foo(){ 'use strict';", "}"},
5106 {NULL, NULL}};
5107
5108 const char* data[] = {
5109 "for(x of 'foo' in {}) {}", "for(var x of 'foo' in {}) {}",
5110 "for(let x of 'foo' in {}) {}", "for(const x of 'foo' in {}) {}", NULL};
5111
5112 static const ParserFlag always_flags[] = {
5113 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst};
5114 RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, always_flags,
5115 arraysize(always_flags));
5116 }
5117
5118
5119 TEST(ForOfYieldIdentifier) {
5120 const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
5121
5122 const char* data[] = {"for(x of yield) {}", "for(var x of yield) {}",
5123 "for(let x of yield) {}", "for(const x of yield) {}",
5124 NULL};
5125
5126 static const ParserFlag always_flags[] = {
5127 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst};
5128 RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, always_flags,
5129 arraysize(always_flags));
5130 }
5131
5132
5133 TEST(ForOfYieldExpression) {
5134 const char* context_data[][2] = {{"", ""},
5135 {"'use strict';", ""},
5136 {"function foo(){ 'use strict';", "}"},
5137 {NULL, NULL}};
5138
5139 const char* data[] = {"function* g() { for(x of yield) {} }",
5140 "function* g() { for(var x of yield) {} }",
5141 "function* g() { for(let x of yield) {} }",
5142 "function* g() { for(const x of yield) {} }", NULL};
5143
5144 static const ParserFlag always_flags[] = {
5145 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst};
5146 RunParserSyncTest(context_data, data, kSuccess, nullptr, 0, always_flags,
5147 arraysize(always_flags));
5148 }
5149
5150
5151 TEST(ForOfExpressionError) {
5152 const char* context_data[][2] = {{"", ""},
5153 {"'use strict';", ""},
5154 {"function foo(){ 'use strict';", "}"},
5155 {NULL, NULL}};
5156
5157 const char* data[] = {
5158 "for(x of [], []) {}", "for(var x of [], []) {}",
5159 "for(let x of [], []) {}", "for(const x of [], []) {}",
5160
5161 // AssignmentExpression should be validated statically:
5162 "for(x of { y = 23 }) {}", "for(var x of { y = 23 }) {}",
5163 "for(let x of { y = 23 }) {}", "for(const x of { y = 23 }) {}", NULL};
5164
5165 static const ParserFlag always_flags[] = {
5166 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst};
5167 RunParserSyncTest(context_data, data, kError, nullptr, 0, always_flags,
5168 arraysize(always_flags));
5169 }
5170
5171
5085 TEST(InvalidUnicodeEscapes) { 5172 TEST(InvalidUnicodeEscapes) {
5086 const char* context_data[][2] = {{"", ""}, 5173 const char* context_data[][2] = {{"", ""},
5087 {"'use strict';", ""}, 5174 {"'use strict';", ""},
5088 {NULL, NULL}}; 5175 {NULL, NULL}};
5089 const char* data[] = { 5176 const char* data[] = {
5090 "var foob\\u123r = 0;", 5177 "var foob\\u123r = 0;",
5091 "var \\u123roo = 0;", 5178 "var \\u123roo = 0;",
5092 "\"foob\\u123rr\"", 5179 "\"foob\\u123rr\"",
5093 // No escapes allowed in regexp flags 5180 // No escapes allowed in regexp flags
5094 "/regex/\\u0069g", 5181 "/regex/\\u0069g",
(...skipping 2743 matching lines...) Expand 10 before | Expand all | Expand 10 after
7838 } 7925 }
7839 7926
7840 7927
7841 TEST(MiscSyntaxErrors) { 7928 TEST(MiscSyntaxErrors) {
7842 const char* context_data[][2] = { 7929 const char* context_data[][2] = {
7843 {"'use strict'", ""}, {"", ""}, {NULL, NULL}}; 7930 {"'use strict'", ""}, {"", ""}, {NULL, NULL}};
7844 const char* error_data[] = {"for (();;) {}", NULL}; 7931 const char* error_data[] = {"for (();;) {}", NULL};
7845 7932
7846 RunParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0); 7933 RunParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0);
7847 } 7934 }
OLDNEW
« 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