| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 205 } |
| 206 | 206 |
| 207 | 207 |
| 208 Handle<String> Parser::LookupSymbol(int symbol_id) { | 208 Handle<String> Parser::LookupSymbol(int symbol_id) { |
| 209 // If there is no preparser symbol data, a negative number will be passed. In | 209 // If there is no preparser symbol data, a negative number will be passed. In |
| 210 // that case, we'll just read the literal from Scanner. This also guards | 210 // that case, we'll just read the literal from Scanner. This also guards |
| 211 // against corrupt preparse data where the symbol id is larger than the symbol | 211 // against corrupt preparse data where the symbol id is larger than the symbol |
| 212 // count. | 212 // count. |
| 213 if (symbol_id < 0 || | 213 if (symbol_id < 0 || |
| 214 (pre_parse_data_ && symbol_id >= pre_parse_data_->symbol_count())) { | 214 (pre_parse_data_ && symbol_id >= pre_parse_data_->symbol_count())) { |
| 215 if (scanner()->is_literal_ascii()) { | 215 return scanner()->AllocateInternalizedString(isolate_); |
| 216 return isolate()->factory()->InternalizeOneByteString( | |
| 217 Vector<const uint8_t>::cast(scanner()->literal_ascii_string())); | |
| 218 } else { | |
| 219 return isolate()->factory()->InternalizeTwoByteString( | |
| 220 scanner()->literal_utf16_string()); | |
| 221 } | |
| 222 } | 216 } |
| 223 return LookupCachedSymbol(symbol_id); | 217 return LookupCachedSymbol(symbol_id); |
| 224 } | 218 } |
| 225 | 219 |
| 226 | 220 |
| 227 Handle<String> Parser::LookupCachedSymbol(int symbol_id) { | 221 Handle<String> Parser::LookupCachedSymbol(int symbol_id) { |
| 228 // Make sure the cache is large enough to hold the symbol identifier. | 222 // Make sure the cache is large enough to hold the symbol identifier. |
| 229 if (symbol_cache_.length() <= symbol_id) { | 223 if (symbol_cache_.length() <= symbol_id) { |
| 230 // Increase length to index + 1. | 224 // Increase length to index + 1. |
| 231 symbol_cache_.AddBlock(Handle<String>::null(), | 225 symbol_cache_.AddBlock(Handle<String>::null(), |
| 232 symbol_id + 1 - symbol_cache_.length(), zone()); | 226 symbol_id + 1 - symbol_cache_.length(), zone()); |
| 233 } | 227 } |
| 234 Handle<String> result = symbol_cache_.at(symbol_id); | 228 Handle<String> result = symbol_cache_.at(symbol_id); |
| 235 if (result.is_null()) { | 229 if (result.is_null()) { |
| 236 if (scanner()->is_literal_ascii()) { | 230 result = scanner()->AllocateInternalizedString(isolate_); |
| 237 result = isolate()->factory()->InternalizeOneByteString( | |
| 238 Vector<const uint8_t>::cast(scanner()->literal_ascii_string())); | |
| 239 } else { | |
| 240 result = isolate()->factory()->InternalizeTwoByteString( | |
| 241 scanner()->literal_utf16_string()); | |
| 242 } | |
| 243 symbol_cache_.at(symbol_id) = result; | 231 symbol_cache_.at(symbol_id) = result; |
| 244 return result; | 232 return result; |
| 245 } | 233 } |
| 246 isolate()->counters()->total_preparse_symbols_skipped()->Increment(); | 234 isolate()->counters()->total_preparse_symbols_skipped()->Increment(); |
| 247 return result; | 235 return result; |
| 248 } | 236 } |
| 249 | 237 |
| 250 | 238 |
| 251 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { | 239 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { |
| 252 // The current pre-data entry must be a FunctionEntry with the given | 240 // The current pre-data entry must be a FunctionEntry with the given |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 int symbol_id = -1; | 483 int symbol_id = -1; |
| 496 if (parser_->pre_parse_data() != NULL) { | 484 if (parser_->pre_parse_data() != NULL) { |
| 497 symbol_id = parser_->pre_parse_data()->GetSymbolIdentifier(); | 485 symbol_id = parser_->pre_parse_data()->GetSymbolIdentifier(); |
| 498 } | 486 } |
| 499 return parser_->LookupSymbol(symbol_id); | 487 return parser_->LookupSymbol(symbol_id); |
| 500 } | 488 } |
| 501 | 489 |
| 502 | 490 |
| 503 Handle<String> ParserTraits::NextLiteralString(Scanner* scanner, | 491 Handle<String> ParserTraits::NextLiteralString(Scanner* scanner, |
| 504 PretenureFlag tenured) { | 492 PretenureFlag tenured) { |
| 505 if (scanner->is_next_literal_ascii()) { | 493 return scanner->AllocateNextLiteralString(parser_->isolate(), tenured); |
| 506 return parser_->isolate_->factory()->NewStringFromAscii( | |
| 507 scanner->next_literal_ascii_string(), tenured); | |
| 508 } else { | |
| 509 return parser_->isolate_->factory()->NewStringFromTwoByte( | |
| 510 scanner->next_literal_utf16_string(), tenured); | |
| 511 } | |
| 512 } | 494 } |
| 513 | 495 |
| 514 | 496 |
| 515 Expression* ParserTraits::ThisExpression( | 497 Expression* ParserTraits::ThisExpression( |
| 516 Scope* scope, | 498 Scope* scope, |
| 517 AstNodeFactory<AstConstructionVisitor>* factory) { | 499 AstNodeFactory<AstConstructionVisitor>* factory) { |
| 518 return factory->NewVariableProxy(scope->receiver()); | 500 return factory->NewVariableProxy(scope->receiver()); |
| 519 } | 501 } |
| 520 | 502 |
| 521 | 503 |
| 522 Literal* ParserTraits::ExpressionFromLiteral( | 504 Literal* ParserTraits::ExpressionFromLiteral( |
| 523 Token::Value token, int pos, | 505 Token::Value token, int pos, |
| 524 Scanner* scanner, | 506 Scanner* scanner, |
| 525 AstNodeFactory<AstConstructionVisitor>* factory) { | 507 AstNodeFactory<AstConstructionVisitor>* factory) { |
| 526 Factory* isolate_factory = parser_->isolate()->factory(); | 508 Factory* isolate_factory = parser_->isolate()->factory(); |
| 527 switch (token) { | 509 switch (token) { |
| 528 case Token::NULL_LITERAL: | 510 case Token::NULL_LITERAL: |
| 529 return factory->NewLiteral(isolate_factory->null_value(), pos); | 511 return factory->NewLiteral(isolate_factory->null_value(), pos); |
| 530 case Token::TRUE_LITERAL: | 512 case Token::TRUE_LITERAL: |
| 531 return factory->NewLiteral(isolate_factory->true_value(), pos); | 513 return factory->NewLiteral(isolate_factory->true_value(), pos); |
| 532 case Token::FALSE_LITERAL: | 514 case Token::FALSE_LITERAL: |
| 533 return factory->NewLiteral(isolate_factory->false_value(), pos); | 515 return factory->NewLiteral(isolate_factory->false_value(), pos); |
| 534 case Token::NUMBER: { | 516 case Token::NUMBER: { |
| 535 ASSERT(scanner->is_literal_ascii()); | 517 double value = scanner->DoubleValue(); |
| 536 double value = StringToDouble(parser_->isolate()->unicode_cache(), | |
| 537 scanner->literal_ascii_string(), | |
| 538 ALLOW_HEX | ALLOW_OCTAL | | |
| 539 ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); | |
| 540 return factory->NewNumberLiteral(value, pos); | 518 return factory->NewNumberLiteral(value, pos); |
| 541 } | 519 } |
| 542 default: | 520 default: |
| 543 ASSERT(false); | 521 ASSERT(false); |
| 544 } | 522 } |
| 545 return NULL; | 523 return NULL; |
| 546 } | 524 } |
| 547 | 525 |
| 548 | 526 |
| 549 Expression* ParserTraits::ExpressionFromIdentifier( | 527 Expression* ParserTraits::ExpressionFromIdentifier( |
| (...skipping 4628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5178 ASSERT(info()->isolate()->has_pending_exception()); | 5156 ASSERT(info()->isolate()->has_pending_exception()); |
| 5179 } else { | 5157 } else { |
| 5180 result = ParseProgram(); | 5158 result = ParseProgram(); |
| 5181 } | 5159 } |
| 5182 } | 5160 } |
| 5183 info()->SetFunction(result); | 5161 info()->SetFunction(result); |
| 5184 return (result != NULL); | 5162 return (result != NULL); |
| 5185 } | 5163 } |
| 5186 | 5164 |
| 5187 } } // namespace v8::internal | 5165 } } // namespace v8::internal |
| OLD | NEW |