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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 result = scanner()->AllocateInternalizedString(isolate_); | 217 result = scanner()->AllocateInternalizedString(isolate_); |
218 ASSERT(!result.is_null()); | 218 ASSERT(!result.is_null()); |
219 symbol_cache_.at(symbol_id) = result; | 219 symbol_cache_.at(symbol_id) = result; |
220 return result; | 220 return result; |
221 } | 221 } |
222 isolate()->counters()->total_preparse_symbols_skipped()->Increment(); | 222 isolate()->counters()->total_preparse_symbols_skipped()->Increment(); |
223 return result; | 223 return result; |
224 } | 224 } |
225 | 225 |
226 | 226 |
227 ScriptDataImpl::ScriptDataImpl(const char* data, int length) | |
228 : owns_store_(false) { | |
229 // The length is obviously invalid. | |
230 if (length % sizeof(unsigned) != 0) { | |
Sven Panne
2014/04/07 12:44:44
Why do we silently return here? Wouldn't an ASSERT
marja
2014/04/09 12:53:55
This data is coming in via the API, maybe the orig
Sven Panne
2014/04/11 08:18:22
I think that silently (not) doing something is qui
| |
231 return; | |
232 } | |
233 | |
234 // Copy the data to ensure it is properly aligned. | |
Sven Panne
2014/04/07 12:44:44
This comment doesn't really belong here.
marja
2014/04/09 12:53:55
Done.
| |
235 int deserialized_data_length = length / sizeof(unsigned); | |
236 // If aligned, don't create a copy of the data. | |
237 if (reinterpret_cast<intptr_t>(data) % sizeof(unsigned) == 0) { | |
Sven Panne
2014/04/07 12:44:44
I think restructuring this function makes things c
marja
2014/04/09 12:53:55
Done.
| |
238 store_ = | |
239 Vector<unsigned>(reinterpret_cast<unsigned*>(const_cast<char*>(data)), | |
240 length / static_cast<int>(sizeof(unsigned))); | |
241 return; | |
242 } | |
243 | |
244 // Copy the data to align it. | |
245 unsigned* deserialized_data = i::NewArray<unsigned>(deserialized_data_length); | |
246 i::CopyBytes(reinterpret_cast<char*>(deserialized_data), | |
247 data, static_cast<size_t>(length)); | |
248 | |
249 // ScriptDataImpl will own the buffer. | |
250 store_ = i::Vector<unsigned>(deserialized_data, deserialized_data_length); | |
251 owns_store_ = true; | |
252 } | |
253 | |
254 | |
227 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { | 255 FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { |
228 // The current pre-data entry must be a FunctionEntry with the given | 256 // The current pre-data entry must be a FunctionEntry with the given |
229 // start position. | 257 // start position. |
230 if ((function_index_ + FunctionEntry::kSize <= store_.length()) | 258 if ((function_index_ + FunctionEntry::kSize <= store_.length()) |
231 && (static_cast<int>(store_[function_index_]) == start)) { | 259 && (static_cast<int>(store_[function_index_]) == start)) { |
232 int index = function_index_; | 260 int index = function_index_; |
233 function_index_ += FunctionEntry::kSize; | 261 function_index_ += FunctionEntry::kSize; |
234 return FunctionEntry(store_.SubVector(index, | 262 return FunctionEntry(store_.SubVector(index, |
235 index + FunctionEntry::kSize)); | 263 index + FunctionEntry::kSize)); |
236 } | 264 } |
(...skipping 4356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4593 if (data >= symbol_data_end_) return -1; | 4621 if (data >= symbol_data_end_) return -1; |
4594 input = *data; | 4622 input = *data; |
4595 result = (result << 7) | (input & 0x7f); | 4623 result = (result << 7) | (input & 0x7f); |
4596 data++; | 4624 data++; |
4597 } | 4625 } |
4598 *source = data; | 4626 *source = data; |
4599 return result; | 4627 return result; |
4600 } | 4628 } |
4601 | 4629 |
4602 | 4630 |
4603 // Create a Scanner for the preparser to use as input, and preparse the source. | |
4604 ScriptDataImpl* PreParserApi::PreParse(Isolate* isolate, | |
4605 Utf16CharacterStream* source) { | |
4606 CompleteParserRecorder recorder; | |
4607 HistogramTimerScope timer(isolate->counters()->pre_parse()); | |
4608 Scanner scanner(isolate->unicode_cache()); | |
4609 intptr_t stack_limit = isolate->stack_guard()->real_climit(); | |
4610 PreParser preparser(&scanner, &recorder, stack_limit); | |
4611 preparser.set_allow_lazy(true); | |
4612 preparser.set_allow_generators(FLAG_harmony_generators); | |
4613 preparser.set_allow_for_of(FLAG_harmony_iteration); | |
4614 preparser.set_allow_harmony_scoping(FLAG_harmony_scoping); | |
4615 preparser.set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | |
4616 scanner.Initialize(source); | |
4617 PreParser::PreParseResult result = preparser.PreParseProgram(); | |
4618 if (result == PreParser::kPreParseStackOverflow) { | |
4619 isolate->StackOverflow(); | |
4620 return NULL; | |
4621 } | |
4622 | |
4623 // Extract the accumulated data from the recorder as a single | |
4624 // contiguous vector that we are responsible for disposing. | |
4625 Vector<unsigned> store = recorder.ExtractData(); | |
4626 return new ScriptDataImpl(store); | |
4627 } | |
4628 | |
4629 | |
4630 bool RegExpParser::ParseRegExp(FlatStringReader* input, | 4631 bool RegExpParser::ParseRegExp(FlatStringReader* input, |
4631 bool multiline, | 4632 bool multiline, |
4632 RegExpCompileData* result, | 4633 RegExpCompileData* result, |
4633 Zone* zone) { | 4634 Zone* zone) { |
4634 ASSERT(result != NULL); | 4635 ASSERT(result != NULL); |
4635 RegExpParser parser(input, &result->error, multiline, zone); | 4636 RegExpParser parser(input, &result->error, multiline, zone); |
4636 RegExpTree* tree = parser.ParsePattern(); | 4637 RegExpTree* tree = parser.ParsePattern(); |
4637 if (parser.failed()) { | 4638 if (parser.failed()) { |
4638 ASSERT(tree == NULL); | 4639 ASSERT(tree == NULL); |
4639 ASSERT(!result->error.is_null()); | 4640 ASSERT(!result->error.is_null()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4678 ASSERT(info()->isolate()->has_pending_exception()); | 4679 ASSERT(info()->isolate()->has_pending_exception()); |
4679 } else { | 4680 } else { |
4680 result = ParseProgram(); | 4681 result = ParseProgram(); |
4681 } | 4682 } |
4682 } | 4683 } |
4683 info()->SetFunction(result); | 4684 info()->SetFunction(result); |
4684 return (result != NULL); | 4685 return (result != NULL); |
4685 } | 4686 } |
4686 | 4687 |
4687 } } // namespace v8::internal | 4688 } } // namespace v8::internal |
OLD | NEW |