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 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(2, zone); | 593 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(2, zone); |
594 args->Add(parser_->factory()->NewStringLiteral(type, pos), zone); | 594 args->Add(parser_->factory()->NewStringLiteral(type, pos), zone); |
595 args->Add(parser_->factory()->NewStringLiteral(arg, pos), zone); | 595 args->Add(parser_->factory()->NewStringLiteral(arg, pos), zone); |
596 CallRuntime* call_constructor = | 596 CallRuntime* call_constructor = |
597 parser_->factory()->NewCallRuntime(constructor, NULL, args, pos); | 597 parser_->factory()->NewCallRuntime(constructor, NULL, args, pos); |
598 return parser_->factory()->NewThrow(call_constructor, pos); | 598 return parser_->factory()->NewThrow(call_constructor, pos); |
599 } | 599 } |
600 | 600 |
601 | 601 |
602 void ParserTraits::ReportMessageAt(Scanner::Location source_location, | 602 void ParserTraits::ReportMessageAt(Scanner::Location source_location, |
603 const char* message, | 603 const char* message, const char* arg, |
604 const char* arg, | 604 ParseErrorType error_type) { |
605 bool is_reference_error) { | |
606 if (parser_->stack_overflow()) { | 605 if (parser_->stack_overflow()) { |
607 // 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 |
608 // 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 |
609 // and we want to report the stack overflow later. | 608 // and we want to report the stack overflow later. |
610 return; | 609 return; |
611 } | 610 } |
612 parser_->has_pending_error_ = true; | 611 parser_->has_pending_error_ = true; |
613 parser_->pending_error_location_ = source_location; | 612 parser_->pending_error_location_ = source_location; |
614 parser_->pending_error_message_ = message; | 613 parser_->pending_error_message_ = message; |
615 parser_->pending_error_char_arg_ = arg; | 614 parser_->pending_error_char_arg_ = arg; |
616 parser_->pending_error_arg_ = NULL; | 615 parser_->pending_error_arg_ = NULL; |
617 parser_->pending_error_is_reference_error_ = is_reference_error; | 616 parser_->pending_error_type_ = error_type; |
618 } | 617 } |
619 | 618 |
620 | 619 |
621 void ParserTraits::ReportMessage(const char* message, | 620 void ParserTraits::ReportMessage(const char* message, const char* arg, |
622 const char* arg, | 621 ParseErrorType error_type) { |
623 bool is_reference_error) { | |
624 Scanner::Location source_location = parser_->scanner()->location(); | 622 Scanner::Location source_location = parser_->scanner()->location(); |
625 ReportMessageAt(source_location, message, arg, is_reference_error); | 623 ReportMessageAt(source_location, message, arg, error_type); |
626 } | 624 } |
627 | 625 |
628 | 626 |
629 void ParserTraits::ReportMessage(const char* message, | 627 void ParserTraits::ReportMessage(const char* message, const AstRawString* arg, |
630 const AstRawString* arg, | 628 ParseErrorType error_type) { |
631 bool is_reference_error) { | |
632 Scanner::Location source_location = parser_->scanner()->location(); | 629 Scanner::Location source_location = parser_->scanner()->location(); |
633 ReportMessageAt(source_location, message, arg, is_reference_error); | 630 ReportMessageAt(source_location, message, arg, error_type); |
634 } | 631 } |
635 | 632 |
636 | 633 |
637 void ParserTraits::ReportMessageAt(Scanner::Location source_location, | 634 void ParserTraits::ReportMessageAt(Scanner::Location source_location, |
638 const char* message, | 635 const char* message, const AstRawString* arg, |
639 const AstRawString* arg, | 636 ParseErrorType error_type) { |
640 bool is_reference_error) { | |
641 if (parser_->stack_overflow()) { | 637 if (parser_->stack_overflow()) { |
642 // Suppress the error message (syntax error or such) in the presence of a | 638 // Suppress the error message (syntax error or such) in the presence of a |
643 // stack overflow. The isolate allows only one pending exception at at time | 639 // stack overflow. The isolate allows only one pending exception at at time |
644 // and we want to report the stack overflow later. | 640 // and we want to report the stack overflow later. |
645 return; | 641 return; |
646 } | 642 } |
647 parser_->has_pending_error_ = true; | 643 parser_->has_pending_error_ = true; |
648 parser_->pending_error_location_ = source_location; | 644 parser_->pending_error_location_ = source_location; |
649 parser_->pending_error_message_ = message; | 645 parser_->pending_error_message_ = message; |
650 parser_->pending_error_char_arg_ = NULL; | 646 parser_->pending_error_char_arg_ = NULL; |
651 parser_->pending_error_arg_ = arg; | 647 parser_->pending_error_arg_ = arg; |
652 parser_->pending_error_is_reference_error_ = is_reference_error; | 648 parser_->pending_error_type_ = error_type; |
653 } | 649 } |
654 | 650 |
655 | 651 |
656 const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) { | 652 const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) { |
657 const AstRawString* result = | 653 const AstRawString* result = |
658 parser_->scanner()->CurrentSymbol(parser_->ast_value_factory()); | 654 parser_->scanner()->CurrentSymbol(parser_->ast_value_factory()); |
659 DCHECK(result != NULL); | 655 DCHECK(result != NULL); |
660 return result; | 656 return result; |
661 } | 657 } |
662 | 658 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 reusable_preparser_(NULL), | 786 reusable_preparser_(NULL), |
791 original_scope_(NULL), | 787 original_scope_(NULL), |
792 target_stack_(NULL), | 788 target_stack_(NULL), |
793 compile_options_(info->compile_options()), | 789 compile_options_(info->compile_options()), |
794 cached_parse_data_(NULL), | 790 cached_parse_data_(NULL), |
795 parsing_lazy_arrow_parameters_(false), | 791 parsing_lazy_arrow_parameters_(false), |
796 has_pending_error_(false), | 792 has_pending_error_(false), |
797 pending_error_message_(NULL), | 793 pending_error_message_(NULL), |
798 pending_error_arg_(NULL), | 794 pending_error_arg_(NULL), |
799 pending_error_char_arg_(NULL), | 795 pending_error_char_arg_(NULL), |
| 796 pending_error_type_(kSyntaxError), |
800 total_preparse_skipped_(0), | 797 total_preparse_skipped_(0), |
801 pre_parse_timer_(NULL), | 798 pre_parse_timer_(NULL), |
802 parsing_on_main_thread_(true) { | 799 parsing_on_main_thread_(true) { |
803 // Even though we were passed CompilationInfo, we should not store it in | 800 // Even though we were passed CompilationInfo, we should not store it in |
804 // Parser - this makes sure that Isolate is not accidentally accessed via | 801 // Parser - this makes sure that Isolate is not accidentally accessed via |
805 // CompilationInfo during background parsing. | 802 // CompilationInfo during background parsing. |
806 DCHECK(!info->script().is_null() || info->source_stream() != NULL); | 803 DCHECK(!info->script().is_null() || info->source_stream() != NULL); |
807 set_allow_lazy(false); // Must be explicitly enabled. | 804 set_allow_lazy(false); // Must be explicitly enabled. |
808 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); | 805 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
809 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 806 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
(...skipping 3072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3882 ParseLazyFunctionBodyWithPreParser(&logger); | 3879 ParseLazyFunctionBodyWithPreParser(&logger); |
3883 if (result == PreParser::kPreParseStackOverflow) { | 3880 if (result == PreParser::kPreParseStackOverflow) { |
3884 // Propagate stack overflow. | 3881 // Propagate stack overflow. |
3885 set_stack_overflow(); | 3882 set_stack_overflow(); |
3886 *ok = false; | 3883 *ok = false; |
3887 return; | 3884 return; |
3888 } | 3885 } |
3889 if (logger.has_error()) { | 3886 if (logger.has_error()) { |
3890 ParserTraits::ReportMessageAt( | 3887 ParserTraits::ReportMessageAt( |
3891 Scanner::Location(logger.start(), logger.end()), logger.message(), | 3888 Scanner::Location(logger.start(), logger.end()), logger.message(), |
3892 logger.argument_opt(), logger.is_reference_error()); | 3889 logger.argument_opt(), logger.error_type()); |
3893 *ok = false; | 3890 *ok = false; |
3894 return; | 3891 return; |
3895 } | 3892 } |
3896 scope_->set_end_position(logger.end()); | 3893 scope_->set_end_position(logger.end()); |
3897 Expect(Token::RBRACE, ok); | 3894 Expect(Token::RBRACE, ok); |
3898 if (!*ok) { | 3895 if (!*ok) { |
3899 return; | 3896 return; |
3900 } | 3897 } |
3901 total_preparse_skipped_ += scope_->end_position() - function_block_pos; | 3898 total_preparse_skipped_ += scope_->end_position() - function_block_pos; |
3902 *materialized_literal_count = logger.literals(); | 3899 *materialized_literal_count = logger.literals(); |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4287 } else if (pending_error_char_arg_ != NULL) { | 4284 } else if (pending_error_char_arg_ != NULL) { |
4288 Handle<String> arg_string = | 4285 Handle<String> arg_string = |
4289 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_)) | 4286 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_)) |
4290 .ToHandleChecked(); | 4287 .ToHandleChecked(); |
4291 elements->set(0, *arg_string); | 4288 elements->set(0, *arg_string); |
4292 } | 4289 } |
4293 isolate->debug()->OnCompileError(script); | 4290 isolate->debug()->OnCompileError(script); |
4294 | 4291 |
4295 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); | 4292 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); |
4296 Handle<Object> error; | 4293 Handle<Object> error; |
4297 MaybeHandle<Object> maybe_error = | 4294 MaybeHandle<Object> maybe_error; |
4298 pending_error_is_reference_error_ | 4295 switch (pending_error_type_) { |
4299 ? factory->NewReferenceError(pending_error_message_, array) | 4296 case kReferenceError: |
4300 : factory->NewSyntaxError(pending_error_message_, array); | 4297 maybe_error = factory->NewReferenceError(pending_error_message_, array); |
| 4298 break; |
| 4299 case kSyntaxError: |
| 4300 maybe_error = factory->NewSyntaxError(pending_error_message_, array); |
| 4301 break; |
| 4302 } |
| 4303 DCHECK(!maybe_error.is_null() || isolate->has_pending_exception()); |
4301 | 4304 |
4302 if (maybe_error.ToHandle(&error)) { | 4305 if (maybe_error.ToHandle(&error)) { |
4303 Handle<JSObject> jserror = Handle<JSObject>::cast(error); | 4306 Handle<JSObject> jserror = Handle<JSObject>::cast(error); |
4304 | 4307 |
4305 Handle<Name> key_start_pos = factory->error_start_pos_symbol(); | 4308 Handle<Name> key_start_pos = factory->error_start_pos_symbol(); |
4306 JSObject::SetProperty(jserror, key_start_pos, | 4309 JSObject::SetProperty(jserror, key_start_pos, |
4307 handle(Smi::FromInt(location.start_pos()), isolate), | 4310 handle(Smi::FromInt(location.start_pos()), isolate), |
4308 SLOPPY).Check(); | 4311 SLOPPY).Check(); |
4309 | 4312 |
4310 Handle<Name> key_end_pos = factory->error_end_pos_symbol(); | 4313 Handle<Name> key_end_pos = factory->error_end_pos_symbol(); |
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5462 } else { | 5465 } else { |
5463 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5466 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
5464 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5467 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
5465 raw_string->length()); | 5468 raw_string->length()); |
5466 } | 5469 } |
5467 } | 5470 } |
5468 | 5471 |
5469 return running_hash; | 5472 return running_hash; |
5470 } | 5473 } |
5471 } } // namespace v8::internal | 5474 } } // namespace v8::internal |
OLD | NEW |