Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: src/parser.cc

Issue 1287063004: [es6] Implement default parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | src/preparser.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 // Even though we were passed ParseInfo, we should not store it in 907 // Even though we were passed ParseInfo, we should not store it in
908 // Parser - this makes sure that Isolate is not accidentally accessed via 908 // Parser - this makes sure that Isolate is not accidentally accessed via
909 // ParseInfo during background parsing. 909 // ParseInfo during background parsing.
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_arrow_functions(FLAG_harmony_arrow_functions); 913 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions);
914 set_allow_harmony_sloppy(FLAG_harmony_sloppy); 914 set_allow_harmony_sloppy(FLAG_harmony_sloppy);
915 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); 915 set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let);
916 set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters); 916 set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters);
917 set_allow_harmony_default_parameters(FLAG_harmony_default_parameters);
917 set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls); 918 set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls);
918 set_allow_harmony_destructuring(FLAG_harmony_destructuring); 919 set_allow_harmony_destructuring(FLAG_harmony_destructuring);
919 set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays); 920 set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays);
920 set_allow_harmony_new_target(FLAG_harmony_new_target); 921 set_allow_harmony_new_target(FLAG_harmony_new_target);
921 set_allow_strong_mode(FLAG_strong_mode); 922 set_allow_strong_mode(FLAG_strong_mode);
922 set_allow_legacy_const(FLAG_legacy_const); 923 set_allow_legacy_const(FLAG_legacy_const);
923 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 924 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
924 ++feature) { 925 ++feature) {
925 use_counts_[feature] = 0; 926 use_counts_[feature] = 0;
926 } 927 }
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 // Parsing patterns as variable reference expression creates 1190 // Parsing patterns as variable reference expression creates
1190 // NewUnresolved references in current scope. Entrer arrow function 1191 // NewUnresolved references in current scope. Entrer arrow function
1191 // scope for formal parameter parsing. 1192 // scope for formal parameter parsing.
1192 BlockState block_state(&scope_, scope); 1193 BlockState block_state(&scope_, scope);
1193 if (Check(Token::LPAREN)) { 1194 if (Check(Token::LPAREN)) {
1194 // '(' StrictFormalParameters ')' 1195 // '(' StrictFormalParameters ')'
1195 ParseFormalParameterList(&formals, &formals_classifier, &ok); 1196 ParseFormalParameterList(&formals, &formals_classifier, &ok);
1196 if (ok) ok = Check(Token::RPAREN); 1197 if (ok) ok = Check(Token::RPAREN);
1197 } else { 1198 } else {
1198 // BindingIdentifier 1199 // BindingIdentifier
1199 const bool is_rest = false; 1200 ParseFormalParameter(&formals, &formals_classifier, &ok);
1200 ParseFormalParameter(is_rest, &formals, &formals_classifier, &ok);
1201 if (ok) { 1201 if (ok) {
1202 DeclareFormalParameter( 1202 DeclareFormalParameter(
1203 formals.scope, formals.at(0), formals.is_simple, 1203 formals.scope, formals.at(0), formals.is_simple,
1204 &formals_classifier); 1204 &formals_classifier);
1205 } 1205 }
1206 } 1206 }
1207 } 1207 }
1208 1208
1209 if (ok) { 1209 if (ok) {
1210 checkpoint.Restore(&formals.materialized_literals_count); 1210 checkpoint.Restore(&formals.materialized_literals_count);
(...skipping 2687 matching lines...) Expand 10 before | Expand all | Expand 10 after
3898 3898
3899 if (expr->IsVariableProxy()) { 3899 if (expr->IsVariableProxy()) {
3900 // When the formal parameter was originally seen, it was parsed as a 3900 // When the formal parameter was originally seen, it was parsed as a
3901 // VariableProxy and recorded as unresolved in the scope. Here we undo that 3901 // VariableProxy and recorded as unresolved in the scope. Here we undo that
3902 // parse-time side-effect for parameters that are single-names (not 3902 // parse-time side-effect for parameters that are single-names (not
3903 // patterns; for patterns that happens uniformly in 3903 // patterns; for patterns that happens uniformly in
3904 // PatternRewriter::VisitVariableProxy). 3904 // PatternRewriter::VisitVariableProxy).
3905 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); 3905 parser_->scope_->RemoveUnresolved(expr->AsVariableProxy());
3906 } 3906 }
3907 3907
3908 AddFormalParameter(parameters, expr, is_rest); 3908 // TODO(rossberg): allow initializers
rossberg 2015/08/12 15:20:27 Need to come up with a test that actually triggers
3909 AddFormalParameter(parameters, expr, nullptr, is_rest);
3909 } 3910 }
3910 3911
3911 3912
3912 void ParserTraits::ParseArrowFunctionFormalParameterList( 3913 void ParserTraits::ParseArrowFunctionFormalParameterList(
3913 ParserFormalParameters* parameters, Expression* expr, 3914 ParserFormalParameters* parameters, Expression* expr,
3914 const Scanner::Location& params_loc, 3915 const Scanner::Location& params_loc,
3915 Scanner::Location* duplicate_loc, bool* ok) { 3916 Scanner::Location* duplicate_loc, bool* ok) {
3916 ParseArrowFunctionFormalParameters(parameters, expr, params_loc, 3917 ParseArrowFunctionFormalParameters(parameters, expr, params_loc,
3917 duplicate_loc, ok); 3918 duplicate_loc, ok);
3918 if (!*ok) return; 3919 if (!*ok) return;
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
4317 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER; 4318 descriptor.declaration_kind = DeclarationDescriptor::PARAMETER;
4318 descriptor.parser = this; 4319 descriptor.parser = this;
4319 descriptor.declaration_scope = scope_; 4320 descriptor.declaration_scope = scope_;
4320 descriptor.scope = scope_; 4321 descriptor.scope = scope_;
4321 descriptor.mode = LET; 4322 descriptor.mode = LET;
4322 descriptor.is_const = false; 4323 descriptor.is_const = false;
4323 descriptor.needs_init = true; 4324 descriptor.needs_init = true;
4324 descriptor.declaration_pos = parameter.pattern->position(); 4325 descriptor.declaration_pos = parameter.pattern->position();
4325 descriptor.initialization_pos = parameter.pattern->position(); 4326 descriptor.initialization_pos = parameter.pattern->position();
4326 descriptor.init_op = Token::INIT_LET; 4327 descriptor.init_op = Token::INIT_LET;
4328 Expression* param =
adamk 2015/08/12 18:22:59 I think this should be called "initializer"
rossberg 2015/08/13 11:06:36 That would confuse it with the actual initializer
4329 factory()->NewVariableProxy(parameters.scope->parameter(i));
4330 if (parameter.initializer != nullptr) {
4331 // IS_UNDEFINED($param) ? initializer : $param
4332 auto condition = factory()->NewCompareOperation(
4333 Token::EQ_STRICT,
4334 factory()->NewVariableProxy(parameters.scope->parameter(i)),
4335 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition),
4336 RelocInfo::kNoPosition);
4337 param = factory()->NewConditional(
4338 condition, parameter.initializer, param, RelocInfo::kNoPosition);
4339 descriptor.initialization_pos = parameter.initializer->position();
4340 }
4327 DeclarationParsingResult::Declaration decl( 4341 DeclarationParsingResult::Declaration decl(
4328 parameter.pattern, parameter.pattern->position(), 4342 parameter.pattern, parameter.pattern->position(), param);
adamk 2015/08/12 18:22:59 The above-suggested renaming would make the callsi
rossberg 2015/08/13 11:06:36 Done.
4329 factory()->NewVariableProxy(parameters.scope->parameter(i)));
4330 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, 4343 PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor,
4331 &decl, nullptr, CHECK_OK); 4344 &decl, nullptr, CHECK_OK);
4332 } 4345 }
4333 return init_block; 4346 return init_block;
4334 } 4347 }
4335 4348
4336 4349
4337 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( 4350 ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
4338 const AstRawString* function_name, int pos, 4351 const AstRawString* function_name, int pos,
4339 const ParserFormalParameters& parameters, FunctionKind kind, 4352 const ParserFormalParameters& parameters, FunctionKind kind,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
4485 if (reusable_preparser_ == NULL) { 4498 if (reusable_preparser_ == NULL) {
4486 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), 4499 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(),
4487 NULL, stack_limit_); 4500 NULL, stack_limit_);
4488 reusable_preparser_->set_allow_lazy(true); 4501 reusable_preparser_->set_allow_lazy(true);
4489 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); 4502 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
4490 SET_ALLOW(natives); 4503 SET_ALLOW(natives);
4491 SET_ALLOW(harmony_arrow_functions); 4504 SET_ALLOW(harmony_arrow_functions);
4492 SET_ALLOW(harmony_sloppy); 4505 SET_ALLOW(harmony_sloppy);
4493 SET_ALLOW(harmony_sloppy_let); 4506 SET_ALLOW(harmony_sloppy_let);
4494 SET_ALLOW(harmony_rest_parameters); 4507 SET_ALLOW(harmony_rest_parameters);
4508 SET_ALLOW(harmony_default_parameters);
4495 SET_ALLOW(harmony_spreadcalls); 4509 SET_ALLOW(harmony_spreadcalls);
4496 SET_ALLOW(harmony_destructuring); 4510 SET_ALLOW(harmony_destructuring);
4497 SET_ALLOW(harmony_spread_arrays); 4511 SET_ALLOW(harmony_spread_arrays);
4498 SET_ALLOW(harmony_new_target); 4512 SET_ALLOW(harmony_new_target);
4499 SET_ALLOW(strong_mode); 4513 SET_ALLOW(strong_mode);
4500 #undef SET_ALLOW 4514 #undef SET_ALLOW
4501 } 4515 }
4502 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4516 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4503 language_mode(), function_state_->kind(), logger, bookmark); 4517 language_mode(), function_state_->kind(), logger, bookmark);
4504 if (pre_parse_timer_ != NULL) { 4518 if (pre_parse_timer_ != NULL) {
(...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after
6010 Expression* Parser::SpreadCallNew(Expression* function, 6024 Expression* Parser::SpreadCallNew(Expression* function,
6011 ZoneList<v8::internal::Expression*>* args, 6025 ZoneList<v8::internal::Expression*>* args,
6012 int pos) { 6026 int pos) {
6013 args->InsertAt(0, function, zone()); 6027 args->InsertAt(0, function, zone());
6014 6028
6015 return factory()->NewCallRuntime( 6029 return factory()->NewCallRuntime(
6016 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 6030 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
6017 } 6031 }
6018 } // namespace internal 6032 } // namespace internal
6019 } // namespace v8 6033 } // namespace v8
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | src/preparser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698