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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { | 84 PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { |
85 pre_parser_->LogSymbol(); | 85 pre_parser_->LogSymbol(); |
86 if (scanner->current_token() == Token::FUTURE_RESERVED_WORD) { | 86 if (scanner->current_token() == Token::FUTURE_RESERVED_WORD) { |
87 return PreParserIdentifier::FutureReserved(); | 87 return PreParserIdentifier::FutureReserved(); |
88 } else if (scanner->current_token() == | 88 } else if (scanner->current_token() == |
89 Token::FUTURE_STRICT_RESERVED_WORD) { | 89 Token::FUTURE_STRICT_RESERVED_WORD) { |
90 return PreParserIdentifier::FutureStrictReserved(); | 90 return PreParserIdentifier::FutureStrictReserved(); |
91 } else if (scanner->current_token() == Token::YIELD) { | 91 } else if (scanner->current_token() == Token::YIELD) { |
92 return PreParserIdentifier::Yield(); | 92 return PreParserIdentifier::Yield(); |
93 } | 93 } |
94 if (scanner->is_literal_ascii()) { | 94 if (scanner->UnescapedLiteralMatches("eval", 4)) { |
95 // Detect strict-mode poison words. | 95 return PreParserIdentifier::Eval(); |
96 if (scanner->literal_length() == 4 && | 96 } |
97 !strncmp(scanner->literal_ascii_string().start(), "eval", 4)) { | 97 if (scanner->UnescapedLiteralMatches("arguments", 9)) { |
98 return PreParserIdentifier::Eval(); | 98 return PreParserIdentifier::Arguments(); |
99 } | |
100 if (scanner->literal_length() == 9 && | |
101 !strncmp(scanner->literal_ascii_string().start(), "arguments", 9)) { | |
102 return PreParserIdentifier::Arguments(); | |
103 } | |
104 } | 99 } |
105 return PreParserIdentifier::Default(); | 100 return PreParserIdentifier::Default(); |
106 } | 101 } |
107 | 102 |
108 | 103 |
109 PreParserExpression PreParserTraits::ExpressionFromString( | 104 PreParserExpression PreParserTraits::ExpressionFromString( |
110 int pos, Scanner* scanner, PreParserFactory* factory) { | 105 int pos, Scanner* scanner, PreParserFactory* factory) { |
111 const int kUseStrictLength = 10; | |
112 const char* kUseStrictChars = "use strict"; | |
113 pre_parser_->LogSymbol(); | 106 pre_parser_->LogSymbol(); |
114 if (scanner->is_literal_ascii() && | 107 if (scanner->UnescapedLiteralMatches("use strict", 10)) { |
115 scanner->literal_length() == kUseStrictLength && | |
116 !scanner->literal_contains_escapes() && | |
117 !strncmp(scanner->literal_ascii_string().start(), kUseStrictChars, | |
118 kUseStrictLength)) { | |
119 return PreParserExpression::UseStrictStringLiteral(); | 108 return PreParserExpression::UseStrictStringLiteral(); |
120 } | 109 } |
121 return PreParserExpression::StringLiteral(); | 110 return PreParserExpression::StringLiteral(); |
122 } | 111 } |
123 | 112 |
124 | 113 |
125 PreParserExpression PreParserTraits::ParseAssignmentExpression(bool accept_IN, | 114 PreParserExpression PreParserTraits::ParseAssignmentExpression(bool accept_IN, |
126 bool* ok) { | 115 bool* ok) { |
127 return pre_parser_->ParseAssignmentExpression(accept_IN, ok); | 116 return pre_parser_->ParseAssignmentExpression(accept_IN, ok); |
128 } | 117 } |
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 Identifier param_name = | 1158 Identifier param_name = |
1170 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 1159 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
1171 if (!eval_args_error_loc.IsValid() && param_name.IsEvalOrArguments()) { | 1160 if (!eval_args_error_loc.IsValid() && param_name.IsEvalOrArguments()) { |
1172 eval_args_error_loc = scanner()->location(); | 1161 eval_args_error_loc = scanner()->location(); |
1173 } | 1162 } |
1174 if (!reserved_error_loc.IsValid() && is_strict_reserved) { | 1163 if (!reserved_error_loc.IsValid() && is_strict_reserved) { |
1175 reserved_error_loc = scanner()->location(); | 1164 reserved_error_loc = scanner()->location(); |
1176 } | 1165 } |
1177 | 1166 |
1178 int prev_value; | 1167 int prev_value; |
1179 if (scanner()->is_literal_ascii()) { | 1168 if (scanner()->is_literal_one_byte()) { |
1180 prev_value = | 1169 prev_value = duplicate_finder.AddAsciiSymbol( |
1181 duplicate_finder.AddAsciiSymbol(scanner()->literal_ascii_string(), 1); | 1170 scanner()->literal_one_byte_string(), 1); |
1182 } else { | 1171 } else { |
1183 prev_value = | 1172 prev_value = |
1184 duplicate_finder.AddUtf16Symbol(scanner()->literal_utf16_string(), 1); | 1173 duplicate_finder.AddUtf16Symbol(scanner()->literal_utf16_string(), 1); |
1185 } | 1174 } |
1186 | 1175 |
1187 if (!dupe_error_loc.IsValid() && prev_value != 0) { | 1176 if (!dupe_error_loc.IsValid() && prev_value != 0) { |
1188 dupe_error_loc = scanner()->location(); | 1177 dupe_error_loc = scanner()->location(); |
1189 } | 1178 } |
1190 | 1179 |
1191 done = (peek() == Token::RPAREN); | 1180 done = (peek() == Token::RPAREN); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 ParseArguments(ok); | 1267 ParseArguments(ok); |
1279 | 1268 |
1280 return Expression::Default(); | 1269 return Expression::Default(); |
1281 } | 1270 } |
1282 | 1271 |
1283 #undef CHECK_OK | 1272 #undef CHECK_OK |
1284 | 1273 |
1285 | 1274 |
1286 void PreParser::LogSymbol() { | 1275 void PreParser::LogSymbol() { |
1287 int identifier_pos = position(); | 1276 int identifier_pos = position(); |
1288 if (scanner()->is_literal_ascii()) { | 1277 if (scanner()->is_literal_one_byte()) { |
1289 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_ascii_string()); | 1278 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_one_byte_string()); |
1290 } else { | 1279 } else { |
1291 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string()); | 1280 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string()); |
1292 } | 1281 } |
1293 } | 1282 } |
1294 | 1283 |
1295 | 1284 |
1296 } } // v8::internal | 1285 } } // v8::internal |
OLD | NEW |