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

Unified Diff: src/preparser.h

Issue 1104223002: [es6] implement optional parameters via desugaring (with scoping) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add a debugger test Created 5 years, 7 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.cc ('k') | src/preparser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 8184bd8d5f5af2bc93a872c80c71ab3b7cce8001..baf8e36a41c978e2076ca9f62ecd96fd6eb2068c 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -84,6 +84,7 @@ class ParserBase : public Traits {
public:
// Shorten type names defined by Traits.
typedef typename Traits::Type::Expression ExpressionT;
+ typedef typename Traits::Type::ExpressionList ExpressionListT;
typedef typename Traits::Type::Identifier IdentifierT;
typedef typename Traits::Type::FormalParameter FormalParameterT;
typedef typename Traits::Type::FormalParameterScope FormalParameterScopeT;
@@ -764,11 +765,14 @@ class ParserBase : public Traits {
bool* ok);
void ParseFormalParameter(FormalParameterScopeT* scope,
- FormalParameterErrorLocations* locs, bool is_rest,
- bool* ok);
+ FormalParameterErrorLocations* locs,
+ ExpressionT* initializer, bool* has_initializer,
+ bool is_rest, bool* ok);
int ParseFormalParameterList(FormalParameterScopeT* scope,
FormalParameterErrorLocations* locs,
- bool* has_rest, bool* ok);
+ ExpressionListT initializers,
+ bool* has_initializers, bool* has_rest,
+ bool* ok);
void CheckArityRestrictions(
int param_count, FunctionLiteral::ArityRestriction arity_restriction,
int formals_start_pos, int formals_end_pos, bool* ok);
@@ -1724,8 +1728,8 @@ class PreParserTraits {
}
V8_INLINE bool DeclareFormalParameter(DuplicateFinder* scope,
- PreParserIdentifier param,
- bool is_rest);
+ PreParserIdentifier param, bool is_rest,
+ int pos);
void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {}
@@ -1916,7 +1920,7 @@ PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function,
bool PreParserTraits::DeclareFormalParameter(
DuplicateFinder* duplicate_finder, PreParserIdentifier current_identifier,
- bool is_rest) {
+ bool is_rest, int pos) {
return pre_parser_->scanner()->FindSymbol(duplicate_finder, 1) != 0;
}
@@ -3468,14 +3472,25 @@ ParserBase<Traits>::ParseMemberExpressionContinuation(
template <class Traits>
void ParserBase<Traits>::ParseFormalParameter(
FormalParameterScopeT* scope, FormalParameterErrorLocations* locs,
- bool is_rest, bool* ok) {
+ ExpressionT* initializer, bool* has_initializer, bool is_rest, bool* ok) {
// FormalParameter[Yield,GeneratorParameter] :
// BindingElement[?Yield, ?GeneratorParameter]
bool is_strict_reserved;
+ int pos = peek_position();
IdentifierT name =
ParseIdentifierOrStrictReservedWord(&is_strict_reserved, ok);
if (!*ok) return;
+ if (Check(Token::ASSIGN)) {
+ // Optional argument initializer
+ // let formalName = IS_UNDEFINED(arguments[i]) ? initializer : arguments[i];
+ static const bool accept_IN = true;
+ ExpressionClassifier classifier;
+ *initializer = ParseAssignmentExpression(accept_IN, &classifier, ok);
+ if (!*ok) return;
+ *has_initializer = true;
+ }
+
// Store locations for possible future error reports.
if (!locs->eval_or_arguments.IsValid() && this->IsEvalOrArguments(name)) {
locs->eval_or_arguments = scanner()->location();
@@ -3486,7 +3501,7 @@ void ParserBase<Traits>::ParseFormalParameter(
if (!locs->reserved.IsValid() && is_strict_reserved) {
locs->reserved = scanner()->location();
}
- bool was_declared = Traits::DeclareFormalParameter(scope, name, is_rest);
+ bool was_declared = Traits::DeclareFormalParameter(scope, name, is_rest, pos);
if (!locs->duplicate.IsValid() && was_declared) {
locs->duplicate = scanner()->location();
}
@@ -3496,7 +3511,8 @@ void ParserBase<Traits>::ParseFormalParameter(
template <class Traits>
int ParserBase<Traits>::ParseFormalParameterList(
FormalParameterScopeT* scope, FormalParameterErrorLocations* locs,
- bool* is_rest, bool* ok) {
+ ExpressionListT initializers, bool* has_initializers, bool* is_rest,
+ bool* ok) {
// FormalParameters[Yield,GeneratorParameter] :
// [empty]
// FormalParameterList[?Yield, ?GeneratorParameter]
@@ -3512,17 +3528,26 @@ int ParserBase<Traits>::ParseFormalParameterList(
// FormalParameter[?Yield,?GeneratorParameter]
int parameter_count = 0;
-
+ DCHECK(scope_->is_function_scope());
if (peek() != Token::RPAREN) {
do {
+ Scope* param_scope = NewScope(scope_, BLOCK_SCOPE);
+ param_scope->set_start_position(scanner()->peek_location().beg_pos);
+ BlockState param_state(&scope_, param_scope);
if (++parameter_count > Code::kMaxArguments) {
ReportMessage("too_many_parameters");
*ok = false;
return -1;
}
+ bool has_initializer = false;
+ ExpressionT initializer = this->EmptyExpression();
*is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS);
- ParseFormalParameter(scope, locs, *is_rest, ok);
+ ParseFormalParameter(scope, locs, &initializer, &has_initializer,
+ *is_rest, ok);
+ param_scope->set_start_position(scanner()->location().end_pos);
if (!*ok) return -1;
+ initializers->Add(initializer, zone());
+ if (has_initializer) *has_initializers = true;
} while (!*is_rest && Check(Token::COMMA));
if (*is_rest && peek() == Token::COMMA) {
@@ -3586,7 +3611,10 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
typename Traits::Type::Factory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, scope,
kArrowFunction, &function_factory);
-
+ DCHECK(scope->is_arrow_scope());
+ Scope* function_body = NewScope(scope, FUNCTION_BODY_SCOPE);
+ DCHECK_EQ(scope->function_body(), function_body);
+ BlockState function_body_state(&scope_, function_body);
if (peek() == Token::ARROW) {
BindingPatternUnexpectedToken(classifier);
}
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698