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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // Usually defined in math.h, but not in MSVC until VS2013+. | 48 // Usually defined in math.h, but not in MSVC until VS2013+. |
49 // Abstracted to work | 49 // Abstracted to work |
50 int isfinite(double value); | 50 int isfinite(double value); |
51 | 51 |
52 } // namespace std | 52 } // namespace std |
53 #endif | 53 #endif |
54 | 54 |
55 namespace v8 { | 55 namespace v8 { |
56 namespace internal { | 56 namespace internal { |
57 | 57 |
| 58 |
| 59 void PreParserTraits::CheckStrictModeLValue(PreParserExpression expression, |
| 60 bool* ok) { |
| 61 if (expression.IsIdentifier() && |
| 62 expression.AsIdentifier().IsEvalOrArguments()) { |
| 63 pre_parser_->ReportMessage("strict_eval_arguments", |
| 64 Vector<const char*>::empty()); |
| 65 *ok = false; |
| 66 } |
| 67 } |
| 68 |
| 69 |
58 void PreParserTraits::ReportMessageAt(Scanner::Location location, | 70 void PreParserTraits::ReportMessageAt(Scanner::Location location, |
59 const char* message, | 71 const char* message, |
60 Vector<const char*> args) { | 72 Vector<const char*> args) { |
61 ReportMessageAt(location.beg_pos, | 73 ReportMessageAt(location.beg_pos, |
62 location.end_pos, | 74 location.end_pos, |
63 message, | 75 message, |
64 args.length() > 0 ? args[0] : NULL); | 76 args.length() > 0 ? args[0] : NULL); |
65 } | 77 } |
66 | 78 |
67 | 79 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 PreParserExpression PreParserTraits::ExpressionFromString( | 116 PreParserExpression PreParserTraits::ExpressionFromString( |
105 int pos, Scanner* scanner, PreParserFactory* factory) { | 117 int pos, Scanner* scanner, PreParserFactory* factory) { |
106 pre_parser_->LogSymbol(); | 118 pre_parser_->LogSymbol(); |
107 if (scanner->UnescapedLiteralMatches("use strict", 10)) { | 119 if (scanner->UnescapedLiteralMatches("use strict", 10)) { |
108 return PreParserExpression::UseStrictStringLiteral(); | 120 return PreParserExpression::UseStrictStringLiteral(); |
109 } | 121 } |
110 return PreParserExpression::StringLiteral(); | 122 return PreParserExpression::StringLiteral(); |
111 } | 123 } |
112 | 124 |
113 | 125 |
114 PreParserExpression PreParserTraits::ParseAssignmentExpression(bool accept_IN, | |
115 bool* ok) { | |
116 return pre_parser_->ParseAssignmentExpression(accept_IN, ok); | |
117 } | |
118 | |
119 | |
120 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { | 126 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { |
121 return pre_parser_->ParseV8Intrinsic(ok); | 127 return pre_parser_->ParseV8Intrinsic(ok); |
122 } | 128 } |
123 | 129 |
124 | 130 |
125 PreParserExpression PreParserTraits::ParseFunctionLiteral( | 131 PreParserExpression PreParserTraits::ParseFunctionLiteral( |
126 PreParserIdentifier name, | 132 PreParserIdentifier name, |
127 Scanner::Location function_name_location, | 133 Scanner::Location function_name_location, |
128 bool name_is_strict_reserved, | 134 bool name_is_strict_reserved, |
129 bool is_generator, | 135 bool is_generator, |
130 int function_token_position, | 136 int function_token_position, |
131 FunctionLiteral::FunctionType type, | 137 FunctionLiteral::FunctionType type, |
132 bool* ok) { | 138 bool* ok) { |
133 return pre_parser_->ParseFunctionLiteral( | 139 return pre_parser_->ParseFunctionLiteral( |
134 name, function_name_location, name_is_strict_reserved, is_generator, | 140 name, function_name_location, name_is_strict_reserved, is_generator, |
135 function_token_position, type, ok); | 141 function_token_position, type, ok); |
136 } | 142 } |
137 | 143 |
138 | 144 |
| 145 PreParserExpression PreParserTraits::ParseYieldExpression(bool* ok) { |
| 146 return pre_parser_->ParseYieldExpression(ok); |
| 147 } |
| 148 |
| 149 |
| 150 PreParserExpression PreParserTraits::ParseConditionalExpression(bool accept_IN, |
| 151 bool* ok) { |
| 152 return pre_parser_->ParseConditionalExpression(accept_IN, ok); |
| 153 } |
| 154 |
| 155 |
139 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 156 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
140 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { | 157 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { |
141 log_ = log; | 158 log_ = log; |
142 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 159 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
143 PreParserScope top_scope(scope_, GLOBAL_SCOPE); | 160 PreParserScope top_scope(scope_, GLOBAL_SCOPE); |
144 FunctionState top_state(&function_state_, &scope_, &top_scope); | 161 FunctionState top_state(&function_state_, &scope_, &top_scope); |
145 scope_->SetStrictMode(strict_mode); | 162 scope_->SetStrictMode(strict_mode); |
146 PreParserScope function_scope(scope_, FUNCTION_SCOPE); | 163 PreParserScope function_scope(scope_, FUNCTION_SCOPE); |
147 FunctionState function_state(&function_state_, &scope_, &function_scope); | 164 FunctionState function_state(&function_state_, &scope_, &function_scope); |
148 function_state.set_is_generator(is_generator); | 165 function_state.set_is_generator(is_generator); |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 | 837 |
821 | 838 |
822 #undef CHECK_OK | 839 #undef CHECK_OK |
823 #define CHECK_OK ok); \ | 840 #define CHECK_OK ok); \ |
824 if (!*ok) return Expression::Default(); \ | 841 if (!*ok) return Expression::Default(); \ |
825 ((void)0 | 842 ((void)0 |
826 #define DUMMY ) // to make indentation work | 843 #define DUMMY ) // to make indentation work |
827 #undef DUMMY | 844 #undef DUMMY |
828 | 845 |
829 | 846 |
830 // Precedence = 2 | |
831 PreParser::Expression PreParser::ParseAssignmentExpression(bool accept_IN, | |
832 bool* ok) { | |
833 // AssignmentExpression :: | |
834 // ConditionalExpression | |
835 // YieldExpression | |
836 // LeftHandSideExpression AssignmentOperator AssignmentExpression | |
837 | |
838 if (function_state_->is_generator() && peek() == Token::YIELD) { | |
839 return ParseYieldExpression(ok); | |
840 } | |
841 | |
842 Scanner::Location before = scanner()->peek_location(); | |
843 Expression expression = ParseConditionalExpression(accept_IN, CHECK_OK); | |
844 | |
845 if (!Token::IsAssignmentOp(peek())) { | |
846 // Parsed conditional expression only (no assignment). | |
847 return expression; | |
848 } | |
849 | |
850 if (strict_mode() == STRICT && | |
851 expression.IsIdentifier() && | |
852 expression.AsIdentifier().IsEvalOrArguments()) { | |
853 Scanner::Location after = scanner()->location(); | |
854 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, | |
855 "strict_eval_arguments", NULL); | |
856 *ok = false; | |
857 return Expression::Default(); | |
858 } | |
859 | |
860 Token::Value op = Next(); // Get assignment operator. | |
861 ParseAssignmentExpression(accept_IN, CHECK_OK); | |
862 | |
863 if ((op == Token::ASSIGN) && expression.IsThisProperty()) { | |
864 function_state_->AddProperty(); | |
865 } | |
866 | |
867 return Expression::Default(); | |
868 } | |
869 | |
870 | |
871 // Precedence = 3 | 847 // Precedence = 3 |
872 PreParser::Expression PreParser::ParseYieldExpression(bool* ok) { | 848 PreParser::Expression PreParser::ParseYieldExpression(bool* ok) { |
873 // YieldExpression :: | 849 // YieldExpression :: |
874 // 'yield' '*'? AssignmentExpression | 850 // 'yield' '*'? AssignmentExpression |
875 Consume(Token::YIELD); | 851 Consume(Token::YIELD); |
876 Check(Token::MUL); | 852 Check(Token::MUL); |
877 | 853 |
878 ParseAssignmentExpression(false, CHECK_OK); | 854 ParseAssignmentExpression(false, CHECK_OK); |
879 | 855 |
880 return Expression::Default(); | 856 return Expression::Default(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 // '~' UnaryExpression | 908 // '~' UnaryExpression |
933 // '!' UnaryExpression | 909 // '!' UnaryExpression |
934 | 910 |
935 Token::Value op = peek(); | 911 Token::Value op = peek(); |
936 if (Token::IsUnaryOp(op)) { | 912 if (Token::IsUnaryOp(op)) { |
937 op = Next(); | 913 op = Next(); |
938 ParseUnaryExpression(ok); | 914 ParseUnaryExpression(ok); |
939 return Expression::Default(); | 915 return Expression::Default(); |
940 } else if (Token::IsCountOp(op)) { | 916 } else if (Token::IsCountOp(op)) { |
941 op = Next(); | 917 op = Next(); |
942 Scanner::Location before = scanner()->peek_location(); | |
943 Expression expression = ParseUnaryExpression(CHECK_OK); | 918 Expression expression = ParseUnaryExpression(CHECK_OK); |
944 if (strict_mode() == STRICT && | 919 if (strict_mode() == STRICT) { |
945 expression.IsIdentifier() && | 920 CheckStrictModeLValue(expression, CHECK_OK); |
946 expression.AsIdentifier().IsEvalOrArguments()) { | |
947 Scanner::Location after = scanner()->location(); | |
948 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, | |
949 "strict_eval_arguments", NULL); | |
950 *ok = false; | |
951 } | 921 } |
952 return Expression::Default(); | 922 return Expression::Default(); |
953 } else { | 923 } else { |
954 return ParsePostfixExpression(ok); | 924 return ParsePostfixExpression(ok); |
955 } | 925 } |
956 } | 926 } |
957 | 927 |
958 | 928 |
959 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { | 929 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { |
960 // PostfixExpression :: | 930 // PostfixExpression :: |
961 // LeftHandSideExpression ('++' | '--')? | 931 // LeftHandSideExpression ('++' | '--')? |
962 | 932 |
963 Scanner::Location before = scanner()->peek_location(); | |
964 Expression expression = ParseLeftHandSideExpression(CHECK_OK); | 933 Expression expression = ParseLeftHandSideExpression(CHECK_OK); |
965 if (!scanner()->HasAnyLineTerminatorBeforeNext() && | 934 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
966 Token::IsCountOp(peek())) { | 935 Token::IsCountOp(peek())) { |
967 if (strict_mode() == STRICT && | 936 if (strict_mode() == STRICT) { |
968 expression.IsIdentifier() && | 937 CheckStrictModeLValue(expression, CHECK_OK); |
969 expression.AsIdentifier().IsEvalOrArguments()) { | |
970 Scanner::Location after = scanner()->location(); | |
971 PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, | |
972 "strict_eval_arguments", NULL); | |
973 *ok = false; | |
974 return Expression::Default(); | |
975 } | 938 } |
976 Next(); | 939 Next(); |
977 return Expression::Default(); | 940 return Expression::Default(); |
978 } | 941 } |
979 return expression; | 942 return expression; |
980 } | 943 } |
981 | 944 |
982 | 945 |
983 PreParser::Expression PreParser::ParseLeftHandSideExpression(bool* ok) { | 946 PreParser::Expression PreParser::ParseLeftHandSideExpression(bool* ok) { |
984 // LeftHandSideExpression :: | 947 // LeftHandSideExpression :: |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 | 1230 |
1268 | 1231 |
1269 void PreParser::LogSymbol() { | 1232 void PreParser::LogSymbol() { |
1270 if (log_->ShouldLogSymbols()) { | 1233 if (log_->ShouldLogSymbols()) { |
1271 scanner()->LogSymbol(log_, position()); | 1234 scanner()->LogSymbol(log_, position()); |
1272 } | 1235 } |
1273 } | 1236 } |
1274 | 1237 |
1275 | 1238 |
1276 } } // v8::internal | 1239 } } // v8::internal |
OLD | NEW |