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

Side by Side Diff: src/compiler.cc

Issue 766663003: harmony-classes: Implement 'super(...)' call syntactic restriction. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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
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 "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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 function_info->set_allows_lazy_compilation_without_context( 612 function_info->set_allows_lazy_compilation_without_context(
611 lit->AllowsLazyCompilationWithoutContext()); 613 lit->AllowsLazyCompilationWithoutContext());
612 function_info->set_strict_mode(lit->strict_mode()); 614 function_info->set_strict_mode(lit->strict_mode());
613 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); 615 function_info->set_uses_arguments(lit->scope()->arguments() != NULL);
614 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); 616 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters());
615 function_info->set_ast_node_count(lit->ast_node_count()); 617 function_info->set_ast_node_count(lit->ast_node_count());
616 function_info->set_is_function(lit->is_function()); 618 function_info->set_is_function(lit->is_function());
617 MaybeDisableOptimization(function_info, lit->dont_optimize_reason()); 619 MaybeDisableOptimization(function_info, lit->dont_optimize_reason());
618 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); 620 function_info->set_dont_cache(lit->flags()->Contains(kDontCache));
619 function_info->set_kind(lit->kind()); 621 function_info->set_kind(lit->kind());
620 function_info->set_uses_super(lit->uses_super()); 622 function_info->set_uses_super_property(lit->uses_super_property());
623 function_info->set_uses_super_constructor_call(
624 lit->uses_super_constructor_call());
621 function_info->set_asm_function(lit->scope()->asm_function()); 625 function_info->set_asm_function(lit->scope()->asm_function());
622 } 626 }
623 627
624 628
625 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, 629 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
626 CompilationInfo* info, 630 CompilationInfo* info,
627 Handle<SharedFunctionInfo> shared) { 631 Handle<SharedFunctionInfo> shared) {
628 // SharedFunctionInfo is passed separately, because if CompilationInfo 632 // SharedFunctionInfo is passed separately, because if CompilationInfo
629 // was created using Script object, it will not have it. 633 // was created using Script object, it will not have it.
630 634
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 if (!info->shared_info().is_null()) { 757 if (!info->shared_info().is_null()) {
754 FunctionLiteral* lit = info->function(); 758 FunctionLiteral* lit = info->function();
755 info->shared_info()->set_ast_node_count(lit->ast_node_count()); 759 info->shared_info()->set_ast_node_count(lit->ast_node_count());
756 MaybeDisableOptimization(info->shared_info(), lit->dont_optimize_reason()); 760 MaybeDisableOptimization(info->shared_info(), lit->dont_optimize_reason());
757 info->shared_info()->set_dont_cache(lit->flags()->Contains(kDontCache)); 761 info->shared_info()->set_dont_cache(lit->flags()->Contains(kDontCache));
758 } 762 }
759 return true; 763 return true;
760 } 764 }
761 765
762 766
767 static void ThrowSuperConstructorCheckError(CompilationInfo* info) {
768 MaybeHandle<Object> obj = info->isolate()->factory()->NewTypeError(
769 "super_constructor_call", HandleVector<Object>(nullptr, 0));
770 Handle<Object> exception;
771 if (!obj.ToHandle(&exception)) return;
772
773 FunctionLiteral* lit = info->function();
774 MessageLocation location(info->script(), lit->start_position(),
775 lit->end_position());
776 USE(info->isolate()->Throw(*exception, &location));
777 }
778
779
780 static bool CheckSuperConstructorCall(CompilationInfo* info) {
781 FunctionLiteral* function = info->function();
782 if (!function->uses_super_constructor_call()) return true;
783
784 if (function->is_default_constructor()) return true;
785
786 ZoneList<Statement*>* body = function->body();
787 CHECK(body->length() > 0);
788
789 int super_call_index = 0;
790 // Allow 'use strict' and similiar and empty statements.
791 while (true) {
792 Statement* stmt = body->at(super_call_index);
rossberg 2014/11/27 19:04:40 Perhaps add CHECK(super_call_index < body->length
Dmitry Lomov (no reviews) 2014/11/27 19:41:56 Done.
793 if (stmt->IsExpressionStatement() &&
794 stmt->AsExpressionStatement()->expression()->IsLiteral()) {
795 super_call_index++;
796 continue;
797 }
798 if (stmt->IsEmptyStatement()) {
799 super_call_index++;
800 continue;
801 }
802 break;
803 }
804
805 ExpressionStatement* exprStm =
806 body->at(super_call_index)->AsExpressionStatement();
807 if (exprStm == nullptr) {
808 ThrowSuperConstructorCheckError(info);
809 return false;
810 }
811 Call* callExpr = exprStm->expression()->AsCall();
812 if (callExpr == nullptr) {
813 ThrowSuperConstructorCheckError(info);
814 return false;
815 }
816
817 if (!callExpr->expression()->IsSuperReference()) {
818 ThrowSuperConstructorCheckError(info);
819 return false;
820 }
821
822 ZoneList<Expression*>* arguments = callExpr->arguments();
823
824 AstThisAccessVisitor this_access_visitor(info->zone());
825 this_access_visitor.VisitExpressions(arguments);
826
827 if (this_access_visitor.HasStackOverflow()) return false;
828 if (this_access_visitor.UsesThis()) {
829 ThrowSuperConstructorCheckError(info);
830 return false;
831 }
832
833 return true;
834 }
835
836
763 bool Compiler::Analyze(CompilationInfo* info) { 837 bool Compiler::Analyze(CompilationInfo* info) {
764 DCHECK(info->function() != NULL); 838 DCHECK(info->function() != NULL);
765 if (!Rewriter::Rewrite(info)) return false; 839 if (!Rewriter::Rewrite(info)) return false;
766 if (!Scope::Analyze(info)) return false; 840 if (!Scope::Analyze(info)) return false;
767 if (!Renumber(info)) return false; 841 if (!Renumber(info)) return false;
768 DCHECK(info->scope() != NULL); 842 DCHECK(info->scope() != NULL);
843 if (!CheckSuperConstructorCall(info)) return false;
769 return true; 844 return true;
770 } 845 }
771 846
772 847
773 bool Compiler::ParseAndAnalyze(CompilationInfo* info) { 848 bool Compiler::ParseAndAnalyze(CompilationInfo* info) {
774 if (!Parser::Parse(info)) return false; 849 if (!Parser::Parse(info)) return false;
775 return Compiler::Analyze(info); 850 return Compiler::Analyze(info);
776 } 851 }
777 852
778 853
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 AllowHandleDereference allow_deref; 1576 AllowHandleDereference allow_deref;
1502 bool tracing_on = info()->IsStub() 1577 bool tracing_on = info()->IsStub()
1503 ? FLAG_trace_hydrogen_stubs 1578 ? FLAG_trace_hydrogen_stubs
1504 : (FLAG_trace_hydrogen && 1579 : (FLAG_trace_hydrogen &&
1505 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); 1580 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter));
1506 return (tracing_on && 1581 return (tracing_on &&
1507 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); 1582 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL);
1508 } 1583 }
1509 1584
1510 } } // namespace v8::internal 1585 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ast-this-access-visitor.cc ('k') | src/messages.js » ('j') | src/messages.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698