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

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: code review (arv, rossberg) 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') | 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 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() {
286 DCHECK(is_block_scope());
287 block_scope_is_class_scope_ = true;
288 }
289 bool is_class_scope() const {
290 return is_block_scope() && block_scope_is_class_scope_;
291 }
284 bool is_declaration_scope() const { 292 bool is_declaration_scope() const {
285 return is_eval_scope() || is_function_scope() || 293 return is_eval_scope() || is_function_scope() ||
286 is_module_scope() || is_script_scope(); 294 is_module_scope() || is_script_scope();
287 } 295 }
288 bool is_strict_eval_scope() const { 296 bool is_strict_eval_scope() const {
289 return is_eval_scope() && is_strict(language_mode_); 297 return is_eval_scope() && is_strict(language_mode_);
290 } 298 }
291 299
292 // Information about which scopes calls eval. 300 // Information about which scopes calls eval.
293 bool calls_eval() const { return scope_calls_eval_; } 301 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; 333 if (outer_scope() == nullptr) return nullptr;
326 return outer_scope()->NearestOuterEvalScope(); 334 return outer_scope()->NearestOuterEvalScope();
327 } 335 }
328 336
329 // --------------------------------------------------------------------------- 337 // ---------------------------------------------------------------------------
330 // Accessors. 338 // Accessors.
331 339
332 // The type of this scope. 340 // The type of this scope.
333 ScopeType scope_type() const { return scope_type_; } 341 ScopeType scope_type() const { return scope_type_; }
334 342
343 FunctionKind function_kind() const { return function_kind_; }
344
335 // The language mode of this scope. 345 // The language mode of this scope.
336 LanguageMode language_mode() const { return language_mode_; } 346 LanguageMode language_mode() const { return language_mode_; }
337 347
338 // The variable corresponding to the 'this' value. 348 // The variable corresponding to the 'this' value.
339 Variable* receiver() { return receiver_; } 349 Variable* receiver() { return receiver_; }
340 350
341 // The variable corresponding to the 'new.target' value. 351 // The variable corresponding to the 'new.target' value.
342 Variable* new_target_var() { return new_target_; } 352 Variable* new_target_var() { return new_target_; }
343 353
344 // The variable holding the function literal for named function 354 // The variable holding the function literal for named function
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 // Implementation. 504 // Implementation.
495 protected: 505 protected:
496 friend class ParserFactory; 506 friend class ParserFactory;
497 507
498 // Scope tree. 508 // Scope tree.
499 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL 509 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL
500 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes 510 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes
501 511
502 // The scope type. 512 // The scope type.
503 ScopeType scope_type_; 513 ScopeType scope_type_;
514 // Some block scopes are tagged as class scopes.
515 bool block_scope_is_class_scope_;
516 // If the scope is a function scope, this is the function kind.
517 FunctionKind function_kind_;
504 518
505 // Debugging support. 519 // Debugging support.
506 const AstRawString* scope_name_; 520 const AstRawString* scope_name_;
507 521
508 // The variables declared in this scope: 522 // The variables declared in this scope:
509 // 523 //
510 // All user-declared variables (incl. parameters). For script scopes 524 // All user-declared variables (incl. parameters). For script scopes
511 // variables may be implicitly 'declared' by being used (possibly in 525 // variables may be implicitly 'declared' by being used (possibly in
512 // an inner scope) with no intervening with statements or eval calls. 526 // an inner scope) with no intervening with statements or eval calls.
513 VariableMap variables_; 527 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'. 665 // parameter should be set to the calling context of 'eval'.
652 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind, 666 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind,
653 AstNodeFactory* factory); 667 AstNodeFactory* factory);
654 MUST_USE_RESULT 668 MUST_USE_RESULT
655 bool ResolveVariable(CompilationInfo* info, VariableProxy* proxy, 669 bool ResolveVariable(CompilationInfo* info, VariableProxy* proxy,
656 AstNodeFactory* factory); 670 AstNodeFactory* factory);
657 MUST_USE_RESULT 671 MUST_USE_RESULT
658 bool ResolveVariablesRecursively(CompilationInfo* info, 672 bool ResolveVariablesRecursively(CompilationInfo* info,
659 AstNodeFactory* factory); 673 AstNodeFactory* factory);
660 674
675 bool CheckStrongModeDeclaration(VariableProxy* proxy, Variable* var);
676
677 // If this scope is a method scope of a class, return the corresponding
678 // class variable, otherwise nullptr.
679 Variable* ClassVariableForMethod() const;
680
661 // Scope analysis. 681 // Scope analysis.
662 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); 682 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval);
663 bool HasTrivialContext() const; 683 bool HasTrivialContext() const;
664 684
665 // Predicates. 685 // Predicates.
666 bool MustAllocate(Variable* var); 686 bool MustAllocate(Variable* var);
667 bool MustAllocateInContext(Variable* var); 687 bool MustAllocateInContext(Variable* var);
668 bool HasArgumentsParameter(Isolate* isolate); 688 bool HasArgumentsParameter(Isolate* isolate);
669 689
670 // Variable allocation. 690 // Variable allocation.
(...skipping 25 matching lines...) Expand all
696 Scope(Zone* zone, Scope* inner_scope, const AstRawString* catch_variable_name, 716 Scope(Zone* zone, Scope* inner_scope, const AstRawString* catch_variable_name,
697 AstValueFactory* value_factory); 717 AstValueFactory* value_factory);
698 718
699 void AddInnerScope(Scope* inner_scope) { 719 void AddInnerScope(Scope* inner_scope) {
700 if (inner_scope != NULL) { 720 if (inner_scope != NULL) {
701 inner_scopes_.Add(inner_scope, zone_); 721 inner_scopes_.Add(inner_scope, zone_);
702 inner_scope->outer_scope_ = this; 722 inner_scope->outer_scope_ = this;
703 } 723 }
704 } 724 }
705 725
706 void SetDefaults(ScopeType type, 726 void SetDefaults(ScopeType type, Scope* outer_scope,
707 Scope* outer_scope, 727 Handle<ScopeInfo> scope_info,
708 Handle<ScopeInfo> scope_info); 728 FunctionKind function_kind = kNormalFunction);
709 729
710 AstValueFactory* ast_value_factory_; 730 AstValueFactory* ast_value_factory_;
711 Zone* zone_; 731 Zone* zone_;
712 732
713 PendingCompilationErrorHandler pending_error_handler_; 733 PendingCompilationErrorHandler pending_error_handler_;
714 }; 734 };
715 735
716 } } // namespace v8::internal 736 } } // namespace v8::internal
717 737
718 #endif // V8_SCOPES_H_ 738 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/scopeinfo.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698