| 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/parser.h" | 5 #include "src/parser.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/ast-literal-reindexer.h" | 9 #include "src/ast-literal-reindexer.h" |
| 10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 function_scope->set_start_position(pos); | 352 function_scope->set_start_position(pos); |
| 353 function_scope->set_end_position(pos); | 353 function_scope->set_end_position(pos); |
| 354 ZoneList<Statement*>* body = NULL; | 354 ZoneList<Statement*>* body = NULL; |
| 355 | 355 |
| 356 { | 356 { |
| 357 AstNodeFactory function_factory(ast_value_factory()); | 357 AstNodeFactory function_factory(ast_value_factory()); |
| 358 FunctionState function_state(&function_state_, &scope_, function_scope, | 358 FunctionState function_state(&function_state_, &scope_, function_scope, |
| 359 kind, &function_factory); | 359 kind, &function_factory); |
| 360 | 360 |
| 361 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); | 361 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); |
| 362 AddAssertIsConstruct(body, pos); | |
| 363 if (call_super) { | 362 if (call_super) { |
| 364 // %_DefaultConstructorCallSuper(new.target, %GetPrototype(<this-fun>)) | 363 // %_DefaultConstructorCallSuper(new.target, %GetPrototype(<this-fun>)) |
| 365 ZoneList<Expression*>* args = | 364 ZoneList<Expression*>* args = |
| 366 new (zone()) ZoneList<Expression*>(2, zone()); | 365 new (zone()) ZoneList<Expression*>(2, zone()); |
| 367 VariableProxy* new_target_proxy = scope_->NewUnresolved( | 366 VariableProxy* new_target_proxy = scope_->NewUnresolved( |
| 368 factory(), ast_value_factory()->new_target_string(), Variable::NORMAL, | 367 factory(), ast_value_factory()->new_target_string(), Variable::NORMAL, |
| 369 pos); | 368 pos); |
| 370 args->Add(new_target_proxy, zone()); | 369 args->Add(new_target_proxy, zone()); |
| 371 VariableProxy* this_function_proxy = scope_->NewUnresolved( | 370 VariableProxy* this_function_proxy = scope_->NewUnresolved( |
| 372 factory(), ast_value_factory()->this_function_string(), | 371 factory(), ast_value_factory()->this_function_string(), |
| (...skipping 4096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4469 DCHECK(log_); | 4468 DCHECK(log_); |
| 4470 // Position right after terminal '}'. | 4469 // Position right after terminal '}'. |
| 4471 int body_end = scanner()->location().end_pos; | 4470 int body_end = scanner()->location().end_pos; |
| 4472 log_->LogFunction(function_block_pos, body_end, *materialized_literal_count, | 4471 log_->LogFunction(function_block_pos, body_end, *materialized_literal_count, |
| 4473 *expected_property_count, scope_->language_mode(), | 4472 *expected_property_count, scope_->language_mode(), |
| 4474 scope_->uses_super_property(), scope_->calls_eval()); | 4473 scope_->uses_super_property(), scope_->calls_eval()); |
| 4475 } | 4474 } |
| 4476 } | 4475 } |
| 4477 | 4476 |
| 4478 | 4477 |
| 4479 void Parser::AddAssertIsConstruct(ZoneList<Statement*>* body, int pos) { | |
| 4480 ZoneList<Expression*>* arguments = | |
| 4481 new (zone()) ZoneList<Expression*>(0, zone()); | |
| 4482 CallRuntime* construct_check = factory()->NewCallRuntime( | |
| 4483 Runtime::kInlineIsConstructCall, arguments, pos); | |
| 4484 CallRuntime* non_callable_error = factory()->NewCallRuntime( | |
| 4485 Runtime::kThrowConstructorNonCallableError, arguments, pos); | |
| 4486 IfStatement* if_statement = factory()->NewIfStatement( | |
| 4487 factory()->NewUnaryOperation(Token::NOT, construct_check, pos), | |
| 4488 factory()->NewReturnStatement(non_callable_error, pos), | |
| 4489 factory()->NewEmptyStatement(pos), pos); | |
| 4490 body->Add(if_statement, zone()); | |
| 4491 } | |
| 4492 | |
| 4493 | |
| 4494 Statement* Parser::BuildAssertIsCoercible(Variable* var) { | 4478 Statement* Parser::BuildAssertIsCoercible(Variable* var) { |
| 4495 // if (var === null || var === undefined) | 4479 // if (var === null || var === undefined) |
| 4496 // throw /* type error kNonCoercible) */; | 4480 // throw /* type error kNonCoercible) */; |
| 4497 | 4481 |
| 4498 Expression* condition = factory()->NewBinaryOperation( | 4482 Expression* condition = factory()->NewBinaryOperation( |
| 4499 Token::OR, factory()->NewCompareOperation( | 4483 Token::OR, factory()->NewCompareOperation( |
| 4500 Token::EQ_STRICT, factory()->NewVariableProxy(var), | 4484 Token::EQ_STRICT, factory()->NewVariableProxy(var), |
| 4501 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), | 4485 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), |
| 4502 RelocInfo::kNoPosition), | 4486 RelocInfo::kNoPosition), |
| 4503 factory()->NewCompareOperation( | 4487 factory()->NewCompareOperation( |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4677 DCHECK(function_name != NULL); | 4661 DCHECK(function_name != NULL); |
| 4678 // If we have a named function expression, we add a local variable | 4662 // If we have a named function expression, we add a local variable |
| 4679 // declaration to the body of the function with the name of the | 4663 // declaration to the body of the function with the name of the |
| 4680 // function and let it refer to the function itself (closure). | 4664 // function and let it refer to the function itself (closure). |
| 4681 // Not having parsed the function body, the language mode may still change, | 4665 // Not having parsed the function body, the language mode may still change, |
| 4682 // so we reserve a spot and create the actual const assignment later. | 4666 // so we reserve a spot and create the actual const assignment later. |
| 4683 DCHECK_EQ(kFunctionNameAssignmentIndex, result->length()); | 4667 DCHECK_EQ(kFunctionNameAssignmentIndex, result->length()); |
| 4684 result->Add(NULL, zone()); | 4668 result->Add(NULL, zone()); |
| 4685 } | 4669 } |
| 4686 | 4670 |
| 4687 // For concise constructors, check that they are constructed, | |
| 4688 // not called. | |
| 4689 if (IsClassConstructor(kind)) { | |
| 4690 AddAssertIsConstruct(result, pos); | |
| 4691 } | |
| 4692 | |
| 4693 ZoneList<Statement*>* body = result; | 4671 ZoneList<Statement*>* body = result; |
| 4694 Scope* inner_scope = scope_; | 4672 Scope* inner_scope = scope_; |
| 4695 Block* inner_block = nullptr; | 4673 Block* inner_block = nullptr; |
| 4696 if (!parameters.is_simple) { | 4674 if (!parameters.is_simple) { |
| 4697 inner_scope = NewScope(scope_, BLOCK_SCOPE); | 4675 inner_scope = NewScope(scope_, BLOCK_SCOPE); |
| 4698 inner_scope->set_is_declaration_scope(); | 4676 inner_scope->set_is_declaration_scope(); |
| 4699 inner_scope->set_start_position(scanner()->location().beg_pos); | 4677 inner_scope->set_start_position(scanner()->location().beg_pos); |
| 4700 inner_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); | 4678 inner_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); |
| 4701 inner_block->set_scope(inner_scope); | 4679 inner_block->set_scope(inner_scope); |
| 4702 body = inner_block->statements(); | 4680 body = inner_block->statements(); |
| (...skipping 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6388 | 6366 |
| 6389 Expression* Parser::SpreadCallNew(Expression* function, | 6367 Expression* Parser::SpreadCallNew(Expression* function, |
| 6390 ZoneList<v8::internal::Expression*>* args, | 6368 ZoneList<v8::internal::Expression*>* args, |
| 6391 int pos) { | 6369 int pos) { |
| 6392 args->InsertAt(0, function, zone()); | 6370 args->InsertAt(0, function, zone()); |
| 6393 | 6371 |
| 6394 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6372 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
| 6395 } | 6373 } |
| 6396 } // namespace internal | 6374 } // namespace internal |
| 6397 } // namespace v8 | 6375 } // namespace v8 |
| OLD | NEW |