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

Unified Diff: src/parser.cc

Issue 1287063004: [es6] Implement default parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix TODO 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index e3e561a31856c1329d998663063e11100ca04db6..a7a31e7173593e67036cf4ffb9de14bb79f2e478 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -916,6 +916,7 @@ Parser::Parser(ParseInfo* info)
set_allow_harmony_sloppy_function(FLAG_harmony_sloppy_function);
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);
@@ -3910,7 +3911,19 @@ void ParserTraits::ParseArrowFunctionFormalParameters(
parser_->scope_->RemoveUnresolved(expr->AsVariableProxy());
}
- AddFormalParameter(parameters, expr, is_rest);
+ Expression* initializer = nullptr;
+ if (!is_rest && parser_->allow_harmony_default_parameters() &&
+ 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
+ ExpressionClassifier init_classifier;
+ initializer =
+ parser_->ParseAssignmentExpression(true, &init_classifier, ok);
+ if (!*ok) return;
+ parser_->ValidateExpression(&init_classifier, ok);
+ if (!*ok) return;
+ parameters->is_simple = false;
+ }
+
+ AddFormalParameter(parameters, expr, initializer, is_rest);
}
@@ -4329,9 +4342,22 @@ Block* Parser::BuildParameterInitializationBlock(
descriptor.declaration_pos = parameter.pattern->position();
descriptor.initialization_pos = parameter.pattern->position();
descriptor.init_op = Token::INIT_LET;
+ Expression* initial_value =
+ 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);
+ initial_value = factory()->NewConditional(
+ condition, parameter.initializer, initial_value,
+ 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(), initial_value);
PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor,
&decl, nullptr, CHECK_OK);
}
@@ -4497,6 +4523,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);
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698