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

Side by Side Diff: src/scopes.cc

Issue 1332873003: Implement sloppy-mode block-defined functions (Annex B 3.3) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: An extra test and comment fix 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
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 #include "src/scopes.h" 5 #include "src/scopes.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/bootstrapper.h" 8 #include "src/bootstrapper.h"
9 #include "src/messages.h" 9 #include "src/messages.h"
10 #include "src/parser.h" 10 #include "src/parser.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash()); 59 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash());
60 if (p != NULL) { 60 if (p != NULL) {
61 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name); 61 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name);
62 DCHECK(p->value != NULL); 62 DCHECK(p->value != NULL);
63 return reinterpret_cast<Variable*>(p->value); 63 return reinterpret_cast<Variable*>(p->value);
64 } 64 }
65 return NULL; 65 return NULL;
66 } 66 }
67 67
68 68
69 SloppyBlockFunctionMap::SloppyBlockFunctionMap(Zone* zone)
70 : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)),
71 zone_(zone) {}
72 SloppyBlockFunctionMap::~SloppyBlockFunctionMap() {}
73
74
75 void SloppyBlockFunctionMap::Declare(const AstRawString* name,
76 DelegateStatement* stmt) {
77 // AstRawStrings are unambiguous, i.e., the same string is always represented
78 // by the same AstRawString*.
79 // FIXME(marja): fix the type of Lookup.
adamk 2015/09/11 15:42:56 What's this TODO about? The return value seems fin
Dan Ehrenberg 2015/09/17 17:44:10 I think it's about using the hash. I copied it fro
80 Entry* p =
81 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(),
82 ZoneAllocationPolicy(zone_));
83 if (!p->value) {
adamk 2015/09/11 15:42:56 Nit: p->value == nullptr is the v8 style here, gen
Dan Ehrenberg 2015/09/17 17:44:10 Done
84 p->value = new (zone_->New(sizeof(ZoneVector<DelegateStatement*>)))
adamk 2015/09/11 15:42:56 Might be worth typedefing ZoneVector<DelegateState
Dan Ehrenberg 2015/09/17 17:44:10 Done
85 ZoneVector<DelegateStatement*>(zone_);
86 }
87 ZoneVector<DelegateStatement*>* delegates =
88 reinterpret_cast<ZoneVector<DelegateStatement*>*>(p->value);
89 delegates->push_back(stmt);
90 }
91
92
69 // ---------------------------------------------------------------------------- 93 // ----------------------------------------------------------------------------
70 // Implementation of Scope 94 // Implementation of Scope
71 95
72 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, 96 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type,
73 AstValueFactory* ast_value_factory, FunctionKind function_kind) 97 AstValueFactory* ast_value_factory, FunctionKind function_kind)
74 : inner_scopes_(4, zone), 98 : inner_scopes_(4, zone),
75 variables_(zone), 99 variables_(zone),
76 temps_(4, zone), 100 temps_(4, zone),
77 params_(4, zone), 101 params_(4, zone),
78 unresolved_(16, zone), 102 unresolved_(16, zone),
79 decls_(4, zone), 103 decls_(4, zone),
80 module_descriptor_( 104 module_descriptor_(
81 scope_type == MODULE_SCOPE ? ModuleDescriptor::New(zone) : NULL), 105 scope_type == MODULE_SCOPE ? ModuleDescriptor::New(zone) : NULL),
106 sloppy_block_function_map_(zone),
82 already_resolved_(false), 107 already_resolved_(false),
83 ast_value_factory_(ast_value_factory), 108 ast_value_factory_(ast_value_factory),
84 zone_(zone), 109 zone_(zone),
85 class_declaration_group_start_(-1) { 110 class_declaration_group_start_(-1) {
86 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null(), 111 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null(),
87 function_kind); 112 function_kind);
88 // The outermost scope must be a script scope. 113 // The outermost scope must be a script scope.
89 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL); 114 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL);
90 DCHECK(!HasIllegalRedeclaration()); 115 DCHECK(!HasIllegalRedeclaration());
91 } 116 }
92 117
93 118
94 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, 119 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type,
95 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory) 120 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory)
96 : inner_scopes_(4, zone), 121 : inner_scopes_(4, zone),
97 variables_(zone), 122 variables_(zone),
98 temps_(4, zone), 123 temps_(4, zone),
99 params_(4, zone), 124 params_(4, zone),
100 unresolved_(16, zone), 125 unresolved_(16, zone),
101 decls_(4, zone), 126 decls_(4, zone),
102 module_descriptor_(NULL), 127 module_descriptor_(NULL),
128 sloppy_block_function_map_(zone),
103 already_resolved_(true), 129 already_resolved_(true),
104 ast_value_factory_(value_factory), 130 ast_value_factory_(value_factory),
105 zone_(zone), 131 zone_(zone),
106 class_declaration_group_start_(-1) { 132 class_declaration_group_start_(-1) {
107 SetDefaults(scope_type, NULL, scope_info); 133 SetDefaults(scope_type, NULL, scope_info);
108 if (!scope_info.is_null()) { 134 if (!scope_info.is_null()) {
109 num_heap_slots_ = scope_info_->ContextLength(); 135 num_heap_slots_ = scope_info_->ContextLength();
110 } 136 }
111 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. 137 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context.
112 num_heap_slots_ = Max(num_heap_slots_, 138 num_heap_slots_ = Max(num_heap_slots_,
113 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); 139 static_cast<int>(Context::MIN_CONTEXT_SLOTS));
114 AddInnerScope(inner_scope); 140 AddInnerScope(inner_scope);
115 } 141 }
116 142
117 143
118 Scope::Scope(Zone* zone, Scope* inner_scope, 144 Scope::Scope(Zone* zone, Scope* inner_scope,
119 const AstRawString* catch_variable_name, 145 const AstRawString* catch_variable_name,
120 AstValueFactory* value_factory) 146 AstValueFactory* value_factory)
121 : inner_scopes_(1, zone), 147 : inner_scopes_(1, zone),
122 variables_(zone), 148 variables_(zone),
123 temps_(0, zone), 149 temps_(0, zone),
124 params_(0, zone), 150 params_(0, zone),
125 unresolved_(0, zone), 151 unresolved_(0, zone),
126 decls_(0, zone), 152 decls_(0, zone),
127 module_descriptor_(NULL), 153 module_descriptor_(NULL),
154 sloppy_block_function_map_(zone),
128 already_resolved_(true), 155 already_resolved_(true),
129 ast_value_factory_(value_factory), 156 ast_value_factory_(value_factory),
130 zone_(zone), 157 zone_(zone),
131 class_declaration_group_start_(-1) { 158 class_declaration_group_start_(-1) {
132 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); 159 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null());
133 AddInnerScope(inner_scope); 160 AddInnerScope(inner_scope);
134 ++num_var_or_const_; 161 ++num_var_or_const_;
135 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; 162 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS;
136 Variable* variable = variables_.Declare(this, 163 Variable* variable = variables_.Declare(this,
137 catch_variable_name, 164 catch_variable_name,
(...skipping 1487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 function_ != NULL && function_->proxy()->var()->IsContextSlot(); 1652 function_ != NULL && function_->proxy()->var()->IsContextSlot();
1626 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1653 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1627 (is_function_var_in_context ? 1 : 0); 1654 (is_function_var_in_context ? 1 : 0);
1628 } 1655 }
1629 1656
1630 1657
1631 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1658 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1632 1659
1633 } // namespace internal 1660 } // namespace internal
1634 } // namespace v8 1661 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698