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 1796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 "var foo = { }; foo.arguments = {};", | 1807 "var foo = { }; foo.arguments = {};", |
1808 NULL | 1808 NULL |
1809 }; | 1809 }; |
1810 | 1810 |
1811 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; | 1811 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; |
1812 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 1812 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
1813 always_flags, arraysize(always_flags)); | 1813 always_flags, arraysize(always_flags)); |
1814 } | 1814 } |
1815 | 1815 |
1816 | 1816 |
| 1817 #define FUTURE_STRICT_RESERVED_WORDS(V) \ |
| 1818 V(implements) \ |
| 1819 V(interface) \ |
| 1820 V(let) \ |
| 1821 V(package) \ |
| 1822 V(private) \ |
| 1823 V(protected) \ |
| 1824 V(public) \ |
| 1825 V(static) \ |
| 1826 V(yield) |
| 1827 |
| 1828 |
| 1829 #define FUTURE_STRICT_RESERVED_STATEMENTS(NAME) \ |
| 1830 "var " #NAME ";", \ |
| 1831 "var foo, " #NAME ";", \ |
| 1832 "try { } catch (" #NAME ") { }", \ |
| 1833 "function " #NAME "() { }", \ |
| 1834 "(function " #NAME "() { })", \ |
| 1835 "function foo(" #NAME ") { }", \ |
| 1836 "function foo(bar, " #NAME ") { }", \ |
| 1837 #NAME " = 1;", \ |
| 1838 #NAME " += 1;", \ |
| 1839 "var foo = " #NAME " = 1;", \ |
| 1840 "++" #NAME ";", \ |
| 1841 #NAME " ++;", |
| 1842 |
| 1843 |
1817 TEST(ErrorsFutureStrictReservedWords) { | 1844 TEST(ErrorsFutureStrictReservedWords) { |
1818 // Tests that both preparsing and parsing produce the right kind of errors for | 1845 // Tests that both preparsing and parsing produce the right kind of errors for |
1819 // using future strict reserved words as identifiers. Without the strict mode, | 1846 // using future strict reserved words as identifiers. Without the strict mode, |
1820 // it's ok to use future strict reserved words as identifiers. With the strict | 1847 // it's ok to use future strict reserved words as identifiers. With the strict |
1821 // mode, it isn't. | 1848 // mode, it isn't. |
1822 const char* context_data[][2] = { | 1849 const char* context_data[][2] = { |
1823 { "\"use strict\";", "" }, | 1850 { "\"use strict\";", "" }, |
1824 { "function test_func() {\"use strict\"; ", "}"}, | 1851 { "function test_func() {\"use strict\"; ", "}"}, |
1825 { "() => { \"use strict\"; ", "}" }, | 1852 { "() => { \"use strict\"; ", "}" }, |
1826 { NULL, NULL } | 1853 { NULL, NULL } |
1827 }; | 1854 }; |
1828 | 1855 |
1829 const char* statement_data[] = { | 1856 const char* statement_data[] { |
1830 "var interface;", | 1857 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) |
1831 "var foo, interface;", | |
1832 "try { } catch (interface) { }", | |
1833 "function interface() { }", | |
1834 "function foo(interface) { }", | |
1835 "function foo(bar, interface) { }", | |
1836 "interface = 1;", | |
1837 "var foo = interface = 1;", | |
1838 "++interface;", | |
1839 "interface++;", | |
1840 "var yield = 13;", | |
1841 NULL | 1858 NULL |
1842 }; | 1859 }; |
1843 | 1860 |
1844 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; | 1861 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; |
1845 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags, | 1862 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags, |
1846 arraysize(always_flags)); | 1863 arraysize(always_flags)); |
| 1864 |
| 1865 static const ParserFlag classes_flags[] = { |
| 1866 kAllowArrowFunctions, kAllowClasses, kAllowHarmonyScoping}; |
| 1867 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, |
| 1868 classes_flags, arraysize(classes_flags)); |
1847 } | 1869 } |
1848 | 1870 |
1849 | 1871 |
1850 TEST(NoErrorsFutureStrictReservedWords) { | 1872 TEST(NoErrorsFutureStrictReservedWords) { |
1851 const char* context_data[][2] = { | 1873 const char* context_data[][2] = { |
1852 { "", "" }, | 1874 { "", "" }, |
1853 { "function test_func() {", "}"}, | 1875 { "function test_func() {", "}"}, |
1854 { "() => {", "}" }, | 1876 { "() => {", "}" }, |
1855 { NULL, NULL } | 1877 { NULL, NULL } |
1856 }; | 1878 }; |
1857 | 1879 |
1858 const char* statement_data[] = { | 1880 const char* statement_data[] = { |
1859 "var interface;", | 1881 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) |
1860 "var foo, interface;", | |
1861 "try { } catch (interface) { }", | |
1862 "function interface() { }", | |
1863 "function foo(interface) { }", | |
1864 "function foo(bar, interface) { }", | |
1865 "interface = 1;", | |
1866 "var foo = interface = 1;", | |
1867 "++interface;", | |
1868 "interface++;", | |
1869 "var yield = 13;", | |
1870 NULL | 1882 NULL |
1871 }; | 1883 }; |
1872 | 1884 |
1873 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; | 1885 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; |
1874 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 1886 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
1875 always_flags, arraysize(always_flags)); | 1887 always_flags, arraysize(always_flags)); |
| 1888 |
| 1889 static const ParserFlag classes_flags[] = { |
| 1890 kAllowArrowFunctions, kAllowClasses, kAllowHarmonyScoping}; |
| 1891 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
| 1892 classes_flags, arraysize(classes_flags)); |
1876 } | 1893 } |
1877 | 1894 |
1878 | 1895 |
1879 TEST(ErrorsReservedWords) { | 1896 TEST(ErrorsReservedWords) { |
1880 // Tests that both preparsing and parsing produce the right kind of errors for | 1897 // Tests that both preparsing and parsing produce the right kind of errors for |
1881 // using future reserved words as identifiers. These tests don't depend on the | 1898 // using future reserved words as identifiers. These tests don't depend on the |
1882 // strict mode. | 1899 // strict mode. |
1883 const char* context_data[][2] = { | 1900 const char* context_data[][2] = { |
1884 { "", "" }, | 1901 { "", "" }, |
1885 { "\"use strict\";", "" }, | 1902 { "\"use strict\";", "" }, |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2245 | 2262 |
2246 TEST(ErrorsIllegalWordsAsLabelsStrict) { | 2263 TEST(ErrorsIllegalWordsAsLabelsStrict) { |
2247 // Tests that illegal tokens as labels produce the correct errors. | 2264 // Tests that illegal tokens as labels produce the correct errors. |
2248 const char* context_data[][2] = { | 2265 const char* context_data[][2] = { |
2249 { "\"use strict\";", "" }, | 2266 { "\"use strict\";", "" }, |
2250 { "function test_func() {\"use strict\"; ", "}"}, | 2267 { "function test_func() {\"use strict\"; ", "}"}, |
2251 { "() => {\"use strict\"; ", "}" }, | 2268 { "() => {\"use strict\"; ", "}" }, |
2252 { NULL, NULL } | 2269 { NULL, NULL } |
2253 }; | 2270 }; |
2254 | 2271 |
| 2272 #define LABELLED_WHILE(NAME) #NAME ": while (true) { break " #NAME "; }", |
2255 const char* statement_data[] = { | 2273 const char* statement_data[] = { |
2256 "super: while(true) { break super; }", | 2274 "super: while(true) { break super; }", |
2257 "interface: while(true) { break interface; }", | 2275 FUTURE_STRICT_RESERVED_WORDS(LABELLED_WHILE) |
2258 "yield: while(true) { break yield; }", | |
2259 NULL | 2276 NULL |
2260 }; | 2277 }; |
| 2278 #undef LABELLED_WHILE |
2261 | 2279 |
2262 RunParserSyncTest(context_data, statement_data, kError); | 2280 RunParserSyncTest(context_data, statement_data, kError); |
2263 } | 2281 } |
2264 | 2282 |
2265 | 2283 |
2266 TEST(NoErrorsIllegalWordsAsLabels) { | 2284 TEST(NoErrorsIllegalWordsAsLabels) { |
2267 // Using eval and arguments as labels is legal even in strict mode. | 2285 // Using eval and arguments as labels is legal even in strict mode. |
2268 const char* context_data[][2] = { | 2286 const char* context_data[][2] = { |
2269 { "", ""}, | 2287 { "", ""}, |
2270 { "function test_func() {", "}" }, | 2288 { "function test_func() {", "}" }, |
(...skipping 10 matching lines...) Expand all Loading... |
2281 "arguments: while(true) { break arguments; }", | 2299 "arguments: while(true) { break arguments; }", |
2282 NULL | 2300 NULL |
2283 }; | 2301 }; |
2284 | 2302 |
2285 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; | 2303 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; |
2286 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 2304 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
2287 always_flags, arraysize(always_flags)); | 2305 always_flags, arraysize(always_flags)); |
2288 } | 2306 } |
2289 | 2307 |
2290 | 2308 |
| 2309 TEST(NoErrorsFutureStrictReservedAsLabelsSloppy) { |
| 2310 const char* context_data[][2] = { |
| 2311 { "", ""}, |
| 2312 { "function test_func() {", "}" }, |
| 2313 { "() => {", "}" }, |
| 2314 { NULL, NULL } |
| 2315 }; |
| 2316 |
| 2317 #define LABELLED_WHILE(NAME) #NAME ": while (true) { break " #NAME "; }", |
| 2318 const char* statement_data[] { |
| 2319 FUTURE_STRICT_RESERVED_WORDS(LABELLED_WHILE) |
| 2320 NULL |
| 2321 }; |
| 2322 #undef LABELLED_WHILE |
| 2323 |
| 2324 static const ParserFlag always_flags[] = {kAllowArrowFunctions}; |
| 2325 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
| 2326 always_flags, arraysize(always_flags)); |
| 2327 } |
| 2328 |
| 2329 |
2291 TEST(ErrorsParenthesizedLabels) { | 2330 TEST(ErrorsParenthesizedLabels) { |
2292 // Parenthesized identifiers shouldn't be recognized as labels. | 2331 // Parenthesized identifiers shouldn't be recognized as labels. |
2293 const char* context_data[][2] = { | 2332 const char* context_data[][2] = { |
2294 { "", ""}, | 2333 { "", ""}, |
2295 { "function test_func() {", "}" }, | 2334 { "function test_func() {", "}" }, |
2296 { "() => {", "}" }, | 2335 { "() => {", "}" }, |
2297 { NULL, NULL } | 2336 { NULL, NULL } |
2298 }; | 2337 }; |
2299 | 2338 |
2300 const char* statement_data[] = { | 2339 const char* statement_data[] = { |
(...skipping 1945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4246 "for(const x = 4, y of [1,2,3]) {}", | 4285 "for(const x = 4, y of [1,2,3]) {}", |
4247 "for(const x = 1, y = 2 in []) {}", | 4286 "for(const x = 1, y = 2 in []) {}", |
4248 "for(const x,y in []) {}", | 4287 "for(const x,y in []) {}", |
4249 "for(const x = 1, y = 2 of []) {}", | 4288 "for(const x = 1, y = 2 of []) {}", |
4250 "for(const x,y of []) {}", | 4289 "for(const x,y of []) {}", |
4251 NULL}; | 4290 NULL}; |
4252 static const ParserFlag always_flags[] = {kAllowHarmonyScoping}; | 4291 static const ParserFlag always_flags[] = {kAllowHarmonyScoping}; |
4253 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 4292 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
4254 arraysize(always_flags)); | 4293 arraysize(always_flags)); |
4255 } | 4294 } |
OLD | NEW |