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/ast-literal-reindexer.h" | 9 #include "src/ast-literal-reindexer.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 : FunctionLiteral::NAMED_EXPRESSION) | 1180 : FunctionLiteral::NAMED_EXPRESSION) |
1181 : FunctionLiteral::DECLARATION; | 1181 : FunctionLiteral::DECLARATION; |
1182 bool ok = true; | 1182 bool ok = true; |
1183 | 1183 |
1184 if (shared_info->is_arrow()) { | 1184 if (shared_info->is_arrow()) { |
1185 Scope* scope = | 1185 Scope* scope = |
1186 NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); | 1186 NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
1187 scope->SetLanguageMode(shared_info->language_mode()); | 1187 scope->SetLanguageMode(shared_info->language_mode()); |
1188 scope->set_start_position(shared_info->start_position()); | 1188 scope->set_start_position(shared_info->start_position()); |
1189 ExpressionClassifier formals_classifier; | 1189 ExpressionClassifier formals_classifier; |
1190 ParserFormalParameterParsingState parsing_state(scope); | 1190 ParserFormalParameters formals(scope); |
1191 Checkpoint checkpoint(this); | 1191 Checkpoint checkpoint(this); |
1192 { | 1192 { |
1193 // Parsing patterns as variable reference expression creates | 1193 // Parsing patterns as variable reference expression creates |
1194 // NewUnresolved references in current scope. Entrer arrow function | 1194 // NewUnresolved references in current scope. Entrer arrow function |
1195 // scope for formal parameter parsing. | 1195 // scope for formal parameter parsing. |
1196 BlockState block_state(&scope_, scope); | 1196 BlockState block_state(&scope_, scope); |
1197 if (Check(Token::LPAREN)) { | 1197 if (Check(Token::LPAREN)) { |
1198 // '(' StrictFormalParameters ')' | 1198 // '(' StrictFormalParameters ')' |
1199 ParseFormalParameterList(&parsing_state, &formals_classifier, &ok); | 1199 ParseFormalParameterList(&formals, &formals_classifier, &ok); |
1200 if (ok) ok = Check(Token::RPAREN); | 1200 if (ok) ok = Check(Token::RPAREN); |
1201 } else { | 1201 } else { |
1202 // BindingIdentifier | 1202 // BindingIdentifier |
1203 const bool is_rest = false; | 1203 const bool is_rest = false; |
1204 ParseFormalParameter(is_rest, &parsing_state, &formals_classifier, | 1204 ParseFormalParameter(is_rest, &formals, &formals_classifier, &ok); |
1205 &ok); | |
1206 } | 1205 } |
1207 } | 1206 } |
1208 | 1207 |
1209 if (ok) { | 1208 if (ok) { |
1210 checkpoint.Restore(&parsing_state.materialized_literals_count); | 1209 checkpoint.Restore(&formals.materialized_literals_count); |
1211 Expression* expression = | 1210 Expression* expression = |
1212 ParseArrowFunctionLiteral(parsing_state, formals_classifier, &ok); | 1211 ParseArrowFunctionLiteral(formals, formals_classifier, &ok); |
1213 if (ok) { | 1212 if (ok) { |
1214 // Scanning must end at the same position that was recorded | 1213 // Scanning must end at the same position that was recorded |
1215 // previously. If not, parsing has been interrupted due to a stack | 1214 // previously. If not, parsing has been interrupted due to a stack |
1216 // overflow, at which point the partially parsed arrow function | 1215 // overflow, at which point the partially parsed arrow function |
1217 // concise body happens to be a valid expression. This is a problem | 1216 // concise body happens to be a valid expression. This is a problem |
1218 // only for arrow functions with single expression bodies, since there | 1217 // only for arrow functions with single expression bodies, since there |
1219 // is no end token such as "}" for normal functions. | 1218 // is no end token such as "}" for normal functions. |
1220 if (scanner()->location().end_pos == shared_info->end_position()) { | 1219 if (scanner()->location().end_pos == shared_info->end_position()) { |
1221 // The pre-parser saw an arrow function here, so the full parser | 1220 // The pre-parser saw an arrow function here, so the full parser |
1222 // must produce a FunctionLiteral. | 1221 // must produce a FunctionLiteral. |
(...skipping 2614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3837 return static_cast<LiteralType>(literal_type->value()); | 3836 return static_cast<LiteralType>(literal_type->value()); |
3838 } | 3837 } |
3839 | 3838 |
3840 | 3839 |
3841 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 3840 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
3842 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 3841 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); |
3843 } | 3842 } |
3844 | 3843 |
3845 | 3844 |
3846 void ParserTraits::ParseArrowFunctionFormalParameters( | 3845 void ParserTraits::ParseArrowFunctionFormalParameters( |
3847 ParserFormalParameterParsingState* parsing_state, Expression* expr, | 3846 ParserFormalParameters* parameters, Expression* expr, |
3848 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 3847 const Scanner::Location& params_loc, |
3849 bool* ok) { | 3848 Scanner::Location* duplicate_loc, bool* ok) { |
3850 if (parsing_state->scope->num_parameters() >= Code::kMaxArguments) { | 3849 if (parameters->scope->num_parameters() >= Code::kMaxArguments) { |
3851 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); | 3850 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); |
3852 *ok = false; | 3851 *ok = false; |
3853 return; | 3852 return; |
3854 } | 3853 } |
3855 | 3854 |
3856 // ArrowFunctionFormals :: | 3855 // ArrowFunctionFormals :: |
3857 // Binary(Token::COMMA, NonTailArrowFunctionFormals, Tail) | 3856 // Binary(Token::COMMA, NonTailArrowFunctionFormals, Tail) |
3858 // Tail | 3857 // Tail |
3859 // NonTailArrowFunctionFormals :: | 3858 // NonTailArrowFunctionFormals :: |
3860 // Binary(Token::COMMA, NonTailArrowFunctionFormals, VariableProxy) | 3859 // Binary(Token::COMMA, NonTailArrowFunctionFormals, VariableProxy) |
3861 // VariableProxy | 3860 // VariableProxy |
3862 // Tail :: | 3861 // Tail :: |
3863 // VariableProxy | 3862 // VariableProxy |
3864 // Spread(VariableProxy) | 3863 // Spread(VariableProxy) |
3865 // | 3864 // |
3866 // As we need to visit the parameters in left-to-right order, we recurse on | 3865 // As we need to visit the parameters in left-to-right order, we recurse on |
3867 // the left-hand side of comma expressions. | 3866 // the left-hand side of comma expressions. |
3868 // | 3867 // |
3869 if (expr->IsBinaryOperation()) { | 3868 if (expr->IsBinaryOperation()) { |
3870 BinaryOperation* binop = expr->AsBinaryOperation(); | 3869 BinaryOperation* binop = expr->AsBinaryOperation(); |
3871 // The classifier has already run, so we know that the expression is a valid | 3870 // The classifier has already run, so we know that the expression is a valid |
3872 // arrow function formals production. | 3871 // arrow function formals production. |
3873 DCHECK_EQ(binop->op(), Token::COMMA); | 3872 DCHECK_EQ(binop->op(), Token::COMMA); |
3874 Expression* left = binop->left(); | 3873 Expression* left = binop->left(); |
3875 Expression* right = binop->right(); | 3874 Expression* right = binop->right(); |
3876 ParseArrowFunctionFormalParameters(parsing_state, left, params_loc, | 3875 ParseArrowFunctionFormalParameters(parameters, left, params_loc, |
3877 duplicate_loc, ok); | 3876 duplicate_loc, ok); |
3878 if (!*ok) return; | 3877 if (!*ok) return; |
3879 // LHS of comma expression should be unparenthesized. | 3878 // LHS of comma expression should be unparenthesized. |
3880 expr = right; | 3879 expr = right; |
3881 } | 3880 } |
3882 | 3881 |
3883 // Only the right-most expression may be a rest parameter. | 3882 // Only the right-most expression may be a rest parameter. |
3884 DCHECK(!parsing_state->has_rest); | 3883 DCHECK(!parameters->has_rest); |
3885 | 3884 |
3886 bool is_rest = false; | 3885 bool is_rest = expr->IsSpread(); |
3887 if (expr->IsSpread()) { | 3886 if (is_rest) expr = expr->AsSpread()->expression(); |
3888 is_rest = true; | |
3889 expr = expr->AsSpread()->expression(); | |
3890 } | |
3891 | 3887 |
3892 if (expr->IsVariableProxy()) { | 3888 if (expr->IsVariableProxy()) { |
3893 // When the formal parameter was originally seen, it was parsed as a | 3889 // When the formal parameter was originally seen, it was parsed as a |
3894 // VariableProxy and recorded as unresolved in the scope. Here we undo that | 3890 // VariableProxy and recorded as unresolved in the scope. Here we undo that |
3895 // parse-time side-effect for parameters that are single-names (not | 3891 // parse-time side-effect for parameters that are single-names (not |
3896 // patterns; for patterns that happens uniformly in | 3892 // patterns; for patterns that happens uniformly in |
3897 // PatternRewriter::VisitVariableProxy). | 3893 // PatternRewriter::VisitVariableProxy). |
3898 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); | 3894 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); |
3899 } | 3895 } |
3900 | 3896 |
3901 ExpressionClassifier classifier; | 3897 ExpressionClassifier classifier; |
3902 DeclareFormalParameter(parsing_state, expr, &classifier, is_rest); | 3898 DeclareFormalParameter(parameters, expr, is_rest, &classifier); |
3903 if (!duplicate_loc->IsValid()) { | 3899 if (!duplicate_loc->IsValid()) { |
3904 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; | 3900 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; |
3905 } | 3901 } |
3906 } | 3902 } |
3907 | 3903 |
3908 | 3904 |
3909 void ParserTraits::ReindexLiterals( | 3905 void ParserTraits::ReindexLiterals(const ParserFormalParameters& parameters) { |
3910 const ParserFormalParameterParsingState& parsing_state) { | |
3911 if (parser_->function_state_->materialized_literal_count() > 0) { | 3906 if (parser_->function_state_->materialized_literal_count() > 0) { |
3912 AstLiteralReindexer reindexer; | 3907 AstLiteralReindexer reindexer; |
3913 | 3908 |
3914 for (const auto p : parsing_state.params) { | 3909 for (const auto p : parameters.params) { |
3915 if (p.pattern != nullptr) reindexer.Reindex(p.pattern); | 3910 if (p.pattern != nullptr) reindexer.Reindex(p.pattern); |
3916 } | 3911 } |
3917 DCHECK(reindexer.count() <= | 3912 DCHECK(reindexer.count() <= |
3918 parser_->function_state_->materialized_literal_count()); | 3913 parser_->function_state_->materialized_literal_count()); |
3919 } | 3914 } |
3920 } | 3915 } |
3921 | 3916 |
3922 | 3917 |
3923 FunctionLiteral* Parser::ParseFunctionLiteral( | 3918 FunctionLiteral* Parser::ParseFunctionLiteral( |
3924 const AstRawString* function_name, Scanner::Location function_name_location, | 3919 const AstRawString* function_name, Scanner::Location function_name_location, |
(...skipping 18 matching lines...) Expand all Loading... |
3943 // Anonymous functions were passed either the empty symbol or a null | 3938 // Anonymous functions were passed either the empty symbol or a null |
3944 // handle as the function name. Remember if we were passed a non-empty | 3939 // handle as the function name. Remember if we were passed a non-empty |
3945 // handle to decide whether to invoke function name inference. | 3940 // handle to decide whether to invoke function name inference. |
3946 bool should_infer_name = function_name == NULL; | 3941 bool should_infer_name = function_name == NULL; |
3947 | 3942 |
3948 // We want a non-null handle as the function name. | 3943 // We want a non-null handle as the function name. |
3949 if (should_infer_name) { | 3944 if (should_infer_name) { |
3950 function_name = ast_value_factory()->empty_string(); | 3945 function_name = ast_value_factory()->empty_string(); |
3951 } | 3946 } |
3952 | 3947 |
3953 int num_parameters = 0; | |
3954 // Function declarations are function scoped in normal mode, so they are | 3948 // Function declarations are function scoped in normal mode, so they are |
3955 // hoisted. In harmony block scoping mode they are block scoped, so they | 3949 // hoisted. In harmony block scoping mode they are block scoped, so they |
3956 // are not hoisted. | 3950 // are not hoisted. |
3957 // | 3951 // |
3958 // One tricky case are function declarations in a local sloppy-mode eval: | 3952 // One tricky case are function declarations in a local sloppy-mode eval: |
3959 // their declaration is hoisted, but they still see the local scope. E.g., | 3953 // their declaration is hoisted, but they still see the local scope. E.g., |
3960 // | 3954 // |
3961 // function() { | 3955 // function() { |
3962 // var x = 0 | 3956 // var x = 0 |
3963 // try { throw 1 } catch (x) { eval("function g() { return x }") } | 3957 // try { throw 1 } catch (x) { eval("function g() { return x }") } |
(...skipping 17 matching lines...) Expand all Loading... |
3981 Scope* declaration_scope = scope_->DeclarationScope(); | 3975 Scope* declaration_scope = scope_->DeclarationScope(); |
3982 Scope* original_declaration_scope = original_scope_->DeclarationScope(); | 3976 Scope* original_declaration_scope = original_scope_->DeclarationScope(); |
3983 Scope* scope = function_type == FunctionLiteral::DECLARATION && | 3977 Scope* scope = function_type == FunctionLiteral::DECLARATION && |
3984 is_sloppy(language_mode) && !allow_harmony_sloppy() && | 3978 is_sloppy(language_mode) && !allow_harmony_sloppy() && |
3985 (original_scope_ == original_declaration_scope || | 3979 (original_scope_ == original_declaration_scope || |
3986 declaration_scope != original_declaration_scope) | 3980 declaration_scope != original_declaration_scope) |
3987 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind) | 3981 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind) |
3988 : NewScope(scope_, FUNCTION_SCOPE, kind); | 3982 : NewScope(scope_, FUNCTION_SCOPE, kind); |
3989 scope->SetLanguageMode(language_mode); | 3983 scope->SetLanguageMode(language_mode); |
3990 ZoneList<Statement*>* body = NULL; | 3984 ZoneList<Statement*>* body = NULL; |
| 3985 int arity = 0; |
3991 int materialized_literal_count = -1; | 3986 int materialized_literal_count = -1; |
3992 int expected_property_count = -1; | 3987 int expected_property_count = -1; |
3993 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 3988 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
3994 ExpressionClassifier formals_classifier(&duplicate_finder); | 3989 ExpressionClassifier formals_classifier(&duplicate_finder); |
3995 FunctionLiteral::EagerCompileHint eager_compile_hint = | 3990 FunctionLiteral::EagerCompileHint eager_compile_hint = |
3996 parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile | 3991 parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile |
3997 : FunctionLiteral::kShouldLazyCompile; | 3992 : FunctionLiteral::kShouldLazyCompile; |
3998 bool should_be_used_once_hint = false; | 3993 bool should_be_used_once_hint = false; |
3999 // Parse function body. | 3994 // Parse function. |
4000 { | 3995 { |
4001 AstNodeFactory function_factory(ast_value_factory()); | 3996 AstNodeFactory function_factory(ast_value_factory()); |
4002 FunctionState function_state(&function_state_, &scope_, scope, kind, | 3997 FunctionState function_state(&function_state_, &scope_, scope, kind, |
4003 &function_factory); | 3998 &function_factory); |
4004 scope_->SetScopeName(function_name); | 3999 scope_->SetScopeName(function_name); |
4005 | 4000 |
4006 if (is_generator) { | 4001 if (is_generator) { |
4007 // For generators, allocating variables in contexts is currently a win | 4002 // For generators, allocating variables in contexts is currently a win |
4008 // because it minimizes the work needed to suspend and resume an | 4003 // because it minimizes the work needed to suspend and resume an |
4009 // activation. | 4004 // activation. |
4010 scope_->ForceContextAllocation(); | 4005 scope_->ForceContextAllocation(); |
4011 | 4006 |
4012 // Calling a generator returns a generator object. That object is stored | 4007 // Calling a generator returns a generator object. That object is stored |
4013 // in a temporary variable, a definition that is used by "yield" | 4008 // in a temporary variable, a definition that is used by "yield" |
4014 // expressions. This also marks the FunctionState as a generator. | 4009 // expressions. This also marks the FunctionState as a generator. |
4015 Variable* temp = scope_->DeclarationScope()->NewTemporary( | 4010 Variable* temp = scope_->DeclarationScope()->NewTemporary( |
4016 ast_value_factory()->dot_generator_object_string()); | 4011 ast_value_factory()->dot_generator_object_string()); |
4017 function_state.set_generator_object_variable(temp); | 4012 function_state.set_generator_object_variable(temp); |
4018 } | 4013 } |
4019 | 4014 |
4020 Expect(Token::LPAREN, CHECK_OK); | 4015 Expect(Token::LPAREN, CHECK_OK); |
4021 int start_position = scanner()->location().beg_pos; | 4016 int start_position = scanner()->location().beg_pos; |
4022 scope_->set_start_position(start_position); | 4017 scope_->set_start_position(start_position); |
4023 ParserFormalParameterParsingState parsing_state(scope); | 4018 ParserFormalParameters formals(scope); |
4024 num_parameters = | 4019 arity = ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); |
4025 ParseFormalParameterList(&parsing_state, &formals_classifier, CHECK_OK); | |
4026 Expect(Token::RPAREN, CHECK_OK); | 4020 Expect(Token::RPAREN, CHECK_OK); |
4027 int formals_end_position = scanner()->location().end_pos; | 4021 int formals_end_position = scanner()->location().end_pos; |
4028 | 4022 |
4029 CheckArityRestrictions(num_parameters, arity_restriction, | 4023 CheckArityRestrictions(arity, arity_restriction, |
4030 parsing_state.has_rest, start_position, | 4024 formals.has_rest, start_position, |
4031 formals_end_position, CHECK_OK); | 4025 formals_end_position, CHECK_OK); |
4032 Expect(Token::LBRACE, CHECK_OK); | 4026 Expect(Token::LBRACE, CHECK_OK); |
4033 | 4027 |
4034 // If we have a named function expression, we add a local variable | 4028 // If we have a named function expression, we add a local variable |
4035 // declaration to the body of the function with the name of the | 4029 // declaration to the body of the function with the name of the |
4036 // function and let it refer to the function itself (closure). | 4030 // function and let it refer to the function itself (closure). |
4037 // NOTE: We create a proxy and resolve it here so that in the | 4031 // NOTE: We create a proxy and resolve it here so that in the |
4038 // future we can change the AST to only refer to VariableProxies | 4032 // future we can change the AST to only refer to VariableProxies |
4039 // instead of Variables and Proxis as is the case now. | 4033 // instead of Variables and Proxis as is the case now. |
4040 Variable* fvar = NULL; | 4034 Variable* fvar = NULL; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4112 is_lazily_parsed = false; | 4106 is_lazily_parsed = false; |
4113 | 4107 |
4114 // This is probably an initialization function. Inform the compiler it | 4108 // This is probably an initialization function. Inform the compiler it |
4115 // should also eager-compile this function, and that we expect it to be | 4109 // should also eager-compile this function, and that we expect it to be |
4116 // used once. | 4110 // used once. |
4117 eager_compile_hint = FunctionLiteral::kShouldEagerCompile; | 4111 eager_compile_hint = FunctionLiteral::kShouldEagerCompile; |
4118 should_be_used_once_hint = true; | 4112 should_be_used_once_hint = true; |
4119 } | 4113 } |
4120 } | 4114 } |
4121 if (!is_lazily_parsed) { | 4115 if (!is_lazily_parsed) { |
4122 body = ParseEagerFunctionBody(function_name, pos, parsing_state, fvar, | 4116 body = ParseEagerFunctionBody(function_name, pos, formals, fvar, |
4123 fvar_init_op, kind, CHECK_OK); | 4117 fvar_init_op, kind, CHECK_OK); |
4124 materialized_literal_count = function_state.materialized_literal_count(); | 4118 materialized_literal_count = function_state.materialized_literal_count(); |
4125 expected_property_count = function_state.expected_property_count(); | 4119 expected_property_count = function_state.expected_property_count(); |
4126 } | 4120 } |
4127 | 4121 |
4128 // Parsing the body may change the language mode in our scope. | 4122 // Parsing the body may change the language mode in our scope. |
4129 language_mode = scope->language_mode(); | 4123 language_mode = scope->language_mode(); |
4130 | 4124 |
4131 if (is_strong(language_mode) && IsSubclassConstructor(kind)) { | 4125 if (is_strong(language_mode) && IsSubclassConstructor(kind)) { |
4132 if (!function_state.super_location().IsValid()) { | 4126 if (!function_state.super_location().IsValid()) { |
4133 ReportMessageAt(function_name_location, | 4127 ReportMessageAt(function_name_location, |
4134 MessageTemplate::kStrongSuperCallMissing, | 4128 MessageTemplate::kStrongSuperCallMissing, |
4135 kReferenceError); | 4129 kReferenceError); |
4136 *ok = false; | 4130 *ok = false; |
4137 return nullptr; | 4131 return nullptr; |
4138 } | 4132 } |
4139 } | 4133 } |
4140 | 4134 |
4141 // Validate name and parameter names. We can do this only after parsing the | 4135 // Validate name and parameter names. We can do this only after parsing the |
4142 // function, since the function can declare itself strict. | 4136 // function, since the function can declare itself strict. |
4143 CheckFunctionName(language_mode, function_name, function_name_validity, | 4137 CheckFunctionName(language_mode, function_name, function_name_validity, |
4144 function_name_location, CHECK_OK); | 4138 function_name_location, CHECK_OK); |
4145 const bool use_strict_params = | |
4146 !parsing_state.is_simple_parameter_list || IsConciseMethod(kind); | |
4147 const bool allow_duplicate_parameters = | 4139 const bool allow_duplicate_parameters = |
4148 is_sloppy(language_mode) && !use_strict_params; | 4140 is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind); |
4149 ValidateFormalParameters(&formals_classifier, language_mode, | 4141 ValidateFormalParameters(&formals_classifier, language_mode, |
4150 allow_duplicate_parameters, CHECK_OK); | 4142 allow_duplicate_parameters, CHECK_OK); |
4151 | 4143 |
4152 if (is_strict(language_mode)) { | 4144 if (is_strict(language_mode)) { |
4153 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), | 4145 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), |
4154 CHECK_OK); | 4146 CHECK_OK); |
4155 } | 4147 } |
4156 if (is_strict(language_mode) || allow_harmony_sloppy()) { | 4148 if (is_strict(language_mode) || allow_harmony_sloppy()) { |
4157 CheckConflictingVarDeclarations(scope, CHECK_OK); | 4149 CheckConflictingVarDeclarations(scope, CHECK_OK); |
4158 } | 4150 } |
4159 } | 4151 } |
4160 | 4152 |
4161 bool has_duplicate_parameters = | 4153 bool has_duplicate_parameters = |
4162 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); | 4154 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); |
4163 FunctionLiteral::ParameterFlag duplicate_parameters = | 4155 FunctionLiteral::ParameterFlag duplicate_parameters = |
4164 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters | 4156 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters |
4165 : FunctionLiteral::kNoDuplicateParameters; | 4157 : FunctionLiteral::kNoDuplicateParameters; |
4166 | 4158 |
4167 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( | 4159 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
4168 function_name, ast_value_factory(), scope, body, | 4160 function_name, ast_value_factory(), scope, body, |
4169 materialized_literal_count, expected_property_count, num_parameters, | 4161 materialized_literal_count, expected_property_count, arity, |
4170 duplicate_parameters, function_type, FunctionLiteral::kIsFunction, | 4162 duplicate_parameters, function_type, FunctionLiteral::kIsFunction, |
4171 eager_compile_hint, kind, pos); | 4163 eager_compile_hint, kind, pos); |
4172 function_literal->set_function_token_position(function_token_pos); | 4164 function_literal->set_function_token_position(function_token_pos); |
4173 if (should_be_used_once_hint) | 4165 if (should_be_used_once_hint) |
4174 function_literal->set_should_be_used_once_hint(); | 4166 function_literal->set_should_be_used_once_hint(); |
4175 | 4167 |
4176 if (scope->has_rest_parameter()) { | 4168 if (scope->has_rest_parameter()) { |
4177 // TODO(caitp): enable optimization of functions with rest params | 4169 // TODO(caitp): enable optimization of functions with rest params |
4178 function_literal->set_dont_optimize_reason(kRestParameter); | 4170 function_literal->set_dont_optimize_reason(kRestParameter); |
4179 } | 4171 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4300 RelocInfo::kNoPosition); | 4292 RelocInfo::kNoPosition); |
4301 IfStatement* if_statement = factory()->NewIfStatement( | 4293 IfStatement* if_statement = factory()->NewIfStatement( |
4302 condition, factory()->NewExpressionStatement(throw_type_error, | 4294 condition, factory()->NewExpressionStatement(throw_type_error, |
4303 RelocInfo::kNoPosition), | 4295 RelocInfo::kNoPosition), |
4304 factory()->NewEmptyStatement(RelocInfo::kNoPosition), | 4296 factory()->NewEmptyStatement(RelocInfo::kNoPosition), |
4305 RelocInfo::kNoPosition); | 4297 RelocInfo::kNoPosition); |
4306 return if_statement; | 4298 return if_statement; |
4307 } | 4299 } |
4308 | 4300 |
4309 | 4301 |
4310 bool Parser::IsSimpleParameterList( | 4302 bool Parser::IsSimpleParameterList(const ParserFormalParameters& parameters) { |
4311 const ParserFormalParameterParsingState& formal_parameters) { | 4303 for (auto parameter : parameters.params) { |
4312 for (auto parameter : formal_parameters.params) { | |
4313 if (parameter.pattern != nullptr) return false; | 4304 if (parameter.pattern != nullptr) return false; |
4314 } | 4305 } |
4315 return true; | 4306 return true; |
4316 } | 4307 } |
4317 | 4308 |
4318 | 4309 |
4319 Block* Parser::BuildParameterInitializationBlock( | 4310 Block* Parser::BuildParameterInitializationBlock( |
4320 const ParserFormalParameterParsingState& formal_parameters, bool* ok) { | 4311 const ParserFormalParameters& parameters, bool* ok) { |
4321 DCHECK(!IsSimpleParameterList(formal_parameters)); | 4312 DCHECK(!IsSimpleParameterList(parameters)); |
4322 DCHECK(scope_->is_function_scope()); | 4313 DCHECK(scope_->is_function_scope()); |
4323 Block* init_block = | 4314 Block* init_block = |
4324 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); | 4315 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); |
4325 for (auto parameter : formal_parameters.params) { | 4316 for (auto parameter : parameters.params) { |
4326 if (parameter.pattern == nullptr) continue; | 4317 if (parameter.pattern == nullptr) continue; |
4327 DeclarationDescriptor descriptor; | 4318 DeclarationDescriptor descriptor; |
4328 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; | 4319 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; |
4329 descriptor.parser = this; | 4320 descriptor.parser = this; |
4330 descriptor.declaration_scope = scope_; | 4321 descriptor.declaration_scope = scope_; |
4331 descriptor.scope = scope_; | 4322 descriptor.scope = scope_; |
4332 descriptor.mode = LET; | 4323 descriptor.mode = LET; |
4333 descriptor.is_const = false; | 4324 descriptor.is_const = false; |
4334 descriptor.needs_init = true; | 4325 descriptor.needs_init = true; |
4335 descriptor.declaration_pos = parameter.pattern->position(); | 4326 descriptor.declaration_pos = parameter.pattern->position(); |
4336 descriptor.initialization_pos = parameter.pattern->position(); | 4327 descriptor.initialization_pos = parameter.pattern->position(); |
4337 descriptor.init_op = Token::INIT_LET; | 4328 descriptor.init_op = Token::INIT_LET; |
4338 DeclarationParsingResult::Declaration decl( | 4329 DeclarationParsingResult::Declaration decl( |
4339 parameter.pattern, parameter.pattern->position(), | 4330 parameter.pattern, parameter.pattern->position(), |
4340 factory()->NewVariableProxy(parameter.var)); | 4331 factory()->NewVariableProxy(parameter.var)); |
4341 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, | 4332 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, |
4342 &decl, nullptr, CHECK_OK); | 4333 &decl, nullptr, CHECK_OK); |
4343 } | 4334 } |
4344 return init_block; | 4335 return init_block; |
4345 } | 4336 } |
4346 | 4337 |
4347 | 4338 |
4348 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( | 4339 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
4349 const AstRawString* function_name, int pos, | 4340 const AstRawString* function_name, int pos, |
4350 const ParserFormalParameterParsingState& formal_parameters, Variable* fvar, | 4341 const ParserFormalParameters& parameters, Variable* fvar, |
4351 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | 4342 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |
4352 bool is_simple_parameter_list = IsSimpleParameterList(formal_parameters); | 4343 bool is_simple_parameter_list = IsSimpleParameterList(parameters); |
4353 | |
4354 // Everything inside an eagerly parsed function will be parsed eagerly | 4344 // Everything inside an eagerly parsed function will be parsed eagerly |
4355 // (see comment above). | 4345 // (see comment above). |
4356 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 4346 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
4357 ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone()); | 4347 ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone()); |
4358 if (fvar != NULL) { | 4348 if (fvar != NULL) { |
4359 VariableProxy* fproxy = scope_->NewUnresolved(factory(), function_name); | 4349 VariableProxy* fproxy = scope_->NewUnresolved(factory(), function_name); |
4360 fproxy->BindTo(fvar); | 4350 fproxy->BindTo(fvar); |
4361 result->Add(factory()->NewExpressionStatement( | 4351 result->Add(factory()->NewExpressionStatement( |
4362 factory()->NewAssignment(fvar_init_op, | 4352 factory()->NewAssignment(fvar_init_op, |
4363 fproxy, | 4353 fproxy, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4430 } | 4420 } |
4431 } | 4421 } |
4432 | 4422 |
4433 Expect(Token::RBRACE, CHECK_OK); | 4423 Expect(Token::RBRACE, CHECK_OK); |
4434 scope_->set_end_position(scanner()->location().end_pos); | 4424 scope_->set_end_position(scanner()->location().end_pos); |
4435 | 4425 |
4436 if (!is_simple_parameter_list) { | 4426 if (!is_simple_parameter_list) { |
4437 DCHECK_NOT_NULL(inner_scope); | 4427 DCHECK_NOT_NULL(inner_scope); |
4438 DCHECK_EQ(body, inner_block->statements()); | 4428 DCHECK_EQ(body, inner_block->statements()); |
4439 scope_->SetLanguageMode(inner_scope->language_mode()); | 4429 scope_->SetLanguageMode(inner_scope->language_mode()); |
4440 Block* init_block = | 4430 Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK); |
4441 BuildParameterInitializationBlock(formal_parameters, CHECK_OK); | |
4442 DCHECK_NOT_NULL(init_block); | 4431 DCHECK_NOT_NULL(init_block); |
4443 | 4432 |
4444 inner_scope->set_end_position(scanner()->location().end_pos); | 4433 inner_scope->set_end_position(scanner()->location().end_pos); |
4445 inner_scope = inner_scope->FinalizeBlockScope(); | 4434 inner_scope = inner_scope->FinalizeBlockScope(); |
4446 if (inner_scope != nullptr) { | 4435 if (inner_scope != nullptr) { |
4447 CheckConflictingVarDeclarations(inner_scope, CHECK_OK); | 4436 CheckConflictingVarDeclarations(inner_scope, CHECK_OK); |
4448 } | 4437 } |
4449 | 4438 |
4450 result->Add(init_block, zone()); | 4439 result->Add(init_block, zone()); |
4451 result->Add(inner_block, zone()); | 4440 result->Add(inner_block, zone()); |
(...skipping 1542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5994 Expression* Parser::SpreadCallNew(Expression* function, | 5983 Expression* Parser::SpreadCallNew(Expression* function, |
5995 ZoneList<v8::internal::Expression*>* args, | 5984 ZoneList<v8::internal::Expression*>* args, |
5996 int pos) { | 5985 int pos) { |
5997 args->InsertAt(0, function, zone()); | 5986 args->InsertAt(0, function, zone()); |
5998 | 5987 |
5999 return factory()->NewCallRuntime( | 5988 return factory()->NewCallRuntime( |
6000 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5989 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
6001 } | 5990 } |
6002 } // namespace internal | 5991 } // namespace internal |
6003 } // namespace v8 | 5992 } // namespace v8 |
OLD | NEW |