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

Side by Side Diff: src/scopes.h

Issue 1311163002: [es6] Correct length for functions with default parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comment Created 5 years, 3 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
« no previous file with comments | « src/parser.h ('k') | src/scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_SCOPES_H_ 5 #ifndef V8_SCOPES_H_
6 #define V8_SCOPES_H_ 6 #define V8_SCOPES_H_
7 7
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/pending-compilation-error-handler.h" 9 #include "src/pending-compilation-error-handler.h"
10 #include "src/zone.h" 10 #include "src/zone.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 DCHECK(is_function_scope()); 121 DCHECK(is_function_scope());
122 // Handle implicit declaration of the function name in named function 122 // Handle implicit declaration of the function name in named function
123 // expressions before other declarations. 123 // expressions before other declarations.
124 decls_.InsertAt(0, declaration, zone()); 124 decls_.InsertAt(0, declaration, zone());
125 function_ = declaration; 125 function_ = declaration;
126 } 126 }
127 127
128 // Declare a parameter in this scope. When there are duplicated 128 // Declare a parameter in this scope. When there are duplicated
129 // parameters the rightmost one 'wins'. However, the implementation 129 // parameters the rightmost one 'wins'. However, the implementation
130 // expects all parameters to be declared and from left to right. 130 // expects all parameters to be declared and from left to right.
131 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, 131 Variable* DeclareParameter(
132 bool is_rest, bool* is_duplicate); 132 const AstRawString* name, VariableMode mode,
133 bool is_optional, bool is_rest, bool* is_duplicate);
133 134
134 // Declare a local variable in this scope. If the variable has been 135 // Declare a local variable in this scope. If the variable has been
135 // declared before, the previously declared variable is returned. 136 // declared before, the previously declared variable is returned.
136 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, 137 Variable* DeclareLocal(const AstRawString* name, VariableMode mode,
137 InitializationFlag init_flag, Variable::Kind kind, 138 InitializationFlag init_flag, Variable::Kind kind,
138 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, 139 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned,
139 int declaration_group_start = -1); 140 int declaration_group_start = -1);
140 141
141 // Declare an implicit global variable in this scope which must be a 142 // Declare an implicit global variable in this scope which must be a
142 // script scope. The variable was introduced (possibly from an inner 143 // script scope. The variable was introduced (possibly from an inner
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 return function_; 359 return function_;
359 } 360 }
360 361
361 // Parameters. The left-most parameter has index 0. 362 // Parameters. The left-most parameter has index 0.
362 // Only valid for function scopes. 363 // Only valid for function scopes.
363 Variable* parameter(int index) const { 364 Variable* parameter(int index) const {
364 DCHECK(is_function_scope()); 365 DCHECK(is_function_scope());
365 return params_[index]; 366 return params_[index];
366 } 367 }
367 368
368 // Returns the default function arity --- does not include rest parameters. 369 // Returns the default function arity excluding default or rest parameters.
369 int default_function_length() const { 370 int default_function_length() const { return arity_; }
370 int count = params_.length();
371 if (rest_index_ >= 0) {
372 DCHECK(count > 0);
373 DCHECK(is_function_scope());
374 --count;
375 }
376 return count;
377 }
378 371
379 int num_parameters() const { return params_.length(); } 372 int num_parameters() const { return params_.length(); }
380 373
381 // A function can have at most one rest parameter. Returns Variable* or NULL. 374 // A function can have at most one rest parameter. Returns Variable* or NULL.
382 Variable* rest_parameter(int* index) const { 375 Variable* rest_parameter(int* index) const {
383 *index = rest_index_; 376 *index = rest_index_;
384 if (rest_index_ < 0) return NULL; 377 if (rest_index_ < 0) return NULL;
385 return rest_parameter_; 378 return rest_parameter_;
386 } 379 }
387 380
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 int num_heap_slots_; 618 int num_heap_slots_;
626 int num_global_slots_; 619 int num_global_slots_;
627 620
628 // The number of modules (including nested ones). 621 // The number of modules (including nested ones).
629 int num_modules_; 622 int num_modules_;
630 623
631 // For module scopes, the host scope's temporary variable binding this module. 624 // For module scopes, the host scope's temporary variable binding this module.
632 Variable* module_var_; 625 Variable* module_var_;
633 626
634 // Info about the parameter list of a function. 627 // Info about the parameter list of a function.
628 int arity_;
635 bool has_simple_parameters_; 629 bool has_simple_parameters_;
636 Variable* rest_parameter_; 630 Variable* rest_parameter_;
637 int rest_index_; 631 int rest_index_;
638 632
639 // Serialized scope info support. 633 // Serialized scope info support.
640 Handle<ScopeInfo> scope_info_; 634 Handle<ScopeInfo> scope_info_;
641 bool already_resolved() { return already_resolved_; } 635 bool already_resolved() { return already_resolved_; }
642 636
643 // Create a non-local variable with a given name. 637 // Create a non-local variable with a given name.
644 // These variables are looked up dynamically at runtime. 638 // These variables are looked up dynamically at runtime.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 PendingCompilationErrorHandler pending_error_handler_; 759 PendingCompilationErrorHandler pending_error_handler_;
766 760
767 // For tracking which classes are declared consecutively. Needed for strong 761 // For tracking which classes are declared consecutively. Needed for strong
768 // mode. 762 // mode.
769 int class_declaration_group_start_; 763 int class_declaration_group_start_;
770 }; 764 };
771 765
772 } } // namespace v8::internal 766 } } // namespace v8::internal
773 767
774 #endif // V8_SCOPES_H_ 768 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698