Chromium Code Reviews| Index: src/parser.cc |
| diff --git a/src/parser.cc b/src/parser.cc |
| index 45202cb3a82b922c7d487061cfff03578cc3a3c9..bfe84cb1f4a0d46da2da8a7cc60d8db1aae37744 100644 |
| --- a/src/parser.cc |
| +++ b/src/parser.cc |
| @@ -914,6 +914,7 @@ Parser::Parser(ParseInfo* info) |
| set_allow_harmony_sloppy(FLAG_harmony_sloppy); |
| set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let); |
| set_allow_harmony_rest_parameters(FLAG_harmony_rest_parameters); |
| + set_allow_harmony_default_parameters(FLAG_harmony_default_parameters); |
| set_allow_harmony_spreadcalls(FLAG_harmony_spreadcalls); |
| set_allow_harmony_destructuring(FLAG_harmony_destructuring); |
| set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays); |
| @@ -1196,8 +1197,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info, |
| if (ok) ok = Check(Token::RPAREN); |
| } else { |
| // BindingIdentifier |
| - const bool is_rest = false; |
| - ParseFormalParameter(is_rest, &formals, &formals_classifier, &ok); |
| + ParseFormalParameter(&formals, &formals_classifier, &ok); |
| if (ok) { |
| DeclareFormalParameter( |
| formals.scope, formals.at(0), formals.is_simple, |
| @@ -3905,7 +3905,8 @@ void ParserTraits::ParseArrowFunctionFormalParameters( |
| parser_->scope_->RemoveUnresolved(expr->AsVariableProxy()); |
| } |
| - AddFormalParameter(parameters, expr, is_rest); |
| + // TODO(rossberg): allow initializers |
|
rossberg
2015/08/12 15:20:27
Need to come up with a test that actually triggers
|
| + AddFormalParameter(parameters, expr, nullptr, is_rest); |
| } |
| @@ -4324,9 +4325,21 @@ Block* Parser::BuildParameterInitializationBlock( |
| descriptor.declaration_pos = parameter.pattern->position(); |
| descriptor.initialization_pos = parameter.pattern->position(); |
| descriptor.init_op = Token::INIT_LET; |
| + 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
|
| + factory()->NewVariableProxy(parameters.scope->parameter(i)); |
| + if (parameter.initializer != nullptr) { |
| + // IS_UNDEFINED($param) ? initializer : $param |
| + auto condition = factory()->NewCompareOperation( |
| + Token::EQ_STRICT, |
| + factory()->NewVariableProxy(parameters.scope->parameter(i)), |
| + factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), |
| + RelocInfo::kNoPosition); |
| + param = factory()->NewConditional( |
| + condition, parameter.initializer, param, RelocInfo::kNoPosition); |
| + descriptor.initialization_pos = parameter.initializer->position(); |
| + } |
| DeclarationParsingResult::Declaration decl( |
| - parameter.pattern, parameter.pattern->position(), |
| - factory()->NewVariableProxy(parameters.scope->parameter(i))); |
| + 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.
|
| PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor, |
| &decl, nullptr, CHECK_OK); |
| } |
| @@ -4492,6 +4505,7 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser( |
| SET_ALLOW(harmony_sloppy); |
| SET_ALLOW(harmony_sloppy_let); |
| SET_ALLOW(harmony_rest_parameters); |
| + SET_ALLOW(harmony_default_parameters); |
| SET_ALLOW(harmony_spreadcalls); |
| SET_ALLOW(harmony_destructuring); |
| SET_ALLOW(harmony_spread_arrays); |