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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 bool is_generator, | 139 bool is_generator, |
140 int function_token_position, | 140 int function_token_position, |
141 FunctionLiteral::FunctionType type, | 141 FunctionLiteral::FunctionType type, |
142 bool* ok) { | 142 bool* ok) { |
143 return pre_parser_->ParseFunctionLiteral( | 143 return pre_parser_->ParseFunctionLiteral( |
144 name, function_name_location, name_is_strict_reserved, is_generator, | 144 name, function_name_location, name_is_strict_reserved, is_generator, |
145 function_token_position, type, ok); | 145 function_token_position, type, ok); |
146 } | 146 } |
147 | 147 |
148 | 148 |
149 PreParserExpression PreParserTraits::ParseMemberWithNewPrefixesExpression( | |
150 bool* ok) { | |
151 return pre_parser_->ParseMemberWithNewPrefixesExpression(ok); | |
152 } | |
153 | |
154 | |
155 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 149 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
156 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { | 150 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { |
157 log_ = log; | 151 log_ = log; |
158 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 152 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
159 PreParserScope top_scope(scope_, GLOBAL_SCOPE); | 153 PreParserScope top_scope(scope_, GLOBAL_SCOPE); |
160 FunctionState top_state(&function_state_, &scope_, &top_scope); | 154 FunctionState top_state(&function_state_, &scope_, &top_scope); |
161 scope_->SetStrictMode(strict_mode); | 155 scope_->SetStrictMode(strict_mode); |
162 PreParserScope function_scope(scope_, FUNCTION_SCOPE); | 156 PreParserScope function_scope(scope_, FUNCTION_SCOPE); |
163 FunctionState function_state(&function_state_, &scope_, &function_scope); | 157 FunctionState function_state(&function_state_, &scope_, &function_scope); |
164 function_state.set_is_generator(is_generator); | 158 function_state.set_is_generator(is_generator); |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 | 830 |
837 | 831 |
838 #undef CHECK_OK | 832 #undef CHECK_OK |
839 #define CHECK_OK ok); \ | 833 #define CHECK_OK ok); \ |
840 if (!*ok) return Expression::Default(); \ | 834 if (!*ok) return Expression::Default(); \ |
841 ((void)0 | 835 ((void)0 |
842 #define DUMMY ) // to make indentation work | 836 #define DUMMY ) // to make indentation work |
843 #undef DUMMY | 837 #undef DUMMY |
844 | 838 |
845 | 839 |
846 PreParser::Expression PreParser::ParseMemberWithNewPrefixesExpression( | |
847 bool* ok) { | |
848 // NewExpression :: | |
849 // ('new')+ MemberExpression | |
850 | |
851 // See Parser::ParseNewExpression. | |
852 | |
853 if (peek() == Token::NEW) { | |
854 Consume(Token::NEW); | |
855 ParseMemberWithNewPrefixesExpression(CHECK_OK); | |
856 Expression expression = Expression::Default(); | |
857 if (peek() == Token::LPAREN) { | |
858 // NewExpression with arguments. | |
859 ParseArguments(CHECK_OK); | |
860 // The expression can still continue with . or [ after the arguments. Here | |
861 // we need to transmit the "is valid left hand side" property of the | |
862 // expression. | |
863 expression = | |
864 ParseMemberExpressionContinuation(Expression::Default(), CHECK_OK); | |
865 } | |
866 return expression; | |
867 } | |
868 // No 'new' keyword. | |
869 return ParseMemberExpression(ok); | |
870 } | |
871 | |
872 | |
873 PreParser::Expression PreParser::ParseMemberExpression(bool* ok) { | |
874 // MemberExpression :: | |
875 // (PrimaryExpression | FunctionLiteral) | |
876 // ('[' Expression ']' | '.' Identifier | Arguments)* | |
877 | |
878 // The '[' Expression ']' and '.' Identifier parts are parsed by | |
879 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the | |
880 // caller. | |
881 | |
882 // Parse the initial primary or function expression. | |
883 Expression result = Expression::Default(); | |
884 if (peek() == Token::FUNCTION) { | |
885 Consume(Token::FUNCTION); | |
886 int function_token_position = position(); | |
887 bool is_generator = allow_generators() && Check(Token::MUL); | |
888 Identifier name = Identifier::Default(); | |
889 bool is_strict_reserved_name = false; | |
890 Scanner::Location function_name_location = Scanner::Location::invalid(); | |
891 FunctionLiteral::FunctionType function_type = | |
892 FunctionLiteral::ANONYMOUS_EXPRESSION; | |
893 if (peek_any_identifier()) { | |
894 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, | |
895 CHECK_OK); | |
896 function_name_location = scanner()->location(); | |
897 function_type = FunctionLiteral::NAMED_EXPRESSION; | |
898 } | |
899 result = ParseFunctionLiteral(name, | |
900 function_name_location, | |
901 is_strict_reserved_name, | |
902 is_generator, | |
903 function_token_position, | |
904 function_type, | |
905 CHECK_OK); | |
906 } else { | |
907 result = ParsePrimaryExpression(CHECK_OK); | |
908 } | |
909 result = ParseMemberExpressionContinuation(result, CHECK_OK); | |
910 return result; | |
911 } | |
912 | |
913 | |
914 PreParser::Expression PreParser::ParseMemberExpressionContinuation( | |
915 PreParserExpression expression, bool* ok) { | |
916 // Parses this part of MemberExpression: | |
917 // ('[' Expression ']' | '.' Identifier)* | |
918 while (true) { | |
919 switch (peek()) { | |
920 case Token::LBRACK: { | |
921 Consume(Token::LBRACK); | |
922 ParseExpression(true, CHECK_OK); | |
923 Expect(Token::RBRACK, CHECK_OK); | |
924 if (expression.IsThis()) { | |
925 expression = Expression::ThisProperty(); | |
926 } else { | |
927 expression = Expression::Property(); | |
928 } | |
929 break; | |
930 } | |
931 case Token::PERIOD: { | |
932 Consume(Token::PERIOD); | |
933 ParseIdentifierName(CHECK_OK); | |
934 if (expression.IsThis()) { | |
935 expression = Expression::ThisProperty(); | |
936 } else { | |
937 expression = Expression::Property(); | |
938 } | |
939 break; | |
940 } | |
941 default: | |
942 return expression; | |
943 } | |
944 } | |
945 ASSERT(false); | |
946 return PreParserExpression::Default(); | |
947 } | |
948 | |
949 | |
950 PreParser::Expression PreParser::ParseFunctionLiteral( | 840 PreParser::Expression PreParser::ParseFunctionLiteral( |
951 Identifier function_name, | 841 Identifier function_name, |
952 Scanner::Location function_name_location, | 842 Scanner::Location function_name_location, |
953 bool name_is_strict_reserved, | 843 bool name_is_strict_reserved, |
954 bool is_generator, | 844 bool is_generator, |
955 int function_token_pos, | 845 int function_token_pos, |
956 FunctionLiteral::FunctionType function_type, | 846 FunctionLiteral::FunctionType function_type, |
957 bool* ok) { | 847 bool* ok) { |
958 // Function :: | 848 // Function :: |
959 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 849 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 | 979 |
1090 | 980 |
1091 void PreParser::LogSymbol() { | 981 void PreParser::LogSymbol() { |
1092 if (log_->ShouldLogSymbols()) { | 982 if (log_->ShouldLogSymbols()) { |
1093 scanner()->LogSymbol(log_, position()); | 983 scanner()->LogSymbol(log_, position()); |
1094 } | 984 } |
1095 } | 985 } |
1096 | 986 |
1097 | 987 |
1098 } } // v8::internal | 988 } } // v8::internal |
OLD | NEW |