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

Side by Side Diff: src/scopes.h

Issue 968263002: [strong] Fix scoping related errors for methods. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fixing unnamed classes + added tests Created 5 years, 9 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/scopeinfo.cc ('k') | src/scopes.cc » ('j') | src/scopes.cc » ('J')
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // allocation binds each unresolved VariableProxy to one Variable and assigns 66 // allocation binds each unresolved VariableProxy to one Variable and assigns
67 // a location. Note that many VariableProxy nodes may refer to the same Java- 67 // a location. Note that many VariableProxy nodes may refer to the same Java-
68 // Script variable. 68 // Script variable.
69 69
70 class Scope: public ZoneObject { 70 class Scope: public ZoneObject {
71 public: 71 public:
72 // --------------------------------------------------------------------------- 72 // ---------------------------------------------------------------------------
73 // Construction 73 // Construction
74 74
75 Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, 75 Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type,
76 AstValueFactory* value_factory); 76 AstValueFactory* value_factory,
77 FunctionKind function_kind = kNormalFunction);
77 78
78 // Compute top scope and allocate variables. For lazy compilation the top 79 // Compute top scope and allocate variables. For lazy compilation the top
79 // scope only contains the single lazily compiled function, so this 80 // scope only contains the single lazily compiled function, so this
80 // doesn't re-allocate variables repeatedly. 81 // doesn't re-allocate variables repeatedly.
81 static bool Analyze(CompilationInfo* info); 82 static bool Analyze(CompilationInfo* info);
82 83
83 static Scope* DeserializeScopeChain(Isolate* isolate, Zone* zone, 84 static Scope* DeserializeScopeChain(Isolate* isolate, Zone* zone,
84 Context* context, Scope* script_scope); 85 Context* context, Scope* script_scope);
85 86
86 // The scope name is only used for printing/debugging. 87 // The scope name is only used for printing/debugging.
87 void SetScopeName(const AstRawString* scope_name) { 88 void SetScopeName(const AstRawString* scope_name) {
88 scope_name_ = scope_name; 89 scope_name_ = scope_name;
89 } 90 }
90 91
91 void Initialize(bool subclass_constructor = false); 92 void Initialize();
92 93
93 // Checks if the block scope is redundant, i.e. it does not contain any 94 // Checks if the block scope is redundant, i.e. it does not contain any
94 // block scoped declarations. In that case it is removed from the scope 95 // block scoped declarations. In that case it is removed from the scope
95 // tree and its children are reparented. 96 // tree and its children are reparented.
96 Scope* FinalizeBlockScope(); 97 Scope* FinalizeBlockScope();
97 98
98 Zone* zone() const { return zone_; } 99 Zone* zone() const { return zone_; }
99 100
100 // --------------------------------------------------------------------------- 101 // ---------------------------------------------------------------------------
101 // Declarations 102 // Declarations
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 bool is_eval_scope() const { return scope_type_ == EVAL_SCOPE; } 275 bool is_eval_scope() const { return scope_type_ == EVAL_SCOPE; }
275 bool is_function_scope() const { 276 bool is_function_scope() const {
276 return scope_type_ == FUNCTION_SCOPE || scope_type_ == ARROW_SCOPE; 277 return scope_type_ == FUNCTION_SCOPE || scope_type_ == ARROW_SCOPE;
277 } 278 }
278 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; } 279 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; }
279 bool is_script_scope() const { return scope_type_ == SCRIPT_SCOPE; } 280 bool is_script_scope() const { return scope_type_ == SCRIPT_SCOPE; }
280 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; } 281 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; }
281 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; } 282 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; }
282 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } 283 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; }
283 bool is_arrow_scope() const { return scope_type_ == ARROW_SCOPE; } 284 bool is_arrow_scope() const { return scope_type_ == ARROW_SCOPE; }
285 void tag_as_class_scope() { block_scope_is_class_scope_ = true; }
arv (Not doing code reviews) 2015/03/06 16:37:24 DCHECK(is_block_scope());
marja 2015/03/09 10:01:38 Done.
286 bool is_class_scope() const {
287 return is_block_scope() && block_scope_is_class_scope_;
288 }
284 bool is_declaration_scope() const { 289 bool is_declaration_scope() const {
285 return is_eval_scope() || is_function_scope() || 290 return is_eval_scope() || is_function_scope() ||
286 is_module_scope() || is_script_scope(); 291 is_module_scope() || is_script_scope();
287 } 292 }
288 bool is_strict_eval_scope() const { 293 bool is_strict_eval_scope() const {
289 return is_eval_scope() && is_strict(language_mode_); 294 return is_eval_scope() && is_strict(language_mode_);
290 } 295 }
291 296
292 // Information about which scopes calls eval. 297 // Information about which scopes calls eval.
293 bool calls_eval() const { return scope_calls_eval_; } 298 bool calls_eval() const { return scope_calls_eval_; }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 if (outer_scope() == nullptr) return nullptr; 330 if (outer_scope() == nullptr) return nullptr;
326 return outer_scope()->NearestOuterEvalScope(); 331 return outer_scope()->NearestOuterEvalScope();
327 } 332 }
328 333
329 // --------------------------------------------------------------------------- 334 // ---------------------------------------------------------------------------
330 // Accessors. 335 // Accessors.
331 336
332 // The type of this scope. 337 // The type of this scope.
333 ScopeType scope_type() const { return scope_type_; } 338 ScopeType scope_type() const { return scope_type_; }
334 339
340 FunctionKind function_kind() const { return function_kind_; }
341
335 // The language mode of this scope. 342 // The language mode of this scope.
336 LanguageMode language_mode() const { return language_mode_; } 343 LanguageMode language_mode() const { return language_mode_; }
337 344
338 // The variable corresponding to the 'this' value. 345 // The variable corresponding to the 'this' value.
339 Variable* receiver() { return receiver_; } 346 Variable* receiver() { return receiver_; }
340 347
341 // The variable corresponding to the 'new.target' value. 348 // The variable corresponding to the 'new.target' value.
342 Variable* new_target_var() { return new_target_; } 349 Variable* new_target_var() { return new_target_; }
343 350
344 // The variable holding the function literal for named function 351 // The variable holding the function literal for named function
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 // Implementation. 501 // Implementation.
495 protected: 502 protected:
496 friend class ParserFactory; 503 friend class ParserFactory;
497 504
498 // Scope tree. 505 // Scope tree.
499 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL 506 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL
500 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes 507 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes
501 508
502 // The scope type. 509 // The scope type.
503 ScopeType scope_type_; 510 ScopeType scope_type_;
511 // Some block scopes are tagged as class scopes.
512 bool block_scope_is_class_scope_;
513 // If the scope is a function scope, this is the function kind.
514 FunctionKind function_kind_;
504 515
505 // Debugging support. 516 // Debugging support.
506 const AstRawString* scope_name_; 517 const AstRawString* scope_name_;
507 518
508 // The variables declared in this scope: 519 // The variables declared in this scope:
509 // 520 //
510 // All user-declared variables (incl. parameters). For script scopes 521 // All user-declared variables (incl. parameters). For script scopes
511 // variables may be implicitly 'declared' by being used (possibly in 522 // variables may be implicitly 'declared' by being used (possibly in
512 // an inner scope) with no intervening with statements or eval calls. 523 // an inner scope) with no intervening with statements or eval calls.
513 VariableMap variables_; 524 VariableMap variables_;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 // parameter should be set to the calling context of 'eval'. 662 // parameter should be set to the calling context of 'eval'.
652 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind, 663 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind,
653 AstNodeFactory* factory); 664 AstNodeFactory* factory);
654 MUST_USE_RESULT 665 MUST_USE_RESULT
655 bool ResolveVariable(CompilationInfo* info, VariableProxy* proxy, 666 bool ResolveVariable(CompilationInfo* info, VariableProxy* proxy,
656 AstNodeFactory* factory); 667 AstNodeFactory* factory);
657 MUST_USE_RESULT 668 MUST_USE_RESULT
658 bool ResolveVariablesRecursively(CompilationInfo* info, 669 bool ResolveVariablesRecursively(CompilationInfo* info,
659 AstNodeFactory* factory); 670 AstNodeFactory* factory);
660 671
672 bool CheckStrongModeDeclaration(VariableProxy* proxy, Variable* var);
673
661 // Scope analysis. 674 // Scope analysis.
662 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); 675 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval);
663 bool HasTrivialContext() const; 676 bool HasTrivialContext() const;
664 677
665 // Predicates. 678 // Predicates.
666 bool MustAllocate(Variable* var); 679 bool MustAllocate(Variable* var);
667 bool MustAllocateInContext(Variable* var); 680 bool MustAllocateInContext(Variable* var);
668 bool HasArgumentsParameter(Isolate* isolate); 681 bool HasArgumentsParameter(Isolate* isolate);
669 682
670 // Variable allocation. 683 // Variable allocation.
(...skipping 25 matching lines...) Expand all
696 Scope(Zone* zone, Scope* inner_scope, const AstRawString* catch_variable_name, 709 Scope(Zone* zone, Scope* inner_scope, const AstRawString* catch_variable_name,
697 AstValueFactory* value_factory); 710 AstValueFactory* value_factory);
698 711
699 void AddInnerScope(Scope* inner_scope) { 712 void AddInnerScope(Scope* inner_scope) {
700 if (inner_scope != NULL) { 713 if (inner_scope != NULL) {
701 inner_scopes_.Add(inner_scope, zone_); 714 inner_scopes_.Add(inner_scope, zone_);
702 inner_scope->outer_scope_ = this; 715 inner_scope->outer_scope_ = this;
703 } 716 }
704 } 717 }
705 718
706 void SetDefaults(ScopeType type, 719 void SetDefaults(ScopeType type, Scope* outer_scope,
707 Scope* outer_scope, 720 Handle<ScopeInfo> scope_info,
708 Handle<ScopeInfo> scope_info); 721 FunctionKind function_kind = kNormalFunction);
722
723 // If this scope is a method scope of a class, return the corresponding
724 // class variable, otherwise nullptr.
725 Variable* ClassVariableForMethod() const;
709 726
710 AstValueFactory* ast_value_factory_; 727 AstValueFactory* ast_value_factory_;
711 Zone* zone_; 728 Zone* zone_;
712 729
713 PendingCompilationErrorHandler pending_error_handler_; 730 PendingCompilationErrorHandler pending_error_handler_;
714 }; 731 };
715 732
716 } } // namespace v8::internal 733 } } // namespace v8::internal
717 734
718 #endif // V8_SCOPES_H_ 735 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/scopeinfo.cc ('k') | src/scopes.cc » ('j') | src/scopes.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698