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

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

Issue 898983002: Add strong mode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Code review + fixes Created 5 years, 10 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 | « src/runtime/runtime.h ('k') | test/unittests/compiler/js-typed-lowering-unittest.cc » ('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 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 kAllowHarmonyScoping, 1353 kAllowHarmonyScoping,
1354 kAllowHarmonyModules, 1354 kAllowHarmonyModules,
1355 kAllowHarmonyNumericLiterals, 1355 kAllowHarmonyNumericLiterals,
1356 kAllowHarmonyArrowFunctions, 1356 kAllowHarmonyArrowFunctions,
1357 kAllowHarmonyClasses, 1357 kAllowHarmonyClasses,
1358 kAllowHarmonyObjectLiterals, 1358 kAllowHarmonyObjectLiterals,
1359 kAllowHarmonyRestParameters, 1359 kAllowHarmonyRestParameters,
1360 kAllowHarmonyTemplates, 1360 kAllowHarmonyTemplates,
1361 kAllowHarmonySloppy, 1361 kAllowHarmonySloppy,
1362 kAllowHarmonyUnicode, 1362 kAllowHarmonyUnicode,
1363 kAllowHarmonyComputedPropertyNames 1363 kAllowHarmonyComputedPropertyNames,
1364 kAllowStrongMode
1364 }; 1365 };
1365 1366
1366 1367
1367 enum ParserSyncTestResult { 1368 enum ParserSyncTestResult {
1368 kSuccessOrError, 1369 kSuccessOrError,
1369 kSuccess, 1370 kSuccess,
1370 kError 1371 kError
1371 }; 1372 };
1372 1373
1373 template <typename Traits> 1374 template <typename Traits>
(...skipping 10 matching lines...) Expand all
1384 parser->set_allow_harmony_arrow_functions( 1385 parser->set_allow_harmony_arrow_functions(
1385 flags.Contains(kAllowHarmonyArrowFunctions)); 1386 flags.Contains(kAllowHarmonyArrowFunctions));
1386 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); 1387 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses));
1387 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates)); 1388 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates));
1388 parser->set_allow_harmony_rest_params( 1389 parser->set_allow_harmony_rest_params(
1389 flags.Contains(kAllowHarmonyRestParameters)); 1390 flags.Contains(kAllowHarmonyRestParameters));
1390 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); 1391 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy));
1391 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); 1392 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode));
1392 parser->set_allow_harmony_computed_property_names( 1393 parser->set_allow_harmony_computed_property_names(
1393 flags.Contains(kAllowHarmonyComputedPropertyNames)); 1394 flags.Contains(kAllowHarmonyComputedPropertyNames));
1395 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode));
1394 } 1396 }
1395 1397
1396 1398
1397 void TestParserSyncWithFlags(i::Handle<i::String> source, 1399 void TestParserSyncWithFlags(i::Handle<i::String> source,
1398 i::EnumSet<ParserFlag> flags, 1400 i::EnumSet<ParserFlag> flags,
1399 ParserSyncTestResult result) { 1401 ParserSyncTestResult result) {
1400 i::Isolate* isolate = CcTest::i_isolate(); 1402 i::Isolate* isolate = CcTest::i_isolate();
1401 i::Factory* factory = isolate->factory(); 1403 i::Factory* factory = isolate->factory();
1402 1404
1403 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1405 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1753 delete[] generated_flags; 1755 delete[] generated_flags;
1754 } 1756 }
1755 1757
1756 1758
1757 TEST(ErrorsEvalAndArguments) { 1759 TEST(ErrorsEvalAndArguments) {
1758 // Tests that both preparsing and parsing produce the right kind of errors for 1760 // 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 1761 // 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 1762 // ok to use "eval" or "arguments" as identifiers. With the strict mode, it
1761 // isn't. 1763 // isn't.
1762 const char* context_data[][2] = { 1764 const char* context_data[][2] = {
1763 { "\"use strict\";", "" }, 1765 {"\"use strict\";", ""},
1764 { "var eval; function test_func() {\"use strict\"; ", "}"}, 1766 {"\"use strong\";", ""},
1765 { NULL, NULL } 1767 {"var eval; function test_func() {\"use strict\"; ", "}"},
1766 }; 1768 {"var eval; function test_func() {\"use strong\"; ", "}"},
1769 {NULL, NULL}};
1767 1770
1768 const char* statement_data[] = { 1771 const char* statement_data[] = {
1769 "var eval;", 1772 "var eval;",
1770 "var arguments", 1773 "var arguments",
1771 "var foo, eval;", 1774 "var foo, eval;",
1772 "var foo, arguments;", 1775 "var foo, arguments;",
1773 "try { } catch (eval) { }", 1776 "try { } catch (eval) { }",
1774 "try { } catch (arguments) { }", 1777 "try { } catch (arguments) { }",
1775 "function eval() { }", 1778 "function eval() { }",
1776 "function arguments() { }", 1779 "function arguments() { }",
1777 "function foo(eval) { }", 1780 "function foo(eval) { }",
1778 "function foo(arguments) { }", 1781 "function foo(arguments) { }",
1779 "function foo(bar, eval) { }", 1782 "function foo(bar, eval) { }",
1780 "function foo(bar, arguments) { }", 1783 "function foo(bar, arguments) { }",
1781 "(eval) => { }", 1784 "(eval) => { }",
1782 "(arguments) => { }", 1785 "(arguments) => { }",
1783 "(foo, eval) => { }", 1786 "(foo, eval) => { }",
1784 "(foo, arguments) => { }", 1787 "(foo, arguments) => { }",
1785 "eval = 1;", 1788 "eval = 1;",
1786 "arguments = 1;", 1789 "arguments = 1;",
1787 "var foo = eval = 1;", 1790 "var foo = eval = 1;",
1788 "var foo = arguments = 1;", 1791 "var foo = arguments = 1;",
1789 "++eval;", 1792 "++eval;",
1790 "++arguments;", 1793 "++arguments;",
1791 "eval++;", 1794 "eval++;",
1792 "arguments++;", 1795 "arguments++;",
1793 NULL 1796 NULL
1794 }; 1797 };
1795 1798
1796 RunParserSyncTest(context_data, statement_data, kError); 1799 static const ParserFlag always_flags[] = {kAllowStrongMode};
1800 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
1801 arraysize(always_flags));
1797 } 1802 }
1798 1803
1799 1804
1800 TEST(NoErrorsEvalAndArgumentsSloppy) { 1805 TEST(NoErrorsEvalAndArgumentsSloppy) {
1801 // Tests that both preparsing and parsing accept "eval" and "arguments" as 1806 // Tests that both preparsing and parsing accept "eval" and "arguments" as
1802 // identifiers when needed. 1807 // identifiers when needed.
1803 const char* context_data[][2] = { 1808 const char* context_data[][2] = {
1804 { "", "" }, 1809 { "", "" },
1805 { "function test_func() {", "}"}, 1810 { "function test_func() {", "}"},
1806 { NULL, NULL } 1811 { NULL, NULL }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 "++" #NAME ";", \ 1898 "++" #NAME ";", \
1894 #NAME " ++;", 1899 #NAME " ++;",
1895 1900
1896 1901
1897 TEST(ErrorsFutureStrictReservedWords) { 1902 TEST(ErrorsFutureStrictReservedWords) {
1898 // Tests that both preparsing and parsing produce the right kind of errors for 1903 // 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, 1904 // 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 1905 // it's ok to use future strict reserved words as identifiers. With the strict
1901 // mode, it isn't. 1906 // mode, it isn't.
1902 const char* context_data[][2] = { 1907 const char* context_data[][2] = {
1903 { "function test_func() {\"use strict\"; ", "}"}, 1908 {"function test_func() {\"use strict\"; ", "}"},
1904 { "() => { \"use strict\"; ", "}" }, 1909 {"() => { \"use strict\"; ", "}"},
1905 { NULL, NULL } 1910 {"function test_func() {\"use strong\"; ", "}"},
1906 }; 1911 {"() => { \"use strong\"; ", "}"},
1912 {NULL, NULL}};
1907 1913
1908 const char* statement_data[] { 1914 const char* statement_data[] {
1909 LIMITED_FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) 1915 LIMITED_FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS)
1910 NULL 1916 NULL
1911 }; 1917 };
1912 1918
1913 RunParserSyncTest(context_data, statement_data, kError); 1919 static const ParserFlag always_flags[] = {kAllowStrongMode};
1914 RunParserSyncTest(context_data, statement_data, kError); 1920 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
1921 arraysize(always_flags));
1922 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
1923 arraysize(always_flags));
1915 } 1924 }
1916 1925
1917 1926
1918 #undef LIMITED_FUTURE_STRICT_RESERVED_WORDS 1927 #undef LIMITED_FUTURE_STRICT_RESERVED_WORDS
1919 1928
1920 1929
1921 TEST(NoErrorsFutureStrictReservedWords) { 1930 TEST(NoErrorsFutureStrictReservedWords) {
1922 const char* context_data[][2] = { 1931 const char* context_data[][2] = {
1923 { "", "" }, 1932 { "", "" },
1924 { "function test_func() {", "}"}, 1933 { "function test_func() {", "}"},
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2082 "yield[100]", 2091 "yield[100]",
2083 NULL 2092 NULL
2084 }; 2093 };
2085 2094
2086 RunParserSyncTest(context_data, statement_data, kSuccess); 2095 RunParserSyncTest(context_data, statement_data, kSuccess);
2087 } 2096 }
2088 2097
2089 2098
2090 TEST(ErrorsYieldStrict) { 2099 TEST(ErrorsYieldStrict) {
2091 const char* context_data[][2] = { 2100 const char* context_data[][2] = {
2092 { "\"use strict\";", "" }, 2101 {"\"use strict\";", ""},
2093 { "\"use strict\"; function not_gen() {", "}" }, 2102 {"\"use strict\"; function not_gen() {", "}"},
2094 { "function test_func() {\"use strict\"; ", "}"}, 2103 {"function test_func() {\"use strict\"; ", "}"},
2095 { "\"use strict\"; function * gen() { function not_gen() {", "} }" }, 2104 {"\"use strict\"; function * gen() { function not_gen() {", "} }"},
2096 { "\"use strict\"; (function not_gen() {", "})" }, 2105 {"\"use strict\"; (function not_gen() {", "})"},
2097 { "\"use strict\"; (function * gen() { (function not_gen() {", "}) })" }, 2106 {"\"use strict\"; (function * gen() { (function not_gen() {", "}) })"},
2098 { "() => {\"use strict\"; ", "}" }, 2107 {"() => {\"use strict\"; ", "}"},
2099 { NULL, NULL } 2108 {"\"use strong\";", ""},
2100 }; 2109 {"\"use strong\"; function not_gen() {", "}"},
2110 {"function test_func() {\"use strong\"; ", "}"},
2111 {"\"use strong\"; function * gen() { function not_gen() {", "} }"},
2112 {"\"use strong\"; (function not_gen() {", "})"},
2113 {"\"use strong\"; (function * gen() { (function not_gen() {", "}) })"},
2114 {"() => {\"use strong\"; ", "}"},
2115 {NULL, NULL}};
2101 2116
2102 const char* statement_data[] = { 2117 const char* statement_data[] = {
2103 "var yield;", 2118 "var yield;",
2104 "var foo, yield;", 2119 "var foo, yield;",
2105 "try { } catch (yield) { }", 2120 "try { } catch (yield) { }",
2106 "function yield() { }", 2121 "function yield() { }",
2107 "(function yield() { })", 2122 "(function yield() { })",
2108 "function foo(yield) { }", 2123 "function foo(yield) { }",
2109 "function foo(bar, yield) { }", 2124 "function foo(bar, yield) { }",
2110 "function * yield() { }", 2125 "function * yield() { }",
2111 "(function * yield() { })", 2126 "(function * yield() { })",
2112 "yield = 1;", 2127 "yield = 1;",
2113 "var foo = yield = 1;", 2128 "var foo = yield = 1;",
2114 "++yield;", 2129 "++yield;",
2115 "yield++;", 2130 "yield++;",
2116 "yield: 34;", 2131 "yield: 34;",
2117 NULL 2132 NULL
2118 }; 2133 };
2119 2134
2120 RunParserSyncTest(context_data, statement_data, kError); 2135 static const ParserFlag always_flags[] = {kAllowStrongMode};
2136 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
2137 arraysize(always_flags));
2121 } 2138 }
2122 2139
2123 2140
2124 TEST(NoErrorsGenerator) { 2141 TEST(NoErrorsGenerator) {
2125 const char* context_data[][2] = { 2142 const char* context_data[][2] = {
2126 { "function * gen() {", "}" }, 2143 { "function * gen() {", "}" },
2127 { "(function * gen() {", "})" }, 2144 { "(function * gen() {", "})" },
2128 { "(function * () {", "})" }, 2145 { "(function * () {", "})" },
2129 { NULL, NULL } 2146 { NULL, NULL }
2130 }; 2147 };
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
2228 RunParserSyncTest(context_data, statement_data, kError); 2245 RunParserSyncTest(context_data, statement_data, kError);
2229 } 2246 }
2230 2247
2231 2248
2232 TEST(ErrorsNameOfStrictFunction) { 2249 TEST(ErrorsNameOfStrictFunction) {
2233 // Tests that illegal tokens as names of a strict function produce the correct 2250 // Tests that illegal tokens as names of a strict function produce the correct
2234 // errors. 2251 // errors.
2235 const char* context_data[][2] = { 2252 const char* context_data[][2] = {
2236 { "function ", ""}, 2253 { "function ", ""},
2237 { "\"use strict\"; function", ""}, 2254 { "\"use strict\"; function", ""},
2255 { "\"use strong\"; function", ""},
2238 { "function * ", ""}, 2256 { "function * ", ""},
2239 { "\"use strict\"; function * ", ""}, 2257 { "\"use strict\"; function * ", ""},
2258 { "\"use strong\"; function * ", ""},
2240 { NULL, NULL } 2259 { NULL, NULL }
2241 }; 2260 };
2242 2261
2243 const char* statement_data[] = { 2262 const char* statement_data[] = {
2244 "eval() {\"use strict\";}", 2263 "eval() {\"use strict\";}",
2245 "arguments() {\"use strict\";}", 2264 "arguments() {\"use strict\";}",
2246 "interface() {\"use strict\";}", 2265 "interface() {\"use strict\";}",
2247 "yield() {\"use strict\";}", 2266 "yield() {\"use strict\";}",
2248 // Future reserved words are always illegal 2267 // Future reserved words are always illegal
2249 "super() { }", 2268 "super() { }",
2250 "super() {\"use strict\";}", 2269 "super() {\"use strict\";}",
2251 NULL 2270 NULL
2252 }; 2271 };
2253 2272
2254 RunParserSyncTest(context_data, statement_data, kError); 2273 static const ParserFlag always_flags[] = {kAllowStrongMode};
2274 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
2275 arraysize(always_flags));
2255 } 2276 }
2256 2277
2257 2278
2258 TEST(NoErrorsNameOfStrictFunction) { 2279 TEST(NoErrorsNameOfStrictFunction) {
2259 const char* context_data[][2] = { 2280 const char* context_data[][2] = {
2260 { "function ", ""}, 2281 { "function ", ""},
2261 { NULL, NULL } 2282 { NULL, NULL }
2262 }; 2283 };
2263 2284
2264 const char* statement_data[] = { 2285 const char* statement_data[] = {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2305 NULL 2326 NULL
2306 }; 2327 };
2307 2328
2308 RunParserSyncTest(context_data, statement_data, kError); 2329 RunParserSyncTest(context_data, statement_data, kError);
2309 } 2330 }
2310 2331
2311 2332
2312 TEST(ErrorsIllegalWordsAsLabelsStrict) { 2333 TEST(ErrorsIllegalWordsAsLabelsStrict) {
2313 // Tests that illegal tokens as labels produce the correct errors. 2334 // Tests that illegal tokens as labels produce the correct errors.
2314 const char* context_data[][2] = { 2335 const char* context_data[][2] = {
2315 { "\"use strict\";", "" }, 2336 {"\"use strict\";", ""},
2316 { "function test_func() {\"use strict\"; ", "}"}, 2337 {"function test_func() {\"use strict\"; ", "}"},
2317 { "() => {\"use strict\"; ", "}" }, 2338 {"() => {\"use strict\"; ", "}"},
2318 { NULL, NULL } 2339 {"\"use strong\";", ""},
2319 }; 2340 {"function test_func() {\"use strong\"; ", "}"},
2341 {"() => {\"use strong\"; ", "}"},
2342 {NULL, NULL}};
2320 2343
2321 #define LABELLED_WHILE(NAME) #NAME ": while (true) { break " #NAME "; }", 2344 #define LABELLED_WHILE(NAME) #NAME ": while (true) { break " #NAME "; }",
2322 const char* statement_data[] = { 2345 const char* statement_data[] = {
2323 "super: while(true) { break super; }", 2346 "super: while(true) { break super; }",
2324 FUTURE_STRICT_RESERVED_WORDS(LABELLED_WHILE) 2347 FUTURE_STRICT_RESERVED_WORDS(LABELLED_WHILE)
2325 NULL 2348 NULL
2326 }; 2349 };
2327 #undef LABELLED_WHILE 2350 #undef LABELLED_WHILE
2328 2351
2329 RunParserSyncTest(context_data, statement_data, kError); 2352 static const ParserFlag always_flags[] = {kAllowStrongMode};
2353 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags,
2354 arraysize(always_flags));
2330 } 2355 }
2331 2356
2332 2357
2333 TEST(NoErrorsIllegalWordsAsLabels) { 2358 TEST(NoErrorsIllegalWordsAsLabels) {
2334 // Using eval and arguments as labels is legal even in strict mode. 2359 // Using eval and arguments as labels is legal even in strict mode.
2335 const char* context_data[][2] = { 2360 const char* context_data[][2] = {
2336 { "", ""}, 2361 { "", ""},
2337 { "function test_func() {", "}" }, 2362 { "function test_func() {", "}" },
2338 { "() => {", "}" }, 2363 { "() => {", "}" },
2339 { "\"use strict\";", "" }, 2364 { "\"use strict\";", "" },
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2396 2421
2397 TEST(NoErrorsParenthesizedDirectivePrologue) { 2422 TEST(NoErrorsParenthesizedDirectivePrologue) {
2398 // Parenthesized directive prologue shouldn't be recognized. 2423 // Parenthesized directive prologue shouldn't be recognized.
2399 const char* context_data[][2] = { 2424 const char* context_data[][2] = {
2400 { "", ""}, 2425 { "", ""},
2401 { NULL, NULL } 2426 { NULL, NULL }
2402 }; 2427 };
2403 2428
2404 const char* statement_data[] = { 2429 const char* statement_data[] = {
2405 "(\"use strict\"); var eval;", 2430 "(\"use strict\"); var eval;",
2431 "(\"use strong\"); var eval;",
2406 NULL 2432 NULL
2407 }; 2433 };
2408 2434
2409 RunParserSyncTest(context_data, statement_data, kSuccess); 2435 static const ParserFlag always_flags[] = {kAllowStrongMode};
2436 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
2437 always_flags, arraysize(always_flags));
2410 } 2438 }
2411 2439
2412 2440
2413 TEST(ErrorsNotAnIdentifierName) { 2441 TEST(ErrorsNotAnIdentifierName) {
2414 const char* context_data[][2] = { 2442 const char* context_data[][2] = {
2415 { "", ""}, 2443 { "", ""},
2416 { "\"use strict\";", ""}, 2444 { "\"use strict\";", ""},
2417 { NULL, NULL } 2445 { NULL, NULL }
2418 }; 2446 };
2419 2447
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2523 {"function foo(bar, eval) {", "}"}, 2551 {"function foo(bar, eval) {", "}"},
2524 {"function foo(bar, arguments) {", "}"}, 2552 {"function foo(bar, arguments) {", "}"},
2525 {"function foo(bar, yield) {", "}"}, 2553 {"function foo(bar, yield) {", "}"},
2526 {"function foo(bar, interface) {", "}"}, 2554 {"function foo(bar, interface) {", "}"},
2527 {"function foo(bar, bar) {", "}"}, 2555 {"function foo(bar, bar) {", "}"},
2528 { NULL, NULL } 2556 { NULL, NULL }
2529 }; 2557 };
2530 2558
2531 const char* strict_statement_data[] = { 2559 const char* strict_statement_data[] = {
2532 "\"use strict\";", 2560 "\"use strict\";",
2561 "\"use strong\";",
2533 NULL 2562 NULL
2534 }; 2563 };
2535 2564
2536 const char* non_strict_statement_data[] = { 2565 const char* non_strict_statement_data[] = {
2537 ";", 2566 ";",
2538 NULL 2567 NULL
2539 }; 2568 };
2540 2569
2541 RunParserSyncTest(context_data, strict_statement_data, kError); 2570 static const ParserFlag always_flags[] = {kAllowStrongMode};
2542 RunParserSyncTest(context_data, non_strict_statement_data, kSuccess); 2571 RunParserSyncTest(context_data, strict_statement_data, kError, NULL, 0,
2572 always_flags, arraysize(always_flags));
2573 RunParserSyncTest(context_data, non_strict_statement_data, kSuccess, NULL, 0,
2574 always_flags, arraysize(always_flags));
2543 } 2575 }
2544 2576
2545 2577
2546 TEST(ErrorsTryWithoutCatchOrFinally) { 2578 TEST(ErrorsTryWithoutCatchOrFinally) {
2547 const char* context_data[][2] = { 2579 const char* context_data[][2] = {
2548 {"", ""}, 2580 {"", ""},
2549 { NULL, NULL } 2581 { NULL, NULL }
2550 }; 2582 };
2551 2583
2552 const char* statement_data[] = { 2584 const char* statement_data[] = {
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
2824 // The test is quite slow, so run it with a reduced set of flags. 2856 // The test is quite slow, so run it with a reduced set of flags.
2825 static const ParserFlag empty_flags[] = {kAllowLazy}; 2857 static const ParserFlag empty_flags[] = {kAllowLazy};
2826 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1); 2858 RunParserSyncTest(context_data, statement_data, kError, empty_flags, 1);
2827 } 2859 }
2828 2860
2829 2861
2830 TEST(StrictDelete) { 2862 TEST(StrictDelete) {
2831 // "delete <Identifier>" is not allowed in strict mode. 2863 // "delete <Identifier>" is not allowed in strict mode.
2832 const char* strict_context_data[][2] = { 2864 const char* strict_context_data[][2] = {
2833 {"\"use strict\"; ", ""}, 2865 {"\"use strict\"; ", ""},
2866 {"\"use strong\"; ", ""},
2834 { NULL, NULL } 2867 { NULL, NULL }
2835 }; 2868 };
2836 2869
2837 const char* sloppy_context_data[][2] = { 2870 const char* sloppy_context_data[][2] = {
2838 {"", ""}, 2871 {"", ""},
2839 { NULL, NULL } 2872 { NULL, NULL }
2840 }; 2873 };
2841 2874
2842 // These are errors in the strict mode. 2875 // These are errors in the strict mode.
2843 const char* sloppy_statement_data[] = { 2876 const char* sloppy_statement_data[] = {
(...skipping 19 matching lines...) Expand all
2863 "delete new foo(bar);", 2896 "delete new foo(bar);",
2864 NULL 2897 NULL
2865 }; 2898 };
2866 2899
2867 // These are always errors 2900 // These are always errors
2868 const char* bad_statement_data[] = { 2901 const char* bad_statement_data[] = {
2869 "delete if;", 2902 "delete if;",
2870 NULL 2903 NULL
2871 }; 2904 };
2872 2905
2873 RunParserSyncTest(strict_context_data, sloppy_statement_data, kError); 2906 static const ParserFlag always_flags[] = {kAllowStrongMode};
2874 RunParserSyncTest(sloppy_context_data, sloppy_statement_data, kSuccess); 2907 RunParserSyncTest(strict_context_data, sloppy_statement_data, kError, NULL, 0,
2908 always_flags, arraysize(always_flags));
2909 RunParserSyncTest(sloppy_context_data, sloppy_statement_data, kSuccess, NULL,
2910 0, always_flags, arraysize(always_flags));
2875 2911
2876 RunParserSyncTest(strict_context_data, good_statement_data, kSuccess); 2912 RunParserSyncTest(strict_context_data, good_statement_data, kSuccess, NULL, 0,
2877 RunParserSyncTest(sloppy_context_data, good_statement_data, kSuccess); 2913 always_flags, arraysize(always_flags));
2914 RunParserSyncTest(sloppy_context_data, good_statement_data, kSuccess, NULL, 0,
2915 always_flags, arraysize(always_flags));
2878 2916
2879 RunParserSyncTest(strict_context_data, bad_statement_data, kError); 2917 RunParserSyncTest(strict_context_data, bad_statement_data, kError, NULL, 0,
2880 RunParserSyncTest(sloppy_context_data, bad_statement_data, kError); 2918 always_flags, arraysize(always_flags));
2919 RunParserSyncTest(sloppy_context_data, bad_statement_data, kError, NULL, 0,
2920 always_flags, arraysize(always_flags));
2881 } 2921 }
2882 2922
2883 2923
2884 TEST(InvalidLeftHandSide) { 2924 TEST(InvalidLeftHandSide) {
2885 const char* assignment_context_data[][2] = { 2925 const char* assignment_context_data[][2] = {
2886 {"", " = 1;"}, 2926 {"", " = 1;"},
2887 {"\"use strict\"; ", " = 1;"}, 2927 {"\"use strict\"; ", " = 1;"},
2888 { NULL, NULL } 2928 { NULL, NULL }
2889 }; 2929 };
2890 2930
(...skipping 2072 matching lines...) Expand 10 before | Expand all | Expand 10 after
4963 } 5003 }
4964 5004
4965 5005
4966 TEST(DeclarationsError) { 5006 TEST(DeclarationsError) {
4967 const char* context_data[][2] = {{"'use strict'; if (true)", ""}, 5007 const char* context_data[][2] = {{"'use strict'; if (true)", ""},
4968 {"'use strict'; if (false) {} else", ""}, 5008 {"'use strict'; if (false) {} else", ""},
4969 {"'use strict'; while (false)", ""}, 5009 {"'use strict'; while (false)", ""},
4970 {"'use strict'; for (;;)", ""}, 5010 {"'use strict'; for (;;)", ""},
4971 {"'use strict'; for (x in y)", ""}, 5011 {"'use strict'; for (x in y)", ""},
4972 {"'use strict'; do ", " while (false)"}, 5012 {"'use strict'; do ", " while (false)"},
5013 {"'use strong'; if (true)", ""},
5014 {"'use strong'; if (false) {} else", ""},
5015 {"'use strong'; while (false)", ""},
5016 {"'use strong'; for (;;)", ""},
5017 {"'use strong'; for (x in y)", ""},
5018 {"'use strong'; do ", " while (false)"},
4973 {NULL, NULL}}; 5019 {NULL, NULL}};
4974 5020
4975 const char* statement_data[] = { 5021 const char* statement_data[] = {
4976 "let x = 1;", 5022 "let x = 1;",
4977 "const x = 1;", 5023 "const x = 1;",
4978 "class C {}", 5024 "class C {}",
4979 NULL}; 5025 NULL};
4980 5026
4981 static const ParserFlag always_flags[] = { 5027 static const ParserFlag always_flags[] = {
4982 kAllowHarmonyClasses, kAllowHarmonyScoping 5028 kAllowHarmonyClasses, kAllowHarmonyScoping, kAllowStrongMode};
4983 };
4984 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, 5029 RunParserSyncTest(context_data, statement_data, kError, NULL, 0,
4985 always_flags, arraysize(always_flags)); 5030 always_flags, arraysize(always_flags));
4986 } 5031 }
5032
5033
5034 void TestLanguageMode(const char* source,
5035 i::LanguageMode expected_language_mode) {
5036 i::Isolate* isolate = CcTest::i_isolate();
5037 i::Factory* factory = isolate->factory();
5038 v8::HandleScope handles(CcTest::isolate());
5039 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
5040 v8::Context::Scope context_scope(context);
5041 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5042 128 * 1024);
5043
5044 i::Handle<i::Script> script =
5045 factory->NewScript(factory->NewStringFromAsciiChecked(source));
5046 i::CompilationInfoWithZone info(script);
5047 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
5048 isolate->heap()->HashSeed(),
5049 isolate->unicode_cache()};
5050 i::Parser parser(&info, &parse_info);
5051 parser.set_allow_strong_mode(true);
5052 info.MarkAsGlobal();
5053 parser.Parse();
5054 CHECK(info.function() != NULL);
5055 CHECK_EQ(expected_language_mode, info.function()->language_mode());
5056 }
5057
5058
5059 TEST(LanguageModeDirectives) {
5060 TestLanguageMode("\"use nothing\"", i::SLOPPY);
5061 TestLanguageMode("\"use strict\"", i::STRICT);
5062 TestLanguageMode("\"use strong\"", i::STRONG);
5063
5064 TestLanguageMode("var x = 1; \"use strict\"", i::SLOPPY);
5065 TestLanguageMode("var x = 1; \"use strong\"", i::SLOPPY);
5066
5067 // Test that multiple directives ("use strict" / "use strong") put the parser
5068 // into the correct mode.
5069 TestLanguageMode("\"use strict\"; \"use strong\";", i::STRONG);
5070 TestLanguageMode("\"use strong\"; \"use strict\";", i::STRONG);
5071
5072 TestLanguageMode("\"use some future directive\"; \"use strict\";", i::STRICT);
5073 TestLanguageMode("\"use some future directive\"; \"use strong\";", i::STRONG);
5074 }
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | test/unittests/compiler/js-typed-lowering-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698