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 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1666 int always_true_len = 0, | 1666 int always_true_len = 0, |
1667 const ParserFlag* always_false_flags = NULL, | 1667 const ParserFlag* always_false_flags = NULL, |
1668 int always_false_len = 0) { | 1668 int always_false_len = 0) { |
1669 v8::HandleScope handles(CcTest::isolate()); | 1669 v8::HandleScope handles(CcTest::isolate()); |
1670 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 1670 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); |
1671 v8::Context::Scope context_scope(context); | 1671 v8::Context::Scope context_scope(context); |
1672 | 1672 |
1673 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 1673 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
1674 i::GetCurrentStackPosition() - 128 * 1024); | 1674 i::GetCurrentStackPosition() - 128 * 1024); |
1675 | 1675 |
| 1676 // Experimental feature flags should not go here; pass the flags as |
| 1677 // always_true_flags if the test needs them. |
1676 static const ParserFlag default_flags[] = { | 1678 static const ParserFlag default_flags[] = { |
1677 kAllowHarmonyArrowFunctions, | |
1678 kAllowHarmonyClasses, | |
1679 kAllowHarmonyNumericLiterals, | |
1680 kAllowHarmonyObjectLiterals, | |
1681 kAllowHarmonyScoping, | |
1682 kAllowHarmonyModules, | |
1683 kAllowHarmonyTemplates, | |
1684 kAllowHarmonySloppy, | |
1685 kAllowHarmonyUnicode, | |
1686 kAllowLazy, | 1679 kAllowLazy, |
1687 kAllowNatives, | 1680 kAllowNatives, |
1688 }; | 1681 }; |
1689 ParserFlag* generated_flags = NULL; | 1682 ParserFlag* generated_flags = NULL; |
1690 if (flags == NULL) { | 1683 if (flags == NULL) { |
1691 flags = default_flags; | 1684 flags = default_flags; |
1692 flags_len = arraysize(default_flags); | 1685 flags_len = arraysize(default_flags); |
1693 if (always_true_flags != NULL || always_false_flags != NULL) { | 1686 if (always_true_flags != NULL || always_false_flags != NULL) { |
1694 // Remove always_true/false_flags from default_flags. | 1687 // Remove always_true/false_flags from default_flags (if present). |
1695 CHECK((always_true_flags != NULL) == (always_true_len > 0)); | 1688 CHECK((always_true_flags != NULL) == (always_true_len > 0)); |
1696 CHECK((always_false_flags != NULL) == (always_false_len > 0)); | 1689 CHECK((always_false_flags != NULL) == (always_false_len > 0)); |
1697 CHECK(always_true_flags == NULL || always_true_len < flags_len); | 1690 generated_flags = new ParserFlag[flags_len + always_true_len]; |
1698 CHECK(always_false_flags == NULL || always_false_len < flags_len); | |
1699 generated_flags = | |
1700 new ParserFlag[flags_len - always_true_len - always_false_len]; | |
1701 int flag_index = 0; | 1691 int flag_index = 0; |
1702 for (int i = 0; i < flags_len; ++i) { | 1692 for (int i = 0; i < flags_len; ++i) { |
1703 bool use_flag = true; | 1693 bool use_flag = true; |
1704 for (int j = 0; use_flag && j < always_true_len; ++j) { | 1694 for (int j = 0; use_flag && j < always_true_len; ++j) { |
1705 if (flags[i] == always_true_flags[j]) use_flag = false; | 1695 if (flags[i] == always_true_flags[j]) use_flag = false; |
1706 } | 1696 } |
1707 for (int j = 0; use_flag && j < always_false_len; ++j) { | 1697 for (int j = 0; use_flag && j < always_false_len; ++j) { |
1708 if (flags[i] == always_false_flags[j]) use_flag = false; | 1698 if (flags[i] == always_false_flags[j]) use_flag = false; |
1709 } | 1699 } |
1710 if (use_flag) generated_flags[flag_index++] = flags[i]; | 1700 if (use_flag) generated_flags[flag_index++] = flags[i]; |
1711 } | 1701 } |
1712 CHECK(flag_index == flags_len - always_true_len - always_false_len); | |
1713 flags_len = flag_index; | 1702 flags_len = flag_index; |
1714 flags = generated_flags; | 1703 flags = generated_flags; |
1715 } | 1704 } |
1716 } | 1705 } |
1717 for (int i = 0; context_data[i][0] != NULL; ++i) { | 1706 for (int i = 0; context_data[i][0] != NULL; ++i) { |
1718 for (int j = 0; statement_data[j] != NULL; ++j) { | 1707 for (int j = 0; statement_data[j] != NULL; ++j) { |
1719 int kPrefixLen = i::StrLength(context_data[i][0]); | 1708 int kPrefixLen = i::StrLength(context_data[i][0]); |
1720 int kStatementLen = i::StrLength(statement_data[j]); | 1709 int kStatementLen = i::StrLength(statement_data[j]); |
1721 int kSuffixLen = i::StrLength(context_data[i][1]); | 1710 int kSuffixLen = i::StrLength(context_data[i][1]); |
1722 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen; | 1711 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1892 { "function test_func() {\"use strict\"; ", "}"}, | 1881 { "function test_func() {\"use strict\"; ", "}"}, |
1893 { "() => { \"use strict\"; ", "}" }, | 1882 { "() => { \"use strict\"; ", "}" }, |
1894 { NULL, NULL } | 1883 { NULL, NULL } |
1895 }; | 1884 }; |
1896 | 1885 |
1897 const char* statement_data[] { | 1886 const char* statement_data[] { |
1898 LIMITED_FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) | 1887 LIMITED_FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) |
1899 NULL | 1888 NULL |
1900 }; | 1889 }; |
1901 | 1890 |
1902 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; | 1891 RunParserSyncTest(context_data, statement_data, kError); |
1903 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, always_flags, | 1892 RunParserSyncTest(context_data, statement_data, kError); |
1904 arraysize(always_flags)); | |
1905 | |
1906 static const ParserFlag classes_flags[] = { | |
1907 kAllowHarmonyArrowFunctions, kAllowHarmonyClasses, kAllowHarmonyScoping}; | |
1908 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, | |
1909 classes_flags, arraysize(classes_flags)); | |
1910 } | 1893 } |
1911 | 1894 |
1912 | 1895 |
1913 #undef LIMITED_FUTURE_STRICT_RESERVED_WORDS | 1896 #undef LIMITED_FUTURE_STRICT_RESERVED_WORDS |
1914 | 1897 |
1915 | 1898 |
1916 TEST(NoErrorsFutureStrictReservedWords) { | 1899 TEST(NoErrorsFutureStrictReservedWords) { |
1917 const char* context_data[][2] = { | 1900 const char* context_data[][2] = { |
1918 { "", "" }, | 1901 { "", "" }, |
1919 { "function test_func() {", "}"}, | 1902 { "function test_func() {", "}"}, |
(...skipping 2628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4548 always_false_flags, arraysize(always_false_flags)); | 4531 always_false_flags, arraysize(always_false_flags)); |
4549 | 4532 |
4550 const char* good_data[] = { | 4533 const char* good_data[] = { |
4551 "let = 1;", | 4534 "let = 1;", |
4552 "for(let = 1;;){}", | 4535 "for(let = 1;;){}", |
4553 NULL}; | 4536 NULL}; |
4554 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0, | 4537 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0, |
4555 always_true_flags, arraysize(always_true_flags), | 4538 always_true_flags, arraysize(always_true_flags), |
4556 always_false_flags, arraysize(always_false_flags)); | 4539 always_false_flags, arraysize(always_false_flags)); |
4557 } | 4540 } |
OLD | NEW |