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

Unified Diff: src/parser.cc

Issue 1189743003: [destructuring] Implement parameter pattern matching. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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/ppc/full-codegen-ppc.cc » ('j') | src/scopes.h » ('J')
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 41a5d36b04ca84962ac1e40fa9c44b4c32e351e3..44a236c2290a0a22a4989ec24ce42df81f64fcd2 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -3811,20 +3811,13 @@ void ParserTraits::ParseArrowFunctionFormalParameters(
expr = expr->AsSpread()->expression();
}
- if (!expr->IsVariableProxy()) {
- // TODO(dslomov): support pattern desugaring
- return;
+ if (expr->IsVariableProxy()) {
+ // When the formal parameter was originally seen, it was parsed as a
+ // VariableProxy and recorded as unresolved in the scope. Here we undo that
+ // parse-time side-effect for parameters that are single-names (not
+ // patterns).
+ parser_->scope_->RemoveUnresolved(expr->AsVariableProxy());
}
- DCHECK(!expr->AsVariableProxy()->is_this());
-
- const AstRawString* raw_name = expr->AsVariableProxy()->raw_name();
- Scanner::Location param_location(expr->position(),
- expr->position() + raw_name->length());
-
- // When the formal parameter was originally seen, it was parsed as a
- // VariableProxy and recorded as unresolved in the scope. Here we undo that
- // parse-time side-effect.
- parser_->scope_->RemoveUnresolved(expr->AsVariableProxy());
ExpressionClassifier classifier;
DeclareFormalParameter(scope, expr, &classifier, *has_rest);
@@ -4217,6 +4210,36 @@ Statement* Parser::BuildAssertIsCoercible(Variable* var) {
}
+Block* Parser::BuildParameterInitializationBlock(bool* ok) {
+ DCHECK(scope_->is_function_scope());
+ Block* init_block = nullptr;
+ for (int i = 0; i < scope_->num_parameters(); i++) {
+ auto parameter = scope_->parameter(i);
+ if (parameter.pattern == nullptr) continue;
+ if (init_block == nullptr) {
+ init_block = factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition);
+ }
+
+ DeclarationDescriptor descriptor;
+ descriptor.parser = this;
+ descriptor.declaration_scope = scope_;
+ descriptor.scope = scope_;
+ descriptor.mode = VAR;
rossberg 2015/06/16 17:02:12 Shouldn't this be LET?
caitp (gmail) 2015/06/16 19:08:09 I think this is VAR unless computed property names
Dmitry Lomov (no reviews) 2015/06/19 15:25:14 Changing to LET - it is always LET for patterns si
+ descriptor.is_const = false;
+ descriptor.needs_init = false;
+ descriptor.declaration_pos = parameter.pattern->position();
+ descriptor.initialization_pos = parameter.pattern->position();
+ descriptor.init_op = Token::ASSIGN;
+ DeclarationParsingResult::Declaration decl(
+ parameter.pattern, parameter.pattern->position(),
+ factory()->NewVariableProxy(parameter.var));
+ PatternRewriter::DeclareAndInitializeVariables(init_block, &descriptor,
+ &decl, nullptr, CHECK_OK);
+ }
+ return init_block;
+}
+
+
ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
const AstRawString* function_name, int pos, Variable* fvar,
Token::Value fvar_init_op, FunctionKind kind, bool* ok) {
@@ -4242,6 +4265,12 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
AddAssertIsConstruct(body, pos);
}
+
+ auto init_block = BuildParameterInitializationBlock(CHECK_OK);
+ if (init_block != nullptr) {
+ body->Add(init_block, zone());
+ }
+
// For generators, allocate and yield an iterator on function entry.
if (IsGeneratorFunction(kind)) {
ZoneList<Expression*>* arguments =
« no previous file with comments | « src/parser.h ('k') | src/ppc/full-codegen-ppc.cc » ('j') | src/scopes.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698