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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 | 75 |
76 void PreParserTraits::ReportMessageAt(int start_pos, | 76 void PreParserTraits::ReportMessageAt(int start_pos, |
77 int end_pos, | 77 int end_pos, |
78 const char* type, | 78 const char* type, |
79 const char* name_opt) { | 79 const char* name_opt) { |
80 pre_parser_->log_->LogMessage(start_pos, end_pos, type, name_opt); | 80 pre_parser_->log_->LogMessage(start_pos, end_pos, type, name_opt); |
81 } | 81 } |
82 | 82 |
83 | 83 |
84 PreParserIdentifier PreParserTraits::GetSymbol() { | 84 PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { |
85 Scanner* scanner = pre_parser_->scanner(); | |
86 pre_parser_->LogSymbol(); | 85 pre_parser_->LogSymbol(); |
87 if (scanner->current_token() == Token::FUTURE_RESERVED_WORD) { | 86 if (scanner->current_token() == Token::FUTURE_RESERVED_WORD) { |
88 return PreParserIdentifier::FutureReserved(); | 87 return PreParserIdentifier::FutureReserved(); |
89 } else if (scanner->current_token() == | 88 } else if (scanner->current_token() == |
90 Token::FUTURE_STRICT_RESERVED_WORD) { | 89 Token::FUTURE_STRICT_RESERVED_WORD) { |
91 return PreParserIdentifier::FutureStrictReserved(); | 90 return PreParserIdentifier::FutureStrictReserved(); |
92 } else if (scanner->current_token() == Token::YIELD) { | 91 } else if (scanner->current_token() == Token::YIELD) { |
93 return PreParserIdentifier::Yield(); | 92 return PreParserIdentifier::Yield(); |
94 } | 93 } |
95 if (scanner->is_literal_ascii()) { | 94 if (scanner->is_literal_ascii()) { |
96 // Detect strict-mode poison words. | 95 // Detect strict-mode poison words. |
97 if (scanner->literal_length() == 4 && | 96 if (scanner->literal_length() == 4 && |
98 !strncmp(scanner->literal_ascii_string().start(), "eval", 4)) { | 97 !strncmp(scanner->literal_ascii_string().start(), "eval", 4)) { |
99 return PreParserIdentifier::Eval(); | 98 return PreParserIdentifier::Eval(); |
100 } | 99 } |
101 if (scanner->literal_length() == 9 && | 100 if (scanner->literal_length() == 9 && |
102 !strncmp(scanner->literal_ascii_string().start(), "arguments", 9)) { | 101 !strncmp(scanner->literal_ascii_string().start(), "arguments", 9)) { |
103 return PreParserIdentifier::Arguments(); | 102 return PreParserIdentifier::Arguments(); |
104 } | 103 } |
105 } | 104 } |
106 return PreParserIdentifier::Default(); | 105 return PreParserIdentifier::Default(); |
107 } | 106 } |
108 | 107 |
109 | 108 |
| 109 PreParserExpression PreParserTraits::ExpressionFromString( |
| 110 int pos, Scanner* scanner, PreParserFactory* factory) { |
| 111 const int kUseStrictLength = 10; |
| 112 const char* kUseStrictChars = "use strict"; |
| 113 pre_parser_->LogSymbol(); |
| 114 if (scanner->is_literal_ascii() && |
| 115 scanner->literal_length() == kUseStrictLength && |
| 116 !scanner->literal_contains_escapes() && |
| 117 !strncmp(scanner->literal_ascii_string().start(), kUseStrictChars, |
| 118 kUseStrictLength)) { |
| 119 return PreParserExpression::UseStrictStringLiteral(); |
| 120 } |
| 121 return PreParserExpression::StringLiteral(); |
| 122 } |
| 123 |
| 124 |
| 125 PreParserExpression PreParserTraits::ParseArrayLiteral(bool* ok) { |
| 126 return pre_parser_->ParseArrayLiteral(ok); |
| 127 } |
| 128 |
| 129 |
| 130 PreParserExpression PreParserTraits::ParseObjectLiteral(bool* ok) { |
| 131 return pre_parser_->ParseObjectLiteral(ok); |
| 132 } |
| 133 |
| 134 |
| 135 PreParserExpression PreParserTraits::ParseExpression(bool accept_IN, bool* ok) { |
| 136 return pre_parser_->ParseExpression(accept_IN, ok); |
| 137 } |
| 138 |
| 139 |
| 140 PreParserExpression PreParserTraits::ParseV8Intrinsic(bool* ok) { |
| 141 return pre_parser_->ParseV8Intrinsic(ok); |
| 142 } |
| 143 |
| 144 |
110 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 145 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
111 LanguageMode mode, bool is_generator, ParserRecorder* log) { | 146 LanguageMode mode, bool is_generator, ParserRecorder* log) { |
112 log_ = log; | 147 log_ = log; |
113 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 148 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
114 PreParserScope top_scope(scope_, GLOBAL_SCOPE); | 149 PreParserScope top_scope(scope_, GLOBAL_SCOPE); |
115 FunctionState top_state(&function_state_, &scope_, &top_scope); | 150 FunctionState top_state(&function_state_, &scope_, &top_scope); |
116 scope_->SetLanguageMode(mode); | 151 scope_->SetLanguageMode(mode); |
117 PreParserScope function_scope(scope_, FUNCTION_SCOPE); | 152 PreParserScope function_scope(scope_, FUNCTION_SCOPE); |
118 FunctionState function_state(&function_state_, &scope_, &function_scope); | 153 FunctionState function_state(&function_state_, &scope_, &function_scope); |
119 function_state.set_is_generator(is_generator); | 154 function_state.set_is_generator(is_generator); |
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 result = Expression::Default(); | 1139 result = Expression::Default(); |
1105 break; | 1140 break; |
1106 } | 1141 } |
1107 default: | 1142 default: |
1108 return result; | 1143 return result; |
1109 } | 1144 } |
1110 } | 1145 } |
1111 } | 1146 } |
1112 | 1147 |
1113 | 1148 |
1114 PreParser::Expression PreParser::ParsePrimaryExpression(bool* ok) { | |
1115 // PrimaryExpression :: | |
1116 // 'this' | |
1117 // 'null' | |
1118 // 'true' | |
1119 // 'false' | |
1120 // Identifier | |
1121 // Number | |
1122 // String | |
1123 // ArrayLiteral | |
1124 // ObjectLiteral | |
1125 // RegExpLiteral | |
1126 // '(' Expression ')' | |
1127 | |
1128 Expression result = Expression::Default(); | |
1129 switch (peek()) { | |
1130 case Token::THIS: { | |
1131 Next(); | |
1132 result = Expression::This(); | |
1133 break; | |
1134 } | |
1135 | |
1136 case Token::FUTURE_RESERVED_WORD: | |
1137 case Token::FUTURE_STRICT_RESERVED_WORD: | |
1138 case Token::YIELD: | |
1139 case Token::IDENTIFIER: { | |
1140 // Using eval or arguments in this context is OK even in strict mode. | |
1141 Identifier id = ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | |
1142 result = Expression::FromIdentifier(id); | |
1143 break; | |
1144 } | |
1145 | |
1146 case Token::NULL_LITERAL: | |
1147 case Token::TRUE_LITERAL: | |
1148 case Token::FALSE_LITERAL: | |
1149 case Token::NUMBER: { | |
1150 Next(); | |
1151 break; | |
1152 } | |
1153 case Token::STRING: { | |
1154 Next(); | |
1155 result = GetStringSymbol(); | |
1156 break; | |
1157 } | |
1158 | |
1159 case Token::ASSIGN_DIV: | |
1160 result = ParseRegExpLiteral(true, CHECK_OK); | |
1161 break; | |
1162 | |
1163 case Token::DIV: | |
1164 result = ParseRegExpLiteral(false, CHECK_OK); | |
1165 break; | |
1166 | |
1167 case Token::LBRACK: | |
1168 result = ParseArrayLiteral(CHECK_OK); | |
1169 break; | |
1170 | |
1171 case Token::LBRACE: | |
1172 result = ParseObjectLiteral(CHECK_OK); | |
1173 break; | |
1174 | |
1175 case Token::LPAREN: | |
1176 Consume(Token::LPAREN); | |
1177 parenthesized_function_ = (peek() == Token::FUNCTION); | |
1178 result = ParseExpression(true, CHECK_OK); | |
1179 Expect(Token::RPAREN, CHECK_OK); | |
1180 break; | |
1181 | |
1182 case Token::MOD: | |
1183 result = ParseV8Intrinsic(CHECK_OK); | |
1184 break; | |
1185 | |
1186 default: { | |
1187 Token::Value next = Next(); | |
1188 ReportUnexpectedToken(next); | |
1189 *ok = false; | |
1190 return Expression::Default(); | |
1191 } | |
1192 } | |
1193 | |
1194 return result; | |
1195 } | |
1196 | |
1197 | |
1198 PreParser::Expression PreParser::ParseArrayLiteral(bool* ok) { | 1149 PreParser::Expression PreParser::ParseArrayLiteral(bool* ok) { |
1199 // ArrayLiteral :: | 1150 // ArrayLiteral :: |
1200 // '[' Expression? (',' Expression?)* ']' | 1151 // '[' Expression? (',' Expression?)* ']' |
1201 Expect(Token::LBRACK, CHECK_OK); | 1152 Expect(Token::LBRACK, CHECK_OK); |
1202 while (peek() != Token::RBRACK) { | 1153 while (peek() != Token::RBRACK) { |
1203 if (peek() != Token::COMMA) { | 1154 if (peek() != Token::COMMA) { |
1204 ParseAssignmentExpression(true, CHECK_OK); | 1155 ParseAssignmentExpression(true, CHECK_OK); |
1205 } | 1156 } |
1206 if (peek() != Token::RBRACK) { | 1157 if (peek() != Token::RBRACK) { |
1207 Expect(Token::COMMA, CHECK_OK); | 1158 Expect(Token::COMMA, CHECK_OK); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 Expect(Token::COMMA, CHECK_OK); | 1210 Expect(Token::COMMA, CHECK_OK); |
1260 } | 1211 } |
1261 continue; // restart the while | 1212 continue; // restart the while |
1262 } | 1213 } |
1263 checker.CheckProperty(next, kValueProperty, CHECK_OK); | 1214 checker.CheckProperty(next, kValueProperty, CHECK_OK); |
1264 break; | 1215 break; |
1265 } | 1216 } |
1266 case Token::STRING: | 1217 case Token::STRING: |
1267 Consume(next); | 1218 Consume(next); |
1268 checker.CheckProperty(next, kValueProperty, CHECK_OK); | 1219 checker.CheckProperty(next, kValueProperty, CHECK_OK); |
1269 GetStringSymbol(); | 1220 LogSymbol(); |
1270 break; | 1221 break; |
1271 case Token::NUMBER: | 1222 case Token::NUMBER: |
1272 Consume(next); | 1223 Consume(next); |
1273 checker.CheckProperty(next, kValueProperty, CHECK_OK); | 1224 checker.CheckProperty(next, kValueProperty, CHECK_OK); |
1274 break; | 1225 break; |
1275 default: | 1226 default: |
1276 if (Token::IsKeyword(next)) { | 1227 if (Token::IsKeyword(next)) { |
1277 Consume(next); | 1228 Consume(next); |
1278 checker.CheckProperty(next, kValueProperty, CHECK_OK); | 1229 checker.CheckProperty(next, kValueProperty, CHECK_OK); |
1279 } else { | 1230 } else { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 void PreParser::LogSymbol() { | 1419 void PreParser::LogSymbol() { |
1469 int identifier_pos = position(); | 1420 int identifier_pos = position(); |
1470 if (scanner()->is_literal_ascii()) { | 1421 if (scanner()->is_literal_ascii()) { |
1471 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_ascii_string()); | 1422 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_ascii_string()); |
1472 } else { | 1423 } else { |
1473 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string()); | 1424 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string()); |
1474 } | 1425 } |
1475 } | 1426 } |
1476 | 1427 |
1477 | 1428 |
1478 PreParser::Expression PreParser::GetStringSymbol() { | |
1479 const int kUseStrictLength = 10; | |
1480 const char* kUseStrictChars = "use strict"; | |
1481 LogSymbol(); | |
1482 if (scanner()->is_literal_ascii() && | |
1483 scanner()->literal_length() == kUseStrictLength && | |
1484 !scanner()->literal_contains_escapes() && | |
1485 !strncmp(scanner()->literal_ascii_string().start(), kUseStrictChars, | |
1486 kUseStrictLength)) { | |
1487 return Expression::UseStrictStringLiteral(); | |
1488 } | |
1489 return Expression::StringLiteral(); | |
1490 } | |
1491 | |
1492 | |
1493 } } // v8::internal | 1429 } } // v8::internal |
OLD | NEW |