OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 248 |
249 Handle<String> Parser::LookupSymbol(int symbol_id) { | 249 Handle<String> Parser::LookupSymbol(int symbol_id) { |
250 // Length of symbol cache is the number of identified symbols. | 250 // Length of symbol cache is the number of identified symbols. |
251 // If we are larger than that, or negative, it's not a cached symbol. | 251 // If we are larger than that, or negative, it's not a cached symbol. |
252 // This might also happen if there is no preparser symbol data, even | 252 // This might also happen if there is no preparser symbol data, even |
253 // if there is some preparser data. | 253 // if there is some preparser data. |
254 if (static_cast<unsigned>(symbol_id) | 254 if (static_cast<unsigned>(symbol_id) |
255 >= static_cast<unsigned>(symbol_cache_.length())) { | 255 >= static_cast<unsigned>(symbol_cache_.length())) { |
256 if (scanner().is_literal_ascii()) { | 256 if (scanner().is_literal_ascii()) { |
257 return isolate()->factory()->LookupOneByteSymbol( | 257 return isolate()->factory()->LookupOneByteSymbol( |
258 scanner().literal_ascii_string()); | 258 Vector<const uint8_t>::cast(scanner().literal_ascii_string())); |
259 } else { | 259 } else { |
260 return isolate()->factory()->LookupTwoByteSymbol( | 260 return isolate()->factory()->LookupTwoByteSymbol( |
261 scanner().literal_utf16_string()); | 261 scanner().literal_utf16_string()); |
262 } | 262 } |
263 } | 263 } |
264 return LookupCachedSymbol(symbol_id); | 264 return LookupCachedSymbol(symbol_id); |
265 } | 265 } |
266 | 266 |
267 | 267 |
268 Handle<String> Parser::LookupCachedSymbol(int symbol_id) { | 268 Handle<String> Parser::LookupCachedSymbol(int symbol_id) { |
269 // Make sure the cache is large enough to hold the symbol identifier. | 269 // Make sure the cache is large enough to hold the symbol identifier. |
270 if (symbol_cache_.length() <= symbol_id) { | 270 if (symbol_cache_.length() <= symbol_id) { |
271 // Increase length to index + 1. | 271 // Increase length to index + 1. |
272 symbol_cache_.AddBlock(Handle<String>::null(), | 272 symbol_cache_.AddBlock(Handle<String>::null(), |
273 symbol_id + 1 - symbol_cache_.length(), zone()); | 273 symbol_id + 1 - symbol_cache_.length(), zone()); |
274 } | 274 } |
275 Handle<String> result = symbol_cache_.at(symbol_id); | 275 Handle<String> result = symbol_cache_.at(symbol_id); |
276 if (result.is_null()) { | 276 if (result.is_null()) { |
277 if (scanner().is_literal_ascii()) { | 277 if (scanner().is_literal_ascii()) { |
278 result = isolate()->factory()->LookupOneByteSymbol( | 278 result = isolate()->factory()->LookupOneByteSymbol( |
279 scanner().literal_ascii_string()); | 279 Vector<const uint8_t>::cast(scanner().literal_ascii_string())); |
280 } else { | 280 } else { |
281 result = isolate()->factory()->LookupTwoByteSymbol( | 281 result = isolate()->factory()->LookupTwoByteSymbol( |
282 scanner().literal_utf16_string()); | 282 scanner().literal_utf16_string()); |
283 } | 283 } |
284 symbol_cache_.at(symbol_id) = result; | 284 symbol_cache_.at(symbol_id) = result; |
285 return result; | 285 return result; |
286 } | 286 } |
287 isolate()->counters()->total_preparse_symbols_skipped()->Increment(); | 287 isolate()->counters()->total_preparse_symbols_skipped()->Increment(); |
288 return result; | 288 return result; |
289 } | 289 } |
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 // TODO(ES6): implement structuring ExportSpecifiers | 1422 // TODO(ES6): implement structuring ExportSpecifiers |
1423 | 1423 |
1424 Expect(Token::EXPORT, CHECK_OK); | 1424 Expect(Token::EXPORT, CHECK_OK); |
1425 | 1425 |
1426 Statement* result = NULL; | 1426 Statement* result = NULL; |
1427 ZoneStringList names(1, zone()); | 1427 ZoneStringList names(1, zone()); |
1428 switch (peek()) { | 1428 switch (peek()) { |
1429 case Token::IDENTIFIER: { | 1429 case Token::IDENTIFIER: { |
1430 Handle<String> name = ParseIdentifier(CHECK_OK); | 1430 Handle<String> name = ParseIdentifier(CHECK_OK); |
1431 // Handle 'module' as a context-sensitive keyword. | 1431 // Handle 'module' as a context-sensitive keyword. |
1432 if (!name->IsEqualTo(CStrVector("module"))) { | 1432 if (!name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("module"))) { |
1433 names.Add(name, zone()); | 1433 names.Add(name, zone()); |
1434 while (peek() == Token::COMMA) { | 1434 while (peek() == Token::COMMA) { |
1435 Consume(Token::COMMA); | 1435 Consume(Token::COMMA); |
1436 name = ParseIdentifier(CHECK_OK); | 1436 name = ParseIdentifier(CHECK_OK); |
1437 names.Add(name, zone()); | 1437 names.Add(name, zone()); |
1438 } | 1438 } |
1439 ExpectSemicolon(CHECK_OK); | 1439 ExpectSemicolon(CHECK_OK); |
1440 result = factory()->NewEmptyStatement(); | 1440 result = factory()->NewEmptyStatement(); |
1441 } else { | 1441 } else { |
1442 result = ParseModuleDeclaration(&names, CHECK_OK); | 1442 result = ParseModuleDeclaration(&names, CHECK_OK); |
(...skipping 3261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4704 } | 4704 } |
4705 Expect(Token::SEMICOLON, ok); | 4705 Expect(Token::SEMICOLON, ok); |
4706 } | 4706 } |
4707 | 4707 |
4708 | 4708 |
4709 void Parser::ExpectContextualKeyword(const char* keyword, bool* ok) { | 4709 void Parser::ExpectContextualKeyword(const char* keyword, bool* ok) { |
4710 Expect(Token::IDENTIFIER, ok); | 4710 Expect(Token::IDENTIFIER, ok); |
4711 if (!*ok) return; | 4711 if (!*ok) return; |
4712 Handle<String> symbol = GetSymbol(ok); | 4712 Handle<String> symbol = GetSymbol(ok); |
4713 if (!*ok) return; | 4713 if (!*ok) return; |
4714 if (!symbol->IsEqualTo(CStrVector(keyword))) { | 4714 if (!symbol->IsUtf8EqualTo(CStrVector(keyword))) { |
4715 *ok = false; | 4715 *ok = false; |
4716 ReportUnexpectedToken(scanner().current_token()); | 4716 ReportUnexpectedToken(scanner().current_token()); |
4717 } | 4717 } |
4718 } | 4718 } |
4719 | 4719 |
4720 | 4720 |
4721 Literal* Parser::GetLiteralUndefined() { | 4721 Literal* Parser::GetLiteralUndefined() { |
4722 return factory()->NewLiteral(isolate()->factory()->undefined_value()); | 4722 return factory()->NewLiteral(isolate()->factory()->undefined_value()); |
4723 } | 4723 } |
4724 | 4724 |
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5929 ASSERT(info->isolate()->has_pending_exception()); | 5929 ASSERT(info->isolate()->has_pending_exception()); |
5930 } else { | 5930 } else { |
5931 result = parser.ParseProgram(); | 5931 result = parser.ParseProgram(); |
5932 } | 5932 } |
5933 } | 5933 } |
5934 info->SetFunction(result); | 5934 info->SetFunction(result); |
5935 return (result != NULL); | 5935 return (result != NULL); |
5936 } | 5936 } |
5937 | 5937 |
5938 } } // namespace v8::internal | 5938 } } // namespace v8::internal |
OLD | NEW |