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

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

Issue 1773653002: [strong] Remove all remainders of strong mode (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Oversight Created 4 years, 9 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 | « test/cctest/test-api.cc ('k') | test/mjsunit/es6/classes-subclass-builtins.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 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 1502
1503 enum ParserFlag { 1503 enum ParserFlag {
1504 kAllowLazy, 1504 kAllowLazy,
1505 kAllowNatives, 1505 kAllowNatives,
1506 kAllowHarmonyDefaultParameters, 1506 kAllowHarmonyDefaultParameters,
1507 kAllowHarmonySloppy, 1507 kAllowHarmonySloppy,
1508 kAllowHarmonySloppyLet, 1508 kAllowHarmonySloppyLet,
1509 kAllowHarmonyDestructuring, 1509 kAllowHarmonyDestructuring,
1510 kAllowHarmonyDestructuringAssignment, 1510 kAllowHarmonyDestructuringAssignment,
1511 kAllowHarmonyNewTarget, 1511 kAllowHarmonyNewTarget,
1512 kAllowStrongMode,
1513 kNoLegacyConst, 1512 kNoLegacyConst,
1514 kAllowHarmonyFunctionSent, 1513 kAllowHarmonyFunctionSent,
1515 kAllowHarmonyRestrictiveDeclarations, 1514 kAllowHarmonyRestrictiveDeclarations,
1516 }; 1515 };
1517 1516
1518 enum ParserSyncTestResult { 1517 enum ParserSyncTestResult {
1519 kSuccessOrError, 1518 kSuccessOrError,
1520 kSuccess, 1519 kSuccess,
1521 kError 1520 kError
1522 }; 1521 };
1523 1522
1524 template <typename Traits> 1523 template <typename Traits>
1525 void SetParserFlags(i::ParserBase<Traits>* parser, 1524 void SetParserFlags(i::ParserBase<Traits>* parser,
1526 i::EnumSet<ParserFlag> flags) { 1525 i::EnumSet<ParserFlag> flags) {
1527 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1526 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1528 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1527 parser->set_allow_natives(flags.Contains(kAllowNatives));
1529 parser->set_allow_harmony_default_parameters( 1528 parser->set_allow_harmony_default_parameters(
1530 flags.Contains(kAllowHarmonyDefaultParameters)); 1529 flags.Contains(kAllowHarmonyDefaultParameters));
1531 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); 1530 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy));
1532 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); 1531 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet));
1533 parser->set_allow_harmony_destructuring_bind( 1532 parser->set_allow_harmony_destructuring_bind(
1534 flags.Contains(kAllowHarmonyDestructuring)); 1533 flags.Contains(kAllowHarmonyDestructuring));
1535 parser->set_allow_harmony_destructuring_assignment( 1534 parser->set_allow_harmony_destructuring_assignment(
1536 flags.Contains(kAllowHarmonyDestructuringAssignment)); 1535 flags.Contains(kAllowHarmonyDestructuringAssignment));
1537 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode));
1538 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst)); 1536 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst));
1539 parser->set_allow_harmony_function_sent( 1537 parser->set_allow_harmony_function_sent(
1540 flags.Contains(kAllowHarmonyFunctionSent)); 1538 flags.Contains(kAllowHarmonyFunctionSent));
1541 parser->set_allow_harmony_restrictive_declarations( 1539 parser->set_allow_harmony_restrictive_declarations(
1542 flags.Contains(kAllowHarmonyRestrictiveDeclarations)); 1540 flags.Contains(kAllowHarmonyRestrictiveDeclarations));
1543 } 1541 }
1544 1542
1545 1543
1546 void TestParserSyncWithFlags(i::Handle<i::String> source, 1544 void TestParserSyncWithFlags(i::Handle<i::String> source,
1547 i::EnumSet<ParserFlag> flags, 1545 i::EnumSet<ParserFlag> flags,
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 } 1920 }
1923 1921
1924 1922
1925 TEST(ErrorsEvalAndArguments) { 1923 TEST(ErrorsEvalAndArguments) {
1926 // Tests that both preparsing and parsing produce the right kind of errors for 1924 // Tests that both preparsing and parsing produce the right kind of errors for
1927 // using "eval" and "arguments" as identifiers. Without the strict mode, it's 1925 // using "eval" and "arguments" as identifiers. Without the strict mode, it's
1928 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it 1926 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it
1929 // isn't. 1927 // isn't.
1930 const char* context_data[][2] = { 1928 const char* context_data[][2] = {
1931 {"\"use strict\";", ""}, 1929 {"\"use strict\";", ""},
1932 {"\"use strong\";", ""},
1933 {"var eval; function test_func() {\"use strict\"; ", "}"}, 1930 {"var eval; function test_func() {\"use strict\"; ", "}"},
1934 {"var eval; function test_func() {\"use strong\"; ", "}"},
1935 {NULL, NULL}}; 1931 {NULL, NULL}};
1936 1932
1937 const char* statement_data[] = { 1933 const char* statement_data[] = {
1938 "var eval;", 1934 "var eval;",
1939 "var arguments", 1935 "var arguments",
1940 "var foo, eval;", 1936 "var foo, eval;",
1941 "var foo, arguments;", 1937 "var foo, arguments;",
1942 "try { } catch (eval) { }", 1938 "try { } catch (eval) { }",
1943 "try { } catch (arguments) { }", 1939 "try { } catch (arguments) { }",
1944 "function eval() { }", 1940 "function eval() { }",
(...skipping 10 matching lines...) Expand all
1955 "arguments = 1;", 1951 "arguments = 1;",
1956 "var foo = eval = 1;", 1952 "var foo = eval = 1;",
1957 "var foo = arguments = 1;", 1953 "var foo = arguments = 1;",
1958 "++eval;", 1954 "++eval;",
1959 "++arguments;", 1955 "++arguments;",
1960 "eval++;", 1956 "eval++;",
1961 "arguments++;", 1957 "arguments++;",
1962 NULL 1958 NULL
1963 }; 1959 };
1964 1960
1965 static const ParserFlag always_flags[] = {kAllowStrongMode}; 1961 RunParserSyncTest(context_data, statement_data, kError);
1966 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
1967 arraysize(always_flags));
1968 } 1962 }
1969 1963
1970 1964
1971 TEST(NoErrorsEvalAndArgumentsSloppy) { 1965 TEST(NoErrorsEvalAndArgumentsSloppy) {
1972 // Tests that both preparsing and parsing accept "eval" and "arguments" as 1966 // Tests that both preparsing and parsing accept "eval" and "arguments" as
1973 // identifiers when needed. 1967 // identifiers when needed.
1974 const char* context_data[][2] = { 1968 const char* context_data[][2] = {
1975 { "", "" }, 1969 { "", "" },
1976 { "function test_func() {", "}"}, 1970 { "function test_func() {", "}"},
1977 { NULL, NULL } 1971 { NULL, NULL }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 2058
2065 2059
2066 TEST(ErrorsFutureStrictReservedWords) { 2060 TEST(ErrorsFutureStrictReservedWords) {
2067 // Tests that both preparsing and parsing produce the right kind of errors for 2061 // Tests that both preparsing and parsing produce the right kind of errors for
2068 // using future strict reserved words as identifiers. Without the strict mode, 2062 // using future strict reserved words as identifiers. Without the strict mode,
2069 // it's ok to use future strict reserved words as identifiers. With the strict 2063 // it's ok to use future strict reserved words as identifiers. With the strict
2070 // mode, it isn't. 2064 // mode, it isn't.
2071 const char* context_data[][2] = { 2065 const char* context_data[][2] = {
2072 {"function test_func() {\"use strict\"; ", "}"}, 2066 {"function test_func() {\"use strict\"; ", "}"},
2073 {"() => { \"use strict\"; ", "}"}, 2067 {"() => { \"use strict\"; ", "}"},
2074 {"function test_func() {\"use strong\"; ", "}"},
2075 {"() => { \"use strong\"; ", "}"},
2076 {NULL, NULL}}; 2068 {NULL, NULL}};
2077 2069
2078 const char* statement_data[] { 2070 const char* statement_data[] {
2079 LIMITED_FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) 2071 LIMITED_FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS)
2080 NULL 2072 NULL
2081 }; 2073 };
2082 2074
2083 static const ParserFlag always_flags[] = {kAllowStrongMode}; 2075 RunParserSyncTest(context_data, statement_data, kError);
2084 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
2085 arraysize(always_flags));
2086 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
2087 arraysize(always_flags));
2088 } 2076 }
2089 2077
2090 2078
2091 #undef LIMITED_FUTURE_STRICT_RESERVED_WORDS 2079 #undef LIMITED_FUTURE_STRICT_RESERVED_WORDS
2092 2080
2093 2081
2094 TEST(NoErrorsFutureStrictReservedWords) { 2082 TEST(NoErrorsFutureStrictReservedWords) {
2095 const char* context_data[][2] = { 2083 const char* context_data[][2] = {
2096 { "", "" }, 2084 { "", "" },
2097 { "function test_func() {", "}"}, 2085 { "function test_func() {", "}"},
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 2242
2255 TEST(ErrorsYieldStrict) { 2243 TEST(ErrorsYieldStrict) {
2256 const char* context_data[][2] = { 2244 const char* context_data[][2] = {
2257 {"\"use strict\";", ""}, 2245 {"\"use strict\";", ""},
2258 {"\"use strict\"; function not_gen() {", "}"}, 2246 {"\"use strict\"; function not_gen() {", "}"},
2259 {"function test_func() {\"use strict\"; ", "}"}, 2247 {"function test_func() {\"use strict\"; ", "}"},
2260 {"\"use strict\"; function * gen() { function not_gen() {", "} }"}, 2248 {"\"use strict\"; function * gen() { function not_gen() {", "} }"},
2261 {"\"use strict\"; (function not_gen() {", "})"}, 2249 {"\"use strict\"; (function not_gen() {", "})"},
2262 {"\"use strict\"; (function * gen() { (function not_gen() {", "}) })"}, 2250 {"\"use strict\"; (function * gen() { (function not_gen() {", "}) })"},
2263 {"() => {\"use strict\"; ", "}"}, 2251 {"() => {\"use strict\"; ", "}"},
2264 {"\"use strong\";", ""},
2265 {"\"use strong\"; function not_gen() {", "}"},
2266 {"function test_func() {\"use strong\"; ", "}"},
2267 {"\"use strong\"; function * gen() { function not_gen() {", "} }"},
2268 {"\"use strong\"; (function not_gen() {", "})"},
2269 {"\"use strong\"; (function * gen() { (function not_gen() {", "}) })"},
2270 {"() => {\"use strong\"; ", "}"},
2271 {NULL, NULL}}; 2252 {NULL, NULL}};
2272 2253
2273 const char* statement_data[] = { 2254 const char* statement_data[] = {
2274 "var yield;", 2255 "var yield;",
2275 "var foo, yield;", 2256 "var foo, yield;",
2276 "try { } catch (yield) { }", 2257 "try { } catch (yield) { }",
2277 "function yield() { }", 2258 "function yield() { }",
2278 "(function yield() { })", 2259 "(function yield() { })",
2279 "function foo(yield) { }", 2260 "function foo(yield) { }",
2280 "function foo(bar, yield) { }", 2261 "function foo(bar, yield) { }",
2281 "function * yield() { }", 2262 "function * yield() { }",
2282 "(function * yield() { })", 2263 "(function * yield() { })",
2283 "yield = 1;", 2264 "yield = 1;",
2284 "var foo = yield = 1;", 2265 "var foo = yield = 1;",
2285 "++yield;", 2266 "++yield;",
2286 "yield++;", 2267 "yield++;",
2287 "yield: 34;", 2268 "yield: 34;",
2288 NULL 2269 NULL
2289 }; 2270 };
2290 2271
2291 static const ParserFlag always_flags[] = {kAllowStrongMode}; 2272 RunParserSyncTest(context_data, statement_data, kError);
2292 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
2293 arraysize(always_flags));
2294 } 2273 }
2295 2274
2296 2275
2297 TEST(ErrorsYieldSloppy) { 2276 TEST(ErrorsYieldSloppy) {
2298 const char* context_data[][2] = { 2277 const char* context_data[][2] = {
2299 { "", "" }, 2278 { "", "" },
2300 { "function not_gen() {", "}" }, 2279 { "function not_gen() {", "}" },
2301 { "(function not_gen() {", "})" }, 2280 { "(function not_gen() {", "})" },
2302 { NULL, NULL } 2281 { NULL, NULL }
2303 }; 2282 };
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2437 RunParserSyncTest(context_data, statement_data, kError); 2416 RunParserSyncTest(context_data, statement_data, kError);
2438 } 2417 }
2439 2418
2440 2419
2441 TEST(ErrorsNameOfStrictFunction) { 2420 TEST(ErrorsNameOfStrictFunction) {
2442 // Tests that illegal tokens as names of a strict function produce the correct 2421 // Tests that illegal tokens as names of a strict function produce the correct
2443 // errors. 2422 // errors.
2444 const char* context_data[][2] = { 2423 const char* context_data[][2] = {
2445 { "function ", ""}, 2424 { "function ", ""},
2446 { "\"use strict\"; function", ""}, 2425 { "\"use strict\"; function", ""},
2447 { "\"use strong\"; function", ""},
2448 { "function * ", ""}, 2426 { "function * ", ""},
2449 { "\"use strict\"; function * ", ""}, 2427 { "\"use strict\"; function * ", ""},
2450 { "\"use strong\"; function * ", ""},
2451 { NULL, NULL } 2428 { NULL, NULL }
2452 }; 2429 };
2453 2430
2454 const char* statement_data[] = { 2431 const char* statement_data[] = {
2455 "eval() {\"use strict\";}", 2432 "eval() {\"use strict\";}",
2456 "arguments() {\"use strict\";}", 2433 "arguments() {\"use strict\";}",
2457 "interface() {\"use strict\";}", 2434 "interface() {\"use strict\";}",
2458 "yield() {\"use strict\";}", 2435 "yield() {\"use strict\";}",
2459 // Future reserved words are always illegal 2436 // Future reserved words are always illegal
2460 "super() { }", 2437 "super() { }",
2461 "super() {\"use strict\";}", 2438 "super() {\"use strict\";}",
2462 NULL 2439 NULL
2463 }; 2440 };
2464 2441
2465 static const ParserFlag always_flags[] = {kAllowStrongMode}; 2442 RunParserSyncTest(context_data, statement_data, kError);
2466 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
2467 arraysize(always_flags));
2468 } 2443 }
2469 2444
2470 2445
2471 TEST(NoErrorsNameOfStrictFunction) { 2446 TEST(NoErrorsNameOfStrictFunction) {
2472 const char* context_data[][2] = { 2447 const char* context_data[][2] = {
2473 { "function ", ""}, 2448 { "function ", ""},
2474 { NULL, NULL } 2449 { NULL, NULL }
2475 }; 2450 };
2476 2451
2477 const char* statement_data[] = { 2452 const char* statement_data[] = {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 RunParserSyncTest(context_data, statement_data, kError); 2496 RunParserSyncTest(context_data, statement_data, kError);
2522 } 2497 }
2523 2498
2524 2499
2525 TEST(ErrorsIllegalWordsAsLabelsStrict) { 2500 TEST(ErrorsIllegalWordsAsLabelsStrict) {
2526 // Tests that illegal tokens as labels produce the correct errors. 2501 // Tests that illegal tokens as labels produce the correct errors.
2527 const char* context_data[][2] = { 2502 const char* context_data[][2] = {
2528 {"\"use strict\";", ""}, 2503 {"\"use strict\";", ""},
2529 {"function test_func() {\"use strict\"; ", "}"}, 2504 {"function test_func() {\"use strict\"; ", "}"},
2530 {"() => {\"use strict\"; ", "}"}, 2505 {"() => {\"use strict\"; ", "}"},
2531 {"\"use strong\";", ""},
2532 {"function test_func() {\"use strong\"; ", "}"},
2533 {"() => {\"use strong\"; ", "}"},
2534 {NULL, NULL}}; 2506 {NULL, NULL}};
2535 2507
2536 #define LABELLED_WHILE(NAME) #NAME ": while (true) { break " #NAME "; }", 2508 #define LABELLED_WHILE(NAME) #NAME ": while (true) { break " #NAME "; }",
2537 const char* statement_data[] = { 2509 const char* statement_data[] = {
2538 "super: while(true) { break super; }", 2510 "super: while(true) { break super; }",
2539 FUTURE_STRICT_RESERVED_WORDS(LABELLED_WHILE) 2511 FUTURE_STRICT_RESERVED_WORDS(LABELLED_WHILE)
2540 NULL 2512 NULL
2541 }; 2513 };
2542 #undef LABELLED_WHILE 2514 #undef LABELLED_WHILE
2543 2515
2544 static const ParserFlag always_flags[] = {kAllowStrongMode}; 2516 RunParserSyncTest(context_data, statement_data, kError);
2545 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
2546 arraysize(always_flags));
2547 } 2517 }
2548 2518
2549 2519
2550 TEST(NoErrorsIllegalWordsAsLabels) { 2520 TEST(NoErrorsIllegalWordsAsLabels) {
2551 // Using eval and arguments as labels is legal even in strict mode. 2521 // Using eval and arguments as labels is legal even in strict mode.
2552 const char* context_data[][2] = { 2522 const char* context_data[][2] = {
2553 { "", ""}, 2523 { "", ""},
2554 { "function test_func() {", "}" }, 2524 { "function test_func() {", "}" },
2555 { "() => {", "}" }, 2525 { "() => {", "}" },
2556 { "\"use strict\";", "" }, 2526 { "\"use strict\";", "" },
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2609 2579
2610 TEST(NoErrorsParenthesizedDirectivePrologue) { 2580 TEST(NoErrorsParenthesizedDirectivePrologue) {
2611 // Parenthesized directive prologue shouldn't be recognized. 2581 // Parenthesized directive prologue shouldn't be recognized.
2612 const char* context_data[][2] = { 2582 const char* context_data[][2] = {
2613 { "", ""}, 2583 { "", ""},
2614 { NULL, NULL } 2584 { NULL, NULL }
2615 }; 2585 };
2616 2586
2617 const char* statement_data[] = { 2587 const char* statement_data[] = {
2618 "(\"use strict\"); var eval;", 2588 "(\"use strict\"); var eval;",
2619 "(\"use strong\"); var eval;",
2620 NULL 2589 NULL
2621 }; 2590 };
2622 2591
2623 static const ParserFlag always_flags[] = {kAllowStrongMode}; 2592 RunParserSyncTest(context_data, statement_data, kSuccess);
2624 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2625 always_flags, arraysize(always_flags));
2626 } 2593 }
2627 2594
2628 2595
2629 TEST(ErrorsNotAnIdentifierName) { 2596 TEST(ErrorsNotAnIdentifierName) {
2630 const char* context_data[][2] = { 2597 const char* context_data[][2] = {
2631 { "", ""}, 2598 { "", ""},
2632 { "\"use strict\";", ""}, 2599 { "\"use strict\";", ""},
2633 { NULL, NULL } 2600 { NULL, NULL }
2634 }; 2601 };
2635 2602
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
2743 {"function foo(bar, eval) {", "}"}, 2710 {"function foo(bar, eval) {", "}"},
2744 {"function foo(bar, arguments) {", "}"}, 2711 {"function foo(bar, arguments) {", "}"},
2745 {"function foo(bar, yield) {", "}"}, 2712 {"function foo(bar, yield) {", "}"},
2746 {"function foo(bar, interface) {", "}"}, 2713 {"function foo(bar, interface) {", "}"},
2747 {"function foo(bar, bar) {", "}"}, 2714 {"function foo(bar, bar) {", "}"},
2748 { NULL, NULL } 2715 { NULL, NULL }
2749 }; 2716 };
2750 2717
2751 const char* strict_statement_data[] = { 2718 const char* strict_statement_data[] = {
2752 "\"use strict\";", 2719 "\"use strict\";",
2753 "\"use strong\";",
2754 NULL 2720 NULL
2755 }; 2721 };
2756 2722
2757 const char* non_strict_statement_data[] = { 2723 const char* non_strict_statement_data[] = {
2758 ";", 2724 ";",
2759 NULL 2725 NULL
2760 }; 2726 };
2761 2727
2762 static const ParserFlag always_flags[] = {kAllowStrongMode}; 2728 RunParserSyncTest(context_data, strict_statement_data, kError);
2763 RunParserSyncTest(context_data, strict_statement_data, kError, NULL, 0, 2729 RunParserSyncTest(context_data, non_strict_statement_data, kSuccess);
2764 always_flags, arraysize(always_flags));
2765 RunParserSyncTest(context_data, non_strict_statement_data, kSuccess, NULL, 0,
2766 always_flags, arraysize(always_flags));
2767 } 2730 }
2768 2731
2769 2732
2770 TEST(ErrorsTryWithoutCatchOrFinally) { 2733 TEST(ErrorsTryWithoutCatchOrFinally) {
2771 const char* context_data[][2] = { 2734 const char* context_data[][2] = {
2772 {"", ""}, 2735 {"", ""},
2773 { NULL, NULL } 2736 { NULL, NULL }
2774 }; 2737 };
2775 2738
2776 const char* statement_data[] = { 2739 const char* statement_data[] = {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
3024 }; 2987 };
3025 2988
3026 // The test is quite slow, so run it with a reduced set of flags. 2989 // The test is quite slow, so run it with a reduced set of flags.
3027 static const ParserFlag empty_flags[] = {kAllowLazy}; 2990 static const ParserFlag empty_flags[] = {kAllowLazy};
3028 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1); 2991 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1);
3029 } 2992 }
3030 2993
3031 2994
3032 TEST(StrictDelete) { 2995 TEST(StrictDelete) {
3033 // "delete <Identifier>" is not allowed in strict mode. 2996 // "delete <Identifier>" is not allowed in strict mode.
3034 const char* strong_context_data[][2] = {
3035 {"\"use strong\"; ", ""},
3036 { NULL, NULL }
3037 };
3038
3039 const char* strict_context_data[][2] = { 2997 const char* strict_context_data[][2] = {
3040 {"\"use strict\"; ", ""}, 2998 {"\"use strict\"; ", ""},
3041 { NULL, NULL } 2999 { NULL, NULL }
3042 }; 3000 };
3043 3001
3044 const char* sloppy_context_data[][2] = { 3002 const char* sloppy_context_data[][2] = {
3045 {"", ""}, 3003 {"", ""},
3046 { NULL, NULL } 3004 { NULL, NULL }
3047 }; 3005 };
3048 3006
(...skipping 21 matching lines...) Expand all
3070 "delete new foo(bar);", 3028 "delete new foo(bar);",
3071 NULL 3029 NULL
3072 }; 3030 };
3073 3031
3074 // These are always errors 3032 // These are always errors
3075 const char* bad_statement_data[] = { 3033 const char* bad_statement_data[] = {
3076 "delete if;", 3034 "delete if;",
3077 NULL 3035 NULL
3078 }; 3036 };
3079 3037
3080 static const ParserFlag always_flags[] = {kAllowStrongMode}; 3038 RunParserSyncTest(strict_context_data, sloppy_statement_data, kError);
3081 RunParserSyncTest(strong_context_data, sloppy_statement_data, kError, NULL, 0, 3039 RunParserSyncTest(sloppy_context_data, sloppy_statement_data, kSuccess);
3082 always_flags, arraysize(always_flags));
3083 RunParserSyncTest(strict_context_data, sloppy_statement_data, kError, NULL, 0,
3084 always_flags, arraysize(always_flags));
3085 RunParserSyncTest(sloppy_context_data, sloppy_statement_data, kSuccess, NULL,
3086 0, always_flags, arraysize(always_flags));
3087 3040
3088 RunParserSyncTest(strong_context_data, good_statement_data, kError, NULL, 0, 3041 RunParserSyncTest(strict_context_data, good_statement_data, kSuccess);
3089 always_flags, arraysize(always_flags)); 3042 RunParserSyncTest(sloppy_context_data, good_statement_data, kSuccess);
3090 RunParserSyncTest(strict_context_data, good_statement_data, kSuccess, NULL, 0,
3091 always_flags, arraysize(always_flags));
3092 RunParserSyncTest(sloppy_context_data, good_statement_data, kSuccess, NULL, 0,
3093 always_flags, arraysize(always_flags));
3094 3043
3095 RunParserSyncTest(strong_context_data, bad_statement_data, kError, NULL, 0, 3044 RunParserSyncTest(strict_context_data, bad_statement_data, kError);
3096 always_flags, arraysize(always_flags)); 3045 RunParserSyncTest(sloppy_context_data, bad_statement_data, kError);
3097 RunParserSyncTest(strict_context_data, bad_statement_data, kError, NULL, 0,
3098 always_flags, arraysize(always_flags));
3099 RunParserSyncTest(sloppy_context_data, bad_statement_data, kError, NULL, 0,
3100 always_flags, arraysize(always_flags));
3101 } 3046 }
3102 3047
3103 3048
3104 TEST(NoErrorsDeclsInCase) { 3049 TEST(NoErrorsDeclsInCase) {
3105 const char* context_data[][2] = { 3050 const char* context_data[][2] = {
3106 {"'use strict'; switch(x) { case 1:", "}"}, 3051 {"'use strict'; switch(x) { case 1:", "}"},
3107 {"function foo() {'use strict'; switch(x) { case 1:", "}}"}, 3052 {"function foo() {'use strict'; switch(x) { case 1:", "}}"},
3108 {"'use strict'; switch(x) { case 1: case 2:", "}"}, 3053 {"'use strict'; switch(x) { case 1: case 2:", "}"},
3109 {"function foo() {'use strict'; switch(x) { case 1: case 2:", "}}"}, 3054 {"function foo() {'use strict'; switch(x) { case 1: case 2:", "}}"},
3110 {"'use strict'; switch(x) { default:", "}"}, 3055 {"'use strict'; switch(x) { default:", "}"},
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
3918 // ensure that nested expressions can still use the 'in' operator, 3863 // ensure that nested expressions can still use the 'in' operator,
3919 const char* loop_context_data[][2] = {{"for (", "; 0;);"}, 3864 const char* loop_context_data[][2] = {{"for (", "; 0;);"},
3920 {nullptr, nullptr}}; 3865 {nullptr, nullptr}};
3921 const char* loop_expr_data[] = {"f => ('key' in {})", nullptr}; 3866 const char* loop_expr_data[] = {"f => ('key' in {})", nullptr};
3922 RunParserSyncTest(loop_context_data, loop_expr_data, kSuccess, flags, 3867 RunParserSyncTest(loop_context_data, loop_expr_data, kSuccess, flags,
3923 arraysize(flags)); 3868 arraysize(flags));
3924 } 3869 }
3925 3870
3926 3871
3927 TEST(ArrowFunctionsSloppyParameterNames) { 3872 TEST(ArrowFunctionsSloppyParameterNames) {
3928 const char* strong_context_data[][2] = {
3929 {"'use strong'; ", ";"},
3930 {"'use strong'; bar ? (", ") : baz;"},
3931 {"'use strong'; bar ? baz : (", ");"},
3932 {"'use strong'; bar, ", ";"},
3933 {"'use strong'; ", ", bar;"},
3934 {NULL, NULL}
3935 };
3936
3937 const char* strict_context_data[][2] = { 3873 const char* strict_context_data[][2] = {
3938 {"'use strict'; ", ";"}, 3874 {"'use strict'; ", ";"},
3939 {"'use strict'; bar ? (", ") : baz;"}, 3875 {"'use strict'; bar ? (", ") : baz;"},
3940 {"'use strict'; bar ? baz : (", ");"}, 3876 {"'use strict'; bar ? baz : (", ");"},
3941 {"'use strict'; bar, ", ";"}, 3877 {"'use strict'; bar, ", ";"},
3942 {"'use strict'; ", ", bar;"}, 3878 {"'use strict'; ", ", bar;"},
3943 {NULL, NULL} 3879 {NULL, NULL}
3944 }; 3880 };
3945 3881
3946 const char* sloppy_context_data[][2] = { 3882 const char* sloppy_context_data[][2] = {
(...skipping 19 matching lines...) Expand all
3966 "(bar, arguments) => {}", 3902 "(bar, arguments) => {}",
3967 "(bar, yield) => {}", 3903 "(bar, yield) => {}",
3968 "(bar, interface) => {}", 3904 "(bar, interface) => {}",
3969 "(interface, eval) => {}", 3905 "(interface, eval) => {}",
3970 "(interface, arguments) => {}", 3906 "(interface, arguments) => {}",
3971 "(eval, interface) => {}", 3907 "(eval, interface) => {}",
3972 "(arguments, interface) => {}", 3908 "(arguments, interface) => {}",
3973 NULL 3909 NULL
3974 }; 3910 };
3975 3911
3976 static const ParserFlag always_flags[] = {kAllowStrongMode}; 3912 RunParserSyncTest(strict_context_data, statement_data, kError);
3977 RunParserSyncTest(strong_context_data, statement_data, kError, NULL, 0, 3913 RunParserSyncTest(sloppy_context_data, statement_data, kSuccess);
3978 always_flags, arraysize(always_flags));
3979 RunParserSyncTest(strict_context_data, statement_data, kError, NULL, 0,
3980 always_flags, arraysize(always_flags));
3981 RunParserSyncTest(sloppy_context_data, statement_data, kSuccess, NULL, 0,
3982 always_flags, arraysize(always_flags));
3983 } 3914 }
3984 3915
3985 3916
3986 TEST(ArrowFunctionsYieldParameterNameInGenerator) { 3917 TEST(ArrowFunctionsYieldParameterNameInGenerator) {
3987 const char* sloppy_function_context_data[][2] = { 3918 const char* sloppy_function_context_data[][2] = {
3988 {"(function f() { (", "); });"}, 3919 {"(function f() { (", "); });"},
3989 {NULL, NULL} 3920 {NULL, NULL}
3990 }; 3921 };
3991 3922
3992 const char* strict_function_context_data[][2] = { 3923 const char* strict_function_context_data[][2] = {
3993 {"(function f() {'use strong'; (", "); });"},
3994 {"(function f() {'use strict'; (", "); });"}, 3924 {"(function f() {'use strict'; (", "); });"},
3995 {NULL, NULL} 3925 {NULL, NULL}
3996 }; 3926 };
3997 3927
3998 const char* generator_context_data[][2] = { 3928 const char* generator_context_data[][2] = {
3999 {"(function *g() {'use strong'; (", "); });"},
4000 {"(function *g() {'use strict'; (", "); });"}, 3929 {"(function *g() {'use strict'; (", "); });"},
4001 {"(function *g() { (", "); });"}, 3930 {"(function *g() { (", "); });"},
4002 {NULL, NULL} 3931 {NULL, NULL}
4003 }; 3932 };
4004 3933
4005 const char* arrow_data[] = { 3934 const char* arrow_data[] = {
4006 "yield => {}", 3935 "yield => {}",
4007 "(yield) => {}", 3936 "(yield) => {}",
4008 "(a, yield) => {}", 3937 "(a, yield) => {}",
4009 "(yield, a) => {}", 3938 "(yield, a) => {}",
4010 "(yield, ...a) => {}", 3939 "(yield, ...a) => {}",
4011 "(a, ...yield) => {}", 3940 "(a, ...yield) => {}",
4012 "({yield}) => {}", 3941 "({yield}) => {}",
4013 "([yield]) => {}", 3942 "([yield]) => {}",
4014 NULL 3943 NULL
4015 }; 3944 };
4016 3945
4017 static const ParserFlag always_flags[] = { kAllowHarmonyDestructuring, 3946 static const ParserFlag always_flags[] = { kAllowHarmonyDestructuring };
4018 kAllowStrongMode};
4019 RunParserSyncTest(sloppy_function_context_data, arrow_data, kSuccess, NULL, 0, 3947 RunParserSyncTest(sloppy_function_context_data, arrow_data, kSuccess, NULL, 0,
4020 always_flags, arraysize(always_flags)); 3948 always_flags, arraysize(always_flags));
4021 RunParserSyncTest(strict_function_context_data, arrow_data, kError, NULL, 0, 3949 RunParserSyncTest(strict_function_context_data, arrow_data, kError, NULL, 0,
4022 always_flags, arraysize(always_flags)); 3950 always_flags, arraysize(always_flags));
4023 RunParserSyncTest(generator_context_data, arrow_data, kError, NULL, 0, 3951 RunParserSyncTest(generator_context_data, arrow_data, kError, NULL, 0,
4024 always_flags, arraysize(always_flags)); 3952 always_flags, arraysize(always_flags));
4025 } 3953 }
4026 3954
4027 3955
4028 TEST(SuperNoErrors) { 3956 TEST(SuperNoErrors) {
(...skipping 1935 matching lines...) Expand 10 before | Expand all | Expand 10 after
5964 } 5892 }
5965 5893
5966 5894
5967 TEST(DeclarationsError) { 5895 TEST(DeclarationsError) {
5968 const char* context_data[][2] = {{"'use strict'; if (true)", ""}, 5896 const char* context_data[][2] = {{"'use strict'; if (true)", ""},
5969 {"'use strict'; if (false) {} else", ""}, 5897 {"'use strict'; if (false) {} else", ""},
5970 {"'use strict'; while (false)", ""}, 5898 {"'use strict'; while (false)", ""},
5971 {"'use strict'; for (;;)", ""}, 5899 {"'use strict'; for (;;)", ""},
5972 {"'use strict'; for (x in y)", ""}, 5900 {"'use strict'; for (x in y)", ""},
5973 {"'use strict'; do ", " while (false)"}, 5901 {"'use strict'; do ", " while (false)"},
5974 {"'use strong'; if (true)", ""},
5975 {"'use strong'; if (false) {} else", ""},
5976 {"'use strong'; while (false)", ""},
5977 {"'use strong'; for (;;)", ""},
5978 {"'use strong'; for (x in y)", ""},
5979 {"'use strong'; do ", " while (false)"},
5980 {NULL, NULL}}; 5902 {NULL, NULL}};
5981 5903
5982 const char* statement_data[] = { 5904 const char* statement_data[] = {
5983 "let x = 1;", 5905 "let x = 1;",
5984 "const x = 1;", 5906 "const x = 1;",
5985 "class C {}", 5907 "class C {}",
5986 NULL}; 5908 NULL};
5987 5909
5988 static const ParserFlag always_flags[] = {kAllowStrongMode}; 5910 RunParserSyncTest(context_data, statement_data, kError);
5989 RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
5990 always_flags, arraysize(always_flags));
5991 } 5911 }
5992 5912
5993 5913
5994 void TestLanguageMode(const char* source, 5914 void TestLanguageMode(const char* source,
5995 i::LanguageMode expected_language_mode) { 5915 i::LanguageMode expected_language_mode) {
5996 i::Isolate* isolate = CcTest::i_isolate(); 5916 i::Isolate* isolate = CcTest::i_isolate();
5997 i::Factory* factory = isolate->factory(); 5917 i::Factory* factory = isolate->factory();
5998 v8::HandleScope handles(CcTest::isolate()); 5918 v8::HandleScope handles(CcTest::isolate());
5999 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); 5919 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
6000 v8::Context::Scope context_scope(context); 5920 v8::Context::Scope context_scope(context);
6001 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5921 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
6002 128 * 1024); 5922 128 * 1024);
6003 5923
6004 i::Handle<i::Script> script = 5924 i::Handle<i::Script> script =
6005 factory->NewScript(factory->NewStringFromAsciiChecked(source)); 5925 factory->NewScript(factory->NewStringFromAsciiChecked(source));
6006 i::Zone zone; 5926 i::Zone zone;
6007 i::ParseInfo info(&zone, script); 5927 i::ParseInfo info(&zone, script);
6008 i::Parser parser(&info); 5928 i::Parser parser(&info);
6009 parser.set_allow_strong_mode(true);
6010 info.set_global(); 5929 info.set_global();
6011 parser.Parse(&info); 5930 parser.Parse(&info);
6012 CHECK(info.literal() != NULL); 5931 CHECK(info.literal() != NULL);
6013 CHECK_EQ(expected_language_mode, info.literal()->language_mode()); 5932 CHECK_EQ(expected_language_mode, info.literal()->language_mode());
6014 } 5933 }
6015 5934
6016 5935
6017 TEST(LanguageModeDirectives) { 5936 TEST(LanguageModeDirectives) {
6018 TestLanguageMode("\"use nothing\"", i::SLOPPY); 5937 TestLanguageMode("\"use nothing\"", i::SLOPPY);
6019 TestLanguageMode("\"use strict\"", i::STRICT); 5938 TestLanguageMode("\"use strict\"", i::STRICT);
6020 TestLanguageMode("\"use strong\"", i::STRONG);
6021 5939
6022 TestLanguageMode("var x = 1; \"use strict\"", i::SLOPPY); 5940 TestLanguageMode("var x = 1; \"use strict\"", i::SLOPPY);
6023 TestLanguageMode("var x = 1; \"use strong\"", i::SLOPPY);
6024
6025 // Test that multiple directives ("use strict" / "use strong") put the parser
6026 // into the correct mode.
6027 TestLanguageMode("\"use strict\"; \"use strong\";", i::STRONG);
6028 TestLanguageMode("\"use strong\"; \"use strict\";", i::STRONG);
6029 5941
6030 TestLanguageMode("\"use some future directive\"; \"use strict\";", i::STRICT); 5942 TestLanguageMode("\"use some future directive\"; \"use strict\";", i::STRICT);
6031 TestLanguageMode("\"use some future directive\"; \"use strong\";", i::STRONG);
6032 }
6033
6034
6035 TEST(MultipleLanguageModeDirectives) {
6036 const char* context_data[][2] = {
6037 { "'use strict'; 'use strong';", "" },
6038 { "'use strong'; 'use strict';", "" },
6039 { "function f() { 'use strict'; 'use strong';", "}" },
6040 { "function f() { 'use strong'; 'use strict';", "}" },
6041 { NULL, NULL }
6042 };
6043
6044 const char* strict_error_data[] = {
6045 "var x = 42; delete x",
6046 NULL};
6047
6048 const char* strong_error_data[] = {
6049 "var x = 42",
6050 NULL};
6051
6052 static const ParserFlag strong_mode_flags[] = {kAllowStrongMode};
6053 RunParserSyncTest(context_data, strict_error_data, kError,
6054 strong_mode_flags, arraysize(strong_mode_flags));
6055 RunParserSyncTest(context_data, strong_error_data, kError, NULL, 0,
6056 strong_mode_flags, arraysize(strong_mode_flags));
6057 } 5943 }
6058 5944
6059 5945
6060 TEST(PropertyNameEvalArguments) { 5946 TEST(PropertyNameEvalArguments) {
6061 const char* context_data[][2] = {{"'use strict';", ""}, 5947 const char* context_data[][2] = {{"'use strict';", ""},
6062 {"'use strong';", ""},
6063 {NULL, NULL}}; 5948 {NULL, NULL}};
6064 5949
6065 const char* statement_data[] = { 5950 const char* statement_data[] = {
6066 "({eval: 1})", 5951 "({eval: 1})",
6067 "({arguments: 1})", 5952 "({arguments: 1})",
6068 "({eval() {}})", 5953 "({eval() {}})",
6069 "({arguments() {}})", 5954 "({arguments() {}})",
6070 "({*eval() {}})", 5955 "({*eval() {}})",
6071 "({*arguments() {}})", 5956 "({*arguments() {}})",
6072 "({get eval() {}})", 5957 "({get eval() {}})",
(...skipping 14 matching lines...) Expand all
6087 "class C {static arguments() {}}", 5972 "class C {static arguments() {}}",
6088 "class C {static *eval() {}}", 5973 "class C {static *eval() {}}",
6089 "class C {static *arguments() {}}", 5974 "class C {static *arguments() {}}",
6090 "class C {static get eval() {}}", 5975 "class C {static get eval() {}}",
6091 "class C {static get arguments() {}}", 5976 "class C {static get arguments() {}}",
6092 "class C {static set eval(_) {}}", 5977 "class C {static set eval(_) {}}",
6093 "class C {static set arguments(_) {}}", 5978 "class C {static set arguments(_) {}}",
6094 5979
6095 NULL}; 5980 NULL};
6096 5981
6097 static const ParserFlag always_flags[] = {kAllowStrongMode}; 5982 RunParserSyncTest(context_data, statement_data, kSuccess);
6098 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
6099 always_flags, arraysize(always_flags));
6100 } 5983 }
6101 5984
6102 5985
6103 TEST(FunctionLiteralDuplicateParameters) { 5986 TEST(FunctionLiteralDuplicateParameters) {
6104 const char* strict_context_data[][2] = 5987 const char* strict_context_data[][2] =
6105 {{"'use strict';(function(", "){})();"}, 5988 {{"'use strict';(function(", "){})();"},
6106 {"(function(", ") { 'use strict'; })();"}, 5989 {"(function(", ") { 'use strict'; })();"},
6107 {"'use strict'; function fn(", ") {}; fn();"}, 5990 {"'use strict'; function fn(", ") {}; fn();"},
6108 {"function fn(", ") { 'use strict'; }; fn();"}, 5991 {"function fn(", ") { 'use strict'; }; fn();"},
6109 {"'use strong';(function(", "){})();"},
6110 {"(function(", ") { 'use strong'; })();"},
6111 {"'use strong'; function fn(", ") {}; fn();"},
6112 {"function fn(", ") { 'use strong'; }; fn();"},
6113 {NULL, NULL}}; 5992 {NULL, NULL}};
6114 5993
6115 const char* sloppy_context_data[][2] = 5994 const char* sloppy_context_data[][2] =
6116 {{"(function(", "){})();"}, 5995 {{"(function(", "){})();"},
6117 {"(function(", ") {})();"}, 5996 {"(function(", ") {})();"},
6118 {"function fn(", ") {}; fn();"}, 5997 {"function fn(", ") {}; fn();"},
6119 {"function fn(", ") {}; fn();"}, 5998 {"function fn(", ") {}; fn();"},
6120 {NULL, NULL}}; 5999 {NULL, NULL}};
6121 6000
6122 const char* data[] = { 6001 const char* data[] = {
6123 "a, a", 6002 "a, a",
6124 "a, a, a", 6003 "a, a, a",
6125 "b, a, a", 6004 "b, a, a",
6126 "a, b, c, c", 6005 "a, b, c, c",
6127 "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, w", 6006 "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, w",
6128 NULL}; 6007 NULL};
6129 6008
6130 static const ParserFlag always_flags[] = { kAllowStrongMode }; 6009 RunParserSyncTest(strict_context_data, data, kError);
6131 RunParserSyncTest(strict_context_data, data, kError, NULL, 0, always_flags, 6010 RunParserSyncTest(sloppy_context_data, data, kSuccess);
6132 arraysize(always_flags));
6133 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, NULL, 0);
6134 } 6011 }
6135 6012
6136 6013
6137 TEST(VarForbiddenInStrongMode) {
6138 const char* strong_context_data[][2] =
6139 {{"'use strong'; ", ""},
6140 {"function f() {'use strong'; ", "}"},
6141 {"function f() {'use strong'; while (true) { ", "} }"},
6142 {NULL, NULL}};
6143
6144 const char* strict_context_data[][2] =
6145 {{"'use strict'; ", ""},
6146 {"function f() {'use strict'; ", "}"},
6147 {"function f() {'use strict'; while (true) { ", "} }"},
6148 {NULL, NULL}};
6149
6150 const char* sloppy_context_data[][2] =
6151 {{"", ""},
6152 {"function f() { ", "}"},
6153 {NULL, NULL}};
6154
6155 const char* var_declarations[] = {
6156 "var x = 0;",
6157 "for (var i = 0; i < 10; i++) { }",
6158 NULL};
6159
6160 const char* let_declarations[] = {
6161 "let x = 0;",
6162 "for (let i = 0; i < 10; i++) { }",
6163 NULL};
6164
6165 const char* const_declarations[] = {
6166 "const x = 0;",
6167 NULL};
6168
6169 static const ParserFlag always_flags[] = {kAllowStrongMode};
6170 RunParserSyncTest(strong_context_data, var_declarations, kError, NULL, 0,
6171 always_flags, arraysize(always_flags));
6172 RunParserSyncTest(strong_context_data, let_declarations, kSuccess, NULL, 0,
6173 always_flags, arraysize(always_flags));
6174 RunParserSyncTest(strong_context_data, const_declarations, kSuccess, NULL, 0,
6175 always_flags, arraysize(always_flags));
6176
6177 RunParserSyncTest(strict_context_data, var_declarations, kSuccess, NULL, 0,
6178 always_flags, arraysize(always_flags));
6179 RunParserSyncTest(strict_context_data, let_declarations, kSuccess, NULL, 0,
6180 always_flags, arraysize(always_flags));
6181
6182 RunParserSyncTest(sloppy_context_data, var_declarations, kSuccess, NULL, 0,
6183 always_flags, arraysize(always_flags));
6184 // At the moment, let declarations are only available in strict mode.
6185 RunParserSyncTest(sloppy_context_data, let_declarations, kError, NULL, 0,
6186 always_flags, arraysize(always_flags));
6187 }
6188
6189
6190 TEST(StrongEmptySubStatements) {
6191 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}};
6192 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}};
6193 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}};
6194
6195 const char* data_error[] = {
6196 "if (1);",
6197 "if (1) {} else;",
6198 "while (1);",
6199 "do; while (1);",
6200 "for (;;);",
6201 "for (x in []);",
6202 "for (x of []);",
6203 "for (const x = 0;;);",
6204 "for (const x in []);",
6205 "for (const x of []);",
6206 NULL};
6207
6208 const char* data_success[] = {
6209 "if (1) {} else {}",
6210 "switch(1) {}",
6211 "1+1;;",
6212 "1+1; ;",
6213 NULL};
6214
6215 static const ParserFlag always_flags[] = {
6216 kAllowStrongMode,
6217 };
6218 RunParserSyncTest(sloppy_context_data, data_error, kSuccess, NULL, 0,
6219 always_flags, arraysize(always_flags));
6220 RunParserSyncTest(strict_context_data, data_error, kSuccess, NULL, 0,
6221 always_flags, arraysize(always_flags));
6222 RunParserSyncTest(strong_context_data, data_error, kError, NULL, 0,
6223 always_flags, arraysize(always_flags));
6224 RunParserSyncTest(strong_context_data, data_success, kSuccess, NULL, 0,
6225 always_flags, arraysize(always_flags));
6226 }
6227
6228
6229 TEST(StrongForIn) {
6230 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}};
6231 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}};
6232 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}};
6233
6234 const char* data[] = {
6235 "for (x in []) {}",
6236 "for (const x in []) {}",
6237 NULL};
6238
6239 static const ParserFlag always_flags[] = {
6240 kAllowStrongMode,
6241 };
6242 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags,
6243 arraysize(always_flags));
6244 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
6245 arraysize(always_flags));
6246 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
6247 arraysize(always_flags));
6248 }
6249
6250
6251 TEST(StrongConstructorThis) {
6252 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}};
6253 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}};
6254 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}};
6255
6256 const char* error_data[] = {
6257 "class C { constructor() { this; } }",
6258 "class C { constructor() { this.a; } }",
6259 "class C { constructor() { this['a']; } }",
6260 "class C { constructor() { (this); } }",
6261 "class C { constructor() { this(); } }",
6262 // TODO(rossberg): arrow functions not handled yet.
6263 // "class C { constructor() { () => this; } }",
6264 "class C { constructor() { this.a = 0, 0; } }",
6265 "class C { constructor() { (this.a = 0); } }",
6266 // "class C { constructor() { (() => this.a = 0)(); } }",
6267 "class C { constructor() { { this.a = 0; } } }",
6268 "class C { constructor() { if (1) this.a = 0; } }",
6269 "class C { constructor() { label: this.a = 0; } }",
6270 "class C { constructor() { this.a = this.b; } }",
6271 "class C { constructor() { this.a = {b: 1}; this.a.b } }",
6272 "class C { constructor() { this.a = {b: 1}; this.a.b = 0 } }",
6273 "class C { constructor() { this.a = function(){}; this.a() } }",
6274 NULL};
6275
6276 const char* success_data[] = {
6277 "class C { constructor() { this.a = 0; } }",
6278 "class C { constructor() { label: 0; this.a = 0; this.b = 6; } }",
6279 NULL};
6280
6281 static const ParserFlag always_flags[] = {kAllowStrongMode};
6282 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0,
6283 always_flags, arraysize(always_flags));
6284 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0,
6285 always_flags, arraysize(always_flags));
6286 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0,
6287 always_flags, arraysize(always_flags));
6288
6289 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0,
6290 always_flags, arraysize(always_flags));
6291 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0,
6292 always_flags, arraysize(always_flags));
6293 RunParserSyncTest(strong_context_data, success_data, kSuccess, NULL, 0,
6294 always_flags, arraysize(always_flags));
6295 }
6296
6297
6298 TEST(StrongConstructorSuper) {
6299 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}};
6300 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}};
6301 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}};
6302
6303 const char* error_data[] = {
6304 "class C extends Object { constructor() {} }",
6305 "class C extends Object { constructor() { super.a; } }",
6306 "class C extends Object { constructor() { super['a']; } }",
6307 "class C extends Object { constructor() { super.a = 0; } }",
6308 "class C extends Object { constructor() { (super.a); } }",
6309 // TODO(rossberg): arrow functions do not handle super yet.
6310 // "class C extends Object { constructor() { () => super.a; } }",
6311 "class C extends Object { constructor() { super(), 0; } }",
6312 "class C extends Object { constructor() { (super()); } }",
6313 // "class C extends Object { constructor() { (() => super())(); } }",
6314 "class C extends Object { constructor() { { super(); } } }",
6315 "class C extends Object { constructor() { if (1) super(); } }",
6316 "class C extends Object { constructor() { label: super(); } }",
6317 "class C extends Object { constructor() { super(), super(); } }",
6318 "class C extends Object { constructor() { super(); super(); } }",
6319 "class C extends Object { constructor() { super(); (super()); } }",
6320 "class C extends Object { constructor() { super(); { super() } } }",
6321 "class C extends Object { constructor() { this.a = 0, super(); } }",
6322 "class C extends Object { constructor() { this.a = 0; super(); } }",
6323 "class C extends Object { constructor() { super(this.a = 0); } }",
6324 "class C extends Object { constructor() { super().a; } }",
6325 NULL};
6326
6327 const char* success_data[] = {
6328 "class C extends Object { constructor() { super(); } }",
6329 "class C extends Object { constructor() { label: 66; super(); } }",
6330 "class C extends Object { constructor() { super(3); this.x = 0; } }",
6331 "class C extends Object { constructor() { 3; super(3); this.x = 0; } }",
6332 NULL};
6333
6334 static const ParserFlag always_flags[] = {kAllowStrongMode};
6335 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0,
6336 always_flags, arraysize(always_flags));
6337 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0,
6338 always_flags, arraysize(always_flags));
6339 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0,
6340 always_flags, arraysize(always_flags));
6341
6342 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0,
6343 always_flags, arraysize(always_flags));
6344 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0,
6345 always_flags, arraysize(always_flags));
6346 RunParserSyncTest(strong_context_data, success_data, kSuccess, NULL, 0,
6347 always_flags, arraysize(always_flags));
6348 }
6349
6350
6351 TEST(StrongConstructorReturns) {
6352 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}};
6353 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}};
6354 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}};
6355
6356 const char* error_data[] = {
6357 "class C extends Object { constructor() { super(); return {}; } }",
6358 "class C extends Object { constructor() { super(); { return {}; } } }",
6359 "class C extends Object { constructor() { super(); if (1) return {}; } }",
6360 "class C extends Object { constructor() { return; super(); } }",
6361 "class C extends Object { constructor() { { return; } super(); } }",
6362 "class C extends Object { constructor() { if (0) return; super(); } }",
6363 "class C { constructor() { return; this.a = 0; } }",
6364 "class C { constructor() { { return; } this.a = 0; } }",
6365 "class C { constructor() { if (0) return; this.a = 0; } }",
6366 "class C { constructor() { this.a = 0; if (0) return; this.b = 0; } }",
6367 NULL};
6368
6369 const char* success_data[] = {
6370 "class C extends Object { constructor() { super(); return; } }",
6371 "class C extends Object { constructor() { super(); { return } } }",
6372 "class C extends Object { constructor() { super(); if (1) return; } }",
6373 "class C { constructor() { this.a = 0; return; } }",
6374 "class C { constructor() { this.a = 0; { return; } } }",
6375 "class C { constructor() { this.a = 0; if (0) return; 65; } }",
6376 "class C extends Array { constructor() { super(); this.a = 9; return } }",
6377 NULL};
6378
6379 static const ParserFlag always_flags[] = {kAllowStrongMode};
6380 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0,
6381 always_flags, arraysize(always_flags));
6382 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0,
6383 always_flags, arraysize(always_flags));
6384 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0,
6385 always_flags, arraysize(always_flags));
6386
6387 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0,
6388 always_flags, arraysize(always_flags));
6389 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0,
6390 always_flags, arraysize(always_flags));
6391 RunParserSyncTest(strong_context_data, success_data, kSuccess, NULL, 0,
6392 always_flags, arraysize(always_flags));
6393 }
6394
6395
6396 TEST(StrongConstructorDirective) {
6397 const char* context_data[][2] = {{"class c { ", " }"},
6398 {"(class c { ", " });"},
6399 {"let a = (class c { ", " });"},
6400 {NULL}};
6401
6402 const char* error_data[] = {
6403 "constructor() { \"use strong\" }",
6404 "constructor(...rest) { \"use strong\" }",
6405 "foo() {} constructor() { \"use strong\" }",
6406 "foo(...rest) { \"use strict\" } constructor() { \"use strong\" }", NULL};
6407
6408 const char* success_data[] = {
6409 "constructor() { \"use strict\" }", "foo() { \"use strong\" }",
6410 "foo() { \"use strong\" } constructor() {}", NULL};
6411
6412 static const ParserFlag always_flags[] = {
6413 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kAllowStrongMode};
6414
6415 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
6416 arraysize(always_flags));
6417 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, always_flags,
6418 arraysize(always_flags));
6419 }
6420
6421
6422 TEST(StrongUndefinedLocal) {
6423 const char* context_data[][2] = {{"", ""}, {NULL}};
6424
6425 const char* data[] = {
6426 "function undefined() {'use strong';}",
6427 "function* undefined() {'use strong';}",
6428 "(function undefined() {'use strong';});",
6429 "{foo: (function undefined(){'use strong';})};",
6430 "(function* undefined() {'use strong';})",
6431 "{foo: (function* undefined(){'use strong';})};",
6432 "function foo(a, b, undefined, c, d) {'use strong';}",
6433 "function* foo(a, b, undefined, c, d) {'use strong';}",
6434 "(function foo(a, b, undefined, c, d) {'use strong';})",
6435 "{foo: (function foo(a, b, undefined, c, d) {'use strong';})};",
6436 "(function* foo(a, b, undefined, c, d) {'use strong';})",
6437 "{foo: (function* foo(a, b, undefined, c, d) {'use strong';})};",
6438 "class C { foo(a, b, undefined, c, d) {'use strong';} }",
6439 "class C { *foo(a, b, undefined, c, d) {'use strong';} }",
6440 "({ foo(a, b, undefined, c, d) {'use strong';} });",
6441 "{ *foo(a, b, undefined, c, d) {'use strong';} });",
6442 "class undefined {'use strong'}",
6443 "(class undefined {'use strong'});",
6444 NULL};
6445
6446 static const ParserFlag always_flags[] = {
6447 kAllowStrongMode, kAllowHarmonySloppy
6448 };
6449
6450 RunParserSyncTest(context_data, data, kError, NULL, 0,
6451 always_flags, arraysize(always_flags));
6452 }
6453
6454
6455 TEST(StrongUndefinedArrow) {
6456 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}};
6457 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}};
6458 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}};
6459
6460 const char* data[] = {
6461 "(undefined => {return});",
6462 "((undefined, b, c) => {return});",
6463 "((a, undefined, c) => {return});",
6464 "((a, b, undefined) => {return});",
6465 NULL};
6466
6467 const char* local_strong[] = {
6468 "(undefined => {'use strong';});",
6469 "((undefined, b, c) => {'use strong';});",
6470 "((a, undefined, c) => {'use strong';});",
6471 "((a, b, undefined) => {'use strong';});",
6472 NULL};
6473
6474 static const ParserFlag always_flags[] = {kAllowStrongMode};
6475 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags,
6476 arraysize(always_flags));
6477 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
6478 arraysize(always_flags));
6479 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
6480 arraysize(always_flags));
6481 RunParserSyncTest(sloppy_context_data, local_strong, kError, NULL, 0,
6482 always_flags, arraysize(always_flags));
6483 }
6484
6485
6486 TEST(StrongDirectEval) {
6487 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}};
6488 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}};
6489
6490 const char* error_data[] = {
6491 "eval();",
6492 "eval([]);",
6493 "(eval)();",
6494 "(((eval)))();",
6495 "eval('function f() {}');",
6496 "function f() {eval()}",
6497 NULL};
6498
6499 const char* success_data[] = {
6500 "eval;",
6501 "eval`foo`;",
6502 "let foo = eval; foo();",
6503 "(1, eval)();",
6504 NULL};
6505
6506 static const ParserFlag always_flags[] = {
6507 kAllowStrongMode
6508 };
6509
6510 RunParserSyncTest(sloppy_context_data, error_data, kSuccess, NULL, 0,
6511 always_flags, arraysize(always_flags));
6512 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0,
6513 always_flags, arraysize(always_flags));
6514 RunParserSyncTest(strong_context_data, success_data, kSuccess, NULL, 0,
6515 always_flags, arraysize(always_flags));
6516 }
6517
6518
6519 TEST(StrongSwitchFallthrough) {
6520 const char* sloppy_context_data[][2] = {
6521 {"function f() { foo:for(;;) { switch(1) {", "};}}"},
6522 {NULL, NULL}
6523 };
6524 const char* strong_context_data[][2] = {
6525 {"function f() { 'use strong'; foo:for(;;) { switch(1) {", "};}}"},
6526 {NULL, NULL}
6527 };
6528
6529 const char* data_success[] = {
6530 "",
6531 "case 1:",
6532 "case 1: case 2:",
6533 "case 1: break;",
6534 "default: throw new TypeError();",
6535 "case 1: case 2: null",
6536 "case 1: case 2: default: 1+1",
6537 "case 1: break; case 2: return; default:",
6538 "case 1: break foo; case 2: return; default:",
6539 "case 1: case 2: break; case 3: continue; case 4: default:",
6540 "case 1: case 2: break; case 3: continue foo; case 4: default:",
6541 "case 1: case 2: {{return;}} case 3: default:",
6542 "case 1: case 2: case 3: default: {1+1;{continue;}}",
6543 "case 1: case 2: {1+1;{1+1;{continue;}}} case 3: default:",
6544 "case 1: if (1) break; else continue; case 2: case 3: default:",
6545 "case 1: case 2: if (1) {{break;}} else break; case 3: default:",
6546 "case 1: if (1) break; else {if (1) break; else break;} case 2: default:",
6547 "case 1: if (1) {if (1) break; else break;} else break; case 2: default:",
6548 NULL};
6549
6550 const char* data_error[] = {
6551 "case 1: case 2: (function(){return}); default:",
6552 "case 1: 1+1; case 2:",
6553 "case 1: bar: break bar; case 2: break;",
6554 "case 1: bar:return; case 2:",
6555 "case 1: bar:{ continue;} case 2:",
6556 "case 1: break; case 2: bar:{ throw new TypeError() } default:",
6557 "case 1: case 2: { bar:{ { break;} } } default: break;",
6558 "case 1: if (1) break; else {}; case 2: default:",
6559 "case 1: case 2: if (1) break; default:",
6560 "case 1: case 2: if (1) break; else 0; default:",
6561 "case 1: case 2: if (1) 0; else break; default:",
6562 "case 1: case 2: case 3: if (1) {} default:",
6563 "case 1: bar:if (1) break; else continue; case 2: case 3: default:",
6564 NULL};
6565
6566 static const ParserFlag always_flags[] = {
6567 kAllowStrongMode
6568 };
6569 RunParserSyncTest(strong_context_data, data_success, kSuccess, NULL, 0,
6570 always_flags, arraysize(always_flags));
6571 RunParserSyncTest(sloppy_context_data, data_error, kSuccess, NULL, 0,
6572 always_flags, arraysize(always_flags));
6573 RunParserSyncTest(strong_context_data, data_error, kError, NULL, 0,
6574 always_flags, arraysize(always_flags));
6575 }
6576
6577
6578 TEST(ArrowFunctionASIErrors) { 6014 TEST(ArrowFunctionASIErrors) {
6579 const char* context_data[][2] = {{"'use strict';", ""}, {"", ""}, 6015 const char* context_data[][2] = {{"'use strict';", ""}, {"", ""},
6580 {NULL, NULL}}; 6016 {NULL, NULL}};
6581 6017
6582 const char* data[] = { 6018 const char* data[] = {
6583 "(a\n=> a)(1)", 6019 "(a\n=> a)(1)",
6584 "(a/*\n*/=> a)(1)", 6020 "(a/*\n*/=> a)(1)",
6585 "((a)\n=> a)(1)", 6021 "((a)\n=> a)(1)",
6586 "((a)/*\n*/=> a)(1)", 6022 "((a)/*\n*/=> a)(1)",
6587 "((a, b)\n=> a + b)(1, 2)", 6023 "((a, b)\n=> a + b)(1, 2)",
6588 "((a, b)/*\n*/=> a + b)(1, 2)", 6024 "((a, b)/*\n*/=> a + b)(1, 2)",
6589 NULL}; 6025 NULL};
6590 RunParserSyncTest(context_data, data, kError); 6026 RunParserSyncTest(context_data, data, kError);
6591 } 6027 }
6592 6028
6593 6029
6594 TEST(StrongModeFreeVariablesDeclaredByPreviousScript) {
6595 i::FLAG_strong_mode = true;
6596 i::FLAG_legacy_const = true;
6597 v8::V8::Initialize();
6598 v8::HandleScope scope(CcTest::isolate());
6599 v8::Context::Scope context_scope(v8::Context::New(CcTest::isolate()));
6600 v8::TryCatch try_catch(CcTest::isolate());
6601
6602 // Introduce a bunch of variables, in all language modes.
6603 const char* script1 =
6604 "var my_var1 = 0; \n"
6605 "function my_func1() { } \n"
6606 "const my_const1 = 0; \n";
6607 CompileRun(v8_str(script1));
6608 CHECK(!try_catch.HasCaught());
6609
6610 const char* script2 =
6611 "\"use strict\"; \n"
6612 "let my_var2 = 0; \n"
6613 "function my_func2() { } \n"
6614 "const my_const2 = 0 \n";
6615 CompileRun(v8_str(script2));
6616 CHECK(!try_catch.HasCaught());
6617
6618 const char* script3 =
6619 "\"use strong\"; \n"
6620 "let my_var3 = 0; \n"
6621 "function my_func3() { } \n"
6622 "const my_const3 = 0; \n";
6623 CompileRun(v8_str(script3));
6624 CHECK(!try_catch.HasCaught());
6625
6626 // Sloppy eval introduces variables in the surrounding scope.
6627 const char* script4 =
6628 "eval('var my_var4 = 0;') \n"
6629 "eval('function my_func4() { }') \n"
6630 "eval('const my_const4 = 0;') \n";
6631 CompileRun(v8_str(script4));
6632 CHECK(!try_catch.HasCaught());
6633
6634 // Test that referencing these variables work.
6635 const char* script5 =
6636 "\"use strong\"; \n"
6637 "my_var1; \n"
6638 "my_func1; \n"
6639 "my_const1; \n"
6640 "my_var2; \n"
6641 "my_func2; \n"
6642 "my_const2; \n"
6643 "my_var3; \n"
6644 "my_func3; \n"
6645 "my_const3; \n"
6646 "my_var4; \n"
6647 "my_func4; \n"
6648 "my_const4; \n";
6649 CompileRun(v8_str(script5));
6650 CHECK(!try_catch.HasCaught());
6651 }
6652
6653
6654 TEST(StrongModeFreeVariablesDeclaredByLanguage) {
6655 i::FLAG_strong_mode = true;
6656 v8::V8::Initialize();
6657 v8::HandleScope scope(CcTest::isolate());
6658 v8::Context::Scope context_scope(v8::Context::New(CcTest::isolate()));
6659 v8::TryCatch try_catch(CcTest::isolate());
6660
6661 const char* script1 =
6662 "\"use strong\"; \n"
6663 "Math; \n"
6664 "RegExp; \n";
6665 CompileRun(v8_str(script1));
6666 CHECK(!try_catch.HasCaught());
6667 }
6668
6669
6670 TEST(StrongModeFreeVariablesDeclaredInGlobalPrototype) {
6671 i::FLAG_strong_mode = true;
6672 v8::V8::Initialize();
6673 v8::HandleScope scope(CcTest::isolate());
6674 v8::Context::Scope context_scope(v8::Context::New(CcTest::isolate()));
6675 v8::TryCatch try_catch(CcTest::isolate());
6676
6677 const char* script1 = "this.__proto__.my_var = 0;\n";
6678 CompileRun(v8_str(script1));
6679 CHECK(!try_catch.HasCaught());
6680
6681 const char* script2 =
6682 "\"use strong\"; \n"
6683 "my_var; \n";
6684 CompileRun(v8_str(script2));
6685 CHECK(!try_catch.HasCaught());
6686 }
6687
6688
6689 static const ParserFlag kAllDestructuringFlags[] = { 6030 static const ParserFlag kAllDestructuringFlags[] = {
6690 kAllowHarmonyDestructuring, kAllowHarmonyDestructuringAssignment, 6031 kAllowHarmonyDestructuring, kAllowHarmonyDestructuringAssignment,
6691 kAllowHarmonyDefaultParameters}; 6032 kAllowHarmonyDefaultParameters};
6692 6033
6693 TEST(DestructuringPositiveTests) { 6034 TEST(DestructuringPositiveTests) {
6694 i::FLAG_harmony_destructuring_bind = true; 6035 i::FLAG_harmony_destructuring_bind = true;
6695 6036
6696 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6037 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6697 {"var ", " = {};"}, 6038 {"var ", " = {};"},
6698 {"'use strict'; const ", " = {};"}, 6039 {"'use strict'; const ", " = {};"},
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
7404 6745
7405 6746
7406 TEST(DefaultParametersYieldInInitializers) { 6747 TEST(DefaultParametersYieldInInitializers) {
7407 // clang-format off 6748 // clang-format off
7408 const char* sloppy_function_context_data[][2] = { 6749 const char* sloppy_function_context_data[][2] = {
7409 {"(function f(", ") { });"}, 6750 {"(function f(", ") { });"},
7410 {NULL, NULL} 6751 {NULL, NULL}
7411 }; 6752 };
7412 6753
7413 const char* strict_function_context_data[][2] = { 6754 const char* strict_function_context_data[][2] = {
7414 {"'use strong'; (function f(", ") { });"},
7415 {"'use strict'; (function f(", ") { });"}, 6755 {"'use strict'; (function f(", ") { });"},
7416 {NULL, NULL} 6756 {NULL, NULL}
7417 }; 6757 };
7418 6758
7419 const char* sloppy_arrow_context_data[][2] = { 6759 const char* sloppy_arrow_context_data[][2] = {
7420 {"((", ")=>{});"}, 6760 {"((", ")=>{});"},
7421 {NULL, NULL} 6761 {NULL, NULL}
7422 }; 6762 };
7423 6763
7424 const char* strict_arrow_context_data[][2] = { 6764 const char* strict_arrow_context_data[][2] = {
7425 {"'use strong'; ((", ")=>{});"},
7426 {"'use strict'; ((", ")=>{});"}, 6765 {"'use strict'; ((", ")=>{});"},
7427 {NULL, NULL} 6766 {NULL, NULL}
7428 }; 6767 };
7429 6768
7430 const char* generator_context_data[][2] = { 6769 const char* generator_context_data[][2] = {
7431 {"'use strong'; (function *g(", ") { });"},
7432 {"'use strict'; (function *g(", ") { });"}, 6770 {"'use strict'; (function *g(", ") { });"},
7433 {"(function *g(", ") { });"}, 6771 {"(function *g(", ") { });"},
7434 {NULL, NULL} 6772 {NULL, NULL}
7435 }; 6773 };
7436 6774
7437 const char* parameter_data[] = { 6775 const char* parameter_data[] = {
7438 "x=yield", 6776 "x=yield",
7439 "x, y=yield", 6777 "x, y=yield",
7440 "{x=yield}", 6778 "{x=yield}",
7441 "[x=yield]", 6779 "[x=yield]",
(...skipping 14 matching lines...) Expand all
7456 "{x}=(yield)", 6794 "{x}=(yield)",
7457 "[x]=(yield)", 6795 "[x]=(yield)",
7458 6796
7459 "{x}=f(yield)", 6797 "{x}=f(yield)",
7460 "[x]=f(yield)", 6798 "[x]=f(yield)",
7461 NULL 6799 NULL
7462 }; 6800 };
7463 6801
7464 // clang-format on 6802 // clang-format on
7465 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring, 6803 static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring,
7466 kAllowHarmonyDefaultParameters, 6804 kAllowHarmonyDefaultParameters};
7467 kAllowStrongMode};
7468 6805
7469 RunParserSyncTest(sloppy_function_context_data, parameter_data, kSuccess, 6806 RunParserSyncTest(sloppy_function_context_data, parameter_data, kSuccess,
7470 NULL, 0, always_flags, arraysize(always_flags)); 6807 NULL, 0, always_flags, arraysize(always_flags));
7471 RunParserSyncTest(sloppy_arrow_context_data, parameter_data, kSuccess, NULL, 6808 RunParserSyncTest(sloppy_arrow_context_data, parameter_data, kSuccess, NULL,
7472 0, always_flags, arraysize(always_flags)); 6809 0, always_flags, arraysize(always_flags));
7473 6810
7474 RunParserSyncTest(strict_function_context_data, parameter_data, kError, NULL, 6811 RunParserSyncTest(strict_function_context_data, parameter_data, kError, NULL,
7475 0, always_flags, arraysize(always_flags)); 6812 0, always_flags, arraysize(always_flags));
7476 RunParserSyncTest(strict_arrow_context_data, parameter_data, kError, NULL, 0, 6813 RunParserSyncTest(strict_arrow_context_data, parameter_data, kError, NULL, 0,
7477 always_flags, arraysize(always_flags)); 6814 always_flags, arraysize(always_flags));
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
7644 kAllowHarmonySloppyLet}; 6981 kAllowHarmonySloppyLet};
7645 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, 6982 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
7646 arraysize(always_flags)); 6983 arraysize(always_flags));
7647 } 6984 }
7648 6985
7649 6986
7650 TEST(LanguageModeDirectivesNonSimpleParameterListErrors) { 6987 TEST(LanguageModeDirectivesNonSimpleParameterListErrors) {
7651 // TC39 deemed "use strict" directives to be an error when occurring in the 6988 // TC39 deemed "use strict" directives to be an error when occurring in the
7652 // body of a function with non-simple parameter list, on 29/7/2015. 6989 // body of a function with non-simple parameter list, on 29/7/2015.
7653 // https://goo.gl/ueA7Ln 6990 // https://goo.gl/ueA7Ln
7654 //
7655 // In V8, this also applies to "use strong " directives.
7656 const char* context_data[][2] = { 6991 const char* context_data[][2] = {
7657 {"function f(", ") { 'use strict'; }"}, 6992 {"function f(", ") { 'use strict'; }"},
7658 {"function f(", ") { 'use strong'; }"},
7659 {"function* g(", ") { 'use strict'; }"}, 6993 {"function* g(", ") { 'use strict'; }"},
7660 {"function* g(", ") { 'use strong'; }"},
7661 {"class c { foo(", ") { 'use strict' }"}, 6994 {"class c { foo(", ") { 'use strict' }"},
7662 {"class c { foo(", ") { 'use strong' }"},
7663 {"var a = (", ") => { 'use strict'; }"}, 6995 {"var a = (", ") => { 'use strict'; }"},
7664 {"var a = (", ") => { 'use strong'; }"},
7665 {"var o = { m(", ") { 'use strict'; }"}, 6996 {"var o = { m(", ") { 'use strict'; }"},
7666 {"var o = { m(", ") { 'use strong'; }"},
7667 {"var o = { *gm(", ") { 'use strict'; }"}, 6997 {"var o = { *gm(", ") { 'use strict'; }"},
7668 {"var o = { *gm(", ") { 'use strong'; }"},
7669 {"var c = { m(", ") { 'use strict'; }"}, 6998 {"var c = { m(", ") { 'use strict'; }"},
7670 {"var c = { m(", ") { 'use strong'; }"},
7671 {"var c = { *gm(", ") { 'use strict'; }"}, 6999 {"var c = { *gm(", ") { 'use strict'; }"},
7672 {"var c = { *gm(", ") { 'use strong'; }"},
7673 7000
7674 {"'use strict'; function f(", ") { 'use strict'; }"}, 7001 {"'use strict'; function f(", ") { 'use strict'; }"},
7675 {"'use strict'; function f(", ") { 'use strong'; }"},
7676 {"'use strict'; function* g(", ") { 'use strict'; }"}, 7002 {"'use strict'; function* g(", ") { 'use strict'; }"},
7677 {"'use strict'; function* g(", ") { 'use strong'; }"},
7678 {"'use strict'; class c { foo(", ") { 'use strict' }"}, 7003 {"'use strict'; class c { foo(", ") { 'use strict' }"},
7679 {"'use strict'; class c { foo(", ") { 'use strong' }"},
7680 {"'use strict'; var a = (", ") => { 'use strict'; }"}, 7004 {"'use strict'; var a = (", ") => { 'use strict'; }"},
7681 {"'use strict'; var a = (", ") => { 'use strong'; }"},
7682 {"'use strict'; var o = { m(", ") { 'use strict'; }"}, 7005 {"'use strict'; var o = { m(", ") { 'use strict'; }"},
7683 {"'use strict'; var o = { m(", ") { 'use strong'; }"},
7684 {"'use strict'; var o = { *gm(", ") { 'use strict'; }"}, 7006 {"'use strict'; var o = { *gm(", ") { 'use strict'; }"},
7685 {"'use strict'; var o = { *gm(", ") { 'use strong'; }"},
7686 {"'use strict'; var c = { m(", ") { 'use strict'; }"}, 7007 {"'use strict'; var c = { m(", ") { 'use strict'; }"},
7687 {"'use strict'; var c = { m(", ") { 'use strong'; }"},
7688 {"'use strict'; var c = { *gm(", ") { 'use strict'; }"}, 7008 {"'use strict'; var c = { *gm(", ") { 'use strict'; }"},
7689 {"'use strict'; var c = { *gm(", ") { 'use strong'; }"},
7690
7691 {"'use strong'; function f(", ") { 'use strict'; }"},
7692 {"'use strong'; function f(", ") { 'use strong'; }"},
7693 {"'use strong'; function* g(", ") { 'use strict'; }"},
7694 {"'use strong'; function* g(", ") { 'use strong'; }"},
7695 {"'use strong'; class c { foo(", ") { 'use strict' }"},
7696 {"'use strong'; class c { foo(", ") { 'use strong' }"},
7697 {"'use strong'; var a = (", ") => { 'use strict'; }"},
7698 {"'use strong'; var a = (", ") => { 'use strong'; }"},
7699 {"'use strong'; var o = { m(", ") { 'use strict'; }"},
7700 {"'use strong'; var o = { m(", ") { 'use strong'; }"},
7701 {"'use strong'; var o = { *gm(", ") { 'use strict'; }"},
7702 {"'use strong'; var o = { *gm(", ") { 'use strong'; }"},
7703 {"'use strong'; var c = { m(", ") { 'use strict'; }"},
7704 {"'use strong'; var c = { m(", ") { 'use strong'; }"},
7705 {"'use strong'; var c = { *gm(", ") { 'use strict'; }"},
7706 {"'use strong'; var c = { *gm(", ") { 'use strong'; }"},
7707 7009
7708 {NULL, NULL}}; 7010 {NULL, NULL}};
7709 7011
7710 const char* data[] = { 7012 const char* data[] = {
7711 // TODO(@caitp): support formal parameter initializers 7013 // TODO(@caitp): support formal parameter initializers
7712 "{}", 7014 "{}",
7713 "[]", 7015 "[]",
7714 "[{}]", 7016 "[{}]",
7715 "{a}", 7017 "{a}",
7716 "a, {b}", 7018 "a, {b}",
7717 "a, b, {c, d, e}", 7019 "a, b, {c, d, e}",
7718 "initializer = true", 7020 "initializer = true",
7719 "a, b, c = 1", 7021 "a, b, c = 1",
7720 "...args", 7022 "...args",
7721 "a, b, ...rest", 7023 "a, b, ...rest",
7722 "[a, b, ...rest]", 7024 "[a, b, ...rest]",
7723 "{ bindingPattern = {} }", 7025 "{ bindingPattern = {} }",
7724 "{ initializedBindingPattern } = { initializedBindingPattern: true }", 7026 "{ initializedBindingPattern } = { initializedBindingPattern: true }",
7725 NULL}; 7027 NULL};
7726 7028
7727 static const ParserFlag always_flags[] = { 7029 static const ParserFlag always_flags[] = {
7728 kAllowHarmonyDefaultParameters, kAllowHarmonyDestructuring, 7030 kAllowHarmonyDefaultParameters, kAllowHarmonyDestructuring,
7729 kAllowHarmonySloppy, kAllowStrongMode}; 7031 kAllowHarmonySloppy};
7730 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 7032 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
7731 arraysize(always_flags)); 7033 arraysize(always_flags));
7732 } 7034 }
7733 7035
7734 7036
7735 TEST(LetSloppyOnly) { 7037 TEST(LetSloppyOnly) {
7736 // clang-format off 7038 // clang-format off
7737 const char* context_data[][2] = { 7039 const char* context_data[][2] = {
7738 {"", ""}, 7040 {"", ""},
7739 {"{", "}"}, 7041 {"{", "}"},
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
8078 RunParserSyncTest(sloppy_context, error_data, kError); 7380 RunParserSyncTest(sloppy_context, error_data, kError);
8079 RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0, 7381 RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0,
8080 restrictive_flags, arraysize(restrictive_flags)); 7382 restrictive_flags, arraysize(restrictive_flags));
8081 RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess); 7383 RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess);
8082 RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0, 7384 RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0,
8083 restrictive_flags, arraysize(restrictive_flags)); 7385 restrictive_flags, arraysize(restrictive_flags));
8084 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess); 7386 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess);
8085 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags, 7387 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags,
8086 arraysize(restrictive_flags)); 7388 arraysize(restrictive_flags));
8087 } 7389 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/mjsunit/es6/classes-subclass-builtins.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698