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

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

Issue 8417035: Introduce extended mode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed more comments. Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | test/mjsunit/debug-scopes.js » ('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 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 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
760 i::ScopeType scope_type; 760 i::ScopeType scope_type;
761 i::LanguageMode language_mode;
761 }; 762 };
762 763
763 const SourceData source_data[] = { 764 const SourceData source_data[] = {
764 { " with ({}) ", "{ block; }", " more;", i::WITH_SCOPE }, 765 { " with ({}) ", "{ block; }", " more;", i::WITH_SCOPE, i::CLASSIC_MODE },
765 { " with ({}) ", "{ block; }", "; more;", i::WITH_SCOPE }, 766 { " with ({}) ", "{ block; }", "; more;", i::WITH_SCOPE, i::CLASSIC_MODE },
766 { " with ({}) ", "{\n" 767 { " with ({}) ", "{\n"
767 " block;\n" 768 " block;\n"
768 " }", "\n" 769 " }", "\n"
769 " more;", i::WITH_SCOPE }, 770 " more;", i::WITH_SCOPE, i::CLASSIC_MODE },
770 { " with ({}) ", "statement;", " more;", i::WITH_SCOPE }, 771 { " with ({}) ", "statement;", " more;", i::WITH_SCOPE, i::CLASSIC_MODE },
771 { " with ({}) ", "statement", "\n" 772 { " with ({}) ", "statement", "\n"
772 " more;", i::WITH_SCOPE }, 773 " more;", i::WITH_SCOPE, i::CLASSIC_MODE },
773 { " with ({})\n" 774 { " with ({})\n"
774 " ", "statement;", "\n" 775 " ", "statement;", "\n"
775 " more;", i::WITH_SCOPE }, 776 " more;", i::WITH_SCOPE, i::CLASSIC_MODE },
776 { " try {} catch ", "(e) { block; }", " more;", i::CATCH_SCOPE }, 777 { " try {} catch ", "(e) { block; }", " more;",
777 { " try {} catch ", "(e) { block; }", "; more;", i::CATCH_SCOPE }, 778 i::CATCH_SCOPE, i::CLASSIC_MODE },
779 { " try {} catch ", "(e) { block; }", "; more;",
780 i::CATCH_SCOPE, i::CLASSIC_MODE },
778 { " try {} catch ", "(e) {\n" 781 { " try {} catch ", "(e) {\n"
779 " block;\n" 782 " block;\n"
780 " }", "\n" 783 " }", "\n"
781 " more;", i::CATCH_SCOPE }, 784 " more;", i::CATCH_SCOPE, i::CLASSIC_MODE },
782 { " try {} catch ", "(e) { block; }", " finally { block; } more;", 785 { " try {} catch ", "(e) { block; }", " finally { block; } more;",
783 i::CATCH_SCOPE }, 786 i::CATCH_SCOPE, i::CLASSIC_MODE },
784 { " start;\n" 787 { " start;\n"
785 " ", "{ let block; }", " more;", i::BLOCK_SCOPE }, 788 " ", "{ let block; }", " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE },
786 { " start;\n" 789 { " start;\n"
787 " ", "{ let block; }", "; more;", i::BLOCK_SCOPE }, 790 " ", "{ let block; }", "; more;", i::BLOCK_SCOPE, i::EXTENDED_MODE },
788 { " start;\n" 791 { " start;\n"
789 " ", "{\n" 792 " ", "{\n"
790 " let block;\n" 793 " let block;\n"
791 " }", "\n" 794 " }", "\n"
792 " more;", i::BLOCK_SCOPE }, 795 " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE },
793 { " start;\n" 796 { " start;\n"
794 " function fun", "(a,b) { infunction; }", " more;", 797 " function fun", "(a,b) { infunction; }", " more;",
795 i::FUNCTION_SCOPE }, 798 i::FUNCTION_SCOPE, i::CLASSIC_MODE },
796 { " start;\n" 799 { " start;\n"
797 " function fun", "(a,b) {\n" 800 " function fun", "(a,b) {\n"
798 " infunction;\n" 801 " infunction;\n"
799 " }", "\n" 802 " }", "\n"
800 " more;", i::FUNCTION_SCOPE }, 803 " more;", i::FUNCTION_SCOPE, i::CLASSIC_MODE },
801 { " (function fun", "(a,b) { infunction; }", ")();", 804 { " (function fun", "(a,b) { infunction; }", ")();",
802 i::FUNCTION_SCOPE }, 805 i::FUNCTION_SCOPE, i::CLASSIC_MODE },
803 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", " more;", 806 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", " more;",
804 i::BLOCK_SCOPE }, 807 i::BLOCK_SCOPE, i::EXTENDED_MODE },
805 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", "; more;", 808 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", "; more;",
806 i::BLOCK_SCOPE }, 809 i::BLOCK_SCOPE, i::EXTENDED_MODE },
807 { " for ", "(let x = 1 ; x < 10; ++ x) {\n" 810 { " for ", "(let x = 1 ; x < 10; ++ x) {\n"
808 " block;\n" 811 " block;\n"
809 " }", "\n" 812 " }", "\n"
810 " more;", i::BLOCK_SCOPE }, 813 " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE },
811 { " for ", "(let x = 1 ; x < 10; ++ x) statement;", " more;", 814 { " for ", "(let x = 1 ; x < 10; ++ x) statement;", " more;",
812 i::BLOCK_SCOPE }, 815 i::BLOCK_SCOPE, i::EXTENDED_MODE },
813 { " for ", "(let x = 1 ; x < 10; ++ x) statement", "\n" 816 { " for ", "(let x = 1 ; x < 10; ++ x) statement", "\n"
814 " more;", i::BLOCK_SCOPE }, 817 " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE },
815 { " for ", "(let x = 1 ; x < 10; ++ x)\n" 818 { " for ", "(let x = 1 ; x < 10; ++ x)\n"
816 " statement;", "\n" 819 " statement;", "\n"
817 " more;", i::BLOCK_SCOPE }, 820 " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE },
818 { " for ", "(let x in {}) { block; }", " more;", i::BLOCK_SCOPE }, 821 { " for ", "(let x in {}) { block; }", " more;",
819 { " for ", "(let x in {}) { block; }", "; more;", i::BLOCK_SCOPE }, 822 i::BLOCK_SCOPE, i::EXTENDED_MODE },
823 { " for ", "(let x in {}) { block; }", "; more;",
824 i::BLOCK_SCOPE, i::EXTENDED_MODE },
820 { " for ", "(let x in {}) {\n" 825 { " for ", "(let x in {}) {\n"
821 " block;\n" 826 " block;\n"
822 " }", "\n" 827 " }", "\n"
823 " more;", i::BLOCK_SCOPE }, 828 " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE },
824 { " for ", "(let x in {}) statement;", " more;", i::BLOCK_SCOPE }, 829 { " for ", "(let x in {}) statement;", " more;",
830 i::BLOCK_SCOPE, i::EXTENDED_MODE },
825 { " for ", "(let x in {}) statement", "\n" 831 { " for ", "(let x in {}) statement", "\n"
826 " more;", i::BLOCK_SCOPE }, 832 " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE },
827 { " for ", "(let x in {})\n" 833 { " for ", "(let x in {})\n"
828 " statement;", "\n" 834 " statement;", "\n"
829 " more;", i::BLOCK_SCOPE }, 835 " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE },
830 { NULL, NULL, NULL, i::EVAL_SCOPE } 836 { NULL, NULL, NULL, i::EVAL_SCOPE, i::CLASSIC_MODE }
831 }; 837 };
832 838
833 v8::HandleScope handles; 839 v8::HandleScope handles;
834 v8::Persistent<v8::Context> context = v8::Context::New(); 840 v8::Persistent<v8::Context> context = v8::Context::New();
835 v8::Context::Scope context_scope(context); 841 v8::Context::Scope context_scope(context);
836 842
837 int marker; 843 int marker;
838 i::Isolate::Current()->stack_guard()->SetStackLimit( 844 i::Isolate::Current()->stack_guard()->SetStackLimit(
839 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 845 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
840 846
841 for (int i = 0; source_data[i].outer_prefix; i++) { 847 for (int i = 0; source_data[i].outer_prefix; i++) {
842 int kPrefixLen = i::StrLength(source_data[i].outer_prefix); 848 int kPrefixLen = i::StrLength(source_data[i].outer_prefix);
843 int kInnerLen = i::StrLength(source_data[i].inner_source); 849 int kInnerLen = i::StrLength(source_data[i].inner_source);
844 int kSuffixLen = i::StrLength(source_data[i].outer_suffix); 850 int kSuffixLen = i::StrLength(source_data[i].outer_suffix);
845 int kProgramSize = kPrefixLen + kInnerLen + kSuffixLen; 851 int kProgramSize = kPrefixLen + kInnerLen + kSuffixLen;
846 i::Vector<char> program = i::Vector<char>::New(kProgramSize + 1); 852 i::Vector<char> program = i::Vector<char>::New(kProgramSize + 1);
847 int length = i::OS::SNPrintF(program, "%s%s%s", 853 int length = i::OS::SNPrintF(program, "%s%s%s",
848 source_data[i].outer_prefix, 854 source_data[i].outer_prefix,
849 source_data[i].inner_source, 855 source_data[i].inner_source,
850 source_data[i].outer_suffix); 856 source_data[i].outer_suffix);
851 CHECK(length == kProgramSize); 857 CHECK(length == kProgramSize);
852 858
853 // Parse program source. 859 // Parse program source.
854 i::Handle<i::String> source( 860 i::Handle<i::String> source(
855 FACTORY->NewStringFromAscii(i::CStrVector(program.start()))); 861 FACTORY->NewStringFromAscii(i::CStrVector(program.start())));
856 i::Handle<i::Script> script = FACTORY->NewScript(source); 862 i::Handle<i::Script> script = FACTORY->NewScript(source);
857 i::Parser parser(script, false, NULL, NULL); 863 i::Parser parser(script, false, NULL, NULL);
858 parser.SetHarmonyScoping(true); 864 parser.SetHarmonyScoping(true);
859 i::FunctionLiteral* function = 865 i::FunctionLiteral* function =
860 parser.ParseProgram(source, true, i::kNonStrictMode); 866 parser.ParseProgram(source, true, source_data[i].language_mode);
861 ASSERT(function != NULL); 867 ASSERT(function != NULL);
862 868
863 // Check scope types and positions. 869 // Check scope types and positions.
864 i::Scope* scope = function->scope(); 870 i::Scope* scope = function->scope();
865 CHECK(scope->is_global_scope()); 871 CHECK(scope->is_global_scope());
866 CHECK_EQ(scope->start_position(), 0); 872 CHECK_EQ(scope->start_position(), 0);
867 CHECK_EQ(scope->end_position(), kProgramSize); 873 CHECK_EQ(scope->end_position(), kProgramSize);
868 CHECK_EQ(scope->inner_scopes()->length(), 1); 874 CHECK_EQ(scope->inner_scopes()->length(), 1);
869 875
870 i::Scope* inner_scope = scope->inner_scopes()->at(0); 876 i::Scope* inner_scope = scope->inner_scopes()->at(0);
871 CHECK_EQ(inner_scope->type(), source_data[i].scope_type); 877 CHECK_EQ(inner_scope->type(), source_data[i].scope_type);
872 CHECK_EQ(inner_scope->start_position(), kPrefixLen); 878 CHECK_EQ(inner_scope->start_position(), kPrefixLen);
873 // The end position of a token is one position after the last 879 // The end position of a token is one position after the last
874 // character belonging to that token. 880 // character belonging to that token.
875 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); 881 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen);
876 } 882 }
877 } 883 }
OLDNEW
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | test/mjsunit/debug-scopes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698