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

Unified Diff: src/ast/scopes.h

Issue 1676883002: [runtime] Optimize and unify rest parameters. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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/ast/scopes.h
diff --git a/src/ast/scopes.h b/src/ast/scopes.h
index 6c261f63c376fdf9357eb06ad8cf397f1c08a9ec..cca7905595477d3a427542709a95dcbc454e2c11 100644
--- a/src/ast/scopes.h
+++ b/src/ast/scopes.h
@@ -428,7 +428,24 @@ class Scope: public ZoneObject {
// Returns the default function arity excluding default or rest parameters.
int default_function_length() const { return arity_; }
- int num_parameters() const { return params_.length(); }
+ // Returns the number of formal parameters, up to but not including the
+ // rest parameter index (if the function has rest parameters), i.e. it
+ // says 2 for
+ //
+ // function foo(a, b) { ... }
+ //
+ // and
+ //
+ // function foo(a, b, ...c) { ... }
+ //
+ // but for
+ //
+ // function foo(a, b, c = 1) { ... }
+ //
+ // we return 3 here.
+ int num_parameters() const {
+ return has_rest_parameter() ? params_.length() - 1 : params_.length();
+ }
// A function can have at most one rest parameter. Returns Variable* or NULL.
Variable* rest_parameter(int* index) const {

Powered by Google App Engine
This is Rietveld 408576698