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

Unified Diff: src/preparser.cc

Issue 1053773006: [es6] implement default/optional parameters (WIP / comments) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Experimental not-quite-TDZ support Created 5 years, 8 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/preparser.h ('k') | src/scopes.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index a02305ffd206bb0a0b5097e9961685cd52c7d5b2..20152caed6a8e4efc001ac5f58c46cfc47c59961 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -929,9 +929,11 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
arity_restriction != FunctionLiteral::SETTER_ARITY);
while (!done) {
bool is_strict_reserved = false;
+ int rest_pos;
is_rest = peek() == Token::ELLIPSIS && allow_harmony_rest_params();
if (is_rest) {
Consume(Token::ELLIPSIS);
+ rest_pos = position();
}
Identifier param_name =
@@ -952,6 +954,36 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
dupe_loc = scanner()->location();
}
+ if (peek() == Token::ASSIGN) {
+ Consume(Token::ASSIGN);
+ static const bool accept_IN = true;
+ ExpressionT defaultValue = ParseAssignmentExpression(accept_IN, CHECK_OK);
+ if (is_rest) {
+ ReportMessageAt(
+ Scanner::Location(rest_pos, scanner()->location().end_pos),
+ "rest_param_default");
+ *ok = false;
+ return Expression::Default();
+ }
+ // Default value is not needed in pre-parser.
+ USE(defaultValue);
+ }
+
+ if (peek() == Token::ASSIGN) {
+ Consume(Token::ASSIGN);
+ static const bool accept_IN = true;
+ ExpressionT defaultValue = ParseAssignmentExpression(accept_IN, CHECK_OK);
+ if (is_rest) {
+ ReportMessageAt(
+ Scanner::Location(rest_pos, scanner()->location().end_pos),
+ "rest_param_default");
+ *ok = false;
+ return Expression::Default();
+ }
+ // Default value is not needed in pre-parser.
+ USE(defaultValue);
+ }
+
if (arity_restriction == FunctionLiteral::SETTER_ARITY) break;
done = (peek() == Token::RPAREN);
if (!done) {
« no previous file with comments | « src/preparser.h ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698