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

Side by Side Diff: test/cctest/test-parsing.cc

Issue 1460393003: [es6] Fix parsing of 'yield' in function and generator expressions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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/preparser.h ('k') | test/mjsunit/es6/generators-parsing.js » ('j') | 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 2203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2214 2214
2215 const char* statement_data[] = { 2215 const char* statement_data[] = {
2216 "var yield;", 2216 "var yield;",
2217 "var foo, yield;", 2217 "var foo, yield;",
2218 "try { } catch (yield) { }", 2218 "try { } catch (yield) { }",
2219 "function yield() { }", 2219 "function yield() { }",
2220 "(function yield() { })", 2220 "(function yield() { })",
2221 "function foo(yield) { }", 2221 "function foo(yield) { }",
2222 "function foo(bar, yield) { }", 2222 "function foo(bar, yield) { }",
2223 "function * yield() { }", 2223 "function * yield() { }",
2224 "(function * yield() { })",
2225 "yield = 1;", 2224 "yield = 1;",
2226 "var foo = yield = 1;", 2225 "var foo = yield = 1;",
2227 "yield * 2;", 2226 "yield * 2;",
2228 "++yield;", 2227 "++yield;",
2229 "yield++;", 2228 "yield++;",
2230 "yield: 34", 2229 "yield: 34",
2231 "function yield(yield) { yield: yield (yield + yield(0)); }", 2230 "function yield(yield) { yield: yield (yield + yield(0)); }",
2232 "({ yield: 1 })", 2231 "({ yield: 1 })",
2233 "({ get yield() { 1 } })", 2232 "({ get yield() { 1 } })",
2234 "yield(100)", 2233 "yield(100)",
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2275 "yield: 34;", 2274 "yield: 34;",
2276 NULL 2275 NULL
2277 }; 2276 };
2278 2277
2279 static const ParserFlag always_flags[] = {kAllowStrongMode}; 2278 static const ParserFlag always_flags[] = {kAllowStrongMode};
2280 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags, 2279 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
2281 arraysize(always_flags)); 2280 arraysize(always_flags));
2282 } 2281 }
2283 2282
2284 2283
2284 TEST(ErrorsYieldSloppy) {
2285 const char* context_data[][2] = {
2286 { "", "" },
2287 { "function not_gen() {", "}" },
2288 { "(function not_gen() {", "})" },
2289 { NULL, NULL }
2290 };
2291
2292 const char* statement_data[] = {
2293 "(function * yield() { })",
2294 NULL
2295 };
2296
2297 RunParserSyncTest(context_data, statement_data, kError);
2298 }
2299
2300
2285 TEST(NoErrorsGenerator) { 2301 TEST(NoErrorsGenerator) {
2286 const char* context_data[][2] = { 2302 const char* context_data[][2] = {
2287 { "function * gen() {", "}" }, 2303 { "function * gen() {", "}" },
2288 { "(function * gen() {", "})" }, 2304 { "(function * gen() {", "})" },
2289 { "(function * () {", "})" }, 2305 { "(function * () {", "})" },
2290 { NULL, NULL } 2306 { NULL, NULL }
2291 }; 2307 };
2292 2308
2293 const char* statement_data[] = { 2309 const char* statement_data[] = {
2294 // A generator without a body is valid. 2310 // A generator without a body is valid.
2295 "" 2311 ""
2296 // Valid yield expressions inside generators. 2312 // Valid yield expressions inside generators.
2297 "yield 2;", 2313 "yield 2;",
2298 "yield * 2;", 2314 "yield * 2;",
2299 "yield * \n 2;", 2315 "yield * \n 2;",
2300 "yield yield 1;", 2316 "yield yield 1;",
2301 "yield * yield * 1;", 2317 "yield * yield * 1;",
2302 "yield 3 + (yield 4);", 2318 "yield 3 + (yield 4);",
2303 "yield * 3 + (yield * 4);", 2319 "yield * 3 + (yield * 4);",
2304 "(yield * 3) + (yield * 4);", 2320 "(yield * 3) + (yield * 4);",
2305 "yield 3; yield 4;", 2321 "yield 3; yield 4;",
2306 "yield * 3; yield * 4;", 2322 "yield * 3; yield * 4;",
2307 "(function (yield) { })", 2323 "(function (yield) { })",
2324 "(function yield() { })",
2308 "yield { yield: 12 }", 2325 "yield { yield: 12 }",
2309 "yield /* comment */ { yield: 12 }", 2326 "yield /* comment */ { yield: 12 }",
2310 "yield * \n { yield: 12 }", 2327 "yield * \n { yield: 12 }",
2311 "yield /* comment */ * \n { yield: 12 }", 2328 "yield /* comment */ * \n { yield: 12 }",
2312 // You can return in a generator. 2329 // You can return in a generator.
2313 "yield 1; return", 2330 "yield 1; return",
2314 "yield * 1; return", 2331 "yield * 1; return",
2315 "yield 1; return 37", 2332 "yield 1; return 37",
2316 "yield * 1; return 37", 2333 "yield * 1; return 37",
2317 "yield 1; return 37; yield 'dead';", 2334 "yield 1; return 37; yield 'dead';",
(...skipping 29 matching lines...) Expand all
2347 { "\"use strict\"; function * gen() {", "}" }, 2364 { "\"use strict\"; function * gen() {", "}" },
2348 { NULL, NULL } 2365 { NULL, NULL }
2349 }; 2366 };
2350 2367
2351 const char* statement_data[] = { 2368 const char* statement_data[] = {
2352 // Invalid yield expressions inside generators. 2369 // Invalid yield expressions inside generators.
2353 "var yield;", 2370 "var yield;",
2354 "var foo, yield;", 2371 "var foo, yield;",
2355 "try { } catch (yield) { }", 2372 "try { } catch (yield) { }",
2356 "function yield() { }", 2373 "function yield() { }",
2357 // The name of the NFE is let-bound in the generator, which does not permit 2374 // The name of the NFE is bound in the generator, which does not permit
2358 // yield to be an identifier. 2375 // yield to be an identifier.
2359 "(function yield() { })",
2360 "(function * yield() { })", 2376 "(function * yield() { })",
2361 // Yield isn't valid as a formal parameter for generators. 2377 // Yield isn't valid as a formal parameter for generators.
2362 "function * foo(yield) { }", 2378 "function * foo(yield) { }",
2363 "(function * foo(yield) { })", 2379 "(function * foo(yield) { })",
2364 "yield = 1;", 2380 "yield = 1;",
2365 "var foo = yield = 1;", 2381 "var foo = yield = 1;",
2366 "++yield;", 2382 "++yield;",
2367 "yield++;", 2383 "yield++;",
2368 "yield *", 2384 "yield *",
2369 "(yield *)", 2385 "(yield *)",
(...skipping 5094 matching lines...) Expand 10 before | Expand all | Expand 10 after
7464 "var publ\\u0069c = 1;", 7480 "var publ\\u0069c = 1;",
7465 "var { publ\\u0069c } = {};", 7481 "var { publ\\u0069c } = {};",
7466 NULL}; 7482 NULL};
7467 RunParserSyncTest(sloppy_context_data, valid_data, kSuccess, NULL, 0, 7483 RunParserSyncTest(sloppy_context_data, valid_data, kSuccess, NULL, 0,
7468 always_flags, arraysize(always_flags)); 7484 always_flags, arraysize(always_flags));
7469 RunParserSyncTest(strict_context_data, valid_data, kError, NULL, 0, 7485 RunParserSyncTest(strict_context_data, valid_data, kError, NULL, 0,
7470 always_flags, arraysize(always_flags)); 7486 always_flags, arraysize(always_flags));
7471 RunModuleParserSyncTest(strict_context_data, valid_data, kError, NULL, 0, 7487 RunModuleParserSyncTest(strict_context_data, valid_data, kError, NULL, 0,
7472 always_flags, arraysize(always_flags)); 7488 always_flags, arraysize(always_flags));
7473 } 7489 }
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | test/mjsunit/es6/generators-parsing.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698