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

Unified Diff: src/scopes.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
Index: src/scopes.cc
diff --git a/src/scopes.cc b/src/scopes.cc
index 63ae7ec1099627c187043ac2cb62e6e4d270f131..9b640d3eb9b654741e185b02284ad22afb4922d2 100644
--- a/src/scopes.cc
+++ b/src/scopes.cc
@@ -459,8 +459,9 @@ Variable* Scope::Lookup(const AstRawString* name) {
}
-Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode,
- bool is_rest, bool* is_duplicate) {
+Variable* Scope::DeclareParameter(const AstRawString* name, Expression* pattern,
+ VariableMode mode, bool is_rest,
+ bool* is_duplicate) {
DCHECK(!already_resolved());
DCHECK(is_function_scope());
Variable* var = variables_.Declare(this, name, mode, Variable::NORMAL,
@@ -470,9 +471,12 @@ Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode,
rest_parameter_ = var;
rest_index_ = num_parameters();
}
- // TODO(wingo): Avoid O(n^2) check.
- *is_duplicate = IsDeclaredParameter(name);
- params_.Add(var, zone());
+
+ if (pattern == nullptr) {
+ // TODO(wingo): Avoid O(n^2) check.
+ *is_duplicate = IsDeclaredParameter(name);
+ }
+ params_.Add(Parameter(var, pattern), zone());
return var;
}
@@ -898,7 +902,7 @@ void Scope::Print(int n) {
PrintF(" (");
for (int i = 0; i < params_.length(); i++) {
if (i > 0) PrintF(", ");
- PrintName(params_[i]->raw_name());
+ PrintName(params_[i].var->raw_name());
}
PrintF(")");
}
@@ -1337,7 +1341,7 @@ bool Scope::MustAllocateInContext(Variable* var) {
bool Scope::HasArgumentsParameter(Isolate* isolate) {
for (int i = 0; i < params_.length(); i++) {
- if (params_[i]->name().is_identical_to(
+ if (params_[i].var->name().is_identical_to(
isolate->factory()->arguments_string())) {
return true;
}
@@ -1398,7 +1402,7 @@ void Scope::AllocateParameterLocals(Isolate* isolate) {
// receive the highest parameter index for that parameter; thus iteration
// order is relevant!
for (int i = params_.length() - 1; i >= 0; --i) {
- Variable* var = params_[i];
+ Variable* var = params_[i].var;
if (var == rest_parameter_) continue;
DCHECK(var->scope() == this);

Powered by Google App Engine
This is Rietveld 408576698