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/bootstrapper.h" | 11 #include "src/bootstrapper.h" |
11 #include "src/codegen.h" | 12 #include "src/codegen.h" |
12 #include "src/compilation-cache.h" | 13 #include "src/compilation-cache.h" |
13 #include "src/compiler/pipeline.h" | 14 #include "src/compiler/pipeline.h" |
14 #include "src/cpu-profiler.h" | 15 #include "src/cpu-profiler.h" |
15 #include "src/debug.h" | 16 #include "src/debug.h" |
16 #include "src/deoptimizer.h" | 17 #include "src/deoptimizer.h" |
17 #include "src/full-codegen.h" | 18 #include "src/full-codegen.h" |
18 #include "src/gdb-jit.h" | 19 #include "src/gdb-jit.h" |
19 #include "src/hydrogen.h" | 20 #include "src/hydrogen.h" |
20 #include "src/isolate-inl.h" | 21 #include "src/isolate-inl.h" |
21 #include "src/lithium.h" | 22 #include "src/lithium.h" |
22 #include "src/liveedit.h" | 23 #include "src/liveedit.h" |
24 #include "src/messages.h" | |
23 #include "src/parser.h" | 25 #include "src/parser.h" |
24 #include "src/rewriter.h" | 26 #include "src/rewriter.h" |
25 #include "src/runtime-profiler.h" | 27 #include "src/runtime-profiler.h" |
26 #include "src/scanner-character-streams.h" | 28 #include "src/scanner-character-streams.h" |
27 #include "src/scopeinfo.h" | 29 #include "src/scopeinfo.h" |
28 #include "src/scopes.h" | 30 #include "src/scopes.h" |
29 #include "src/typing.h" | 31 #include "src/typing.h" |
30 #include "src/vm-state-inl.h" | 32 #include "src/vm-state-inl.h" |
31 | 33 |
32 namespace v8 { | 34 namespace v8 { |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
608 function_info->set_allows_lazy_compilation_without_context( | 610 function_info->set_allows_lazy_compilation_without_context( |
609 lit->AllowsLazyCompilationWithoutContext()); | 611 lit->AllowsLazyCompilationWithoutContext()); |
610 function_info->set_strict_mode(lit->strict_mode()); | 612 function_info->set_strict_mode(lit->strict_mode()); |
611 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); | 613 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
612 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); | 614 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
613 function_info->set_ast_node_count(lit->ast_node_count()); | 615 function_info->set_ast_node_count(lit->ast_node_count()); |
614 function_info->set_is_function(lit->is_function()); | 616 function_info->set_is_function(lit->is_function()); |
615 MaybeDisableOptimization(function_info, lit->dont_optimize_reason()); | 617 MaybeDisableOptimization(function_info, lit->dont_optimize_reason()); |
616 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); | 618 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); |
617 function_info->set_kind(lit->kind()); | 619 function_info->set_kind(lit->kind()); |
618 function_info->set_uses_super(lit->uses_super()); | 620 function_info->set_uses_super_property(lit->uses_super_property()); |
621 function_info->set_uses_super_constructor_call( | |
622 lit->uses_super_constructor_call()); | |
619 function_info->set_asm_function(lit->scope()->asm_function()); | 623 function_info->set_asm_function(lit->scope()->asm_function()); |
620 } | 624 } |
621 | 625 |
622 | 626 |
623 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 627 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
624 CompilationInfo* info, | 628 CompilationInfo* info, |
625 Handle<SharedFunctionInfo> shared) { | 629 Handle<SharedFunctionInfo> shared) { |
626 // SharedFunctionInfo is passed separately, because if CompilationInfo | 630 // SharedFunctionInfo is passed separately, because if CompilationInfo |
627 // was created using Script object, it will not have it. | 631 // was created using Script object, it will not have it. |
628 | 632 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
751 if (!info->shared_info().is_null()) { | 755 if (!info->shared_info().is_null()) { |
752 FunctionLiteral* lit = info->function(); | 756 FunctionLiteral* lit = info->function(); |
753 info->shared_info()->set_ast_node_count(lit->ast_node_count()); | 757 info->shared_info()->set_ast_node_count(lit->ast_node_count()); |
754 MaybeDisableOptimization(info->shared_info(), lit->dont_optimize_reason()); | 758 MaybeDisableOptimization(info->shared_info(), lit->dont_optimize_reason()); |
755 info->shared_info()->set_dont_cache(lit->flags()->Contains(kDontCache)); | 759 info->shared_info()->set_dont_cache(lit->flags()->Contains(kDontCache)); |
756 } | 760 } |
757 return true; | 761 return true; |
758 } | 762 } |
759 | 763 |
760 | 764 |
765 static void ThrowSuperConstructorCheckError(CompilationInfo* info) { | |
766 MaybeHandle<Object> obj = info->isolate()->factory()->NewTypeError( | |
767 "super_constructor_call", HandleVector<Object>(nullptr, 0)); | |
768 Handle<Object> exception; | |
769 if (!obj.ToHandle(&exception)) return; | |
770 | |
771 FunctionLiteral* lit = info->function(); | |
772 MessageLocation location(info->script(), lit->start_position(), | |
arv (Not doing code reviews)
2014/12/01 15:14:07
This position is not all that good.
| |
773 lit->end_position()); | |
774 USE(info->isolate()->Throw(*exception, &location)); | |
775 } | |
776 | |
777 | |
778 static bool CheckSuperConstructorCall(CompilationInfo* info) { | |
779 FunctionLiteral* function = info->function(); | |
780 if (!function->uses_super_constructor_call()) return true; | |
781 | |
782 if (function->is_default_constructor()) return true; | |
783 | |
784 ZoneList<Statement*>* body = function->body(); | |
785 CHECK(body->length() > 0); | |
786 | |
787 int super_call_index = 0; | |
788 // Allow 'use strict' and similiar and empty statements. | |
789 while (true) { | |
790 CHECK(super_call_index < body->length()); // We know there is a super call. | |
791 Statement* stmt = body->at(super_call_index); | |
792 if (stmt->IsExpressionStatement() && | |
793 stmt->AsExpressionStatement()->expression()->IsLiteral()) { | |
794 super_call_index++; | |
795 continue; | |
796 } | |
797 if (stmt->IsEmptyStatement()) { | |
798 super_call_index++; | |
799 continue; | |
800 } | |
801 break; | |
802 } | |
803 | |
804 ExpressionStatement* exprStm = | |
805 body->at(super_call_index)->AsExpressionStatement(); | |
806 if (exprStm == nullptr) { | |
807 ThrowSuperConstructorCheckError(info); | |
808 return false; | |
809 } | |
810 Call* callExpr = exprStm->expression()->AsCall(); | |
811 if (callExpr == nullptr) { | |
812 ThrowSuperConstructorCheckError(info); | |
813 return false; | |
814 } | |
815 | |
816 if (!callExpr->expression()->IsSuperReference()) { | |
817 ThrowSuperConstructorCheckError(info); | |
818 return false; | |
819 } | |
820 | |
821 ZoneList<Expression*>* arguments = callExpr->arguments(); | |
822 | |
823 AstThisAccessVisitor this_access_visitor(info->zone()); | |
824 this_access_visitor.VisitExpressions(arguments); | |
825 | |
826 if (this_access_visitor.HasStackOverflow()) return false; | |
827 if (this_access_visitor.UsesThis()) { | |
828 ThrowSuperConstructorCheckError(info); | |
829 return false; | |
830 } | |
831 | |
832 return true; | |
833 } | |
834 | |
835 | |
761 bool Compiler::Analyze(CompilationInfo* info) { | 836 bool Compiler::Analyze(CompilationInfo* info) { |
762 DCHECK(info->function() != NULL); | 837 DCHECK(info->function() != NULL); |
763 if (!Rewriter::Rewrite(info)) return false; | 838 if (!Rewriter::Rewrite(info)) return false; |
764 if (!Scope::Analyze(info)) return false; | 839 if (!Scope::Analyze(info)) return false; |
765 if (!Renumber(info)) return false; | 840 if (!Renumber(info)) return false; |
766 DCHECK(info->scope() != NULL); | 841 DCHECK(info->scope() != NULL); |
842 if (!CheckSuperConstructorCall(info)) return false; | |
767 return true; | 843 return true; |
768 } | 844 } |
769 | 845 |
770 | 846 |
771 bool Compiler::ParseAndAnalyze(CompilationInfo* info) { | 847 bool Compiler::ParseAndAnalyze(CompilationInfo* info) { |
772 if (!Parser::Parse(info)) return false; | 848 if (!Parser::Parse(info)) return false; |
773 return Compiler::Analyze(info); | 849 return Compiler::Analyze(info); |
774 } | 850 } |
775 | 851 |
776 | 852 |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1499 AllowHandleDereference allow_deref; | 1575 AllowHandleDereference allow_deref; |
1500 bool tracing_on = info()->IsStub() | 1576 bool tracing_on = info()->IsStub() |
1501 ? FLAG_trace_hydrogen_stubs | 1577 ? FLAG_trace_hydrogen_stubs |
1502 : (FLAG_trace_hydrogen && | 1578 : (FLAG_trace_hydrogen && |
1503 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1579 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
1504 return (tracing_on && | 1580 return (tracing_on && |
1505 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1581 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
1506 } | 1582 } |
1507 | 1583 |
1508 } } // namespace v8::internal | 1584 } } // namespace v8::internal |
OLD | NEW |