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

Unified Diff: src/scopes.cc

Issue 885243002: Implement parsing of ES6 Rest Parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 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
« src/scanner.cc ('K') | « src/scopes.h ('k') | src/token.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scopes.cc
diff --git a/src/scopes.cc b/src/scopes.cc
index 01e311e292d05be9801948a7fd6758b2861d8d88..13e8ecd1efa09d0fabf6a444ade615ecd257708c 100644
--- a/src/scopes.cc
+++ b/src/scopes.cc
@@ -180,6 +180,8 @@ void Scope::SetDefaults(ScopeType scope_type,
num_heap_slots_ = 0;
num_modules_ = 0;
module_var_ = NULL,
+ rest_parameter_ = NULL;
+ rest_index_ = -1;
scope_info_ = scope_info;
start_position_ = RelocInfo::kNoPosition;
end_position_ = RelocInfo::kNoPosition;
@@ -450,11 +452,17 @@ Variable* Scope::Lookup(const AstRawString* name) {
}
-Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode) {
+Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode,
+ bool is_rest) {
DCHECK(!already_resolved());
DCHECK(is_function_scope());
Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL,
kCreatedInitialized);
+ if (is_rest) {
+ DCHECK_EQ(NULL, rest_parameter_);
+ rest_parameter_ = var;
+ rest_index_ = num_parameters();
+ }
params_.Add(var, zone());
return var;
}
@@ -1286,12 +1294,18 @@ void Scope::AllocateParameterLocals() {
uses_sloppy_arguments = strict_mode() == SLOPPY;
}
+ if (rest_parameter_ && !MustAllocate(rest_parameter_)) {
+ rest_parameter_ = NULL;
+ }
+
// The same parameter may occur multiple times in the parameters_ list.
// If it does, and if it is not copied into the context object, it must
// 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];
+ if (var == rest_parameter_) continue;
+
DCHECK(var->scope() == this);
if (uses_sloppy_arguments || has_forced_context_allocation()) {
// Force context allocation of the parameter.
@@ -1359,6 +1373,10 @@ void Scope::AllocateNonParameterLocals() {
if (function_ != NULL) {
AllocateNonParameterLocal(function_->proxy()->var());
}
+
+ if (rest_parameter_) {
+ AllocateNonParameterLocal(rest_parameter_);
+ }
}
« src/scanner.cc ('K') | « src/scopes.h ('k') | src/token.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698