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 "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 | 601 |
602 void ParserTraits::ReportMessageAt(Scanner::Location source_location, | 602 void ParserTraits::ReportMessageAt(Scanner::Location source_location, |
603 const char* message, const char* arg, | 603 const char* message, const char* arg, |
604 ParseErrorType error_type) { | 604 ParseErrorType error_type) { |
605 if (parser_->stack_overflow()) { | 605 if (parser_->stack_overflow()) { |
606 // Suppress the error message (syntax error or such) in the presence of a | 606 // Suppress the error message (syntax error or such) in the presence of a |
607 // stack overflow. The isolate allows only one pending exception at at time | 607 // stack overflow. The isolate allows only one pending exception at at time |
608 // and we want to report the stack overflow later. | 608 // and we want to report the stack overflow later. |
609 return; | 609 return; |
610 } | 610 } |
611 parser_->has_pending_error_ = true; | 611 parser_->pending_error_handler_.ReportMessageAt(source_location.beg_pos, |
612 parser_->pending_error_location_ = source_location; | 612 source_location.end_pos, |
613 parser_->pending_error_message_ = message; | 613 message, arg, error_type); |
614 parser_->pending_error_char_arg_ = arg; | |
615 parser_->pending_error_arg_ = NULL; | |
616 parser_->pending_error_type_ = error_type; | |
617 } | 614 } |
618 | 615 |
619 | 616 |
620 void ParserTraits::ReportMessage(const char* message, const char* arg, | 617 void ParserTraits::ReportMessage(const char* message, const char* arg, |
621 ParseErrorType error_type) { | 618 ParseErrorType error_type) { |
622 Scanner::Location source_location = parser_->scanner()->location(); | 619 Scanner::Location source_location = parser_->scanner()->location(); |
623 ReportMessageAt(source_location, message, arg, error_type); | 620 ReportMessageAt(source_location, message, arg, error_type); |
624 } | 621 } |
625 | 622 |
626 | 623 |
627 void ParserTraits::ReportMessage(const char* message, const AstRawString* arg, | 624 void ParserTraits::ReportMessage(const char* message, const AstRawString* arg, |
628 ParseErrorType error_type) { | 625 ParseErrorType error_type) { |
629 Scanner::Location source_location = parser_->scanner()->location(); | 626 Scanner::Location source_location = parser_->scanner()->location(); |
630 ReportMessageAt(source_location, message, arg, error_type); | 627 ReportMessageAt(source_location, message, arg, error_type); |
631 } | 628 } |
632 | 629 |
633 | 630 |
634 void ParserTraits::ReportMessageAt(Scanner::Location source_location, | 631 void ParserTraits::ReportMessageAt(Scanner::Location source_location, |
635 const char* message, const AstRawString* arg, | 632 const char* message, const AstRawString* arg, |
636 ParseErrorType error_type) { | 633 ParseErrorType error_type) { |
637 if (parser_->stack_overflow()) { | 634 if (parser_->stack_overflow()) { |
638 // Suppress the error message (syntax error or such) in the presence of a | 635 // Suppress the error message (syntax error or such) in the presence of a |
639 // stack overflow. The isolate allows only one pending exception at at time | 636 // stack overflow. The isolate allows only one pending exception at at time |
640 // and we want to report the stack overflow later. | 637 // and we want to report the stack overflow later. |
641 return; | 638 return; |
642 } | 639 } |
643 parser_->has_pending_error_ = true; | 640 parser_->pending_error_handler_.ReportMessageAt(source_location.beg_pos, |
644 parser_->pending_error_location_ = source_location; | 641 source_location.end_pos, |
645 parser_->pending_error_message_ = message; | 642 message, arg, error_type); |
646 parser_->pending_error_char_arg_ = NULL; | |
647 parser_->pending_error_arg_ = arg; | |
648 parser_->pending_error_type_ = error_type; | |
649 } | 643 } |
650 | 644 |
651 | 645 |
652 const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) { | 646 const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) { |
653 const AstRawString* result = | 647 const AstRawString* result = |
654 parser_->scanner()->CurrentSymbol(parser_->ast_value_factory()); | 648 parser_->scanner()->CurrentSymbol(parser_->ast_value_factory()); |
655 DCHECK(result != NULL); | 649 DCHECK(result != NULL); |
656 return result; | 650 return result; |
657 } | 651 } |
658 | 652 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 : ParserBase<ParserTraits>(info->zone(), &scanner_, stack_limit, | 776 : ParserBase<ParserTraits>(info->zone(), &scanner_, stack_limit, |
783 info->extension(), info->ast_value_factory(), | 777 info->extension(), info->ast_value_factory(), |
784 NULL, this), | 778 NULL, this), |
785 scanner_(unicode_cache), | 779 scanner_(unicode_cache), |
786 reusable_preparser_(NULL), | 780 reusable_preparser_(NULL), |
787 original_scope_(NULL), | 781 original_scope_(NULL), |
788 target_stack_(NULL), | 782 target_stack_(NULL), |
789 compile_options_(info->compile_options()), | 783 compile_options_(info->compile_options()), |
790 cached_parse_data_(NULL), | 784 cached_parse_data_(NULL), |
791 parsing_lazy_arrow_parameters_(false), | 785 parsing_lazy_arrow_parameters_(false), |
792 has_pending_error_(false), | |
793 pending_error_message_(NULL), | |
794 pending_error_arg_(NULL), | |
795 pending_error_char_arg_(NULL), | |
796 pending_error_type_(kSyntaxError), | |
797 total_preparse_skipped_(0), | 786 total_preparse_skipped_(0), |
798 pre_parse_timer_(NULL), | 787 pre_parse_timer_(NULL), |
799 parsing_on_main_thread_(true) { | 788 parsing_on_main_thread_(true) { |
800 // Even though we were passed CompilationInfo, we should not store it in | 789 // Even though we were passed CompilationInfo, we should not store it in |
801 // Parser - this makes sure that Isolate is not accidentally accessed via | 790 // Parser - this makes sure that Isolate is not accidentally accessed via |
802 // CompilationInfo during background parsing. | 791 // CompilationInfo during background parsing. |
803 DCHECK(!info->script().is_null() || info->source_stream() != NULL); | 792 DCHECK(!info->script().is_null() || info->source_stream() != NULL); |
804 set_allow_lazy(false); // Must be explicitly enabled. | 793 set_allow_lazy(false); // Must be explicitly enabled. |
805 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); | 794 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
806 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 795 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
(...skipping 3469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4276 script->set_source_url(*source_url); | 4265 script->set_source_url(*source_url); |
4277 } | 4266 } |
4278 if (scanner_.source_mapping_url()->length() > 0) { | 4267 if (scanner_.source_mapping_url()->length() > 0) { |
4279 Handle<String> source_mapping_url = | 4268 Handle<String> source_mapping_url = |
4280 scanner_.source_mapping_url()->Internalize(isolate); | 4269 scanner_.source_mapping_url()->Internalize(isolate); |
4281 script->set_source_mapping_url(*source_mapping_url); | 4270 script->set_source_mapping_url(*source_mapping_url); |
4282 } | 4271 } |
4283 } | 4272 } |
4284 | 4273 |
4285 | 4274 |
4286 void Parser::ThrowPendingError(Isolate* isolate, Handle<Script> script) { | |
4287 DCHECK(ast_value_factory()->IsInternalized()); | |
4288 if (has_pending_error_) { | |
4289 MessageLocation location(script, pending_error_location_.beg_pos, | |
4290 pending_error_location_.end_pos); | |
4291 Factory* factory = isolate->factory(); | |
4292 bool has_arg = | |
4293 pending_error_arg_ != NULL || pending_error_char_arg_ != NULL; | |
4294 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0); | |
4295 if (pending_error_arg_ != NULL) { | |
4296 Handle<String> arg_string = pending_error_arg_->string(); | |
4297 elements->set(0, *arg_string); | |
4298 } else if (pending_error_char_arg_ != NULL) { | |
4299 Handle<String> arg_string = | |
4300 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_)) | |
4301 .ToHandleChecked(); | |
4302 elements->set(0, *arg_string); | |
4303 } | |
4304 isolate->debug()->OnCompileError(script); | |
4305 | |
4306 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); | |
4307 Handle<Object> error; | |
4308 switch (pending_error_type_) { | |
4309 case kReferenceError: | |
4310 error = factory->NewReferenceError(pending_error_message_, array); | |
4311 break; | |
4312 case kSyntaxError: | |
4313 error = factory->NewSyntaxError(pending_error_message_, array); | |
4314 break; | |
4315 } | |
4316 | |
4317 Handle<JSObject> jserror = Handle<JSObject>::cast(error); | |
4318 | |
4319 Handle<Name> key_start_pos = factory->error_start_pos_symbol(); | |
4320 JSObject::SetProperty(jserror, key_start_pos, | |
4321 handle(Smi::FromInt(location.start_pos()), isolate), | |
4322 SLOPPY).Check(); | |
4323 | |
4324 Handle<Name> key_end_pos = factory->error_end_pos_symbol(); | |
4325 JSObject::SetProperty(jserror, key_end_pos, | |
4326 handle(Smi::FromInt(location.end_pos()), isolate), | |
4327 SLOPPY).Check(); | |
4328 | |
4329 Handle<Name> key_script = factory->error_script_symbol(); | |
4330 JSObject::SetProperty(jserror, key_script, script, SLOPPY).Check(); | |
4331 | |
4332 isolate->Throw(*error, &location); | |
4333 } | |
4334 } | |
4335 | |
4336 | |
4337 void Parser::Internalize(Isolate* isolate, Handle<Script> script, bool error) { | 4275 void Parser::Internalize(Isolate* isolate, Handle<Script> script, bool error) { |
4338 // Internalize strings. | 4276 // Internalize strings. |
4339 ast_value_factory()->Internalize(isolate); | 4277 ast_value_factory()->Internalize(isolate); |
4340 | 4278 |
4341 // Error processing. | 4279 // Error processing. |
4342 if (error) { | 4280 if (error) { |
4343 if (stack_overflow()) { | 4281 if (stack_overflow()) { |
4344 isolate->StackOverflow(); | 4282 isolate->StackOverflow(); |
4345 } else { | 4283 } else { |
4346 ThrowPendingError(isolate, script); | 4284 DCHECK(pending_error_handler_.has_pending_error()); |
| 4285 pending_error_handler_.ThrowPendingError(isolate, script); |
4347 } | 4286 } |
4348 } | 4287 } |
4349 | 4288 |
4350 // Move statistics to Isolate. | 4289 // Move statistics to Isolate. |
4351 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 4290 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
4352 ++feature) { | 4291 ++feature) { |
4353 for (int i = 0; i < use_counts_[feature]; ++i) { | 4292 for (int i = 0; i < use_counts_[feature]; ++i) { |
4354 isolate->CountUsage(v8::Isolate::UseCounterFeature(feature)); | 4293 isolate->CountUsage(v8::Isolate::UseCounterFeature(feature)); |
4355 } | 4294 } |
4356 } | 4295 } |
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5475 } else { | 5414 } else { |
5476 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5415 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
5477 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5416 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
5478 raw_string->length()); | 5417 raw_string->length()); |
5479 } | 5418 } |
5480 } | 5419 } |
5481 | 5420 |
5482 return running_hash; | 5421 return running_hash; |
5483 } | 5422 } |
5484 } } // namespace v8::internal | 5423 } } // namespace v8::internal |
OLD | NEW |