| 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 2290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2301 const char* statement_data[] = { | 2301 const char* statement_data[] = { |
| 2302 "(function * yield() { })", | 2302 "(function * yield() { })", |
| 2303 NULL | 2303 NULL |
| 2304 }; | 2304 }; |
| 2305 | 2305 |
| 2306 RunParserSyncTest(context_data, statement_data, kError); | 2306 RunParserSyncTest(context_data, statement_data, kError); |
| 2307 } | 2307 } |
| 2308 | 2308 |
| 2309 | 2309 |
| 2310 TEST(NoErrorsGenerator) { | 2310 TEST(NoErrorsGenerator) { |
| 2311 // clang-format off |
| 2311 const char* context_data[][2] = { | 2312 const char* context_data[][2] = { |
| 2312 { "function * gen() {", "}" }, | 2313 { "function * gen() {", "}" }, |
| 2313 { "(function * gen() {", "})" }, | 2314 { "(function * gen() {", "})" }, |
| 2314 { "(function * () {", "})" }, | 2315 { "(function * () {", "})" }, |
| 2315 { NULL, NULL } | 2316 { NULL, NULL } |
| 2316 }; | 2317 }; |
| 2317 | 2318 |
| 2318 const char* statement_data[] = { | 2319 const char* statement_data[] = { |
| 2319 // A generator without a body is valid. | 2320 // A generator without a body is valid. |
| 2320 "" | 2321 "" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2338 // You can return in a generator. | 2339 // You can return in a generator. |
| 2339 "yield 1; return", | 2340 "yield 1; return", |
| 2340 "yield * 1; return", | 2341 "yield * 1; return", |
| 2341 "yield 1; return 37", | 2342 "yield 1; return 37", |
| 2342 "yield * 1; return 37", | 2343 "yield * 1; return 37", |
| 2343 "yield 1; return 37; yield 'dead';", | 2344 "yield 1; return 37; yield 'dead';", |
| 2344 "yield * 1; return 37; yield * 'dead';", | 2345 "yield * 1; return 37; yield * 'dead';", |
| 2345 // Yield is still a valid key in object literals. | 2346 // Yield is still a valid key in object literals. |
| 2346 "({ yield: 1 })", | 2347 "({ yield: 1 })", |
| 2347 "({ get yield() { } })", | 2348 "({ get yield() { } })", |
| 2349 // And in assignment pattern computed properties |
| 2350 "({ [yield]: x } = { })", |
| 2348 // Yield without RHS. | 2351 // Yield without RHS. |
| 2349 "yield;", | 2352 "yield;", |
| 2350 "yield", | 2353 "yield", |
| 2351 "yield\n", | 2354 "yield\n", |
| 2352 "yield /* comment */" | 2355 "yield /* comment */" |
| 2353 "yield // comment\n" | 2356 "yield // comment\n" |
| 2354 "(yield)", | 2357 "(yield)", |
| 2355 "[yield]", | 2358 "[yield]", |
| 2356 "{yield}", | 2359 "{yield}", |
| 2357 "yield, yield", | 2360 "yield, yield", |
| 2358 "yield; yield", | 2361 "yield; yield", |
| 2359 "(yield) ? yield : yield", | 2362 "(yield) ? yield : yield", |
| 2360 "(yield) \n ? yield : yield", | 2363 "(yield) \n ? yield : yield", |
| 2361 // If there is a newline before the next token, we don't look for RHS. | 2364 // If there is a newline before the next token, we don't look for RHS. |
| 2362 "yield\nfor (;;) {}", | 2365 "yield\nfor (;;) {}", |
| 2363 NULL | 2366 NULL |
| 2364 }; | 2367 }; |
| 2368 // clang-format on |
| 2365 | 2369 |
| 2366 RunParserSyncTest(context_data, statement_data, kSuccess); | 2370 static const ParserFlag always_flags[] = { |
| 2371 kAllowHarmonyDestructuringAssignment}; |
| 2372 RunParserSyncTest(context_data, statement_data, kSuccess, nullptr, 0, |
| 2373 always_flags, arraysize(always_flags)); |
| 2367 } | 2374 } |
| 2368 | 2375 |
| 2369 | 2376 |
| 2370 TEST(ErrorsYieldGenerator) { | 2377 TEST(ErrorsYieldGenerator) { |
| 2378 // clang-format off |
| 2371 const char* context_data[][2] = { | 2379 const char* context_data[][2] = { |
| 2372 { "function * gen() {", "}" }, | 2380 { "function * gen() {", "}" }, |
| 2373 { "\"use strict\"; function * gen() {", "}" }, | 2381 { "\"use strict\"; function * gen() {", "}" }, |
| 2374 { NULL, NULL } | 2382 { NULL, NULL } |
| 2375 }; | 2383 }; |
| 2376 | 2384 |
| 2377 const char* statement_data[] = { | 2385 const char* statement_data[] = { |
| 2378 // Invalid yield expressions inside generators. | 2386 // Invalid yield expressions inside generators. |
| 2379 "var yield;", | 2387 "var yield;", |
| 2380 "var foo, yield;", | 2388 "var foo, yield;", |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2401 "yield / yield", | 2409 "yield / yield", |
| 2402 "+ yield", | 2410 "+ yield", |
| 2403 "+ yield 3", | 2411 "+ yield 3", |
| 2404 // Invalid (no newline allowed between yield and *). | 2412 // Invalid (no newline allowed between yield and *). |
| 2405 "yield\n*3", | 2413 "yield\n*3", |
| 2406 // Invalid (we see a newline, so we parse {yield:42} as a statement, not an | 2414 // Invalid (we see a newline, so we parse {yield:42} as a statement, not an |
| 2407 // object literal, and yield is not a valid label). | 2415 // object literal, and yield is not a valid label). |
| 2408 "yield\n{yield: 42}", | 2416 "yield\n{yield: 42}", |
| 2409 "yield /* comment */\n {yield: 42}", | 2417 "yield /* comment */\n {yield: 42}", |
| 2410 "yield //comment\n {yield: 42}", | 2418 "yield //comment\n {yield: 42}", |
| 2419 // Destructuring binding and assignment are both disallowed |
| 2420 "var [yield] = [42];", |
| 2421 "var {foo: yield} = {a: 42};", |
| 2422 "[yield] = [42];", |
| 2423 "({a: yield} = {a: 42});", |
| 2424 // Also disallow full yield expressions on LHS |
| 2425 "var [yield 24] = [42];", |
| 2426 "var {foo: yield 24} = {a: 42};", |
| 2427 "[yield 24] = [42];", |
| 2428 "({a: yield 24} = {a: 42});", |
| 2411 NULL | 2429 NULL |
| 2412 }; | 2430 }; |
| 2431 // clang-format on |
| 2413 | 2432 |
| 2414 RunParserSyncTest(context_data, statement_data, kError); | 2433 RunParserSyncTest(context_data, statement_data, kError); |
| 2415 } | 2434 } |
| 2416 | 2435 |
| 2417 | 2436 |
| 2418 TEST(ErrorsNameOfStrictFunction) { | 2437 TEST(ErrorsNameOfStrictFunction) { |
| 2419 // Tests that illegal tokens as names of a strict function produce the correct | 2438 // Tests that illegal tokens as names of a strict function produce the correct |
| 2420 // errors. | 2439 // errors. |
| 2421 const char* context_data[][2] = { | 2440 const char* context_data[][2] = { |
| 2422 { "function ", ""}, | 2441 { "function ", ""}, |
| (...skipping 5533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7956 } | 7975 } |
| 7957 | 7976 |
| 7958 | 7977 |
| 7959 TEST(MiscSyntaxErrors) { | 7978 TEST(MiscSyntaxErrors) { |
| 7960 const char* context_data[][2] = { | 7979 const char* context_data[][2] = { |
| 7961 {"'use strict'", ""}, {"", ""}, {NULL, NULL}}; | 7980 {"'use strict'", ""}, {"", ""}, {NULL, NULL}}; |
| 7962 const char* error_data[] = {"for (();;) {}", NULL}; | 7981 const char* error_data[] = {"for (();;) {}", NULL}; |
| 7963 | 7982 |
| 7964 RunParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0); | 7983 RunParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0); |
| 7965 } | 7984 } |
| OLD | NEW |