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 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 data.Dispose(); | 1207 data.Dispose(); |
1208 return i::Handle<i::String>::cast(result); | 1208 return i::Handle<i::String>::cast(result); |
1209 } | 1209 } |
1210 | 1210 |
1211 | 1211 |
1212 enum ParserFlag { | 1212 enum ParserFlag { |
1213 kAllowLazy, | 1213 kAllowLazy, |
1214 kAllowNativesSyntax, | 1214 kAllowNativesSyntax, |
1215 kAllowHarmonyScoping, | 1215 kAllowHarmonyScoping, |
1216 kAllowModules, | 1216 kAllowModules, |
1217 kAllowGenerators, | |
1218 kAllowHarmonyNumericLiterals, | 1217 kAllowHarmonyNumericLiterals, |
1219 kAllowArrowFunctions, | 1218 kAllowArrowFunctions, |
1220 kAllowClasses, | 1219 kAllowClasses, |
1221 kAllowHarmonyObjectLiterals | 1220 kAllowHarmonyObjectLiterals |
1222 }; | 1221 }; |
1223 | 1222 |
1224 | 1223 |
1225 enum ParserSyncTestResult { | 1224 enum ParserSyncTestResult { |
1226 kSuccessOrError, | 1225 kSuccessOrError, |
1227 kSuccess, | 1226 kSuccess, |
1228 kError | 1227 kError |
1229 }; | 1228 }; |
1230 | 1229 |
1231 template <typename Traits> | 1230 template <typename Traits> |
1232 void SetParserFlags(i::ParserBase<Traits>* parser, | 1231 void SetParserFlags(i::ParserBase<Traits>* parser, |
1233 i::EnumSet<ParserFlag> flags) { | 1232 i::EnumSet<ParserFlag> flags) { |
1234 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1233 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
1235 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); | 1234 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); |
1236 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); | 1235 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); |
1237 parser->set_allow_modules(flags.Contains(kAllowModules)); | 1236 parser->set_allow_modules(flags.Contains(kAllowModules)); |
1238 parser->set_allow_generators(flags.Contains(kAllowGenerators)); | |
1239 parser->set_allow_harmony_numeric_literals( | 1237 parser->set_allow_harmony_numeric_literals( |
1240 flags.Contains(kAllowHarmonyNumericLiterals)); | 1238 flags.Contains(kAllowHarmonyNumericLiterals)); |
1241 parser->set_allow_harmony_object_literals( | 1239 parser->set_allow_harmony_object_literals( |
1242 flags.Contains(kAllowHarmonyObjectLiterals)); | 1240 flags.Contains(kAllowHarmonyObjectLiterals)); |
1243 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); | 1241 parser->set_allow_arrow_functions(flags.Contains(kAllowArrowFunctions)); |
1244 parser->set_allow_classes(flags.Contains(kAllowClasses)); | 1242 parser->set_allow_classes(flags.Contains(kAllowClasses)); |
1245 } | 1243 } |
1246 | 1244 |
1247 | 1245 |
1248 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1246 void TestParserSyncWithFlags(i::Handle<i::String> source, |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 }; | 1441 }; |
1444 | 1442 |
1445 v8::HandleScope handles(CcTest::isolate()); | 1443 v8::HandleScope handles(CcTest::isolate()); |
1446 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1444 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
1447 v8::Context::Scope context_scope(context); | 1445 v8::Context::Scope context_scope(context); |
1448 | 1446 |
1449 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 1447 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
1450 i::GetCurrentStackPosition() - 128 * 1024); | 1448 i::GetCurrentStackPosition() - 128 * 1024); |
1451 | 1449 |
1452 static const ParserFlag flags1[] = { | 1450 static const ParserFlag flags1[] = { |
1453 kAllowLazy, kAllowHarmonyScoping, | 1451 kAllowLazy, kAllowHarmonyScoping, |
1454 kAllowModules, kAllowGenerators, | 1452 kAllowModules, kAllowArrowFunctions, |
1455 kAllowArrowFunctions, kAllowHarmonyNumericLiterals, | 1453 kAllowHarmonyNumericLiterals, kAllowHarmonyObjectLiterals}; |
1456 kAllowHarmonyObjectLiterals}; | |
1457 for (int i = 0; context_data[i][0] != NULL; ++i) { | 1454 for (int i = 0; context_data[i][0] != NULL; ++i) { |
1458 for (int j = 0; statement_data[j] != NULL; ++j) { | 1455 for (int j = 0; statement_data[j] != NULL; ++j) { |
1459 for (int k = 0; termination_data[k] != NULL; ++k) { | 1456 for (int k = 0; termination_data[k] != NULL; ++k) { |
1460 int kPrefixLen = i::StrLength(context_data[i][0]); | 1457 int kPrefixLen = i::StrLength(context_data[i][0]); |
1461 int kStatementLen = i::StrLength(statement_data[j]); | 1458 int kStatementLen = i::StrLength(statement_data[j]); |
1462 int kTerminationLen = i::StrLength(termination_data[k]); | 1459 int kTerminationLen = i::StrLength(termination_data[k]); |
1463 int kSuffixLen = i::StrLength(context_data[i][1]); | 1460 int kSuffixLen = i::StrLength(context_data[i][1]); |
1464 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen | 1461 int kProgramSize = kPrefixLen + kStatementLen + kTerminationLen |
1465 + kSuffixLen + i::StrLength("label: for (;;) { }"); | 1462 + kSuffixLen + i::StrLength("label: for (;;) { }"); |
1466 | 1463 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 const ParserFlag* always_true_flags = NULL, | 1518 const ParserFlag* always_true_flags = NULL, |
1522 int always_true_flags_len = 0) { | 1519 int always_true_flags_len = 0) { |
1523 v8::HandleScope handles(CcTest::isolate()); | 1520 v8::HandleScope handles(CcTest::isolate()); |
1524 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1521 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
1525 v8::Context::Scope context_scope(context); | 1522 v8::Context::Scope context_scope(context); |
1526 | 1523 |
1527 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 1524 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
1528 i::GetCurrentStackPosition() - 128 * 1024); | 1525 i::GetCurrentStackPosition() - 128 * 1024); |
1529 | 1526 |
1530 static const ParserFlag default_flags[] = { | 1527 static const ParserFlag default_flags[] = { |
1531 kAllowArrowFunctions, kAllowClasses, | 1528 kAllowArrowFunctions, kAllowClasses, |
1532 kAllowGenerators, kAllowHarmonyNumericLiterals, | 1529 kAllowHarmonyNumericLiterals, kAllowHarmonyObjectLiterals, |
1533 kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, | 1530 kAllowHarmonyScoping, kAllowLazy, |
1534 kAllowLazy, kAllowModules, | 1531 kAllowModules, kAllowNativesSyntax, |
1535 kAllowNativesSyntax, | |
1536 }; | 1532 }; |
1537 ParserFlag* generated_flags = NULL; | 1533 ParserFlag* generated_flags = NULL; |
1538 if (flags == NULL) { | 1534 if (flags == NULL) { |
1539 flags = default_flags; | 1535 flags = default_flags; |
1540 flags_len = arraysize(default_flags); | 1536 flags_len = arraysize(default_flags); |
1541 if (always_true_flags != NULL) { | 1537 if (always_true_flags != NULL) { |
1542 // Remove always_true_flags from default_flags. | 1538 // Remove always_true_flags from default_flags. |
1543 CHECK(always_true_flags_len < flags_len); | 1539 CHECK(always_true_flags_len < flags_len); |
1544 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; | 1540 generated_flags = new ParserFlag[flags_len - always_true_flags_len]; |
1545 int flag_index = 0; | 1541 int flag_index = 0; |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1887 "yield++;", | 1883 "yield++;", |
1888 "yield: 34", | 1884 "yield: 34", |
1889 "function yield(yield) { yield: yield (yield + yield(0)); }", | 1885 "function yield(yield) { yield: yield (yield + yield(0)); }", |
1890 "({ yield: 1 })", | 1886 "({ yield: 1 })", |
1891 "({ get yield() { 1 } })", | 1887 "({ get yield() { 1 } })", |
1892 "yield(100)", | 1888 "yield(100)", |
1893 "yield[100]", | 1889 "yield[100]", |
1894 NULL | 1890 NULL |
1895 }; | 1891 }; |
1896 | 1892 |
1897 // This test requires kAllowGenerators to succeed. | 1893 RunParserSyncTest(context_data, statement_data, kSuccess); |
1898 static const ParserFlag always_true_flags[] = { kAllowGenerators }; | |
1899 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | |
1900 always_true_flags, 1); | |
1901 } | 1894 } |
1902 | 1895 |
1903 | 1896 |
1904 TEST(ErrorsYieldStrict) { | 1897 TEST(ErrorsYieldStrict) { |
1905 const char* context_data[][2] = { | 1898 const char* context_data[][2] = { |
1906 { "\"use strict\";", "" }, | 1899 { "\"use strict\";", "" }, |
1907 { "\"use strict\"; function not_gen() {", "}" }, | 1900 { "\"use strict\"; function not_gen() {", "}" }, |
1908 { "function test_func() {\"use strict\"; ", "}"}, | 1901 { "function test_func() {\"use strict\"; ", "}"}, |
1909 { "\"use strict\"; function * gen() { function not_gen() {", "} }" }, | 1902 { "\"use strict\"; function * gen() { function not_gen() {", "} }" }, |
1910 { "\"use strict\"; (function not_gen() {", "})" }, | 1903 { "\"use strict\"; (function not_gen() {", "})" }, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1983 "{yield}", | 1976 "{yield}", |
1984 "yield, yield", | 1977 "yield, yield", |
1985 "yield; yield", | 1978 "yield; yield", |
1986 "(yield) ? yield : yield", | 1979 "(yield) ? yield : yield", |
1987 "(yield) \n ? yield : yield", | 1980 "(yield) \n ? yield : yield", |
1988 // If there is a newline before the next token, we don't look for RHS. | 1981 // If there is a newline before the next token, we don't look for RHS. |
1989 "yield\nfor (;;) {}", | 1982 "yield\nfor (;;) {}", |
1990 NULL | 1983 NULL |
1991 }; | 1984 }; |
1992 | 1985 |
1993 // This test requires kAllowGenerators to succeed. | 1986 RunParserSyncTest(context_data, statement_data, kSuccess); |
1994 static const ParserFlag always_true_flags[] = { | |
1995 kAllowGenerators | |
1996 }; | |
1997 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | |
1998 always_true_flags, 1); | |
1999 } | 1987 } |
2000 | 1988 |
2001 | 1989 |
2002 TEST(ErrorsYieldGenerator) { | 1990 TEST(ErrorsYieldGenerator) { |
2003 const char* context_data[][2] = { | 1991 const char* context_data[][2] = { |
2004 { "function * gen() {", "}" }, | 1992 { "function * gen() {", "}" }, |
2005 { "\"use strict\"; function * gen() {", "}" }, | 1993 { "\"use strict\"; function * gen() {", "}" }, |
2006 { NULL, NULL } | 1994 { NULL, NULL } |
2007 }; | 1995 }; |
2008 | 1996 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2099 }; | 2087 }; |
2100 | 2088 |
2101 const char* statement_data[] = { | 2089 const char* statement_data[] = { |
2102 "eval() { }", | 2090 "eval() { }", |
2103 "arguments() { }", | 2091 "arguments() { }", |
2104 "interface() { }", | 2092 "interface() { }", |
2105 "yield() { }", | 2093 "yield() { }", |
2106 NULL | 2094 NULL |
2107 }; | 2095 }; |
2108 | 2096 |
2109 // This test requires kAllowGenerators to succeed. | 2097 RunParserSyncTest(context_data, statement_data, kSuccess); |
2110 static const ParserFlag always_true_flags[] = { | |
2111 kAllowGenerators | |
2112 }; | |
2113 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | |
2114 always_true_flags, 1); | |
2115 } | 2098 } |
2116 | 2099 |
2117 | 2100 |
2118 TEST(ErrorsIllegalWordsAsLabelsSloppy) { | 2101 TEST(ErrorsIllegalWordsAsLabelsSloppy) { |
2119 // Using future reserved words as labels is always an error. | 2102 // Using future reserved words as labels is always an error. |
2120 const char* context_data[][2] = { | 2103 const char* context_data[][2] = { |
2121 { "", ""}, | 2104 { "", ""}, |
2122 { "function test_func() {", "}" }, | 2105 { "function test_func() {", "}" }, |
2123 { "() => {", "}" }, | 2106 { "() => {", "}" }, |
2124 { NULL, NULL } | 2107 { NULL, NULL } |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3303 "(a = b) => {}", | 3286 "(a = b) => {}", |
3304 "(a = b, c) => {}", | 3287 "(a = b, c) => {}", |
3305 "(a, b = c) => {}", | 3288 "(a, b = c) => {}", |
3306 "(foo ? bar : baz) => {}", | 3289 "(foo ? bar : baz) => {}", |
3307 "(a, foo ? bar : baz) => {}", | 3290 "(a, foo ? bar : baz) => {}", |
3308 "(foo ? bar : baz, a) => {}", | 3291 "(foo ? bar : baz, a) => {}", |
3309 NULL | 3292 NULL |
3310 }; | 3293 }; |
3311 | 3294 |
3312 // The test is quite slow, so run it with a reduced set of flags. | 3295 // The test is quite slow, so run it with a reduced set of flags. |
3313 static const ParserFlag flags[] = { | 3296 static const ParserFlag flags[] = {kAllowLazy, kAllowHarmonyScoping}; |
3314 kAllowLazy, kAllowHarmonyScoping, kAllowGenerators | |
3315 }; | |
3316 static const ParserFlag always_flags[] = { kAllowArrowFunctions }; | 3297 static const ParserFlag always_flags[] = { kAllowArrowFunctions }; |
3317 RunParserSyncTest(context_data, statement_data, kError, flags, | 3298 RunParserSyncTest(context_data, statement_data, kError, flags, |
3318 arraysize(flags), always_flags, arraysize(always_flags)); | 3299 arraysize(flags), always_flags, arraysize(always_flags)); |
3319 } | 3300 } |
3320 | 3301 |
3321 | 3302 |
3322 TEST(NoErrorsArrowFunctions) { | 3303 TEST(NoErrorsArrowFunctions) { |
3323 // Tests that parser and preparser accept valid arrow functions syntax. | 3304 // Tests that parser and preparser accept valid arrow functions syntax. |
3324 const char* context_data[][2] = { | 3305 const char* context_data[][2] = { |
3325 {"", ";"}, | 3306 {"", ";"}, |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3549 "x() {}, 'x'() {}", | 3530 "x() {}, 'x'() {}", |
3550 "0() {}, '0'() {}", | 3531 "0() {}, '0'() {}", |
3551 "1.0() {}, 1: 1", | 3532 "1.0() {}, 1: 1", |
3552 NULL | 3533 NULL |
3553 }; | 3534 }; |
3554 | 3535 |
3555 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals}; | 3536 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals}; |
3556 RunParserSyncTest(context_data, params_data, kError, NULL, 0, | 3537 RunParserSyncTest(context_data, params_data, kError, NULL, 0, |
3557 always_flags, arraysize(always_flags)); | 3538 always_flags, arraysize(always_flags)); |
3558 } | 3539 } |
OLD | NEW |