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

Side by Side Diff: src/scopes.h

Issue 1060913005: [strong] Stricter check for referring to other classes inside methods. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: code review (rossberg@) Created 5 years, 8 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.cc ('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"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace internal { 13 namespace internal {
14 14
15 class ParseInfo; 15 class ParseInfo;
16 16
17 // A hash map to support fast variable declaration and lookup. 17 // A hash map to support fast variable declaration and lookup.
18 class VariableMap: public ZoneHashMap { 18 class VariableMap: public ZoneHashMap {
19 public: 19 public:
20 explicit VariableMap(Zone* zone); 20 explicit VariableMap(Zone* zone);
21 21
22 virtual ~VariableMap(); 22 virtual ~VariableMap();
23 23
24 Variable* Declare(Scope* scope, const AstRawString* name, VariableMode mode, 24 Variable* Declare(Scope* scope, const AstRawString* name, VariableMode mode,
25 Variable::Kind kind, InitializationFlag initialization_flag, 25 Variable::Kind kind, InitializationFlag initialization_flag,
26 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); 26 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned,
27 int declaration_group_start = -1);
27 28
28 Variable* Lookup(const AstRawString* name); 29 Variable* Lookup(const AstRawString* name);
29 30
30 Zone* zone() const { return zone_; } 31 Zone* zone() const { return zone_; }
31 32
32 private: 33 private:
33 Zone* zone_; 34 Zone* zone_;
34 }; 35 };
35 36
36 37
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // Declare a parameter in this scope. When there are duplicated 125 // Declare a parameter in this scope. When there are duplicated
125 // parameters the rightmost one 'wins'. However, the implementation 126 // parameters the rightmost one 'wins'. However, the implementation
126 // expects all parameters to be declared and from left to right. 127 // expects all parameters to be declared and from left to right.
127 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, 128 Variable* DeclareParameter(const AstRawString* name, VariableMode mode,
128 bool is_rest, bool* is_duplicate); 129 bool is_rest, bool* is_duplicate);
129 130
130 // Declare a local variable in this scope. If the variable has been 131 // Declare a local variable in this scope. If the variable has been
131 // declared before, the previously declared variable is returned. 132 // declared before, the previously declared variable is returned.
132 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, 133 Variable* DeclareLocal(const AstRawString* name, VariableMode mode,
133 InitializationFlag init_flag, Variable::Kind kind, 134 InitializationFlag init_flag, Variable::Kind kind,
134 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); 135 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned,
136 int declaration_group_start = -1);
135 137
136 // Declare an implicit global variable in this scope which must be a 138 // Declare an implicit global variable in this scope which must be a
137 // script scope. The variable was introduced (possibly from an inner 139 // script scope. The variable was introduced (possibly from an inner
138 // scope) by a reference to an unresolved variable with no intervening 140 // scope) by a reference to an unresolved variable with no intervening
139 // with statements or eval calls. 141 // with statements or eval calls.
140 Variable* DeclareDynamicGlobal(const AstRawString* name); 142 Variable* DeclareDynamicGlobal(const AstRawString* name);
141 143
142 // Create a new unresolved variable. 144 // Create a new unresolved variable.
143 VariableProxy* NewUnresolved(AstNodeFactory* factory, 145 VariableProxy* NewUnresolved(AstNodeFactory* factory,
144 const AstRawString* name, 146 const AstRawString* name,
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 406
405 // Inner scope list. 407 // Inner scope list.
406 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } 408 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; }
407 409
408 // The scope immediately surrounding this scope, or NULL. 410 // The scope immediately surrounding this scope, or NULL.
409 Scope* outer_scope() const { return outer_scope_; } 411 Scope* outer_scope() const { return outer_scope_; }
410 412
411 // The ModuleDescriptor for this scope; only for module scopes. 413 // The ModuleDescriptor for this scope; only for module scopes.
412 ModuleDescriptor* module() const { return module_descriptor_; } 414 ModuleDescriptor* module() const { return module_descriptor_; }
413 415
416
417 void set_class_declaration_group_start(int position) {
418 class_declaration_group_start_ = position;
419 }
420
421 int class_declaration_group_start() const {
422 return class_declaration_group_start_;
423 }
424
414 // --------------------------------------------------------------------------- 425 // ---------------------------------------------------------------------------
415 // Variable allocation. 426 // Variable allocation.
416 427
417 // Collect stack and context allocated local variables in this scope. Note 428 // Collect stack and context allocated local variables in this scope. Note
418 // that the function variable - if present - is not collected and should be 429 // that the function variable - if present - is not collected and should be
419 // handled separately. 430 // handled separately.
420 void CollectStackAndContextLocals( 431 void CollectStackAndContextLocals(
421 ZoneList<Variable*>* stack_locals, ZoneList<Variable*>* context_locals, 432 ZoneList<Variable*>* stack_locals, ZoneList<Variable*>* context_locals,
422 ZoneList<Variable*>* strong_mode_free_variables = nullptr); 433 ZoneList<Variable*>* strong_mode_free_variables = nullptr);
423 434
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 MUST_USE_RESULT 681 MUST_USE_RESULT
671 bool ResolveVariable(ParseInfo* info, VariableProxy* proxy, 682 bool ResolveVariable(ParseInfo* info, VariableProxy* proxy,
672 AstNodeFactory* factory); 683 AstNodeFactory* factory);
673 MUST_USE_RESULT 684 MUST_USE_RESULT
674 bool ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory); 685 bool ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory);
675 686
676 bool CheckStrongModeDeclaration(VariableProxy* proxy, Variable* var); 687 bool CheckStrongModeDeclaration(VariableProxy* proxy, Variable* var);
677 688
678 // If this scope is a method scope of a class, return the corresponding 689 // If this scope is a method scope of a class, return the corresponding
679 // class variable, otherwise nullptr. 690 // class variable, otherwise nullptr.
680 Variable* ClassVariableForMethod() const; 691 ClassVariable* ClassVariableForMethod() const;
681 692
682 // Scope analysis. 693 // Scope analysis.
683 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); 694 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval);
684 bool HasTrivialContext() const; 695 bool HasTrivialContext() const;
685 696
686 // Predicates. 697 // Predicates.
687 bool MustAllocate(Variable* var); 698 bool MustAllocate(Variable* var);
688 bool MustAllocateInContext(Variable* var); 699 bool MustAllocateInContext(Variable* var);
689 bool HasArgumentsParameter(Isolate* isolate); 700 bool HasArgumentsParameter(Isolate* isolate);
690 701
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 } 736 }
726 737
727 void SetDefaults(ScopeType type, Scope* outer_scope, 738 void SetDefaults(ScopeType type, Scope* outer_scope,
728 Handle<ScopeInfo> scope_info, 739 Handle<ScopeInfo> scope_info,
729 FunctionKind function_kind = kNormalFunction); 740 FunctionKind function_kind = kNormalFunction);
730 741
731 AstValueFactory* ast_value_factory_; 742 AstValueFactory* ast_value_factory_;
732 Zone* zone_; 743 Zone* zone_;
733 744
734 PendingCompilationErrorHandler pending_error_handler_; 745 PendingCompilationErrorHandler pending_error_handler_;
746
747 // For tracking which classes are declared consecutively. Needed for strong
748 // mode.
749 int class_declaration_group_start_;
735 }; 750 };
736 751
737 } } // namespace v8::internal 752 } } // namespace v8::internal
738 753
739 #endif // V8_SCOPES_H_ 754 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698