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" | |
11 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
12 #include "src/codegen.h" | 11 #include "src/codegen.h" |
13 #include "src/compilation-cache.h" | 12 #include "src/compilation-cache.h" |
14 #include "src/compiler/pipeline.h" | 13 #include "src/compiler/pipeline.h" |
15 #include "src/cpu-profiler.h" | 14 #include "src/cpu-profiler.h" |
16 #include "src/debug.h" | 15 #include "src/debug.h" |
17 #include "src/deoptimizer.h" | 16 #include "src/deoptimizer.h" |
18 #include "src/full-codegen.h" | 17 #include "src/full-codegen.h" |
19 #include "src/gdb-jit.h" | 18 #include "src/gdb-jit.h" |
20 #include "src/hydrogen.h" | 19 #include "src/hydrogen.h" |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 if (!info->shared_info().is_null()) { | 741 if (!info->shared_info().is_null()) { |
743 FunctionLiteral* lit = info->function(); | 742 FunctionLiteral* lit = info->function(); |
744 info->shared_info()->set_ast_node_count(lit->ast_node_count()); | 743 info->shared_info()->set_ast_node_count(lit->ast_node_count()); |
745 MaybeDisableOptimization(info->shared_info(), lit->dont_optimize_reason()); | 744 MaybeDisableOptimization(info->shared_info(), lit->dont_optimize_reason()); |
746 info->shared_info()->set_dont_cache(lit->flags()->Contains(kDontCache)); | 745 info->shared_info()->set_dont_cache(lit->flags()->Contains(kDontCache)); |
747 } | 746 } |
748 return true; | 747 return true; |
749 } | 748 } |
750 | 749 |
751 | 750 |
752 static void ThrowSuperConstructorCheckError(CompilationInfo* info, | |
753 Statement* stmt) { | |
754 MaybeHandle<Object> obj = info->isolate()->factory()->NewTypeError( | |
755 "super_constructor_call", HandleVector<Object>(nullptr, 0)); | |
756 Handle<Object> exception; | |
757 if (!obj.ToHandle(&exception)) return; | |
758 | |
759 MessageLocation location(info->script(), stmt->position(), stmt->position()); | |
760 USE(info->isolate()->Throw(*exception, &location)); | |
761 } | |
762 | |
763 | |
764 static bool CheckSuperConstructorCall(CompilationInfo* info) { | |
765 FunctionLiteral* function = info->function(); | |
766 if (FLAG_experimental_classes) return true; | |
767 if (!function->uses_super_constructor_call()) return true; | |
768 if (IsDefaultConstructor(function->kind())) return true; | |
769 | |
770 ZoneList<Statement*>* body = function->body(); | |
771 CHECK(body->length() > 0); | |
772 | |
773 int super_call_index = 0; | |
774 // Allow 'use strict' and similiar and empty statements. | |
775 while (true) { | |
776 CHECK(super_call_index < body->length()); // We know there is a super call. | |
777 Statement* stmt = body->at(super_call_index); | |
778 if (stmt->IsExpressionStatement() && | |
779 stmt->AsExpressionStatement()->expression()->IsLiteral()) { | |
780 super_call_index++; | |
781 continue; | |
782 } | |
783 if (stmt->IsEmptyStatement()) { | |
784 super_call_index++; | |
785 continue; | |
786 } | |
787 break; | |
788 } | |
789 | |
790 Statement* stmt = body->at(super_call_index); | |
791 ExpressionStatement* exprStm = stmt->AsExpressionStatement(); | |
792 if (exprStm == nullptr) { | |
793 ThrowSuperConstructorCheckError(info, stmt); | |
794 return false; | |
795 } | |
796 Call* callExpr = exprStm->expression()->AsCall(); | |
797 if (callExpr == nullptr) { | |
798 ThrowSuperConstructorCheckError(info, stmt); | |
799 return false; | |
800 } | |
801 | |
802 if (!callExpr->expression()->IsSuperReference()) { | |
803 ThrowSuperConstructorCheckError(info, stmt); | |
804 return false; | |
805 } | |
806 | |
807 ZoneList<Expression*>* arguments = callExpr->arguments(); | |
808 | |
809 AstThisAccessVisitor this_access_visitor(info->isolate(), info->zone()); | |
810 this_access_visitor.VisitExpressions(arguments); | |
811 | |
812 if (this_access_visitor.HasStackOverflow()) return false; | |
813 if (this_access_visitor.UsesThis()) { | |
814 ThrowSuperConstructorCheckError(info, stmt); | |
815 return false; | |
816 } | |
817 return true; | |
818 } | |
819 | |
820 | |
821 bool Compiler::Analyze(CompilationInfo* info) { | 751 bool Compiler::Analyze(CompilationInfo* info) { |
822 DCHECK(info->function() != NULL); | 752 DCHECK(info->function() != NULL); |
823 if (!Rewriter::Rewrite(info)) return false; | 753 if (!Rewriter::Rewrite(info)) return false; |
824 if (!Scope::Analyze(info)) return false; | 754 if (!Scope::Analyze(info)) return false; |
825 if (!Renumber(info)) return false; | 755 if (!Renumber(info)) return false; |
826 DCHECK(info->scope() != NULL); | 756 DCHECK(info->scope() != NULL); |
827 if (!CheckSuperConstructorCall(info)) return false; | |
828 return true; | 757 return true; |
829 } | 758 } |
830 | 759 |
831 | 760 |
832 bool Compiler::ParseAndAnalyze(CompilationInfo* info) { | 761 bool Compiler::ParseAndAnalyze(CompilationInfo* info) { |
833 if (!Parser::ParseStatic(info)) return false; | 762 if (!Parser::ParseStatic(info)) return false; |
834 return Compiler::Analyze(info); | 763 return Compiler::Analyze(info); |
835 } | 764 } |
836 | 765 |
837 | 766 |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 } | 1516 } |
1588 | 1517 |
1589 | 1518 |
1590 #if DEBUG | 1519 #if DEBUG |
1591 void CompilationInfo::PrintAstForTesting() { | 1520 void CompilationInfo::PrintAstForTesting() { |
1592 PrintF("--- Source from AST ---\n%s\n", | 1521 PrintF("--- Source from AST ---\n%s\n", |
1593 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1522 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
1594 } | 1523 } |
1595 #endif | 1524 #endif |
1596 } } // namespace v8::internal | 1525 } } // namespace v8::internal |
OLD | NEW |