OLD | NEW |
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 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2275 NULL | 2275 NULL |
2276 }; | 2276 }; |
2277 | 2277 |
2278 static const ParserFlag always_flags[] = {kAllowStrongMode}; | 2278 static const ParserFlag always_flags[] = {kAllowStrongMode}; |
2279 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags, | 2279 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags, |
2280 arraysize(always_flags)); | 2280 arraysize(always_flags)); |
2281 } | 2281 } |
2282 | 2282 |
2283 | 2283 |
2284 TEST(ErrorsYieldSloppy) { | 2284 TEST(ErrorsYieldSloppy) { |
2285 const char* context_data[][2] = { | 2285 const char* context_data[][2] = {{"", ""}, |
2286 { "", "" }, | 2286 {"function not_gen() {", "}"}, |
2287 { "function not_gen() {", "}" }, | 2287 {"(function not_gen() {", "})"}, |
2288 { "(function not_gen() {", "})" }, | 2288 {NULL, NULL}}; |
2289 { NULL, NULL } | |
2290 }; | |
2291 | 2289 |
2292 const char* statement_data[] = { | 2290 const char* statement_data[] = {"(function * yield() { })", NULL}; |
2293 "(function * yield() { })", | |
2294 NULL | |
2295 }; | |
2296 | 2291 |
2297 RunParserSyncTest(context_data, statement_data, kError); | 2292 RunParserSyncTest(context_data, statement_data, kError); |
2298 } | 2293 } |
2299 | 2294 |
2300 | 2295 |
2301 TEST(NoErrorsGenerator) { | 2296 TEST(NoErrorsGenerator) { |
2302 const char* context_data[][2] = { | 2297 const char* context_data[][2] = { |
2303 { "function * gen() {", "}" }, | 2298 { "function * gen() {", "}" }, |
2304 { "(function * gen() {", "})" }, | 2299 { "(function * gen() {", "})" }, |
2305 { "(function * () {", "})" }, | 2300 { "(function * () {", "})" }, |
2306 { NULL, NULL } | 2301 { NULL, NULL } |
2307 }; | 2302 }; |
2308 | 2303 |
2309 const char* statement_data[] = { | 2304 const char* statement_data[] = { |
2310 // A generator without a body is valid. | 2305 // A generator without a body is valid. |
2311 "" | 2306 "" |
2312 // Valid yield expressions inside generators. | 2307 // Valid yield expressions inside generators. |
2313 "yield 2;", | 2308 "yield 2;", |
2314 "yield * 2;", | 2309 "yield * 2;", "yield * \n 2;", "yield yield 1;", "yield * yield * 1;", |
2315 "yield * \n 2;", | 2310 "yield 3 + (yield 4);", "yield * 3 + (yield * 4);", |
2316 "yield yield 1;", | 2311 "(yield * 3) + (yield * 4);", "yield 3; yield 4;", |
2317 "yield * yield * 1;", | 2312 "yield * 3; yield * 4;", "(function (yield) { })", |
2318 "yield 3 + (yield 4);", | 2313 "(function yield() { })", "yield { yield: 12 }", |
2319 "yield * 3 + (yield * 4);", | 2314 "yield /* comment */ { yield: 12 }", "yield * \n { yield: 12 }", |
2320 "(yield * 3) + (yield * 4);", | 2315 "yield /* comment */ * \n { yield: 12 }", |
2321 "yield 3; yield 4;", | 2316 // You can return in a generator. |
2322 "yield * 3; yield * 4;", | 2317 "yield 1; return", "yield * 1; return", "yield 1; return 37", |
2323 "(function (yield) { })", | 2318 "yield * 1; return 37", "yield 1; return 37; yield 'dead';", |
2324 "(function yield() { })", | 2319 "yield * 1; return 37; yield * 'dead';", |
2325 "yield { yield: 12 }", | 2320 // Yield is still a valid key in object literals. |
2326 "yield /* comment */ { yield: 12 }", | 2321 "({ yield: 1 })", "({ get yield() { } })", |
2327 "yield * \n { yield: 12 }", | 2322 // Yield without RHS. |
2328 "yield /* comment */ * \n { yield: 12 }", | 2323 "yield;", "yield", "yield\n", |
2329 // You can return in a generator. | 2324 "yield /* comment */" |
2330 "yield 1; return", | 2325 "yield // comment\n" |
2331 "yield * 1; return", | 2326 "(yield)", |
2332 "yield 1; return 37", | 2327 "[yield]", "{yield}", "yield, yield", "yield; yield", |
2333 "yield * 1; return 37", | 2328 "(yield) ? yield : yield", "(yield) \n ? yield : yield", |
2334 "yield 1; return 37; yield 'dead';", | 2329 // If there is a newline before the next token, we don't look for RHS. |
2335 "yield * 1; return 37; yield * 'dead';", | 2330 "yield\nfor (;;) {}", NULL}; |
2336 // Yield is still a valid key in object literals. | |
2337 "({ yield: 1 })", | |
2338 "({ get yield() { } })", | |
2339 // Yield without RHS. | |
2340 "yield;", | |
2341 "yield", | |
2342 "yield\n", | |
2343 "yield /* comment */" | |
2344 "yield // comment\n" | |
2345 "(yield)", | |
2346 "[yield]", | |
2347 "{yield}", | |
2348 "yield, yield", | |
2349 "yield; yield", | |
2350 "(yield) ? yield : yield", | |
2351 "(yield) \n ? yield : yield", | |
2352 // If there is a newline before the next token, we don't look for RHS. | |
2353 "yield\nfor (;;) {}", | |
2354 NULL | |
2355 }; | |
2356 | 2331 |
2357 RunParserSyncTest(context_data, statement_data, kSuccess); | 2332 RunParserSyncTest(context_data, statement_data, kSuccess); |
2358 } | 2333 } |
2359 | 2334 |
2360 | 2335 |
2361 TEST(ErrorsYieldGenerator) { | 2336 TEST(ErrorsYieldGenerator) { |
2362 const char* context_data[][2] = { | 2337 const char* context_data[][2] = { |
2363 { "function * gen() {", "}" }, | 2338 { "function * gen() {", "}" }, |
2364 { "\"use strict\"; function * gen() {", "}" }, | 2339 { "\"use strict\"; function * gen() {", "}" }, |
2365 { NULL, NULL } | 2340 { NULL, NULL } |
2366 }; | 2341 }; |
2367 | 2342 |
2368 const char* statement_data[] = { | 2343 const char* statement_data[] = { |
2369 // Invalid yield expressions inside generators. | 2344 // Invalid yield expressions inside generators. |
2370 "var yield;", | 2345 "var yield;", "var foo, yield;", "try { } catch (yield) { }", |
2371 "var foo, yield;", | 2346 "function yield() { }", |
2372 "try { } catch (yield) { }", | 2347 // The name of the NFE is bound in the generator, which does not permit |
2373 "function yield() { }", | 2348 // yield to be an identifier. |
2374 // The name of the NFE is bound in the generator, which does not permit | 2349 "(function * yield() { })", |
2375 // yield to be an identifier. | 2350 // Yield isn't valid as a formal parameter for generators. |
2376 "(function * yield() { })", | 2351 "function * foo(yield) { }", "(function * foo(yield) { })", "yield = 1;", |
2377 // Yield isn't valid as a formal parameter for generators. | 2352 "var foo = yield = 1;", "++yield;", "yield++;", "yield *", "(yield *)", |
2378 "function * foo(yield) { }", | 2353 // Yield binds very loosely, so this parses as "yield (3 + yield 4)", |
2379 "(function * foo(yield) { })", | 2354 // which |
2380 "yield = 1;", | 2355 // is invalid. |
2381 "var foo = yield = 1;", | 2356 "yield 3 + yield 4;", "yield: 34", "yield ? 1 : 2", |
2382 "++yield;", | 2357 // Parses as yield (/ yield): invalid. |
2383 "yield++;", | 2358 "yield / yield", "+ yield", "+ yield 3", |
2384 "yield *", | 2359 // Invalid (no newline allowed between yield and *). |
2385 "(yield *)", | 2360 "yield\n*3", |
2386 // Yield binds very loosely, so this parses as "yield (3 + yield 4)", which | 2361 // Invalid (we see a newline, so we parse {yield:42} as a statement, not |
2387 // is invalid. | 2362 // an |
2388 "yield 3 + yield 4;", | 2363 // object literal, and yield is not a valid label). |
2389 "yield: 34", | 2364 "yield\n{yield: 42}", "yield /* comment */\n {yield: 42}", |
2390 "yield ? 1 : 2", | 2365 "yield //comment\n {yield: 42}", NULL}; |
2391 // Parses as yield (/ yield): invalid. | |
2392 "yield / yield", | |
2393 "+ yield", | |
2394 "+ yield 3", | |
2395 // Invalid (no newline allowed between yield and *). | |
2396 "yield\n*3", | |
2397 // Invalid (we see a newline, so we parse {yield:42} as a statement, not an | |
2398 // object literal, and yield is not a valid label). | |
2399 "yield\n{yield: 42}", | |
2400 "yield /* comment */\n {yield: 42}", | |
2401 "yield //comment\n {yield: 42}", | |
2402 NULL | |
2403 }; | |
2404 | 2366 |
2405 RunParserSyncTest(context_data, statement_data, kError); | 2367 RunParserSyncTest(context_data, statement_data, kError); |
2406 } | 2368 } |
2407 | 2369 |
2408 | 2370 |
2409 TEST(ErrorsNameOfStrictFunction) { | 2371 TEST(ErrorsNameOfStrictFunction) { |
2410 // Tests that illegal tokens as names of a strict function produce the correct | 2372 // Tests that illegal tokens as names of a strict function produce the correct |
2411 // errors. | 2373 // errors. |
2412 const char* context_data[][2] = { | 2374 const char* context_data[][2] = { |
2413 { "function ", ""}, | 2375 { "function ", ""}, |
(...skipping 5065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7479 "var publ\\u0069c = 1;", | 7441 "var publ\\u0069c = 1;", |
7480 "var { publ\\u0069c } = {};", | 7442 "var { publ\\u0069c } = {};", |
7481 NULL}; | 7443 NULL}; |
7482 RunParserSyncTest(sloppy_context_data, valid_data, kSuccess, NULL, 0, | 7444 RunParserSyncTest(sloppy_context_data, valid_data, kSuccess, NULL, 0, |
7483 always_flags, arraysize(always_flags)); | 7445 always_flags, arraysize(always_flags)); |
7484 RunParserSyncTest(strict_context_data, valid_data, kError, NULL, 0, | 7446 RunParserSyncTest(strict_context_data, valid_data, kError, NULL, 0, |
7485 always_flags, arraysize(always_flags)); | 7447 always_flags, arraysize(always_flags)); |
7486 RunModuleParserSyncTest(strict_context_data, valid_data, kError, NULL, 0, | 7448 RunModuleParserSyncTest(strict_context_data, valid_data, kError, NULL, 0, |
7487 always_flags, arraysize(always_flags)); | 7449 always_flags, arraysize(always_flags)); |
7488 } | 7450 } |
OLD | NEW |