| 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/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 return result; | 608 return result; |
| 609 } | 609 } |
| 610 | 610 |
| 611 | 611 |
| 612 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { | 612 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { |
| 613 return parser_->scanner()->NextSymbol(parser_->ast_value_factory_); | 613 return parser_->scanner()->NextSymbol(parser_->ast_value_factory_); |
| 614 } | 614 } |
| 615 | 615 |
| 616 | 616 |
| 617 Expression* ParserTraits::ThisExpression( | 617 Expression* ParserTraits::ThisExpression( |
| 618 Scope* scope, | 618 Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) { |
| 619 AstNodeFactory<AstConstructionVisitor>* factory) { | 619 return factory->NewVariableProxy(scope->receiver(), pos); |
| 620 return factory->NewVariableProxy(scope->receiver()); | |
| 621 } | 620 } |
| 622 | 621 |
| 623 | 622 |
| 624 Literal* ParserTraits::ExpressionFromLiteral( | 623 Literal* ParserTraits::ExpressionFromLiteral( |
| 625 Token::Value token, int pos, | 624 Token::Value token, int pos, |
| 626 Scanner* scanner, | 625 Scanner* scanner, |
| 627 AstNodeFactory<AstConstructionVisitor>* factory) { | 626 AstNodeFactory<AstConstructionVisitor>* factory) { |
| 628 switch (token) { | 627 switch (token) { |
| 629 case Token::NULL_LITERAL: | 628 case Token::NULL_LITERAL: |
| 630 return factory->NewNullLiteral(pos); | 629 return factory->NewNullLiteral(pos); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 !body->at(0)->AsExpressionStatement()-> | 845 !body->at(0)->AsExpressionStatement()-> |
| 847 expression()->IsFunctionLiteral()) { | 846 expression()->IsFunctionLiteral()) { |
| 848 ReportMessage("single_function_literal"); | 847 ReportMessage("single_function_literal"); |
| 849 ok = false; | 848 ok = false; |
| 850 } | 849 } |
| 851 } | 850 } |
| 852 | 851 |
| 853 ast_value_factory_->Internalize(isolate()); | 852 ast_value_factory_->Internalize(isolate()); |
| 854 if (ok) { | 853 if (ok) { |
| 855 result = factory()->NewFunctionLiteral( | 854 result = factory()->NewFunctionLiteral( |
| 856 ast_value_factory_->empty_string(), | 855 ast_value_factory_->empty_string(), ast_value_factory_, scope_, body, |
| 857 ast_value_factory_, | |
| 858 scope_, | |
| 859 body, | |
| 860 function_state.materialized_literal_count(), | 856 function_state.materialized_literal_count(), |
| 861 function_state.expected_property_count(), | 857 function_state.expected_property_count(), |
| 862 function_state.handler_count(), | 858 function_state.handler_count(), 0, |
| 863 0, | |
| 864 FunctionLiteral::kNoDuplicateParameters, | 859 FunctionLiteral::kNoDuplicateParameters, |
| 865 FunctionLiteral::ANONYMOUS_EXPRESSION, | 860 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval, |
| 866 FunctionLiteral::kGlobalOrEval, | 861 FunctionLiteral::kNotParenthesized, FunctionLiteral::kNormalFunction, |
| 867 FunctionLiteral::kNotParenthesized, | |
| 868 FunctionLiteral::kNotGenerator, | |
| 869 0); | 862 0); |
| 870 result->set_ast_properties(factory()->visitor()->ast_properties()); | 863 result->set_ast_properties(factory()->visitor()->ast_properties()); |
| 871 result->set_dont_optimize_reason( | 864 result->set_dont_optimize_reason( |
| 872 factory()->visitor()->dont_optimize_reason()); | 865 factory()->visitor()->dont_optimize_reason()); |
| 873 } else if (stack_overflow()) { | 866 } else if (stack_overflow()) { |
| 874 isolate()->StackOverflow(); | 867 isolate()->StackOverflow(); |
| 875 } else { | 868 } else { |
| 876 ThrowPendingError(); | 869 ThrowPendingError(); |
| 877 } | 870 } |
| 878 } | 871 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 FunctionState function_state(&function_state_, &scope_, scope, zone(), | 941 FunctionState function_state(&function_state_, &scope_, scope, zone(), |
| 949 ast_value_factory_); | 942 ast_value_factory_); |
| 950 ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); | 943 ASSERT(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); |
| 951 ASSERT(info()->strict_mode() == shared_info->strict_mode()); | 944 ASSERT(info()->strict_mode() == shared_info->strict_mode()); |
| 952 scope->SetStrictMode(shared_info->strict_mode()); | 945 scope->SetStrictMode(shared_info->strict_mode()); |
| 953 FunctionLiteral::FunctionType function_type = shared_info->is_expression() | 946 FunctionLiteral::FunctionType function_type = shared_info->is_expression() |
| 954 ? (shared_info->is_anonymous() | 947 ? (shared_info->is_anonymous() |
| 955 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 948 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
| 956 : FunctionLiteral::NAMED_EXPRESSION) | 949 : FunctionLiteral::NAMED_EXPRESSION) |
| 957 : FunctionLiteral::DECLARATION; | 950 : FunctionLiteral::DECLARATION; |
| 951 bool is_generator = shared_info->is_generator(); |
| 958 bool ok = true; | 952 bool ok = true; |
| 959 result = ParseFunctionLiteral(raw_name, | 953 |
| 960 Scanner::Location::invalid(), | 954 if (shared_info->is_arrow()) { |
| 961 false, // Strict mode name already checked. | 955 ASSERT(!is_generator); |
| 962 shared_info->is_generator(), | 956 result = reinterpret_cast<FunctionLiteral*>(ParseExpression(false, &ok)); |
| 963 RelocInfo::kNoPosition, | 957 } else { |
| 964 function_type, | 958 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(), |
| 965 FunctionLiteral::NORMAL_ARITY, | 959 false, // Strict mode name already checked. |
| 966 &ok); | 960 is_generator, RelocInfo::kNoPosition, |
| 961 function_type, |
| 962 FunctionLiteral::NORMAL_ARITY, &ok); |
| 963 } |
| 967 // Make sure the results agree. | 964 // Make sure the results agree. |
| 968 ASSERT(ok == (result != NULL)); | 965 ASSERT(ok == (result != NULL)); |
| 969 } | 966 } |
| 970 | 967 |
| 971 // Make sure the target stack is empty. | 968 // Make sure the target stack is empty. |
| 972 ASSERT(target_stack_ == NULL); | 969 ASSERT(target_stack_ == NULL); |
| 973 | 970 |
| 974 ast_value_factory_->Internalize(isolate()); | 971 ast_value_factory_->Internalize(isolate()); |
| 975 if (result == NULL) { | 972 if (result == NULL) { |
| 976 if (stack_overflow()) { | 973 if (stack_overflow()) { |
| (...skipping 2580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3557 CHECK_OK); | 3554 CHECK_OK); |
| 3558 } | 3555 } |
| 3559 ast_properties = *factory()->visitor()->ast_properties(); | 3556 ast_properties = *factory()->visitor()->ast_properties(); |
| 3560 dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); | 3557 dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); |
| 3561 | 3558 |
| 3562 if (allow_harmony_scoping() && strict_mode() == STRICT) { | 3559 if (allow_harmony_scoping() && strict_mode() == STRICT) { |
| 3563 CheckConflictingVarDeclarations(scope, CHECK_OK); | 3560 CheckConflictingVarDeclarations(scope, CHECK_OK); |
| 3564 } | 3561 } |
| 3565 } | 3562 } |
| 3566 | 3563 |
| 3567 FunctionLiteral::IsGeneratorFlag generator = is_generator | 3564 FunctionLiteral::KindFlag kind = is_generator |
| 3568 ? FunctionLiteral::kIsGenerator | 3565 ? FunctionLiteral::kGeneratorFunction |
| 3569 : FunctionLiteral::kNotGenerator; | 3566 : FunctionLiteral::kNormalFunction; |
| 3570 FunctionLiteral* function_literal = | 3567 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
| 3571 factory()->NewFunctionLiteral(function_name, | 3568 function_name, ast_value_factory_, scope, body, |
| 3572 ast_value_factory_, | 3569 materialized_literal_count, expected_property_count, handler_count, |
| 3573 scope, | 3570 num_parameters, duplicate_parameters, function_type, |
| 3574 body, | 3571 FunctionLiteral::kIsFunction, parenthesized, kind, pos); |
| 3575 materialized_literal_count, | |
| 3576 expected_property_count, | |
| 3577 handler_count, | |
| 3578 num_parameters, | |
| 3579 duplicate_parameters, | |
| 3580 function_type, | |
| 3581 FunctionLiteral::kIsFunction, | |
| 3582 parenthesized, | |
| 3583 generator, | |
| 3584 pos); | |
| 3585 function_literal->set_function_token_position(function_token_pos); | 3572 function_literal->set_function_token_position(function_token_pos); |
| 3586 function_literal->set_ast_properties(&ast_properties); | 3573 function_literal->set_ast_properties(&ast_properties); |
| 3587 function_literal->set_dont_optimize_reason(dont_optimize_reason); | 3574 function_literal->set_dont_optimize_reason(dont_optimize_reason); |
| 3588 | 3575 |
| 3589 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); | 3576 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); |
| 3590 return function_literal; | 3577 return function_literal; |
| 3591 } | 3578 } |
| 3592 | 3579 |
| 3593 | 3580 |
| 3594 void Parser::SkipLazyFunctionBody(const AstRawString* function_name, | 3581 void Parser::SkipLazyFunctionBody(const AstRawString* function_name, |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4795 info()->SetAstValueFactory(ast_value_factory_); | 4782 info()->SetAstValueFactory(ast_value_factory_); |
| 4796 } | 4783 } |
| 4797 ast_value_factory_ = NULL; | 4784 ast_value_factory_ = NULL; |
| 4798 | 4785 |
| 4799 InternalizeUseCounts(); | 4786 InternalizeUseCounts(); |
| 4800 | 4787 |
| 4801 return (result != NULL); | 4788 return (result != NULL); |
| 4802 } | 4789 } |
| 4803 | 4790 |
| 4804 } } // namespace v8::internal | 4791 } } // namespace v8::internal |
| OLD | NEW |