| 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 3855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3866 scope_->ForceContextAllocation(); | 3866 scope_->ForceContextAllocation(); |
| 3867 | 3867 |
| 3868 // Calling a generator returns a generator object. That object is stored | 3868 // Calling a generator returns a generator object. That object is stored |
| 3869 // in a temporary variable, a definition that is used by "yield" | 3869 // in a temporary variable, a definition that is used by "yield" |
| 3870 // expressions. This also marks the FunctionState as a generator. | 3870 // expressions. This also marks the FunctionState as a generator. |
| 3871 Variable* temp = scope_->DeclarationScope()->NewTemporary( | 3871 Variable* temp = scope_->DeclarationScope()->NewTemporary( |
| 3872 ast_value_factory()->dot_generator_object_string()); | 3872 ast_value_factory()->dot_generator_object_string()); |
| 3873 function_state.set_generator_object_variable(temp); | 3873 function_state.set_generator_object_variable(temp); |
| 3874 } | 3874 } |
| 3875 | 3875 |
| 3876 // FormalParameterList :: | |
| 3877 // '(' (Identifier)*[','] ')' | |
| 3878 Expect(Token::LPAREN, CHECK_OK); | |
| 3879 scope->set_start_position(scanner()->location().beg_pos); | |
| 3880 | |
| 3881 // We don't yet know if the function will be strict, so we cannot yet | 3876 // We don't yet know if the function will be strict, so we cannot yet |
| 3882 // produce errors for parameter names or duplicates. However, we remember | 3877 // produce errors for parameter names or duplicates. However, we remember |
| 3883 // the locations of these errors if they occur and produce the errors later. | 3878 // the locations of these errors if they occur and produce the errors later. |
| 3884 Scanner::Location eval_args_loc = Scanner::Location::invalid(); | 3879 Scanner::Location eval_args_loc = Scanner::Location::invalid(); |
| 3885 Scanner::Location dupe_loc = Scanner::Location::invalid(); | 3880 Scanner::Location dupe_loc = Scanner::Location::invalid(); |
| 3886 Scanner::Location reserved_loc = Scanner::Location::invalid(); | 3881 Scanner::Location reserved_loc = Scanner::Location::invalid(); |
| 3887 | 3882 |
| 3888 // Similarly for strong mode. | 3883 // Similarly for strong mode. |
| 3889 Scanner::Location undefined_loc = Scanner::Location::invalid(); | 3884 Scanner::Location undefined_loc = Scanner::Location::invalid(); |
| 3890 | 3885 |
| 3891 bool is_rest = false; | 3886 bool has_rest = false; |
| 3892 bool done = arity_restriction == FunctionLiteral::GETTER_ARITY || | 3887 Expect(Token::LPAREN, CHECK_OK); |
| 3893 (peek() == Token::RPAREN && | 3888 int start_position = scanner()->location().beg_pos; |
| 3894 arity_restriction != FunctionLiteral::SETTER_ARITY); | 3889 ZoneList<const AstRawString*>* params = |
| 3895 while (!done) { | 3890 ParseFormalParameterList(&eval_args_loc, &undefined_loc, &dupe_loc, |
| 3896 bool is_strict_reserved = false; | 3891 &reserved_loc, &has_rest, CHECK_OK); |
| 3897 is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params(); | 3892 Expect(Token::RPAREN, CHECK_OK); |
| 3898 if (is_rest) { | 3893 int formals_end_position = scanner()->location().end_pos; |
| 3899 Consume(Token::ELLIPSIS); | |
| 3900 } | |
| 3901 | 3894 |
| 3902 const AstRawString* param_name = | 3895 CheckArityRestrictions(params->length(), arity_restriction, start_position, |
| 3903 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 3896 formals_end_position, CHECK_OK); |
| 3904 | 3897 |
| 3905 // Store locations for possible future error reports. | 3898 scope->set_start_position(start_position); |
| 3906 if (!eval_args_loc.IsValid() && IsEvalOrArguments(param_name)) { | |
| 3907 eval_args_loc = scanner()->location(); | |
| 3908 } | |
| 3909 if (!undefined_loc.IsValid() && IsUndefined(param_name)) { | |
| 3910 undefined_loc = scanner()->location(); | |
| 3911 } | |
| 3912 if (!reserved_loc.IsValid() && is_strict_reserved) { | |
| 3913 reserved_loc = scanner()->location(); | |
| 3914 } | |
| 3915 if (!dupe_loc.IsValid() && | |
| 3916 scope_->IsDeclaredParameter(param_name)) { | |
| 3917 duplicate_parameters = FunctionLiteral::kHasDuplicateParameters; | |
| 3918 dupe_loc = scanner()->location(); | |
| 3919 } | |
| 3920 | 3899 |
| 3900 num_parameters = params->length(); |
| 3901 if (dupe_loc.IsValid()) { |
| 3902 duplicate_parameters = FunctionLiteral::kHasDuplicateParameters; |
| 3903 } |
| 3904 |
| 3905 for (int i = 0; i < params->length(); i++) { |
| 3906 const AstRawString* param_name = params->at(i); |
| 3907 int is_rest = has_rest && i == params->length() - 1; |
| 3921 Variable* var = scope_->DeclareParameter(param_name, VAR, is_rest); | 3908 Variable* var = scope_->DeclareParameter(param_name, VAR, is_rest); |
| 3922 if (is_sloppy(scope->language_mode())) { | 3909 if (is_sloppy(scope->language_mode())) { |
| 3923 // TODO(sigurds) Mark every parameter as maybe assigned. This is a | 3910 // TODO(sigurds) Mark every parameter as maybe assigned. This is a |
| 3924 // conservative approximation necessary to account for parameters | 3911 // conservative approximation necessary to account for parameters |
| 3925 // that are assigned via the arguments array. | 3912 // that are assigned via the arguments array. |
| 3926 var->set_maybe_assigned(); | 3913 var->set_maybe_assigned(); |
| 3927 } | 3914 } |
| 3928 | |
| 3929 num_parameters++; | |
| 3930 if (num_parameters > Code::kMaxArguments) { | |
| 3931 ReportMessage("too_many_parameters"); | |
| 3932 *ok = false; | |
| 3933 return NULL; | |
| 3934 } | |
| 3935 if (arity_restriction == FunctionLiteral::SETTER_ARITY) break; | |
| 3936 done = (peek() == Token::RPAREN); | |
| 3937 if (!done) { | |
| 3938 if (is_rest) { | |
| 3939 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); | |
| 3940 *ok = false; | |
| 3941 return NULL; | |
| 3942 } | |
| 3943 Expect(Token::COMMA, CHECK_OK); | |
| 3944 } | |
| 3945 } | 3915 } |
| 3946 Expect(Token::RPAREN, CHECK_OK); | |
| 3947 | 3916 |
| 3948 Expect(Token::LBRACE, CHECK_OK); | 3917 Expect(Token::LBRACE, CHECK_OK); |
| 3949 | 3918 |
| 3950 // If we have a named function expression, we add a local variable | 3919 // If we have a named function expression, we add a local variable |
| 3951 // declaration to the body of the function with the name of the | 3920 // declaration to the body of the function with the name of the |
| 3952 // function and let it refer to the function itself (closure). | 3921 // function and let it refer to the function itself (closure). |
| 3953 // NOTE: We create a proxy and resolve it here so that in the | 3922 // NOTE: We create a proxy and resolve it here so that in the |
| 3954 // future we can change the AST to only refer to VariableProxies | 3923 // future we can change the AST to only refer to VariableProxies |
| 3955 // instead of Variables and Proxis as is the case now. | 3924 // instead of Variables and Proxis as is the case now. |
| 3956 Variable* fvar = NULL; | 3925 Variable* fvar = NULL; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4018 materialized_literal_count = function_state.materialized_literal_count(); | 3987 materialized_literal_count = function_state.materialized_literal_count(); |
| 4019 expected_property_count = function_state.expected_property_count(); | 3988 expected_property_count = function_state.expected_property_count(); |
| 4020 handler_count = function_state.handler_count(); | 3989 handler_count = function_state.handler_count(); |
| 4021 } | 3990 } |
| 4022 | 3991 |
| 4023 // Validate name and parameter names. We can do this only after parsing the | 3992 // Validate name and parameter names. We can do this only after parsing the |
| 4024 // function, since the function can declare itself strict. | 3993 // function, since the function can declare itself strict. |
| 4025 CheckFunctionName(language_mode(), kind, function_name, | 3994 CheckFunctionName(language_mode(), kind, function_name, |
| 4026 name_is_strict_reserved, function_name_location, | 3995 name_is_strict_reserved, function_name_location, |
| 4027 CHECK_OK); | 3996 CHECK_OK); |
| 4028 const bool use_strict_params = is_rest || IsConciseMethod(kind); | 3997 const bool use_strict_params = has_rest || IsConciseMethod(kind); |
| 4029 CheckFunctionParameterNames(language_mode(), use_strict_params, | 3998 CheckFunctionParameterNames(language_mode(), use_strict_params, |
| 4030 eval_args_loc, undefined_loc, dupe_loc, | 3999 eval_args_loc, undefined_loc, dupe_loc, |
| 4031 reserved_loc, CHECK_OK); | 4000 reserved_loc, CHECK_OK); |
| 4032 | 4001 |
| 4033 if (is_strict(language_mode())) { | 4002 if (is_strict(language_mode())) { |
| 4034 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), | 4003 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), |
| 4035 CHECK_OK); | 4004 CHECK_OK); |
| 4036 } | 4005 } |
| 4037 if (is_strict(language_mode())) { | 4006 if (is_strict(language_mode())) { |
| 4038 CheckConflictingVarDeclarations(scope, CHECK_OK); | 4007 CheckConflictingVarDeclarations(scope, CHECK_OK); |
| (...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5759 | 5728 |
| 5760 Expression* Parser::SpreadCallNew(Expression* function, | 5729 Expression* Parser::SpreadCallNew(Expression* function, |
| 5761 ZoneList<v8::internal::Expression*>* args, | 5730 ZoneList<v8::internal::Expression*>* args, |
| 5762 int pos) { | 5731 int pos) { |
| 5763 args->InsertAt(0, function, zone()); | 5732 args->InsertAt(0, function, zone()); |
| 5764 | 5733 |
| 5765 return factory()->NewCallRuntime( | 5734 return factory()->NewCallRuntime( |
| 5766 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5735 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
| 5767 } | 5736 } |
| 5768 } } // namespace v8::internal | 5737 } } // namespace v8::internal |
| OLD | NEW |