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

Unified Diff: src/scopes.h

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/scanner.cc ('k') | src/scopes.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scopes.h
diff --git a/src/scopes.h b/src/scopes.h
index 98a3014dbcbcad75ee4b9080c9c20ab89888c5e7..2e418be219b08844bd94f3f7cc9643aea23ec606 100644
--- a/src/scopes.h
+++ b/src/scopes.h
@@ -126,7 +126,8 @@ class Scope: public ZoneObject {
// Declare a parameter in this scope. When there are duplicated
// parameters the rightmost one 'wins'. However, the implementation
// expects all parameters to be declared and from left to right.
- Variable* DeclareParameter(const AstRawString* name, VariableMode mode);
+ Variable* DeclareParameter(const AstRawString* name, VariableMode mode,
+ bool is_rest = false);
// Declare a local variable in this scope. If the variable has been
// declared before, the previously declared variable is returned.
@@ -358,8 +359,32 @@ class Scope: public ZoneObject {
return params_[index];
}
+ // Returns the default function arity --- does not include rest parameters.
+ int default_function_length() const {
+ int count = params_.length();
+ if (rest_index_ >= 0) {
+ DCHECK(count > 0);
+ DCHECK(is_function_scope());
+ --count;
+ }
+ return count;
+ }
+
int num_parameters() const { return params_.length(); }
+ // A function can have at most one rest parameter. Returns Variable* or NULL.
+ Variable* rest_parameter(int* index) const {
+ *index = rest_index_;
+ if (rest_index_ < 0) return NULL;
+ return rest_parameter_;
+ }
+
+ bool is_simple_parameter_list() const {
+ DCHECK(is_function_scope());
+ if (rest_index_ >= 0) return false;
+ return true;
+ }
+
// The local variable 'arguments' if we need to allocate it; NULL otherwise.
Variable* arguments() const { return arguments_; }
@@ -555,6 +580,10 @@ class Scope: public ZoneObject {
// For module scopes, the host scope's internal variable binding this module.
Variable* module_var_;
+ // Rest parameter
+ Variable* rest_parameter_;
+ int rest_index_;
+
// Serialized scope info support.
Handle<ScopeInfo> scope_info_;
bool already_resolved() { return already_resolved_; }
« src/scanner.cc ('K') | « src/scanner.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698