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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_AST_SCOPES_H_ 5 #ifndef V8_AST_SCOPES_H_
6 #define V8_AST_SCOPES_H_ 6 #define V8_AST_SCOPES_H_
7 7
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/hashmap.h" 9 #include "src/hashmap.h"
10 #include "src/pending-compilation-error-handler.h" 10 #include "src/pending-compilation-error-handler.h"
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // Parameters. The left-most parameter has index 0. 421 // Parameters. The left-most parameter has index 0.
422 // Only valid for function scopes. 422 // Only valid for function scopes.
423 Variable* parameter(int index) const { 423 Variable* parameter(int index) const {
424 DCHECK(is_function_scope()); 424 DCHECK(is_function_scope());
425 return params_[index]; 425 return params_[index];
426 } 426 }
427 427
428 // Returns the default function arity excluding default or rest parameters. 428 // Returns the default function arity excluding default or rest parameters.
429 int default_function_length() const { return arity_; } 429 int default_function_length() const { return arity_; }
430 430
431 int num_parameters() const { return params_.length(); } 431 // Returns the number of formal parameters, up to but not including the
432 // rest parameter index (if the function has rest parameters), i.e. it
433 // says 2 for
434 //
435 // function foo(a, b) { ... }
436 //
437 // and
438 //
439 // function foo(a, b, ...c) { ... }
440 //
441 // but for
442 //
443 // function foo(a, b, c = 1) { ... }
444 //
445 // we return 3 here.
446 int num_parameters() const {
447 return has_rest_parameter() ? params_.length() - 1 : params_.length();
448 }
432 449
433 // A function can have at most one rest parameter. Returns Variable* or NULL. 450 // A function can have at most one rest parameter. Returns Variable* or NULL.
434 Variable* rest_parameter(int* index) const { 451 Variable* rest_parameter(int* index) const {
435 *index = rest_index_; 452 *index = rest_index_;
436 if (rest_index_ < 0) return NULL; 453 if (rest_index_ < 0) return NULL;
437 return rest_parameter_; 454 return rest_parameter_;
438 } 455 }
439 456
440 bool has_rest_parameter() const { return rest_index_ >= 0; } 457 bool has_rest_parameter() const { return rest_index_ >= 0; }
441 458
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 857
841 // For tracking which classes are declared consecutively. Needed for strong 858 // For tracking which classes are declared consecutively. Needed for strong
842 // mode. 859 // mode.
843 int class_declaration_group_start_; 860 int class_declaration_group_start_;
844 }; 861 };
845 862
846 } // namespace internal 863 } // namespace internal
847 } // namespace v8 864 } // namespace v8
848 865
849 #endif // V8_AST_SCOPES_H_ 866 #endif // V8_AST_SCOPES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698