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 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 DCHECK(!info->script().is_null() || info->source_stream() != NULL); | 910 DCHECK(!info->script().is_null() || info->source_stream() != NULL); |
911 set_allow_lazy(info->allow_lazy_parsing()); | 911 set_allow_lazy(info->allow_lazy_parsing()); |
912 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); | 912 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
913 set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules); | 913 set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules); |
914 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions); | 914 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions); |
915 set_allow_harmony_sloppy(FLAG_harmony_sloppy); | 915 set_allow_harmony_sloppy(FLAG_harmony_sloppy); |
916 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); | 916 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); |
917 set_allow_harmony_unicode(FLAG_harmony_unicode); | 917 set_allow_harmony_unicode(FLAG_harmony_unicode); |
918 set_allow_harmony_computed_property_names( | 918 set_allow_harmony_computed_property_names( |
919 FLAG_harmony_computed_property_names); | 919 FLAG_harmony_computed_property_names); |
920 set_allow_harmony_rest_params(FLAG_harmony_rest_parameters); | 920 set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters); |
921 set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls); | 921 set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls); |
922 set_allow_harmony_destructuring(FLAG_harmony_destructuring); | 922 set_allow_harmony_destructuring(FLAG_harmony_destructuring); |
923 set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays); | 923 set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays); |
924 set_allow_harmony_new_target(FLAG_harmony_new_target); | 924 set_allow_harmony_new_target(FLAG_harmony_new_target); |
925 set_allow_strong_mode(FLAG_strong_mode); | 925 set_allow_strong_mode(FLAG_strong_mode); |
926 set_allow_legacy_const(FLAG_legacy_const); | 926 set_allow_legacy_const(FLAG_legacy_const); |
927 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 927 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
928 ++feature) { | 928 ++feature) { |
929 use_counts_[feature] = 0; | 929 use_counts_[feature] = 0; |
930 } | 930 } |
(...skipping 2909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3840 | 3840 |
3841 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 3841 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
3842 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 3842 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); |
3843 } | 3843 } |
3844 | 3844 |
3845 | 3845 |
3846 void ParserTraits::ParseArrowFunctionFormalParameters( | 3846 void ParserTraits::ParseArrowFunctionFormalParameters( |
3847 ParserFormalParameters* parameters, Expression* expr, | 3847 ParserFormalParameters* parameters, Expression* expr, |
3848 const Scanner::Location& params_loc, | 3848 const Scanner::Location& params_loc, |
3849 Scanner::Location* duplicate_loc, bool* ok) { | 3849 Scanner::Location* duplicate_loc, bool* ok) { |
3850 if (parameters->scope->num_parameters() >= Code::kMaxArguments) { | 3850 if (parameters->arity >= Code::kMaxArguments) { |
3851 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); | 3851 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); |
3852 *ok = false; | 3852 *ok = false; |
3853 return; | 3853 return; |
3854 } | 3854 } |
3855 | 3855 |
3856 // ArrowFunctionFormals :: | 3856 // ArrowFunctionFormals :: |
3857 // Binary(Token::COMMA, NonTailArrowFunctionFormals, Tail) | 3857 // Binary(Token::COMMA, NonTailArrowFunctionFormals, Tail) |
3858 // Tail | 3858 // Tail |
3859 // NonTailArrowFunctionFormals :: | 3859 // NonTailArrowFunctionFormals :: |
3860 // Binary(Token::COMMA, NonTailArrowFunctionFormals, VariableProxy) | 3860 // Binary(Token::COMMA, NonTailArrowFunctionFormals, VariableProxy) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3894 | 3894 |
3895 if (expr->IsVariableProxy()) { | 3895 if (expr->IsVariableProxy()) { |
3896 // When the formal parameter was originally seen, it was parsed as a | 3896 // When the formal parameter was originally seen, it was parsed as a |
3897 // VariableProxy and recorded as unresolved in the scope. Here we undo that | 3897 // VariableProxy and recorded as unresolved in the scope. Here we undo that |
3898 // parse-time side-effect for parameters that are single-names (not | 3898 // parse-time side-effect for parameters that are single-names (not |
3899 // patterns; for patterns that happens uniformly in | 3899 // patterns; for patterns that happens uniformly in |
3900 // PatternRewriter::VisitVariableProxy). | 3900 // PatternRewriter::VisitVariableProxy). |
3901 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); | 3901 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); |
3902 } | 3902 } |
3903 | 3903 |
| 3904 ++parameters->arity; |
3904 ExpressionClassifier classifier; | 3905 ExpressionClassifier classifier; |
3905 DeclareFormalParameter(parameters, expr, is_rest, &classifier); | 3906 DeclareFormalParameter(parameters, expr, is_rest, &classifier); |
3906 if (!duplicate_loc->IsValid()) { | 3907 if (!duplicate_loc->IsValid()) { |
3907 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; | 3908 *duplicate_loc = classifier.duplicate_formal_parameter_error().location; |
3908 } | 3909 } |
3909 } | 3910 } |
3910 | 3911 |
3911 | 3912 |
3912 void ParserTraits::ReindexLiterals(const ParserFormalParameters& parameters) { | 3913 void ParserTraits::ReindexLiterals(const ParserFormalParameters& parameters) { |
3913 if (parser_->function_state_->materialized_literal_count() > 0) { | 3914 if (parser_->function_state_->materialized_literal_count() > 0) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3982 Scope* declaration_scope = scope_->DeclarationScope(); | 3983 Scope* declaration_scope = scope_->DeclarationScope(); |
3983 Scope* original_declaration_scope = original_scope_->DeclarationScope(); | 3984 Scope* original_declaration_scope = original_scope_->DeclarationScope(); |
3984 Scope* scope = function_type == FunctionLiteral::DECLARATION && | 3985 Scope* scope = function_type == FunctionLiteral::DECLARATION && |
3985 is_sloppy(language_mode) && !allow_harmony_sloppy() && | 3986 is_sloppy(language_mode) && !allow_harmony_sloppy() && |
3986 (original_scope_ == original_declaration_scope || | 3987 (original_scope_ == original_declaration_scope || |
3987 declaration_scope != original_declaration_scope) | 3988 declaration_scope != original_declaration_scope) |
3988 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind) | 3989 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind) |
3989 : NewScope(scope_, FUNCTION_SCOPE, kind); | 3990 : NewScope(scope_, FUNCTION_SCOPE, kind); |
3990 scope->SetLanguageMode(language_mode); | 3991 scope->SetLanguageMode(language_mode); |
3991 ZoneList<Statement*>* body = NULL; | 3992 ZoneList<Statement*>* body = NULL; |
3992 int arity = 0; | 3993 int arity = -1; |
3993 int materialized_literal_count = -1; | 3994 int materialized_literal_count = -1; |
3994 int expected_property_count = -1; | 3995 int expected_property_count = -1; |
3995 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 3996 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
3996 ExpressionClassifier formals_classifier(&duplicate_finder); | 3997 ExpressionClassifier formals_classifier(&duplicate_finder); |
3997 FunctionLiteral::EagerCompileHint eager_compile_hint = | 3998 FunctionLiteral::EagerCompileHint eager_compile_hint = |
3998 parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile | 3999 parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile |
3999 : FunctionLiteral::kShouldLazyCompile; | 4000 : FunctionLiteral::kShouldLazyCompile; |
4000 bool should_be_used_once_hint = false; | 4001 bool should_be_used_once_hint = false; |
4001 // Parse function. | 4002 // Parse function. |
4002 { | 4003 { |
(...skipping 13 matching lines...) Expand all Loading... |
4016 // expressions. This also marks the FunctionState as a generator. | 4017 // expressions. This also marks the FunctionState as a generator. |
4017 Variable* temp = scope_->NewTemporary( | 4018 Variable* temp = scope_->NewTemporary( |
4018 ast_value_factory()->dot_generator_object_string()); | 4019 ast_value_factory()->dot_generator_object_string()); |
4019 function_state.set_generator_object_variable(temp); | 4020 function_state.set_generator_object_variable(temp); |
4020 } | 4021 } |
4021 | 4022 |
4022 Expect(Token::LPAREN, CHECK_OK); | 4023 Expect(Token::LPAREN, CHECK_OK); |
4023 int start_position = scanner()->location().beg_pos; | 4024 int start_position = scanner()->location().beg_pos; |
4024 scope_->set_start_position(start_position); | 4025 scope_->set_start_position(start_position); |
4025 ParserFormalParameters formals(scope); | 4026 ParserFormalParameters formals(scope); |
4026 arity = ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); | 4027 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); |
| 4028 arity = formals.arity; |
| 4029 DCHECK(arity == formals.params.length()); |
4027 Expect(Token::RPAREN, CHECK_OK); | 4030 Expect(Token::RPAREN, CHECK_OK); |
4028 int formals_end_position = scanner()->location().end_pos; | 4031 int formals_end_position = scanner()->location().end_pos; |
4029 | 4032 |
4030 CheckArityRestrictions(arity, arity_restriction, | 4033 CheckArityRestrictions(arity, arity_restriction, |
4031 formals.has_rest, start_position, | 4034 formals.has_rest, start_position, |
4032 formals_end_position, CHECK_OK); | 4035 formals_end_position, CHECK_OK); |
4033 Expect(Token::LBRACE, CHECK_OK); | 4036 Expect(Token::LBRACE, CHECK_OK); |
4034 | 4037 |
4035 // If we have a named function expression, we add a local variable | 4038 // If we have a named function expression, we add a local variable |
4036 // declaration to the body of the function with the name of the | 4039 // declaration to the body of the function with the name of the |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4305 return if_statement; | 4308 return if_statement; |
4306 } | 4309 } |
4307 | 4310 |
4308 | 4311 |
4309 Block* Parser::BuildParameterInitializationBlock( | 4312 Block* Parser::BuildParameterInitializationBlock( |
4310 const ParserFormalParameters& parameters, bool* ok) { | 4313 const ParserFormalParameters& parameters, bool* ok) { |
4311 DCHECK(!parameters.is_simple); | 4314 DCHECK(!parameters.is_simple); |
4312 DCHECK(scope_->is_function_scope()); | 4315 DCHECK(scope_->is_function_scope()); |
4313 Block* init_block = | 4316 Block* init_block = |
4314 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); | 4317 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); |
4315 for (auto parameter : parameters.params) { | 4318 for (int i = 0; i < parameters.params.length(); ++i) { |
| 4319 auto parameter = parameters.params[i]; |
4316 if (parameter.pattern == nullptr) continue; | 4320 if (parameter.pattern == nullptr) continue; |
4317 DeclarationDescriptor descriptor; | 4321 DeclarationDescriptor descriptor; |
4318 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; | 4322 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; |
4319 descriptor.parser = this; | 4323 descriptor.parser = this; |
4320 descriptor.declaration_scope = scope_; | 4324 descriptor.declaration_scope = scope_; |
4321 descriptor.scope = scope_; | 4325 descriptor.scope = scope_; |
4322 descriptor.mode = LET; | 4326 descriptor.mode = LET; |
4323 descriptor.is_const = false; | 4327 descriptor.is_const = false; |
4324 descriptor.needs_init = true; | 4328 descriptor.needs_init = true; |
4325 descriptor.declaration_pos = parameter.pattern->position(); | 4329 descriptor.declaration_pos = parameter.pattern->position(); |
4326 descriptor.initialization_pos = parameter.pattern->position(); | 4330 descriptor.initialization_pos = parameter.pattern->position(); |
4327 descriptor.init_op = Token::INIT_LET; | 4331 descriptor.init_op = Token::INIT_LET; |
4328 DeclarationParsingResult::Declaration decl( | 4332 DeclarationParsingResult::Declaration decl( |
4329 parameter.pattern, parameter.pattern->position(), | 4333 parameter.pattern, parameter.pattern->position(), |
4330 factory()->NewVariableProxy(parameter.var)); | 4334 factory()->NewVariableProxy(parameters.scope->parameter(i))); |
4331 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, | 4335 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, |
4332 &decl, nullptr, CHECK_OK); | 4336 &decl, nullptr, CHECK_OK); |
4333 } | 4337 } |
4334 return init_block; | 4338 return init_block; |
4335 } | 4339 } |
4336 | 4340 |
4337 | 4341 |
4338 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( | 4342 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
4339 const AstRawString* function_name, int pos, | 4343 const AstRawString* function_name, int pos, |
4340 const ParserFormalParameters& parameters, Variable* fvar, | 4344 const ParserFormalParameters& parameters, Variable* fvar, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4456 NULL, stack_limit_); | 4460 NULL, stack_limit_); |
4457 reusable_preparser_->set_allow_lazy(true); | 4461 reusable_preparser_->set_allow_lazy(true); |
4458 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); | 4462 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); |
4459 SET_ALLOW(natives); | 4463 SET_ALLOW(natives); |
4460 SET_ALLOW(harmony_modules); | 4464 SET_ALLOW(harmony_modules); |
4461 SET_ALLOW(harmony_arrow_functions); | 4465 SET_ALLOW(harmony_arrow_functions); |
4462 SET_ALLOW(harmony_sloppy); | 4466 SET_ALLOW(harmony_sloppy); |
4463 SET_ALLOW(harmony_sloppy_let); | 4467 SET_ALLOW(harmony_sloppy_let); |
4464 SET_ALLOW(harmony_unicode); | 4468 SET_ALLOW(harmony_unicode); |
4465 SET_ALLOW(harmony_computed_property_names); | 4469 SET_ALLOW(harmony_computed_property_names); |
4466 SET_ALLOW(harmony_rest_params); | 4470 SET_ALLOW(harmony_rest_parameters); |
4467 SET_ALLOW(harmony_spreadcalls); | 4471 SET_ALLOW(harmony_spreadcalls); |
4468 SET_ALLOW(harmony_destructuring); | 4472 SET_ALLOW(harmony_destructuring); |
4469 SET_ALLOW(harmony_spread_arrays); | 4473 SET_ALLOW(harmony_spread_arrays); |
4470 SET_ALLOW(harmony_new_target); | 4474 SET_ALLOW(harmony_new_target); |
4471 SET_ALLOW(strong_mode); | 4475 SET_ALLOW(strong_mode); |
4472 #undef SET_ALLOW | 4476 #undef SET_ALLOW |
4473 } | 4477 } |
4474 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 4478 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( |
4475 language_mode(), function_state_->kind(), logger, bookmark); | 4479 language_mode(), function_state_->kind(), logger, bookmark); |
4476 if (pre_parse_timer_ != NULL) { | 4480 if (pre_parse_timer_ != NULL) { |
(...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5982 Expression* Parser::SpreadCallNew(Expression* function, | 5986 Expression* Parser::SpreadCallNew(Expression* function, |
5983 ZoneList<v8::internal::Expression*>* args, | 5987 ZoneList<v8::internal::Expression*>* args, |
5984 int pos) { | 5988 int pos) { |
5985 args->InsertAt(0, function, zone()); | 5989 args->InsertAt(0, function, zone()); |
5986 | 5990 |
5987 return factory()->NewCallRuntime( | 5991 return factory()->NewCallRuntime( |
5988 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5992 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
5989 } | 5993 } |
5990 } // namespace internal | 5994 } // namespace internal |
5991 } // namespace v8 | 5995 } // namespace v8 |
OLD | NEW |