| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 // Escaped ']'s wont end the character class. | 739 // Escaped ']'s wont end the character class. |
| 740 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]"); | 740 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]"); |
| 741 // Escaped slashes are not terminating. | 741 // Escaped slashes are not terminating. |
| 742 TestScanRegExp("/\\//flipperwald", "\\/"); | 742 TestScanRegExp("/\\//flipperwald", "\\/"); |
| 743 // Starting with '=' works too. | 743 // Starting with '=' works too. |
| 744 TestScanRegExp("/=/", "="); | 744 TestScanRegExp("/=/", "="); |
| 745 TestScanRegExp("/=?/", "=?"); | 745 TestScanRegExp("/=?/", "=?"); |
| 746 } | 746 } |
| 747 | 747 |
| 748 | 748 |
| 749 TEST(ScopePositiosn) { | 749 TEST(ScopePositions) { |
| 750 // Test the parser for correctly setting the start and end positions | 750 // Test the parser for correctly setting the start and end positions |
| 751 // of a scope. We check the scope positions of exactly one scope | 751 // of a scope. We check the scope positions of exactly one scope |
| 752 // nested in the global scope of a program. 'inner source' is the | 752 // nested in the global scope of a program. 'inner source' is the |
| 753 // source code that determines the part of the source belonging | 753 // source code that determines the part of the source belonging |
| 754 // to the nested scope. 'outer_prefix' and 'outer_suffix' are | 754 // to the nested scope. 'outer_prefix' and 'outer_suffix' are |
| 755 // parts of the source that belong to the global scope. | 755 // parts of the source that belong to the global scope. |
| 756 struct SourceData { | 756 struct SourceData { |
| 757 const char* outer_prefix; | 757 const char* outer_prefix; |
| 758 const char* inner_source; | 758 const char* inner_source; |
| 759 const char* outer_suffix; | 759 const char* outer_suffix; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 | 836 |
| 837 int marker; | 837 int marker; |
| 838 i::Isolate::Current()->stack_guard()->SetStackLimit( | 838 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 839 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 839 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 840 | 840 |
| 841 for (int i = 0; source_data[i].outer_prefix; i++) { | 841 for (int i = 0; source_data[i].outer_prefix; i++) { |
| 842 size_t kPrefixLen = strlen(source_data[i].outer_prefix); | 842 size_t kPrefixLen = strlen(source_data[i].outer_prefix); |
| 843 size_t kInnerLen = strlen(source_data[i].inner_source); | 843 size_t kInnerLen = strlen(source_data[i].inner_source); |
| 844 size_t kSuffixLen = strlen(source_data[i].outer_suffix); | 844 size_t kSuffixLen = strlen(source_data[i].outer_suffix); |
| 845 size_t kProgramSize = kPrefixLen + kInnerLen + kSuffixLen; | 845 size_t kProgramSize = kPrefixLen + kInnerLen + kSuffixLen; |
| 846 i::SmartArrayPointer<char> program( | 846 i::Vector<char> program = i::Vector<char>::New(kProgramSize + 1); |
| 847 reinterpret_cast<char*>(malloc(kProgramSize + 1))); | 847 size_t length; |
| 848 snprintf(*program, kProgramSize + 1, "%s%s%s", | 848 length = i::OS::SNPrintF(program, "%s%s%s", |
| 849 source_data[i].outer_prefix, | 849 source_data[i].outer_prefix, |
| 850 source_data[i].inner_source, | 850 source_data[i].inner_source, |
| 851 source_data[i].outer_suffix); | 851 source_data[i].outer_suffix); |
| 852 ASSERT(length == kProgramSize); |
| 852 | 853 |
| 853 // Parse program source. | 854 // Parse program source. |
| 854 i::Handle<i::String> source( | 855 i::Handle<i::String> source( |
| 855 FACTORY->NewStringFromAscii(i::CStrVector(*program))); | 856 FACTORY->NewStringFromAscii(i::CStrVector(program.start()))); |
| 856 i::Handle<i::Script> script = FACTORY->NewScript(source); | 857 i::Handle<i::Script> script = FACTORY->NewScript(source); |
| 857 i::Parser parser(script, false, NULL, NULL); | 858 i::Parser parser(script, false, NULL, NULL); |
| 858 parser.SetHarmonyScoping(true); | 859 parser.SetHarmonyScoping(true); |
| 859 i::FunctionLiteral* function = | 860 i::FunctionLiteral* function = |
| 860 parser.ParseProgram(source, true, i::kNonStrictMode); | 861 parser.ParseProgram(source, true, i::kNonStrictMode); |
| 862 ASSERT(function != NULL); |
| 861 | 863 |
| 862 // Check scope types and positions. | 864 // Check scope types and positions. |
| 863 i::Scope* scope = function->scope(); | 865 i::Scope* scope = function->scope(); |
| 864 CHECK(scope->is_global_scope()); | 866 CHECK(scope->is_global_scope()); |
| 865 CHECK_EQ(scope->start_position(), 0); | 867 CHECK_EQ(scope->start_position(), 0); |
| 866 CHECK_EQ(scope->end_position(), kProgramSize); | 868 CHECK_EQ(scope->end_position(), kProgramSize); |
| 867 CHECK_EQ(scope->inner_scopes()->length(), 1); | 869 CHECK_EQ(scope->inner_scopes()->length(), 1); |
| 868 | 870 |
| 869 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 871 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
| 870 CHECK_EQ(inner_scope->type(), source_data[i].scope_type); | 872 CHECK_EQ(inner_scope->type(), source_data[i].scope_type); |
| 871 CHECK_EQ(inner_scope->start_position(), kPrefixLen); | 873 CHECK_EQ(inner_scope->start_position(), kPrefixLen); |
| 872 // The end position of a token is one position after the last | 874 // The end position of a token is one position after the last |
| 873 // character belonging to that token. | 875 // character belonging to that token. |
| 874 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); | 876 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); |
| 875 } | 877 } |
| 876 } | 878 } |
| OLD | NEW |