| 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/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
| 10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
| (...skipping 2707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2718 MessageTemplate::kStrongConstructorReturnValue); | 2718 MessageTemplate::kStrongConstructorReturnValue); |
| 2719 *ok = false; | 2719 *ok = false; |
| 2720 return NULL; | 2720 return NULL; |
| 2721 } | 2721 } |
| 2722 | 2722 |
| 2723 int pos = peek_position(); | 2723 int pos = peek_position(); |
| 2724 return_value = ParseExpression(true, CHECK_OK); | 2724 return_value = ParseExpression(true, CHECK_OK); |
| 2725 | 2725 |
| 2726 if (IsSubclassConstructor(function_state_->kind())) { | 2726 if (IsSubclassConstructor(function_state_->kind())) { |
| 2727 // For subclass constructors we need to return this in case of undefined | 2727 // For subclass constructors we need to return this in case of undefined |
| 2728 // and throw an exception in case of a non object. | 2728 // return a Smi (transformed into an exception in the ConstructStub) |
| 2729 // for a non object. |
| 2729 // | 2730 // |
| 2730 // return expr; | 2731 // return expr; |
| 2731 // | 2732 // |
| 2732 // Is rewritten as: | 2733 // Is rewritten as: |
| 2733 // | 2734 // |
| 2734 // return (temp = expr) === undefined ? this : | 2735 // return (temp = expr) === undefined ? this : |
| 2735 // %_IsJSReceiver(temp) ? temp : throw new TypeError(...); | 2736 // %_IsJSReceiver(temp) ? temp : 1; |
| 2737 |
| 2738 // temp = expr |
| 2736 Variable* temp = scope_->NewTemporary( | 2739 Variable* temp = scope_->NewTemporary( |
| 2737 ast_value_factory()->empty_string()); | 2740 ast_value_factory()->empty_string()); |
| 2738 Assignment* assign = factory()->NewAssignment( | 2741 Assignment* assign = factory()->NewAssignment( |
| 2739 Token::ASSIGN, factory()->NewVariableProxy(temp), return_value, pos); | 2742 Token::ASSIGN, factory()->NewVariableProxy(temp), return_value, pos); |
| 2740 | 2743 |
| 2741 Expression* throw_expression = | |
| 2742 NewThrowTypeError(MessageTemplate::kDerivedConstructorReturn, | |
| 2743 ast_value_factory()->empty_string(), pos); | |
| 2744 | |
| 2745 // %_IsJSReceiver(temp) | 2744 // %_IsJSReceiver(temp) |
| 2746 ZoneList<Expression*>* is_spec_object_args = | 2745 ZoneList<Expression*>* is_spec_object_args = |
| 2747 new (zone()) ZoneList<Expression*>(1, zone()); | 2746 new (zone()) ZoneList<Expression*>(1, zone()); |
| 2748 is_spec_object_args->Add(factory()->NewVariableProxy(temp), zone()); | 2747 is_spec_object_args->Add(factory()->NewVariableProxy(temp), zone()); |
| 2749 Expression* is_spec_object_call = factory()->NewCallRuntime( | 2748 Expression* is_spec_object_call = factory()->NewCallRuntime( |
| 2750 Runtime::kInlineIsJSReceiver, is_spec_object_args, pos); | 2749 Runtime::kInlineIsJSReceiver, is_spec_object_args, pos); |
| 2751 | 2750 |
| 2752 // %_IsJSReceiver(temp) ? temp : throw_expression | 2751 // %_IsJSReceiver(temp) ? temp : throw_expression |
| 2753 Expression* is_object_conditional = factory()->NewConditional( | 2752 Expression* is_object_conditional = factory()->NewConditional( |
| 2754 is_spec_object_call, factory()->NewVariableProxy(temp), | 2753 is_spec_object_call, factory()->NewVariableProxy(temp), |
| 2755 throw_expression, pos); | 2754 factory()->NewSmiLiteral(1, pos), pos); |
| 2756 | 2755 |
| 2757 // temp === undefined | 2756 // temp === undefined |
| 2758 Expression* is_undefined = factory()->NewCompareOperation( | 2757 Expression* is_undefined = factory()->NewCompareOperation( |
| 2759 Token::EQ_STRICT, assign, | 2758 Token::EQ_STRICT, assign, |
| 2760 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), pos); | 2759 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), pos); |
| 2761 | 2760 |
| 2762 // is_undefined ? this : is_object_conditional | 2761 // is_undefined ? this : is_object_conditional |
| 2763 return_value = factory()->NewConditional( | 2762 return_value = factory()->NewConditional( |
| 2764 is_undefined, ThisExpression(scope_, factory(), pos), | 2763 is_undefined, ThisExpression(scope_, factory(), pos), |
| 2765 is_object_conditional, pos); | 2764 is_object_conditional, pos); |
| (...skipping 2932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5698 auto class_literal = value->AsClassLiteral(); | 5697 auto class_literal = value->AsClassLiteral(); |
| 5699 if (class_literal->raw_name() == nullptr) { | 5698 if (class_literal->raw_name() == nullptr) { |
| 5700 class_literal->set_raw_name(name); | 5699 class_literal->set_raw_name(name); |
| 5701 } | 5700 } |
| 5702 } | 5701 } |
| 5703 } | 5702 } |
| 5704 | 5703 |
| 5705 | 5704 |
| 5706 } // namespace internal | 5705 } // namespace internal |
| 5707 } // namespace v8 | 5706 } // namespace v8 |
| OLD | NEW |