Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: src/parser.cc

Issue 289373005: Parser: delay throwing errors. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 void ParserTraits::ReportMessageAt(Scanner::Location source_location, 623 void ParserTraits::ReportMessageAt(Scanner::Location source_location,
624 const char* message, 624 const char* message,
625 const char* arg, 625 const char* arg,
626 bool is_reference_error) { 626 bool is_reference_error) {
627 if (parser_->stack_overflow()) { 627 if (parser_->stack_overflow()) {
628 // Suppress the error message (syntax error or such) in the presence of a 628 // Suppress the error message (syntax error or such) in the presence of a
629 // stack overflow. The isolate allows only one pending exception at at time 629 // stack overflow. The isolate allows only one pending exception at at time
630 // and we want to report the stack overflow later. 630 // and we want to report the stack overflow later.
631 return; 631 return;
632 } 632 }
633 MessageLocation location(parser_->script_, 633 parser_->has_pending_error_ = true;
634 source_location.beg_pos, 634 parser_->pending_error_location_ = source_location;
635 source_location.end_pos); 635 parser_->pending_error_message_ = message;
636 Factory* factory = parser_->isolate()->factory(); 636 parser_->pending_error_char_arg_ = arg;
637 Handle<FixedArray> elements = factory->NewFixedArray(arg == NULL ? 0 : 1); 637 parser_->pending_error_arg_ = Handle<String>();
638 if (arg != NULL) { 638 parser_->pending_error_is_reference_error_ = is_reference_error;
639 Handle<String> arg_string =
640 factory->NewStringFromUtf8(CStrVector(arg)).ToHandleChecked();
641 elements->set(0, *arg_string);
642 }
643 Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
644 Handle<Object> result = is_reference_error
645 ? factory->NewReferenceError(message, array)
646 : factory->NewSyntaxError(message, array);
647 parser_->isolate()->Throw(*result, &location);
648 } 639 }
649 640
650 641
651 void ParserTraits::ReportMessage(const char* message, 642 void ParserTraits::ReportMessage(const char* message,
652 MaybeHandle<String> arg, 643 MaybeHandle<String> arg,
653 bool is_reference_error) { 644 bool is_reference_error) {
654 Scanner::Location source_location = parser_->scanner()->location(); 645 Scanner::Location source_location = parser_->scanner()->location();
655 ReportMessageAt(source_location, message, arg, is_reference_error); 646 ReportMessageAt(source_location, message, arg, is_reference_error);
656 } 647 }
657 648
658 649
659 void ParserTraits::ReportMessageAt(Scanner::Location source_location, 650 void ParserTraits::ReportMessageAt(Scanner::Location source_location,
660 const char* message, 651 const char* message,
661 MaybeHandle<String> arg, 652 MaybeHandle<String> arg,
662 bool is_reference_error) { 653 bool is_reference_error) {
663 if (parser_->stack_overflow()) { 654 if (parser_->stack_overflow()) {
664 // Suppress the error message (syntax error or such) in the presence of a 655 // Suppress the error message (syntax error or such) in the presence of a
665 // stack overflow. The isolate allows only one pending exception at at time 656 // stack overflow. The isolate allows only one pending exception at at time
666 // and we want to report the stack overflow later. 657 // and we want to report the stack overflow later.
667 return; 658 return;
668 } 659 }
669 MessageLocation location(parser_->script_, 660 parser_->has_pending_error_ = true;
670 source_location.beg_pos, 661 parser_->pending_error_location_ = source_location;
671 source_location.end_pos); 662 parser_->pending_error_message_ = message;
672 Factory* factory = parser_->isolate()->factory(); 663 parser_->pending_error_char_arg_ = NULL;
673 Handle<FixedArray> elements = factory->NewFixedArray(arg.is_null() ? 0 : 1); 664 parser_->pending_error_arg_ = arg;
674 if (!arg.is_null()) { 665 parser_->pending_error_is_reference_error_ = is_reference_error;
675 elements->set(0, *(arg.ToHandleChecked()));
676 }
677 Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
678 Handle<Object> result = is_reference_error
679 ? factory->NewReferenceError(message, array)
680 : factory->NewSyntaxError(message, array);
681 parser_->isolate()->Throw(*result, &location);
682 } 666 }
683 667
684 668
685 Handle<String> ParserTraits::GetSymbol(Scanner* scanner) { 669 Handle<String> ParserTraits::GetSymbol(Scanner* scanner) {
686 Handle<String> result = 670 Handle<String> result =
687 parser_->scanner()->AllocateInternalizedString(parser_->isolate()); 671 parser_->scanner()->AllocateInternalizedString(parser_->isolate());
688 ASSERT(!result.is_null()); 672 ASSERT(!result.is_null());
689 return result; 673 return result;
690 } 674 }
691 675
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 info->zone(), 767 info->zone(),
784 this), 768 this),
785 isolate_(info->isolate()), 769 isolate_(info->isolate()),
786 script_(info->script()), 770 script_(info->script()),
787 scanner_(isolate_->unicode_cache()), 771 scanner_(isolate_->unicode_cache()),
788 reusable_preparser_(NULL), 772 reusable_preparser_(NULL),
789 original_scope_(NULL), 773 original_scope_(NULL),
790 target_stack_(NULL), 774 target_stack_(NULL),
791 cached_data_(NULL), 775 cached_data_(NULL),
792 cached_data_mode_(NO_CACHED_DATA), 776 cached_data_mode_(NO_CACHED_DATA),
793 info_(info) { 777 info_(info),
778 has_pending_error_(false),
779 pending_error_message_(NULL),
780 pending_error_char_arg_(NULL) {
794 ASSERT(!script_.is_null()); 781 ASSERT(!script_.is_null());
795 isolate_->set_ast_node_id(0); 782 isolate_->set_ast_node_id(0);
796 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); 783 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
797 set_allow_modules(!info->is_native() && FLAG_harmony_modules); 784 set_allow_modules(!info->is_native() && FLAG_harmony_modules);
798 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); 785 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
799 set_allow_lazy(false); // Must be explicitly enabled. 786 set_allow_lazy(false); // Must be explicitly enabled.
800 set_allow_generators(FLAG_harmony_generators); 787 set_allow_generators(FLAG_harmony_generators);
801 set_allow_for_of(FLAG_harmony_iteration); 788 set_allow_for_of(FLAG_harmony_iteration);
802 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); 789 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
803 } 790 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 FunctionLiteral::ANONYMOUS_EXPRESSION, 922 FunctionLiteral::ANONYMOUS_EXPRESSION,
936 FunctionLiteral::kGlobalOrEval, 923 FunctionLiteral::kGlobalOrEval,
937 FunctionLiteral::kNotParenthesized, 924 FunctionLiteral::kNotParenthesized,
938 FunctionLiteral::kNotGenerator, 925 FunctionLiteral::kNotGenerator,
939 0); 926 0);
940 result->set_ast_properties(factory()->visitor()->ast_properties()); 927 result->set_ast_properties(factory()->visitor()->ast_properties());
941 result->set_dont_optimize_reason( 928 result->set_dont_optimize_reason(
942 factory()->visitor()->dont_optimize_reason()); 929 factory()->visitor()->dont_optimize_reason());
943 } else if (stack_overflow()) { 930 } else if (stack_overflow()) {
944 isolate()->StackOverflow(); 931 isolate()->StackOverflow();
932 } else {
933 ThrowPendingError();
945 } 934 }
946 } 935 }
947 936
948 // Make sure the target stack is empty. 937 // Make sure the target stack is empty.
949 ASSERT(target_stack_ == NULL); 938 ASSERT(target_stack_ == NULL);
950 939
951 return result; 940 return result;
952 } 941 }
953 942
954 943
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 function_type, 1018 function_type,
1030 &ok); 1019 &ok);
1031 // Make sure the results agree. 1020 // Make sure the results agree.
1032 ASSERT(ok == (result != NULL)); 1021 ASSERT(ok == (result != NULL));
1033 } 1022 }
1034 1023
1035 // Make sure the target stack is empty. 1024 // Make sure the target stack is empty.
1036 ASSERT(target_stack_ == NULL); 1025 ASSERT(target_stack_ == NULL);
1037 1026
1038 if (result == NULL) { 1027 if (result == NULL) {
1039 if (stack_overflow()) isolate()->StackOverflow(); 1028 if (stack_overflow()) {
1029 isolate()->StackOverflow();
1030 } else {
1031 ThrowPendingError();
1032 }
1040 } else { 1033 } else {
1041 Handle<String> inferred_name(shared_info->inferred_name()); 1034 Handle<String> inferred_name(shared_info->inferred_name());
1042 result->set_inferred_name(inferred_name); 1035 result->set_inferred_name(inferred_name);
1043 } 1036 }
1044 return result; 1037 return result;
1045 } 1038 }
1046 1039
1047 1040
1048 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, 1041 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
1049 int end_token, 1042 int end_token,
(...skipping 2622 matching lines...) Expand 10 before | Expand all | Expand 10 after
3672 // Register that a break target found at the given stop in the 3665 // Register that a break target found at the given stop in the
3673 // target stack has been used from the top of the target stack. Add 3666 // target stack has been used from the top of the target stack. Add
3674 // the break target to any TargetCollectors passed on the stack. 3667 // the break target to any TargetCollectors passed on the stack.
3675 for (Target* t = target_stack_; t != stop; t = t->previous()) { 3668 for (Target* t = target_stack_; t != stop; t = t->previous()) {
3676 TargetCollector* collector = t->node()->AsTargetCollector(); 3669 TargetCollector* collector = t->node()->AsTargetCollector();
3677 if (collector != NULL) collector->AddTarget(target, zone()); 3670 if (collector != NULL) collector->AddTarget(target, zone());
3678 } 3671 }
3679 } 3672 }
3680 3673
3681 3674
3675 void Parser::ThrowPendingError() {
3676 if (has_pending_error_) {
3677 MessageLocation location(script_,
3678 pending_error_location_.beg_pos,
3679 pending_error_location_.end_pos);
3680 Factory* factory = isolate()->factory();
3681 bool has_arg =
3682 !pending_error_arg_.is_null() || pending_error_char_arg_ != NULL;
3683 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0);
3684 if (!pending_error_arg_.is_null()) {
3685 elements->set(0, *(pending_error_arg_.ToHandleChecked()));
3686 } else if (pending_error_char_arg_ != NULL) {
3687 Handle<String> arg_string =
3688 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_))
3689 .ToHandleChecked();
3690 elements->set(0, *arg_string);
3691 }
3692 Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
3693 Handle<Object> result = pending_error_is_reference_error_
3694 ? factory->NewReferenceError(pending_error_message_, array)
3695 : factory->NewSyntaxError(pending_error_message_, array);
3696 isolate()->Throw(*result, &location);
3697 }
3698 }
3699
3700
3682 // ---------------------------------------------------------------------------- 3701 // ----------------------------------------------------------------------------
3683 // Regular expressions 3702 // Regular expressions
3684 3703
3685 3704
3686 RegExpParser::RegExpParser(FlatStringReader* in, 3705 RegExpParser::RegExpParser(FlatStringReader* in,
3687 Handle<String>* error, 3706 Handle<String>* error,
3688 bool multiline, 3707 bool multiline,
3689 Zone* zone) 3708 Zone* zone)
3690 : isolate_(zone->isolate()), 3709 : isolate_(zone->isolate()),
3691 zone_(zone), 3710 zone_(zone),
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
4599 ASSERT(info()->isolate()->has_pending_exception()); 4618 ASSERT(info()->isolate()->has_pending_exception());
4600 } else { 4619 } else {
4601 result = ParseProgram(); 4620 result = ParseProgram();
4602 } 4621 }
4603 } 4622 }
4604 info()->SetFunction(result); 4623 info()->SetFunction(result);
4605 return (result != NULL); 4624 return (result != NULL);
4606 } 4625 }
4607 4626
4608 } } // namespace v8::internal 4627 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698