| 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 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules); | 809 set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules); |
| 810 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions); | 810 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions); |
| 811 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 811 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
| 812 set_allow_harmony_classes(FLAG_harmony_classes); | 812 set_allow_harmony_classes(FLAG_harmony_classes); |
| 813 set_allow_harmony_object_literals(FLAG_harmony_object_literals); | 813 set_allow_harmony_object_literals(FLAG_harmony_object_literals); |
| 814 set_allow_harmony_templates(FLAG_harmony_templates); | 814 set_allow_harmony_templates(FLAG_harmony_templates); |
| 815 set_allow_harmony_sloppy(FLAG_harmony_sloppy); | 815 set_allow_harmony_sloppy(FLAG_harmony_sloppy); |
| 816 set_allow_harmony_unicode(FLAG_harmony_unicode); | 816 set_allow_harmony_unicode(FLAG_harmony_unicode); |
| 817 set_allow_harmony_computed_property_names( | 817 set_allow_harmony_computed_property_names( |
| 818 FLAG_harmony_computed_property_names); | 818 FLAG_harmony_computed_property_names); |
| 819 set_allow_harmony_rest_params(FLAG_harmony_rest_parameters); |
| 819 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 820 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 820 ++feature) { | 821 ++feature) { |
| 821 use_counts_[feature] = 0; | 822 use_counts_[feature] = 0; |
| 822 } | 823 } |
| 823 if (info->ast_value_factory() == NULL) { | 824 if (info->ast_value_factory() == NULL) { |
| 824 // info takes ownership of AstValueFactory. | 825 // info takes ownership of AstValueFactory. |
| 825 info->SetAstValueFactory( | 826 info->SetAstValueFactory( |
| 826 new AstValueFactory(zone(), parse_info->hash_seed)); | 827 new AstValueFactory(zone(), parse_info->hash_seed)); |
| 827 } | 828 } |
| 828 } | 829 } |
| (...skipping 2839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3668 Expect(Token::LPAREN, CHECK_OK); | 3669 Expect(Token::LPAREN, CHECK_OK); |
| 3669 scope->set_start_position(scanner()->location().beg_pos); | 3670 scope->set_start_position(scanner()->location().beg_pos); |
| 3670 | 3671 |
| 3671 // We don't yet know if the function will be strict, so we cannot yet | 3672 // We don't yet know if the function will be strict, so we cannot yet |
| 3672 // produce errors for parameter names or duplicates. However, we remember | 3673 // produce errors for parameter names or duplicates. However, we remember |
| 3673 // the locations of these errors if they occur and produce the errors later. | 3674 // the locations of these errors if they occur and produce the errors later. |
| 3674 Scanner::Location eval_args_error_log = Scanner::Location::invalid(); | 3675 Scanner::Location eval_args_error_log = Scanner::Location::invalid(); |
| 3675 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); | 3676 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); |
| 3676 Scanner::Location reserved_loc = Scanner::Location::invalid(); | 3677 Scanner::Location reserved_loc = Scanner::Location::invalid(); |
| 3677 | 3678 |
| 3679 bool is_rest = false; |
| 3678 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || | 3680 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || |
| 3679 (peek() == Token::RPAREN && | 3681 (peek() == Token::RPAREN && |
| 3680 arity_restriction != FunctionLiteral::SETTER_ARITY); | 3682 arity_restriction != FunctionLiteral::SETTER_ARITY); |
| 3681 while (!done) { | 3683 while (!done) { |
| 3682 bool is_strict_reserved = false; | 3684 bool is_strict_reserved = false; |
| 3685 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params(); |
| 3686 if (is_rest) { |
| 3687 Consume(Token::ELLIPSIS); |
| 3688 } |
| 3689 |
| 3683 const AstRawString* param_name = | 3690 const AstRawString* param_name = |
| 3684 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 3691 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
| 3685 | 3692 |
| 3686 // Store locations for possible future error reports. | 3693 // Store locations for possible future error reports. |
| 3687 if (!eval_args_error_log.IsValid() && IsEvalOrArguments(param_name)) { | 3694 if (!eval_args_error_log.IsValid() && IsEvalOrArguments(param_name)) { |
| 3688 eval_args_error_log = scanner()->location(); | 3695 eval_args_error_log = scanner()->location(); |
| 3689 } | 3696 } |
| 3690 if (!reserved_loc.IsValid() && is_strict_reserved) { | 3697 if (!reserved_loc.IsValid() && is_strict_reserved) { |
| 3691 reserved_loc = scanner()->location(); | 3698 reserved_loc = scanner()->location(); |
| 3692 } | 3699 } |
| 3693 if (!dupe_error_loc.IsValid() && scope_->IsDeclared(param_name)) { | 3700 if (!dupe_error_loc.IsValid() && scope_->IsDeclared(param_name)) { |
| 3694 duplicate_parameters = FunctionLiteral::kHasDuplicateParameters; | 3701 duplicate_parameters = FunctionLiteral::kHasDuplicateParameters; |
| 3695 dupe_error_loc = scanner()->location(); | 3702 dupe_error_loc = scanner()->location(); |
| 3696 } | 3703 } |
| 3697 | 3704 |
| 3698 Variable* var = scope_->DeclareParameter(param_name, VAR); | 3705 Variable* var = scope_->DeclareParameter(param_name, VAR, is_rest); |
| 3699 if (scope->strict_mode() == SLOPPY) { | 3706 if (scope->strict_mode() == SLOPPY) { |
| 3700 // TODO(sigurds) Mark every parameter as maybe assigned. This is a | 3707 // TODO(sigurds) Mark every parameter as maybe assigned. This is a |
| 3701 // conservative approximation necessary to account for parameters | 3708 // conservative approximation necessary to account for parameters |
| 3702 // that are assigned via the arguments array. | 3709 // that are assigned via the arguments array. |
| 3703 var->set_maybe_assigned(); | 3710 var->set_maybe_assigned(); |
| 3704 } | 3711 } |
| 3705 | 3712 |
| 3706 num_parameters++; | 3713 num_parameters++; |
| 3707 if (num_parameters > Code::kMaxArguments) { | 3714 if (num_parameters > Code::kMaxArguments) { |
| 3708 ReportMessage("too_many_parameters"); | 3715 ReportMessage("too_many_parameters"); |
| 3709 *ok = false; | 3716 *ok = false; |
| 3710 return NULL; | 3717 return NULL; |
| 3711 } | 3718 } |
| 3712 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break; | 3719 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break; |
| 3713 done = (peek() == Token::RPAREN); | 3720 done = (peek() == Token::RPAREN); |
| 3714 if (!done) Expect(Token::COMMA, CHECK_OK); | 3721 if (!done) { |
| 3722 if (is_rest) { |
| 3723 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); |
| 3724 *ok = false; |
| 3725 return NULL; |
| 3726 } |
| 3727 Expect(Token::COMMA, CHECK_OK); |
| 3728 } |
| 3715 } | 3729 } |
| 3716 Expect(Token::RPAREN, CHECK_OK); | 3730 Expect(Token::RPAREN, CHECK_OK); |
| 3717 | 3731 |
| 3718 Expect(Token::LBRACE, CHECK_OK); | 3732 Expect(Token::LBRACE, CHECK_OK); |
| 3719 | 3733 |
| 3720 // If we have a named function expression, we add a local variable | 3734 // If we have a named function expression, we add a local variable |
| 3721 // declaration to the body of the function with the name of the | 3735 // declaration to the body of the function with the name of the |
| 3722 // function and let it refer to the function itself (closure). | 3736 // function and let it refer to the function itself (closure). |
| 3723 // NOTE: We create a proxy and resolve it here so that in the | 3737 // NOTE: We create a proxy and resolve it here so that in the |
| 3724 // future we can change the AST to only refer to VariableProxies | 3738 // future we can change the AST to only refer to VariableProxies |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3787 } else { | 3801 } else { |
| 3788 body = ParseEagerFunctionBody(function_name, pos, fvar, fvar_init_op, | 3802 body = ParseEagerFunctionBody(function_name, pos, fvar, fvar_init_op, |
| 3789 is_generator, CHECK_OK); | 3803 is_generator, CHECK_OK); |
| 3790 materialized_literal_count = function_state.materialized_literal_count(); | 3804 materialized_literal_count = function_state.materialized_literal_count(); |
| 3791 expected_property_count = function_state.expected_property_count(); | 3805 expected_property_count = function_state.expected_property_count(); |
| 3792 handler_count = function_state.handler_count(); | 3806 handler_count = function_state.handler_count(); |
| 3793 } | 3807 } |
| 3794 | 3808 |
| 3795 // Validate strict mode. | 3809 // Validate strict mode. |
| 3796 // Concise methods use StrictFormalParameters. | 3810 // Concise methods use StrictFormalParameters. |
| 3797 if (strict_mode() == STRICT || IsConciseMethod(kind)) { | 3811 // Functions for which IsSimpleParameterList() returns false use |
| 3812 // StrictFormalParameters. |
| 3813 if (strict_mode() == STRICT || IsConciseMethod(kind) || is_rest) { |
| 3798 CheckStrictFunctionNameAndParameters(function_name, | 3814 CheckStrictFunctionNameAndParameters(function_name, |
| 3799 name_is_strict_reserved, | 3815 name_is_strict_reserved, |
| 3800 function_name_location, | 3816 function_name_location, |
| 3801 eval_args_error_log, | 3817 eval_args_error_log, |
| 3802 dupe_error_loc, | 3818 dupe_error_loc, |
| 3803 reserved_loc, | 3819 reserved_loc, |
| 3804 CHECK_OK); | 3820 CHECK_OK); |
| 3805 } | 3821 } |
| 3806 if (strict_mode() == STRICT) { | 3822 if (strict_mode() == STRICT) { |
| 3807 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), | 3823 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3972 reusable_preparser_->set_allow_harmony_numeric_literals( | 3988 reusable_preparser_->set_allow_harmony_numeric_literals( |
| 3973 allow_harmony_numeric_literals()); | 3989 allow_harmony_numeric_literals()); |
| 3974 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes()); | 3990 reusable_preparser_->set_allow_harmony_classes(allow_harmony_classes()); |
| 3975 reusable_preparser_->set_allow_harmony_object_literals( | 3991 reusable_preparser_->set_allow_harmony_object_literals( |
| 3976 allow_harmony_object_literals()); | 3992 allow_harmony_object_literals()); |
| 3977 reusable_preparser_->set_allow_harmony_templates(allow_harmony_templates()); | 3993 reusable_preparser_->set_allow_harmony_templates(allow_harmony_templates()); |
| 3978 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy()); | 3994 reusable_preparser_->set_allow_harmony_sloppy(allow_harmony_sloppy()); |
| 3979 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode()); | 3995 reusable_preparser_->set_allow_harmony_unicode(allow_harmony_unicode()); |
| 3980 reusable_preparser_->set_allow_harmony_computed_property_names( | 3996 reusable_preparser_->set_allow_harmony_computed_property_names( |
| 3981 allow_harmony_computed_property_names()); | 3997 allow_harmony_computed_property_names()); |
| 3998 reusable_preparser_->set_allow_harmony_rest_params( |
| 3999 allow_harmony_rest_params()); |
| 3982 } | 4000 } |
| 3983 PreParser::PreParseResult result = | 4001 PreParser::PreParseResult result = |
| 3984 reusable_preparser_->PreParseLazyFunction(strict_mode(), | 4002 reusable_preparser_->PreParseLazyFunction(strict_mode(), |
| 3985 is_generator(), | 4003 is_generator(), |
| 3986 logger); | 4004 logger); |
| 3987 if (pre_parse_timer_ != NULL) { | 4005 if (pre_parse_timer_ != NULL) { |
| 3988 pre_parse_timer_->Stop(); | 4006 pre_parse_timer_->Stop(); |
| 3989 } | 4007 } |
| 3990 return result; | 4008 return result; |
| 3991 } | 4009 } |
| (...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5365 } else { | 5383 } else { |
| 5366 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5384 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
| 5367 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5385 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
| 5368 raw_string->length()); | 5386 raw_string->length()); |
| 5369 } | 5387 } |
| 5370 } | 5388 } |
| 5371 | 5389 |
| 5372 return running_hash; | 5390 return running_hash; |
| 5373 } | 5391 } |
| 5374 } } // namespace v8::internal | 5392 } } // namespace v8::internal |
| OLD | NEW |