Chromium Code Reviews| 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 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1754 } | 1754 } |
| 1755 | 1755 |
| 1756 | 1756 |
| 1757 TEST(ErrorsEvalAndArguments) { | 1757 TEST(ErrorsEvalAndArguments) { |
| 1758 // Tests that both preparsing and parsing produce the right kind of errors for | 1758 // Tests that both preparsing and parsing produce the right kind of errors for |
| 1759 // using "eval" and "arguments" as identifiers. Without the strict mode, it's | 1759 // using "eval" and "arguments" as identifiers. Without the strict mode, it's |
| 1760 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it | 1760 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it |
| 1761 // isn't. | 1761 // isn't. |
| 1762 const char* context_data[][2] = { | 1762 const char* context_data[][2] = { |
| 1763 { "\"use strict\";", "" }, | 1763 { "\"use strict\";", "" }, |
| 1764 { "\"use sanity\";", "" }, | |
| 1764 { "var eval; function test_func() {\"use strict\"; ", "}"}, | 1765 { "var eval; function test_func() {\"use strict\"; ", "}"}, |
| 1766 { "var eval; function test_func() {\"use sanity\"; ", "}"}, | |
| 1765 { NULL, NULL } | 1767 { NULL, NULL } |
| 1766 }; | 1768 }; |
| 1767 | 1769 |
| 1768 const char* statement_data[] = { | 1770 const char* statement_data[] = { |
| 1769 "var eval;", | 1771 "var eval;", |
| 1770 "var arguments", | 1772 "var arguments", |
| 1771 "var foo, eval;", | 1773 "var foo, eval;", |
| 1772 "var foo, arguments;", | 1774 "var foo, arguments;", |
| 1773 "try { } catch (eval) { }", | 1775 "try { } catch (eval) { }", |
| 1774 "try { } catch (arguments) { }", | 1776 "try { } catch (arguments) { }", |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1895 | 1897 |
| 1896 | 1898 |
| 1897 TEST(ErrorsFutureStrictReservedWords) { | 1899 TEST(ErrorsFutureStrictReservedWords) { |
| 1898 // Tests that both preparsing and parsing produce the right kind of errors for | 1900 // Tests that both preparsing and parsing produce the right kind of errors for |
| 1899 // using future strict reserved words as identifiers. Without the strict mode, | 1901 // using future strict reserved words as identifiers. Without the strict mode, |
| 1900 // it's ok to use future strict reserved words as identifiers. With the strict | 1902 // it's ok to use future strict reserved words as identifiers. With the strict |
| 1901 // mode, it isn't. | 1903 // mode, it isn't. |
| 1902 const char* context_data[][2] = { | 1904 const char* context_data[][2] = { |
| 1903 { "function test_func() {\"use strict\"; ", "}"}, | 1905 { "function test_func() {\"use strict\"; ", "}"}, |
| 1904 { "() => { \"use strict\"; ", "}" }, | 1906 { "() => { \"use strict\"; ", "}" }, |
| 1907 { "function test_func() {\"use sanity\"; ", "}"}, | |
| 1908 { "() => { \"use sanity\"; ", "}" }, | |
| 1905 { NULL, NULL } | 1909 { NULL, NULL } |
| 1906 }; | 1910 }; |
| 1907 | 1911 |
| 1908 const char* statement_data[] { | 1912 const char* statement_data[] { |
| 1909 LIMITED_FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) | 1913 LIMITED_FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) |
| 1910 NULL | 1914 NULL |
| 1911 }; | 1915 }; |
| 1912 | 1916 |
| 1913 RunParserSyncTest(context_data, statement_data, kError); | 1917 RunParserSyncTest(context_data, statement_data, kError); |
| 1914 RunParserSyncTest(context_data, statement_data, kError); | 1918 RunParserSyncTest(context_data, statement_data, kError); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2089 | 2093 |
| 2090 TEST(ErrorsYieldStrict) { | 2094 TEST(ErrorsYieldStrict) { |
| 2091 const char* context_data[][2] = { | 2095 const char* context_data[][2] = { |
| 2092 { "\"use strict\";", "" }, | 2096 { "\"use strict\";", "" }, |
| 2093 { "\"use strict\"; function not_gen() {", "}" }, | 2097 { "\"use strict\"; function not_gen() {", "}" }, |
| 2094 { "function test_func() {\"use strict\"; ", "}"}, | 2098 { "function test_func() {\"use strict\"; ", "}"}, |
| 2095 { "\"use strict\"; function * gen() { function not_gen() {", "} }" }, | 2099 { "\"use strict\"; function * gen() { function not_gen() {", "} }" }, |
| 2096 { "\"use strict\"; (function not_gen() {", "})" }, | 2100 { "\"use strict\"; (function not_gen() {", "})" }, |
| 2097 { "\"use strict\"; (function * gen() { (function not_gen() {", "}) })" }, | 2101 { "\"use strict\"; (function * gen() { (function not_gen() {", "}) })" }, |
| 2098 { "() => {\"use strict\"; ", "}" }, | 2102 { "() => {\"use strict\"; ", "}" }, |
| 2103 { "\"use sanity\";", "" }, | |
| 2104 { "\"use sanity\"; function not_gen() {", "}" }, | |
| 2105 { "function test_func() {\"use sanity\"; ", "}"}, | |
| 2106 { "\"use sanity\"; function * gen() { function not_gen() {", "} }" }, | |
| 2107 { "\"use sanity\"; (function not_gen() {", "})" }, | |
| 2108 { "\"use sanity\"; (function * gen() { (function not_gen() {", "}) })" }, | |
| 2109 { "() => {\"use sanity\"; ", "}" }, | |
| 2099 { NULL, NULL } | 2110 { NULL, NULL } |
| 2100 }; | 2111 }; |
| 2101 | 2112 |
| 2102 const char* statement_data[] = { | 2113 const char* statement_data[] = { |
| 2103 "var yield;", | 2114 "var yield;", |
| 2104 "var foo, yield;", | 2115 "var foo, yield;", |
| 2105 "try { } catch (yield) { }", | 2116 "try { } catch (yield) { }", |
| 2106 "function yield() { }", | 2117 "function yield() { }", |
| 2107 "(function yield() { })", | 2118 "(function yield() { })", |
| 2108 "function foo(yield) { }", | 2119 "function foo(yield) { }", |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2228 RunParserSyncTest(context_data, statement_data, kError); | 2239 RunParserSyncTest(context_data, statement_data, kError); |
| 2229 } | 2240 } |
| 2230 | 2241 |
| 2231 | 2242 |
| 2232 TEST(ErrorsNameOfStrictFunction) { | 2243 TEST(ErrorsNameOfStrictFunction) { |
| 2233 // Tests that illegal tokens as names of a strict function produce the correct | 2244 // Tests that illegal tokens as names of a strict function produce the correct |
| 2234 // errors. | 2245 // errors. |
| 2235 const char* context_data[][2] = { | 2246 const char* context_data[][2] = { |
| 2236 { "function ", ""}, | 2247 { "function ", ""}, |
| 2237 { "\"use strict\"; function", ""}, | 2248 { "\"use strict\"; function", ""}, |
| 2249 { "\"use sanity\"; function", ""}, | |
| 2238 { "function * ", ""}, | 2250 { "function * ", ""}, |
| 2239 { "\"use strict\"; function * ", ""}, | 2251 { "\"use strict\"; function * ", ""}, |
| 2252 { "\"use sanity\"; function * ", ""}, | |
| 2240 { NULL, NULL } | 2253 { NULL, NULL } |
| 2241 }; | 2254 }; |
| 2242 | 2255 |
| 2243 const char* statement_data[] = { | 2256 const char* statement_data[] = { |
| 2244 "eval() {\"use strict\";}", | 2257 "eval() {\"use strict\";}", |
| 2245 "arguments() {\"use strict\";}", | 2258 "arguments() {\"use strict\";}", |
| 2246 "interface() {\"use strict\";}", | 2259 "interface() {\"use strict\";}", |
| 2247 "yield() {\"use strict\";}", | 2260 "yield() {\"use strict\";}", |
| 2248 // Future reserved words are always illegal | 2261 // Future reserved words are always illegal |
| 2249 "function super() { }", | 2262 "function super() { }", |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2308 RunParserSyncTest(context_data, statement_data, kError); | 2321 RunParserSyncTest(context_data, statement_data, kError); |
| 2309 } | 2322 } |
| 2310 | 2323 |
| 2311 | 2324 |
| 2312 TEST(ErrorsIllegalWordsAsLabelsStrict) { | 2325 TEST(ErrorsIllegalWordsAsLabelsStrict) { |
| 2313 // Tests that illegal tokens as labels produce the correct errors. | 2326 // Tests that illegal tokens as labels produce the correct errors. |
| 2314 const char* context_data[][2] = { | 2327 const char* context_data[][2] = { |
| 2315 { "\"use strict\";", "" }, | 2328 { "\"use strict\";", "" }, |
| 2316 { "function test_func() {\"use strict\"; ", "}"}, | 2329 { "function test_func() {\"use strict\"; ", "}"}, |
| 2317 { "() => {\"use strict\"; ", "}" }, | 2330 { "() => {\"use strict\"; ", "}" }, |
| 2331 { "\"use sanity\";", "" }, | |
| 2332 { "function test_func() {\"use sanity\"; ", "}"}, | |
| 2333 { "() => {\"use sanity\"; ", "}" }, | |
| 2318 { NULL, NULL } | 2334 { NULL, NULL } |
| 2319 }; | 2335 }; |
| 2320 | 2336 |
| 2321 #define LABELLED_WHILE(NAME) #NAME ": while (true) { break " #NAME "; }", | 2337 #define LABELLED_WHILE(NAME) #NAME ": while (true) { break " #NAME "; }", |
| 2322 const char* statement_data[] = { | 2338 const char* statement_data[] = { |
| 2323 "super: while(true) { break super; }", | 2339 "super: while(true) { break super; }", |
| 2324 FUTURE_STRICT_RESERVED_WORDS(LABELLED_WHILE) | 2340 FUTURE_STRICT_RESERVED_WORDS(LABELLED_WHILE) |
| 2325 NULL | 2341 NULL |
| 2326 }; | 2342 }; |
| 2327 #undef LABELLED_WHILE | 2343 #undef LABELLED_WHILE |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2396 | 2412 |
| 2397 TEST(NoErrorsParenthesizedDirectivePrologue) { | 2413 TEST(NoErrorsParenthesizedDirectivePrologue) { |
| 2398 // Parenthesized directive prologue shouldn't be recognized. | 2414 // Parenthesized directive prologue shouldn't be recognized. |
| 2399 const char* context_data[][2] = { | 2415 const char* context_data[][2] = { |
| 2400 { "", ""}, | 2416 { "", ""}, |
| 2401 { NULL, NULL } | 2417 { NULL, NULL } |
| 2402 }; | 2418 }; |
| 2403 | 2419 |
| 2404 const char* statement_data[] = { | 2420 const char* statement_data[] = { |
| 2405 "(\"use strict\"); var eval;", | 2421 "(\"use strict\"); var eval;", |
| 2422 "(\"use sanity\"); var eval;", | |
| 2406 NULL | 2423 NULL |
| 2407 }; | 2424 }; |
| 2408 | 2425 |
| 2409 RunParserSyncTest(context_data, statement_data, kSuccess); | 2426 RunParserSyncTest(context_data, statement_data, kSuccess); |
| 2410 } | 2427 } |
| 2411 | 2428 |
| 2412 | 2429 |
| 2413 TEST(ErrorsNotAnIdentifierName) { | 2430 TEST(ErrorsNotAnIdentifierName) { |
| 2414 const char* context_data[][2] = { | 2431 const char* context_data[][2] = { |
| 2415 { "", ""}, | 2432 { "", ""}, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2523 {"function foo(bar, eval) {", "}"}, | 2540 {"function foo(bar, eval) {", "}"}, |
| 2524 {"function foo(bar, arguments) {", "}"}, | 2541 {"function foo(bar, arguments) {", "}"}, |
| 2525 {"function foo(bar, yield) {", "}"}, | 2542 {"function foo(bar, yield) {", "}"}, |
| 2526 {"function foo(bar, interface) {", "}"}, | 2543 {"function foo(bar, interface) {", "}"}, |
| 2527 {"function foo(bar, bar) {", "}"}, | 2544 {"function foo(bar, bar) {", "}"}, |
| 2528 { NULL, NULL } | 2545 { NULL, NULL } |
| 2529 }; | 2546 }; |
| 2530 | 2547 |
| 2531 const char* strict_statement_data[] = { | 2548 const char* strict_statement_data[] = { |
| 2532 "\"use strict\";", | 2549 "\"use strict\";", |
| 2550 "\"use sanity\";", | |
| 2533 NULL | 2551 NULL |
| 2534 }; | 2552 }; |
| 2535 | 2553 |
| 2536 const char* non_strict_statement_data[] = { | 2554 const char* non_strict_statement_data[] = { |
| 2537 ";", | 2555 ";", |
| 2538 NULL | 2556 NULL |
| 2539 }; | 2557 }; |
| 2540 | 2558 |
| 2541 RunParserSyncTest(context_data, strict_statement_data, kError); | 2559 RunParserSyncTest(context_data, strict_statement_data, kError); |
| 2542 RunParserSyncTest(context_data, non_strict_statement_data, kSuccess); | 2560 RunParserSyncTest(context_data, non_strict_statement_data, kSuccess); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2824 // The test is quite slow, so run it with a reduced set of flags. | 2842 // The test is quite slow, so run it with a reduced set of flags. |
| 2825 static const ParserFlag empty_flags[] = {kAllowLazy}; | 2843 static const ParserFlag empty_flags[] = {kAllowLazy}; |
| 2826 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1); | 2844 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1); |
| 2827 } | 2845 } |
| 2828 | 2846 |
| 2829 | 2847 |
| 2830 TEST(StrictDelete) { | 2848 TEST(StrictDelete) { |
| 2831 // "delete <Identifier>" is not allowed in strict mode. | 2849 // "delete <Identifier>" is not allowed in strict mode. |
| 2832 const char* strict_context_data[][2] = { | 2850 const char* strict_context_data[][2] = { |
| 2833 {"\"use strict\"; ", ""}, | 2851 {"\"use strict\"; ", ""}, |
| 2852 {"\"use sanity\"; ", ""}, | |
| 2834 { NULL, NULL } | 2853 { NULL, NULL } |
| 2835 }; | 2854 }; |
| 2836 | 2855 |
| 2837 const char* sloppy_context_data[][2] = { | 2856 const char* sloppy_context_data[][2] = { |
| 2838 {"", ""}, | 2857 {"", ""}, |
| 2839 { NULL, NULL } | 2858 { NULL, NULL } |
| 2840 }; | 2859 }; |
| 2841 | 2860 |
| 2842 // These are errors in the strict mode. | 2861 // These are errors in the strict mode. |
| 2843 const char* sloppy_statement_data[] = { | 2862 const char* sloppy_statement_data[] = { |
| (...skipping 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4963 } | 4982 } |
| 4964 | 4983 |
| 4965 | 4984 |
| 4966 TEST(DeclarationsError) { | 4985 TEST(DeclarationsError) { |
| 4967 const char* context_data[][2] = {{"'use strict'; if (true)", ""}, | 4986 const char* context_data[][2] = {{"'use strict'; if (true)", ""}, |
| 4968 {"'use strict'; if (false) {} else", ""}, | 4987 {"'use strict'; if (false) {} else", ""}, |
| 4969 {"'use strict'; while (false)", ""}, | 4988 {"'use strict'; while (false)", ""}, |
| 4970 {"'use strict'; for (;;)", ""}, | 4989 {"'use strict'; for (;;)", ""}, |
| 4971 {"'use strict'; for (x in y)", ""}, | 4990 {"'use strict'; for (x in y)", ""}, |
| 4972 {"'use strict'; do ", " while (false)"}, | 4991 {"'use strict'; do ", " while (false)"}, |
| 4992 {"'use sanity'; if (true)", ""}, | |
| 4993 {"'use sanity'; if (false) {} else", ""}, | |
| 4994 {"'use sanity'; while (false)", ""}, | |
| 4995 {"'use sanity'; for (;;)", ""}, | |
| 4996 {"'use sanity'; for (x in y)", ""}, | |
| 4997 {"'use sanity'; do ", " while (false)"}, | |
| 4973 {NULL, NULL}}; | 4998 {NULL, NULL}}; |
|
rossberg
2015/02/04 16:18:09
Maybe add a test checking multiple directives.
marja
2015/02/05 12:11:37
Done.
| |
| 4974 | 4999 |
| 4975 const char* statement_data[] = { | 5000 const char* statement_data[] = { |
| 4976 "let x = 1;", | 5001 "let x = 1;", |
| 4977 "const x = 1;", | 5002 "const x = 1;", |
| 4978 "class C {}", | 5003 "class C {}", |
| 4979 NULL}; | 5004 NULL}; |
| 4980 | 5005 |
| 4981 static const ParserFlag always_flags[] = { | 5006 static const ParserFlag always_flags[] = { |
| 4982 kAllowHarmonyClasses, kAllowHarmonyScoping | 5007 kAllowHarmonyClasses, kAllowHarmonyScoping |
| 4983 }; | 5008 }; |
| 4984 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, | 5009 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, |
| 4985 always_flags, arraysize(always_flags)); | 5010 always_flags, arraysize(always_flags)); |
| 4986 } | 5011 } |
| OLD | NEW |