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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 165 } |
166 | 166 |
167 FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, | 167 FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, |
168 bool call_super, int pos, | 168 bool call_super, int pos, |
169 int end_pos) { | 169 int end_pos) { |
170 int materialized_literal_count = -1; | 170 int materialized_literal_count = -1; |
171 int expected_property_count = -1; | 171 int expected_property_count = -1; |
172 const int parameter_count = 0; | 172 const int parameter_count = 0; |
173 if (name == nullptr) name = ast_value_factory()->empty_string(); | 173 if (name == nullptr) name = ast_value_factory()->empty_string(); |
174 | 174 |
175 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor | 175 FunctionKind kind = call_super ? FunctionKind::kDefaultDerivedConstructor |
176 : FunctionKind::kDefaultBaseConstructor; | 176 : FunctionKind::kDefaultBaseConstructor; |
177 DeclarationScope* function_scope = NewFunctionScope(kind); | 177 DeclarationScope* function_scope = NewFunctionScope(kind); |
178 SetLanguageMode(function_scope, STRICT); | 178 SetLanguageMode(function_scope, STRICT); |
179 // Set start and end position to the same value | 179 // Set start and end position to the same value |
180 function_scope->set_start_position(pos); | 180 function_scope->set_start_position(pos); |
181 function_scope->set_end_position(pos); | 181 function_scope->set_end_position(pos); |
182 ZoneList<Statement*>* body = NULL; | 182 ZoneList<Statement*>* body = NULL; |
183 | 183 |
184 { | 184 { |
185 FunctionState function_state(&function_state_, &scope_state_, | 185 FunctionState function_state(&function_state_, &scope_state_, |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 // must produce a FunctionLiteral. | 928 // must produce a FunctionLiteral. |
929 DCHECK(expression->IsFunctionLiteral()); | 929 DCHECK(expression->IsFunctionLiteral()); |
930 result = expression->AsFunctionLiteral(); | 930 result = expression->AsFunctionLiteral(); |
931 } else { | 931 } else { |
932 ok = false; | 932 ok = false; |
933 } | 933 } |
934 } | 934 } |
935 } | 935 } |
936 } else if (IsDefaultConstructor(kind)) { | 936 } else if (IsDefaultConstructor(kind)) { |
937 DCHECK_EQ(scope(), outer); | 937 DCHECK_EQ(scope(), outer); |
938 bool is_subclass_constructor = IsSubclassConstructor(kind); | 938 result = DefaultConstructor(raw_name, IsDerivedConstructor(kind), |
939 result = DefaultConstructor(raw_name, is_subclass_constructor, | |
940 info->start_position(), info->end_position()); | 939 info->start_position(), info->end_position()); |
941 } else { | 940 } else { |
942 result = ParseFunctionLiteral( | 941 result = ParseFunctionLiteral( |
943 raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind, | 942 raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind, |
944 kNoSourcePosition, function_type, info->language_mode(), &ok); | 943 kNoSourcePosition, function_type, info->language_mode(), &ok); |
945 } | 944 } |
946 // Make sure the results agree. | 945 // Make sure the results agree. |
947 DCHECK(ok == (result != nullptr)); | 946 DCHECK(ok == (result != nullptr)); |
948 } | 947 } |
949 | 948 |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1571 DCHECK_NOT_NULL(label); | 1570 DCHECK_NOT_NULL(label); |
1572 if (labels != nullptr) { | 1571 if (labels != nullptr) { |
1573 for (int i = labels->length(); i-- > 0;) { | 1572 for (int i = labels->length(); i-- > 0;) { |
1574 if (labels->at(i) == label) return true; | 1573 if (labels->at(i) == label) return true; |
1575 } | 1574 } |
1576 } | 1575 } |
1577 return false; | 1576 return false; |
1578 } | 1577 } |
1579 | 1578 |
1580 Expression* Parser::RewriteReturn(Expression* return_value, int pos) { | 1579 Expression* Parser::RewriteReturn(Expression* return_value, int pos) { |
1581 if (IsSubclassConstructor(function_state_->kind())) { | 1580 if (IsDerivedConstructor(function_state_->kind())) { |
1582 // For subclass constructors we need to return this in case of undefined | 1581 // For subclass constructors we need to return this in case of undefined |
1583 // return a Smi (transformed into an exception in the ConstructStub) | 1582 // return a Smi (transformed into an exception in the ConstructStub) |
1584 // for a non object. | 1583 // for a non object. |
1585 // | 1584 // |
1586 // return expr; | 1585 // return expr; |
1587 // | 1586 // |
1588 // Is rewritten as: | 1587 // Is rewritten as: |
1589 // | 1588 // |
1590 // return (temp = expr) === undefined ? this : | 1589 // return (temp = expr) === undefined ? this : |
1591 // %_IsJSReceiver(temp) ? temp : 1; | 1590 // %_IsJSReceiver(temp) ? temp : 1; |
(...skipping 1596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3188 kNoSourcePosition), | 3187 kNoSourcePosition), |
3189 zone()); | 3188 zone()); |
3190 } else if (IsAsyncFunction(kind)) { | 3189 } else if (IsAsyncFunction(kind)) { |
3191 const bool accept_IN = true; | 3190 const bool accept_IN = true; |
3192 ParseAsyncFunctionBody(inner_scope, body, kind, FunctionBodyType::kNormal, | 3191 ParseAsyncFunctionBody(inner_scope, body, kind, FunctionBodyType::kNormal, |
3193 accept_IN, pos, CHECK_OK); | 3192 accept_IN, pos, CHECK_OK); |
3194 } else { | 3193 } else { |
3195 ParseStatementList(body, Token::RBRACE, CHECK_OK); | 3194 ParseStatementList(body, Token::RBRACE, CHECK_OK); |
3196 } | 3195 } |
3197 | 3196 |
3198 if (IsSubclassConstructor(kind)) { | 3197 if (IsDerivedConstructor(kind)) { |
3199 body->Add(factory()->NewReturnStatement(ThisExpression(kNoSourcePosition), | 3198 body->Add(factory()->NewReturnStatement(ThisExpression(kNoSourcePosition), |
3200 kNoSourcePosition), | 3199 kNoSourcePosition), |
3201 zone()); | 3200 zone()); |
3202 } | 3201 } |
3203 } | 3202 } |
3204 | 3203 |
3205 Expect(Token::RBRACE, CHECK_OK); | 3204 Expect(Token::RBRACE, CHECK_OK); |
3206 scope()->set_end_position(scanner()->location().end_pos); | 3205 scope()->set_end_position(scanner()->location().end_pos); |
3207 | 3206 |
3208 if (!parameters.is_simple) { | 3207 if (!parameters.is_simple) { |
(...skipping 1922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5131 | 5130 |
5132 return final_loop; | 5131 return final_loop; |
5133 } | 5132 } |
5134 | 5133 |
5135 #undef CHECK_OK | 5134 #undef CHECK_OK |
5136 #undef CHECK_OK_VOID | 5135 #undef CHECK_OK_VOID |
5137 #undef CHECK_FAILED | 5136 #undef CHECK_FAILED |
5138 | 5137 |
5139 } // namespace internal | 5138 } // namespace internal |
5140 } // namespace v8 | 5139 } // namespace v8 |
OLD | NEW |