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/compiler.h" | 7 #include "src/compiler.h" |
8 | 8 |
9 #include "src/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
10 #include "src/ast-this-access-visitor.h" | 10 #include "src/ast-this-access-visitor.h" |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 if (!info->shared_info().is_null()) { | 755 if (!info->shared_info().is_null()) { |
756 FunctionLiteral* lit = info->function(); | 756 FunctionLiteral* lit = info->function(); |
757 info->shared_info()->set_ast_node_count(lit->ast_node_count()); | 757 info->shared_info()->set_ast_node_count(lit->ast_node_count()); |
758 MaybeDisableOptimization(info->shared_info(), lit->dont_optimize_reason()); | 758 MaybeDisableOptimization(info->shared_info(), lit->dont_optimize_reason()); |
759 info->shared_info()->set_dont_cache(lit->flags()->Contains(kDontCache)); | 759 info->shared_info()->set_dont_cache(lit->flags()->Contains(kDontCache)); |
760 } | 760 } |
761 return true; | 761 return true; |
762 } | 762 } |
763 | 763 |
764 | 764 |
765 static void ThrowSuperConstructorCheckError(CompilationInfo* info) { | 765 static void ThrowSuperConstructorCheckError(CompilationInfo* info, |
| 766 Statement* stmt) { |
766 MaybeHandle<Object> obj = info->isolate()->factory()->NewTypeError( | 767 MaybeHandle<Object> obj = info->isolate()->factory()->NewTypeError( |
767 "super_constructor_call", HandleVector<Object>(nullptr, 0)); | 768 "super_constructor_call", HandleVector<Object>(nullptr, 0)); |
768 Handle<Object> exception; | 769 Handle<Object> exception; |
769 if (!obj.ToHandle(&exception)) return; | 770 if (!obj.ToHandle(&exception)) return; |
770 | 771 |
771 FunctionLiteral* lit = info->function(); | 772 MessageLocation location(info->script(), stmt->position(), stmt->position()); |
772 MessageLocation location(info->script(), lit->start_position(), | |
773 lit->end_position()); | |
774 USE(info->isolate()->Throw(*exception, &location)); | 773 USE(info->isolate()->Throw(*exception, &location)); |
775 } | 774 } |
776 | 775 |
777 | 776 |
778 static bool CheckSuperConstructorCall(CompilationInfo* info) { | 777 static bool CheckSuperConstructorCall(CompilationInfo* info) { |
779 FunctionLiteral* function = info->function(); | 778 FunctionLiteral* function = info->function(); |
780 if (!function->uses_super_constructor_call()) return true; | 779 if (!function->uses_super_constructor_call()) return true; |
781 | 780 |
782 if (function->is_default_constructor()) return true; | 781 if (function->is_default_constructor()) return true; |
783 | 782 |
(...skipping 10 matching lines...) Expand all Loading... |
794 super_call_index++; | 793 super_call_index++; |
795 continue; | 794 continue; |
796 } | 795 } |
797 if (stmt->IsEmptyStatement()) { | 796 if (stmt->IsEmptyStatement()) { |
798 super_call_index++; | 797 super_call_index++; |
799 continue; | 798 continue; |
800 } | 799 } |
801 break; | 800 break; |
802 } | 801 } |
803 | 802 |
804 ExpressionStatement* exprStm = | 803 Statement* stmt = body->at(super_call_index); |
805 body->at(super_call_index)->AsExpressionStatement(); | 804 ExpressionStatement* exprStm = stmt->AsExpressionStatement(); |
806 if (exprStm == nullptr) { | 805 if (exprStm == nullptr) { |
807 ThrowSuperConstructorCheckError(info); | 806 ThrowSuperConstructorCheckError(info, stmt); |
808 return false; | 807 return false; |
809 } | 808 } |
810 Call* callExpr = exprStm->expression()->AsCall(); | 809 Call* callExpr = exprStm->expression()->AsCall(); |
811 if (callExpr == nullptr) { | 810 if (callExpr == nullptr) { |
812 ThrowSuperConstructorCheckError(info); | 811 ThrowSuperConstructorCheckError(info, stmt); |
813 return false; | 812 return false; |
814 } | 813 } |
815 | 814 |
816 if (!callExpr->expression()->IsSuperReference()) { | 815 if (!callExpr->expression()->IsSuperReference()) { |
817 ThrowSuperConstructorCheckError(info); | 816 ThrowSuperConstructorCheckError(info, stmt); |
818 return false; | 817 return false; |
819 } | 818 } |
820 | 819 |
821 ZoneList<Expression*>* arguments = callExpr->arguments(); | 820 ZoneList<Expression*>* arguments = callExpr->arguments(); |
822 | 821 |
823 AstThisAccessVisitor this_access_visitor(info->zone()); | 822 AstThisAccessVisitor this_access_visitor(info->zone()); |
824 this_access_visitor.VisitExpressions(arguments); | 823 this_access_visitor.VisitExpressions(arguments); |
825 | 824 |
826 if (this_access_visitor.HasStackOverflow()) return false; | 825 if (this_access_visitor.HasStackOverflow()) return false; |
827 if (this_access_visitor.UsesThis()) { | 826 if (this_access_visitor.UsesThis()) { |
828 ThrowSuperConstructorCheckError(info); | 827 ThrowSuperConstructorCheckError(info, stmt); |
829 return false; | 828 return false; |
830 } | 829 } |
831 | 830 |
832 return true; | 831 return true; |
833 } | 832 } |
834 | 833 |
835 | 834 |
836 bool Compiler::Analyze(CompilationInfo* info) { | 835 bool Compiler::Analyze(CompilationInfo* info) { |
837 DCHECK(info->function() != NULL); | 836 DCHECK(info->function() != NULL); |
838 if (!Rewriter::Rewrite(info)) return false; | 837 if (!Rewriter::Rewrite(info)) return false; |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1575 AllowHandleDereference allow_deref; | 1574 AllowHandleDereference allow_deref; |
1576 bool tracing_on = info()->IsStub() | 1575 bool tracing_on = info()->IsStub() |
1577 ? FLAG_trace_hydrogen_stubs | 1576 ? FLAG_trace_hydrogen_stubs |
1578 : (FLAG_trace_hydrogen && | 1577 : (FLAG_trace_hydrogen && |
1579 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1578 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
1580 return (tracing_on && | 1579 return (tracing_on && |
1581 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1580 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
1582 } | 1581 } |
1583 | 1582 |
1584 } } // namespace v8::internal | 1583 } } // namespace v8::internal |
OLD | NEW |