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/parser.h" | 5 #include "src/parser.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 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
909 // Parser - this makes sure that Isolate is not accidentally accessed via | 909 // Parser - this makes sure that Isolate is not accidentally accessed via |
910 // ParseInfo during background parsing. | 910 // ParseInfo during background parsing. |
911 DCHECK(!info->script().is_null() || info->source_stream() != NULL); | 911 DCHECK(!info->script().is_null() || info->source_stream() != NULL); |
912 set_allow_lazy(info->allow_lazy_parsing()); | 912 set_allow_lazy(info->allow_lazy_parsing()); |
913 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); | 913 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
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_function(FLAG_harmony_sloppy_function); | 916 set_allow_harmony_sloppy_function(FLAG_harmony_sloppy_function); |
917 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); | 917 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); |
918 set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters); | 918 set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters); |
919 set_allow_harmony_default_parameters(FLAG_harmony_default_parameters); | |
919 set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls); | 920 set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls); |
920 set_allow_harmony_destructuring(FLAG_harmony_destructuring); | 921 set_allow_harmony_destructuring(FLAG_harmony_destructuring); |
921 set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays); | 922 set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays); |
922 set_allow_harmony_new_target(FLAG_harmony_new_target); | 923 set_allow_harmony_new_target(FLAG_harmony_new_target); |
923 set_allow_strong_mode(FLAG_strong_mode); | 924 set_allow_strong_mode(FLAG_strong_mode); |
924 set_allow_legacy_const(FLAG_legacy_const); | 925 set_allow_legacy_const(FLAG_legacy_const); |
925 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 926 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
926 ++feature) { | 927 ++feature) { |
927 use_counts_[feature] = 0; | 928 use_counts_[feature] = 0; |
928 } | 929 } |
(...skipping 2974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3903 | 3904 |
3904 if (expr->IsVariableProxy()) { | 3905 if (expr->IsVariableProxy()) { |
3905 // When the formal parameter was originally seen, it was parsed as a | 3906 // When the formal parameter was originally seen, it was parsed as a |
3906 // VariableProxy and recorded as unresolved in the scope. Here we undo that | 3907 // VariableProxy and recorded as unresolved in the scope. Here we undo that |
3907 // parse-time side-effect for parameters that are single-names (not | 3908 // parse-time side-effect for parameters that are single-names (not |
3908 // patterns; for patterns that happens uniformly in | 3909 // patterns; for patterns that happens uniformly in |
3909 // PatternRewriter::VisitVariableProxy). | 3910 // PatternRewriter::VisitVariableProxy). |
3910 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); | 3911 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); |
3911 } | 3912 } |
3912 | 3913 |
3913 AddFormalParameter(parameters, expr, is_rest); | 3914 Expression* initializer = nullptr; |
3915 if (!is_rest && parser_->allow_harmony_default_parameters() && | |
3916 parser_->Check(Token::ASSIGN)) { | |
wingo
2015/08/24 14:10:10
How on earth does this work? This function is cal
rossberg
2015/08/24 14:18:15
You are right, it doesn't make sense. 8} Not sure
| |
3917 ExpressionClassifier init_classifier; | |
3918 initializer = | |
3919 parser_->ParseAssignmentExpression(true, &init_classifier, ok); | |
3920 if (!*ok) return; | |
3921 parser_->ValidateExpression(&init_classifier, ok); | |
3922 if (!*ok) return; | |
3923 parameters->is_simple = false; | |
3924 } | |
3925 | |
3926 AddFormalParameter(parameters, expr, initializer, is_rest); | |
3914 } | 3927 } |
3915 | 3928 |
3916 | 3929 |
3917 void ParserTraits::ParseArrowFunctionFormalParameterList( | 3930 void ParserTraits::ParseArrowFunctionFormalParameterList( |
3918 ParserFormalParameters* parameters, Expression* expr, | 3931 ParserFormalParameters* parameters, Expression* expr, |
3919 const Scanner::Location& params_loc, | 3932 const Scanner::Location& params_loc, |
3920 Scanner::Location* duplicate_loc, bool* ok) { | 3933 Scanner::Location* duplicate_loc, bool* ok) { |
3921 ParseArrowFunctionFormalParameters(parameters, expr, params_loc, | 3934 ParseArrowFunctionFormalParameters(parameters, expr, params_loc, |
3922 duplicate_loc, ok); | 3935 duplicate_loc, ok); |
3923 if (!*ok) return; | 3936 if (!*ok) return; |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4322 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; | 4335 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; |
4323 descriptor.parser = this; | 4336 descriptor.parser = this; |
4324 descriptor.declaration_scope = scope_; | 4337 descriptor.declaration_scope = scope_; |
4325 descriptor.scope = scope_; | 4338 descriptor.scope = scope_; |
4326 descriptor.mode = LET; | 4339 descriptor.mode = LET; |
4327 descriptor.is_const = false; | 4340 descriptor.is_const = false; |
4328 descriptor.needs_init = true; | 4341 descriptor.needs_init = true; |
4329 descriptor.declaration_pos = parameter.pattern->position(); | 4342 descriptor.declaration_pos = parameter.pattern->position(); |
4330 descriptor.initialization_pos = parameter.pattern->position(); | 4343 descriptor.initialization_pos = parameter.pattern->position(); |
4331 descriptor.init_op = Token::INIT_LET; | 4344 descriptor.init_op = Token::INIT_LET; |
4345 Expression* initial_value = | |
4346 factory()->NewVariableProxy(parameters.scope->parameter(i)); | |
4347 if (parameter.initializer != nullptr) { | |
4348 // IS_UNDEFINED($param) ? initializer : $param | |
4349 auto condition = factory()->NewCompareOperation( | |
4350 Token::EQ_STRICT, | |
4351 factory()->NewVariableProxy(parameters.scope->parameter(i)), | |
4352 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), | |
4353 RelocInfo::kNoPosition); | |
4354 initial_value = factory()->NewConditional( | |
4355 condition, parameter.initializer, initial_value, | |
4356 RelocInfo::kNoPosition); | |
4357 descriptor.initialization_pos = parameter.initializer->position(); | |
4358 } | |
4332 DeclarationParsingResult::Declaration decl( | 4359 DeclarationParsingResult::Declaration decl( |
4333 parameter.pattern, parameter.pattern->position(), | 4360 parameter.pattern, parameter.pattern->position(), initial_value); |
4334 factory()->NewVariableProxy(parameters.scope->parameter(i))); | |
4335 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, | 4361 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, |
4336 &decl, nullptr, CHECK_OK); | 4362 &decl, nullptr, CHECK_OK); |
4337 } | 4363 } |
4338 return init_block; | 4364 return init_block; |
4339 } | 4365 } |
4340 | 4366 |
4341 | 4367 |
4342 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( | 4368 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
4343 const AstRawString* function_name, int pos, | 4369 const AstRawString* function_name, int pos, |
4344 const ParserFormalParameters& parameters, FunctionKind kind, | 4370 const ParserFormalParameters& parameters, FunctionKind kind, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4490 if (reusable_preparser_ == NULL) { | 4516 if (reusable_preparser_ == NULL) { |
4491 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), | 4517 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), |
4492 NULL, stack_limit_); | 4518 NULL, stack_limit_); |
4493 reusable_preparser_->set_allow_lazy(true); | 4519 reusable_preparser_->set_allow_lazy(true); |
4494 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); | 4520 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); |
4495 SET_ALLOW(natives); | 4521 SET_ALLOW(natives); |
4496 SET_ALLOW(harmony_arrow_functions); | 4522 SET_ALLOW(harmony_arrow_functions); |
4497 SET_ALLOW(harmony_sloppy); | 4523 SET_ALLOW(harmony_sloppy); |
4498 SET_ALLOW(harmony_sloppy_let); | 4524 SET_ALLOW(harmony_sloppy_let); |
4499 SET_ALLOW(harmony_rest_parameters); | 4525 SET_ALLOW(harmony_rest_parameters); |
4526 SET_ALLOW(harmony_default_parameters); | |
4500 SET_ALLOW(harmony_spreadcalls); | 4527 SET_ALLOW(harmony_spreadcalls); |
4501 SET_ALLOW(harmony_destructuring); | 4528 SET_ALLOW(harmony_destructuring); |
4502 SET_ALLOW(harmony_spread_arrays); | 4529 SET_ALLOW(harmony_spread_arrays); |
4503 SET_ALLOW(harmony_new_target); | 4530 SET_ALLOW(harmony_new_target); |
4504 SET_ALLOW(strong_mode); | 4531 SET_ALLOW(strong_mode); |
4505 #undef SET_ALLOW | 4532 #undef SET_ALLOW |
4506 } | 4533 } |
4507 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 4534 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( |
4508 language_mode(), function_state_->kind(), logger, bookmark); | 4535 language_mode(), function_state_->kind(), logger, bookmark); |
4509 if (pre_parse_timer_ != NULL) { | 4536 if (pre_parse_timer_ != NULL) { |
(...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6015 Expression* Parser::SpreadCallNew(Expression* function, | 6042 Expression* Parser::SpreadCallNew(Expression* function, |
6016 ZoneList<v8::internal::Expression*>* args, | 6043 ZoneList<v8::internal::Expression*>* args, |
6017 int pos) { | 6044 int pos) { |
6018 args->InsertAt(0, function, zone()); | 6045 args->InsertAt(0, function, zone()); |
6019 | 6046 |
6020 return factory()->NewCallRuntime( | 6047 return factory()->NewCallRuntime( |
6021 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 6048 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
6022 } | 6049 } |
6023 } // namespace internal | 6050 } // namespace internal |
6024 } // namespace v8 | 6051 } // namespace v8 |
OLD | NEW |