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/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 ZoneList<Statement*>* body = NULL; | 352 ZoneList<Statement*>* body = NULL; |
353 | 353 |
354 { | 354 { |
355 AstNodeFactory function_factory(ast_value_factory()); | 355 AstNodeFactory function_factory(ast_value_factory()); |
356 FunctionState function_state(&function_state_, &scope_, function_scope, | 356 FunctionState function_state(&function_state_, &scope_, function_scope, |
357 kind, &function_factory); | 357 kind, &function_factory); |
358 | 358 |
359 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); | 359 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); |
360 AddAssertIsConstruct(body, pos); | 360 AddAssertIsConstruct(body, pos); |
361 if (call_super) { | 361 if (call_super) { |
| 362 // %_DefaultConstructorCallSuper(new.target, .this_function) |
362 ZoneList<Expression*>* args = | 363 ZoneList<Expression*>* args = |
363 new (zone()) ZoneList<Expression*>(0, zone()); | 364 new (zone()) ZoneList<Expression*>(2, zone()); |
| 365 VariableProxy* new_target_proxy = scope_->NewUnresolved( |
| 366 factory(), ast_value_factory()->new_target_string(), Variable::NORMAL, |
| 367 pos); |
| 368 args->Add(new_target_proxy, zone()); |
| 369 VariableProxy* this_function_proxy = scope_->NewUnresolved( |
| 370 factory(), ast_value_factory()->this_function_string(), |
| 371 Variable::NORMAL, pos); |
| 372 args->Add(this_function_proxy, zone()); |
364 CallRuntime* call = factory()->NewCallRuntime( | 373 CallRuntime* call = factory()->NewCallRuntime( |
365 ast_value_factory()->empty_string(), | 374 ast_value_factory()->empty_string(), |
366 Runtime::FunctionForId(Runtime::kInlineDefaultConstructorCallSuper), | 375 Runtime::FunctionForId(Runtime::kInlineDefaultConstructorCallSuper), |
367 args, pos); | 376 args, pos); |
368 body->Add(factory()->NewReturnStatement(call, pos), zone()); | 377 body->Add(factory()->NewReturnStatement(call, pos), zone()); |
369 } | 378 } |
370 | 379 |
371 materialized_literal_count = function_state.materialized_literal_count(); | 380 materialized_literal_count = function_state.materialized_literal_count(); |
372 expected_property_count = function_state.expected_property_count(); | 381 expected_property_count = function_state.expected_property_count(); |
373 handler_count = function_state.handler_count(); | 382 handler_count = function_state.handler_count(); |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 } | 749 } |
741 | 750 |
742 | 751 |
743 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, | 752 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, |
744 int pos) { | 753 int pos) { |
745 return scope->NewUnresolved(factory, | 754 return scope->NewUnresolved(factory, |
746 parser_->ast_value_factory()->this_string(), | 755 parser_->ast_value_factory()->this_string(), |
747 Variable::THIS, pos, pos + 4); | 756 Variable::THIS, pos, pos + 4); |
748 } | 757 } |
749 | 758 |
750 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, | 759 Expression* ParserTraits::SuperPropertyReference(Scope* scope, |
751 int pos) { | 760 AstNodeFactory* factory, |
752 // TODO(arv): Split into SuperProperty and SuperCall? | 761 int pos) { |
753 VariableProxy* home_object_proxy = scope->NewUnresolved( | 762 VariableProxy* home_object_proxy = scope->NewUnresolved( |
754 factory, parser_->ast_value_factory()->home_object_string(), | 763 factory, parser_->ast_value_factory()->home_object_string(), |
755 Variable::NORMAL, pos); | 764 Variable::NORMAL, pos); |
756 | 765 return factory->NewSuperPropertyReference( |
757 return factory->NewSuperReference( | |
758 ThisExpression(scope, factory, pos)->AsVariableProxy(), home_object_proxy, | 766 ThisExpression(scope, factory, pos)->AsVariableProxy(), home_object_proxy, |
759 pos); | 767 pos); |
760 } | 768 } |
761 | 769 |
762 | 770 |
| 771 Expression* ParserTraits::SuperCallReference(Scope* scope, |
| 772 AstNodeFactory* factory, int pos) { |
| 773 VariableProxy* new_target_proxy = scope->NewUnresolved( |
| 774 factory, parser_->ast_value_factory()->new_target_string(), |
| 775 Variable::NORMAL, pos); |
| 776 VariableProxy* this_function_proxy = scope->NewUnresolved( |
| 777 factory, parser_->ast_value_factory()->this_function_string(), |
| 778 Variable::NORMAL, pos); |
| 779 return factory->NewSuperCallReference( |
| 780 ThisExpression(scope, factory, pos)->AsVariableProxy(), new_target_proxy, |
| 781 this_function_proxy, pos); |
| 782 } |
| 783 |
| 784 |
763 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope, | 785 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope, |
764 int pos, int end_pos) { | 786 int pos, int end_pos) { |
765 return parser_->DefaultConstructor(call_super, scope, pos, end_pos); | 787 return parser_->DefaultConstructor(call_super, scope, pos, end_pos); |
766 } | 788 } |
767 | 789 |
768 | 790 |
769 Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, | 791 Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, |
770 Scanner* scanner, | 792 Scanner* scanner, |
771 AstNodeFactory* factory) { | 793 AstNodeFactory* factory) { |
772 switch (token) { | 794 switch (token) { |
(...skipping 4964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5737 zone()); | 5759 zone()); |
5738 return list; | 5760 return list; |
5739 } | 5761 } |
5740 UNREACHABLE(); | 5762 UNREACHABLE(); |
5741 } | 5763 } |
5742 | 5764 |
5743 | 5765 |
5744 Expression* Parser::SpreadCall(Expression* function, | 5766 Expression* Parser::SpreadCall(Expression* function, |
5745 ZoneList<v8::internal::Expression*>* args, | 5767 ZoneList<v8::internal::Expression*>* args, |
5746 int pos) { | 5768 int pos) { |
5747 if (function->IsSuperReference()) { | 5769 if (function->IsSuperCallReference()) { |
5748 // Super calls | 5770 // Super calls |
| 5771 // %_CallSuperWithSpread(%ReflectConstruct(<super>, args, new.target)) |
5749 args->InsertAt(0, function, zone()); | 5772 args->InsertAt(0, function, zone()); |
5750 args->Add(factory()->NewVariableProxy(scope_->new_target_var()), zone()); | 5773 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); |
5751 Expression* result = factory()->NewCallRuntime( | 5774 Expression* result = factory()->NewCallRuntime( |
5752 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5775 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
5753 args = new (zone()) ZoneList<Expression*>(0, zone()); | 5776 args = new (zone()) ZoneList<Expression*>(1, zone()); |
5754 args->Add(result, zone()); | 5777 args->Add(result, zone()); |
5755 return factory()->NewCallRuntime( | 5778 return factory()->NewCallRuntime( |
5756 ast_value_factory()->empty_string(), | 5779 ast_value_factory()->empty_string(), |
5757 Runtime::FunctionForId(Runtime::kInlineCallSuperWithSpread), args, pos); | 5780 Runtime::FunctionForId(Runtime::kInlineCallSuperWithSpread), args, pos); |
5758 } else { | 5781 } else { |
5759 if (function->IsProperty()) { | 5782 if (function->IsProperty()) { |
5760 // Method calls | 5783 // Method calls |
5761 if (function->AsProperty()->IsSuperAccess()) { | 5784 if (function->AsProperty()->IsSuperAccess()) { |
5762 Expression* home = | 5785 Expression* home = |
5763 ThisExpression(scope_, factory(), RelocInfo::kNoPosition); | 5786 ThisExpression(scope_, factory(), RelocInfo::kNoPosition); |
(...skipping 26 matching lines...) Expand all Loading... |
5790 | 5813 |
5791 Expression* Parser::SpreadCallNew(Expression* function, | 5814 Expression* Parser::SpreadCallNew(Expression* function, |
5792 ZoneList<v8::internal::Expression*>* args, | 5815 ZoneList<v8::internal::Expression*>* args, |
5793 int pos) { | 5816 int pos) { |
5794 args->InsertAt(0, function, zone()); | 5817 args->InsertAt(0, function, zone()); |
5795 | 5818 |
5796 return factory()->NewCallRuntime( | 5819 return factory()->NewCallRuntime( |
5797 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5820 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
5798 } | 5821 } |
5799 } } // namespace v8::internal | 5822 } } // namespace v8::internal |
OLD | NEW |