OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "api.h" | 7 #include "api.h" |
8 #include "ast.h" | 8 #include "ast.h" |
9 #include "bootstrapper.h" | 9 #include "bootstrapper.h" |
10 #include "char-predicates-inl.h" | 10 #include "char-predicates-inl.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // Only call immediately after adding an atom or character! | 175 // Only call immediately after adding an atom or character! |
176 UNREACHABLE(); | 176 UNREACHABLE(); |
177 return; | 177 return; |
178 } | 178 } |
179 terms_.Add( | 179 terms_.Add( |
180 new(zone()) RegExpQuantifier(min, max, quantifier_type, atom), zone()); | 180 new(zone()) RegExpQuantifier(min, max, quantifier_type, atom), zone()); |
181 LAST(ADD_TERM); | 181 LAST(ADD_TERM); |
182 } | 182 } |
183 | 183 |
184 | 184 |
185 Handle<String> Parser::LookupCachedSymbol(int symbol_id) { | |
186 // Make sure the cache is large enough to hold the symbol identifier. | |
187 if (symbol_cache_.length() <= symbol_id) { | |
188 // Increase length to index + 1. | |
189 symbol_cache_.AddBlock(Handle<String>::null(), | |
190 symbol_id + 1 - symbol_cache_.length(), zone()); | |
191 } | |
192 Handle<String> result = symbol_cache_.at(symbol_id); | |
193 if (result.is_null()) { | |
194 result = scanner()->AllocateInternalizedString(isolate_); | |
195 ASSERT(!result.is_null()); | |
196 symbol_cache_.at(symbol_id) = result; | |
197 return result; | |
198 } | |
199 isolate()->counters()->total_preparse_symbols_skipped()->Increment(); | |
200 return result; | |
201 } | |
202 | |
203 | |
204 ScriptData* ScriptData::New(const char* data, int length) { | 185 ScriptData* ScriptData::New(const char* data, int length) { |
205 // The length is obviously invalid. | 186 // The length is obviously invalid. |
206 if (length % sizeof(unsigned) != 0) { | 187 if (length % sizeof(unsigned) != 0) { |
207 return NULL; | 188 return NULL; |
208 } | 189 } |
209 | 190 |
210 int deserialized_data_length = length / sizeof(unsigned); | 191 int deserialized_data_length = length / sizeof(unsigned); |
211 unsigned* deserialized_data; | 192 unsigned* deserialized_data; |
212 bool owns_store = reinterpret_cast<intptr_t>(data) % sizeof(unsigned) != 0; | 193 bool owns_store = reinterpret_cast<intptr_t>(data) % sizeof(unsigned) != 0; |
213 if (owns_store) { | 194 if (owns_store) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 if (store_.length() < PreparseDataConstants::kHeaderSize + pos) { | 254 if (store_.length() < PreparseDataConstants::kHeaderSize + pos) { |
274 return false; | 255 return false; |
275 } | 256 } |
276 return true; | 257 return true; |
277 } | 258 } |
278 // Check that the space allocated for function entries is sane. | 259 // Check that the space allocated for function entries is sane. |
279 int functions_size = | 260 int functions_size = |
280 static_cast<int>(store_[PreparseDataConstants::kFunctionsSizeOffset]); | 261 static_cast<int>(store_[PreparseDataConstants::kFunctionsSizeOffset]); |
281 if (functions_size < 0) return false; | 262 if (functions_size < 0) return false; |
282 if (functions_size % FunctionEntry::kSize != 0) return false; | 263 if (functions_size % FunctionEntry::kSize != 0) return false; |
283 // Check that the count of symbols is non-negative. | |
284 int symbol_count = | |
285 static_cast<int>(store_[PreparseDataConstants::kSymbolCountOffset]); | |
286 if (symbol_count < 0) return false; | |
287 // Check that the total size has room for header and function entries. | 264 // Check that the total size has room for header and function entries. |
288 int minimum_size = | 265 int minimum_size = |
289 PreparseDataConstants::kHeaderSize + functions_size; | 266 PreparseDataConstants::kHeaderSize + functions_size; |
290 if (store_.length() < minimum_size) return false; | 267 if (store_.length() < minimum_size) return false; |
291 return true; | 268 return true; |
292 } | 269 } |
293 | 270 |
294 | 271 |
295 | 272 |
296 const char* ScriptData::ReadString(unsigned* start, int* chars) { | 273 const char* ScriptData::ReadString(unsigned* start, int* chars) { |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 } | 677 } |
701 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); | 678 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); |
702 Handle<Object> result = is_reference_error | 679 Handle<Object> result = is_reference_error |
703 ? factory->NewReferenceError(message, array) | 680 ? factory->NewReferenceError(message, array) |
704 : factory->NewSyntaxError(message, array); | 681 : factory->NewSyntaxError(message, array); |
705 parser_->isolate()->Throw(*result, &location); | 682 parser_->isolate()->Throw(*result, &location); |
706 } | 683 } |
707 | 684 |
708 | 685 |
709 Handle<String> ParserTraits::GetSymbol(Scanner* scanner) { | 686 Handle<String> ParserTraits::GetSymbol(Scanner* scanner) { |
710 if (parser_->cached_data_mode() == CONSUME_CACHED_DATA) { | |
711 int symbol_id = (*parser_->cached_data())->GetSymbolIdentifier(); | |
712 // If there is no symbol data, -1 will be returned. | |
713 if (symbol_id >= 0 && | |
714 symbol_id < (*parser_->cached_data())->symbol_count()) { | |
715 return parser_->LookupCachedSymbol(symbol_id); | |
716 } | |
717 } else if (parser_->cached_data_mode() == PRODUCE_CACHED_DATA) { | |
718 // Parser is never used inside lazy functions (it falls back to PreParser | |
719 // instead), so we can produce the symbol data unconditionally. | |
720 parser_->scanner()->LogSymbol(parser_->log_, parser_->position()); | |
721 } | |
722 Handle<String> result = | 687 Handle<String> result = |
723 parser_->scanner()->AllocateInternalizedString(parser_->isolate()); | 688 parser_->scanner()->AllocateInternalizedString(parser_->isolate()); |
724 ASSERT(!result.is_null()); | 689 ASSERT(!result.is_null()); |
725 return result; | 690 return result; |
726 } | 691 } |
727 | 692 |
728 | 693 |
729 Handle<String> ParserTraits::NextLiteralString(Scanner* scanner, | 694 Handle<String> ParserTraits::NextLiteralString(Scanner* scanner, |
730 PretenureFlag tenured) { | 695 PretenureFlag tenured) { |
731 return scanner->AllocateNextLiteralString(parser_->isolate(), tenured); | 696 return scanner->AllocateNextLiteralString(parser_->isolate(), tenured); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 | 777 |
813 | 778 |
814 Parser::Parser(CompilationInfo* info) | 779 Parser::Parser(CompilationInfo* info) |
815 : ParserBase<ParserTraits>(&scanner_, | 780 : ParserBase<ParserTraits>(&scanner_, |
816 info->isolate()->stack_guard()->real_climit(), | 781 info->isolate()->stack_guard()->real_climit(), |
817 info->extension(), | 782 info->extension(), |
818 NULL, | 783 NULL, |
819 info->zone(), | 784 info->zone(), |
820 this), | 785 this), |
821 isolate_(info->isolate()), | 786 isolate_(info->isolate()), |
822 symbol_cache_(0, info->zone()), | |
823 script_(info->script()), | 787 script_(info->script()), |
824 scanner_(isolate_->unicode_cache()), | 788 scanner_(isolate_->unicode_cache()), |
825 reusable_preparser_(NULL), | 789 reusable_preparser_(NULL), |
826 original_scope_(NULL), | 790 original_scope_(NULL), |
827 target_stack_(NULL), | 791 target_stack_(NULL), |
828 cached_data_(NULL), | 792 cached_data_(NULL), |
829 cached_data_mode_(NO_CACHED_DATA), | 793 cached_data_mode_(NO_CACHED_DATA), |
830 info_(info) { | 794 info_(info) { |
831 ASSERT(!script_.is_null()); | 795 ASSERT(!script_.is_null()); |
832 isolate_->set_ast_node_id(0); | 796 isolate_->set_ast_node_id(0); |
(...skipping 3832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4665 ASSERT(info()->isolate()->has_pending_exception()); | 4629 ASSERT(info()->isolate()->has_pending_exception()); |
4666 } else { | 4630 } else { |
4667 result = ParseProgram(); | 4631 result = ParseProgram(); |
4668 } | 4632 } |
4669 } | 4633 } |
4670 info()->SetFunction(result); | 4634 info()->SetFunction(result); |
4671 return (result != NULL); | 4635 return (result != NULL); |
4672 } | 4636 } |
4673 | 4637 |
4674 } } // namespace v8::internal | 4638 } } // namespace v8::internal |
OLD | NEW |