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

Side by Side Diff: src/contexts.cc

Issue 2908009: Create a separate class to encapsulate ScopeInfo serialization.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/compiler.cc ('k') | src/factory.h » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 PrintF("=> found property in context object %p\n", *extension); 113 PrintF("=> found property in context object %p\n", *extension);
114 } 114 }
115 return extension; 115 return extension;
116 } 116 }
117 } 117 }
118 118
119 if (context->is_function_context()) { 119 if (context->is_function_context()) {
120 // we have context-local slots 120 // we have context-local slots
121 121
122 // check non-parameter locals in context 122 // check non-parameter locals in context
123 Handle<Object> scope_info(context->closure()->shared()->scope_info()); 123 Handle<SerializedScopeInfo> scope_info(
124 context->closure()->shared()->scope_info());
124 Variable::Mode mode; 125 Variable::Mode mode;
125 int index = ScopeInfo<>::ContextSlotIndex(*scope_info, *name, &mode); 126 int index = scope_info->ContextSlotIndex(*name, &mode);
126 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); 127 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS);
127 if (index >= 0) { 128 if (index >= 0) {
128 // slot found 129 // slot found
129 if (FLAG_trace_contexts) { 130 if (FLAG_trace_contexts) {
130 PrintF("=> found local in context slot %d (mode = %d)\n", 131 PrintF("=> found local in context slot %d (mode = %d)\n",
131 index, mode); 132 index, mode);
132 } 133 }
133 *index_ = index; 134 *index_ = index;
134 // Note: Fixed context slots are statically allocated by the compiler. 135 // Note: Fixed context slots are statically allocated by the compiler.
135 // Statically allocated variables always have a statically known mode, 136 // Statically allocated variables always have a statically known mode,
136 // which is the mode with which they were declared when added to the 137 // which is the mode with which they were declared when added to the
137 // scope. Thus, the DYNAMIC mode (which corresponds to dynamically 138 // scope. Thus, the DYNAMIC mode (which corresponds to dynamically
138 // declared variables that were introduced through declaration nodes) 139 // declared variables that were introduced through declaration nodes)
139 // must not appear here. 140 // must not appear here.
140 switch (mode) { 141 switch (mode) {
141 case Variable::INTERNAL: // fall through 142 case Variable::INTERNAL: // fall through
142 case Variable::VAR: *attributes = NONE; break; 143 case Variable::VAR: *attributes = NONE; break;
143 case Variable::CONST: *attributes = READ_ONLY; break; 144 case Variable::CONST: *attributes = READ_ONLY; break;
144 case Variable::DYNAMIC: UNREACHABLE(); break; 145 case Variable::DYNAMIC: UNREACHABLE(); break;
145 case Variable::DYNAMIC_GLOBAL: UNREACHABLE(); break; 146 case Variable::DYNAMIC_GLOBAL: UNREACHABLE(); break;
146 case Variable::DYNAMIC_LOCAL: UNREACHABLE(); break; 147 case Variable::DYNAMIC_LOCAL: UNREACHABLE(); break;
147 case Variable::TEMPORARY: UNREACHABLE(); break; 148 case Variable::TEMPORARY: UNREACHABLE(); break;
148 } 149 }
149 return context; 150 return context;
150 } 151 }
151 152
152 // check parameter locals in context 153 // check parameter locals in context
153 int param_index = ScopeInfo<>::ParameterIndex(*scope_info, *name); 154 int param_index = scope_info->ParameterIndex(*name);
154 if (param_index >= 0) { 155 if (param_index >= 0) {
155 // slot found. 156 // slot found.
156 int index = 157 int index =
157 ScopeInfo<>::ContextSlotIndex(*scope_info, 158 scope_info->ContextSlotIndex(Heap::arguments_shadow_symbol(), NULL);
158 Heap::arguments_shadow_symbol(),
159 NULL);
160 ASSERT(index >= 0); // arguments must exist and be in the heap context 159 ASSERT(index >= 0); // arguments must exist and be in the heap context
161 Handle<JSObject> arguments(JSObject::cast(context->get(index))); 160 Handle<JSObject> arguments(JSObject::cast(context->get(index)));
162 ASSERT(arguments->HasLocalProperty(Heap::length_symbol())); 161 ASSERT(arguments->HasLocalProperty(Heap::length_symbol()));
163 if (FLAG_trace_contexts) { 162 if (FLAG_trace_contexts) {
164 PrintF("=> found parameter %d in arguments object\n", param_index); 163 PrintF("=> found parameter %d in arguments object\n", param_index);
165 } 164 }
166 *index_ = param_index; 165 *index_ = param_index;
167 *attributes = NONE; 166 *attributes = NONE;
168 return arguments; 167 return arguments;
169 } 168 }
170 169
171 // check intermediate context (holding only the function name variable) 170 // check intermediate context (holding only the function name variable)
172 if (follow_context_chain) { 171 if (follow_context_chain) {
173 int index = ScopeInfo<>::FunctionContextSlotIndex(*scope_info, *name); 172 int index = scope_info->FunctionContextSlotIndex(*name);
174 if (index >= 0) { 173 if (index >= 0) {
175 // slot found 174 // slot found
176 if (FLAG_trace_contexts) { 175 if (FLAG_trace_contexts) {
177 PrintF("=> found intermediate function in context slot %d\n", 176 PrintF("=> found intermediate function in context slot %d\n",
178 index); 177 index);
179 } 178 }
180 *index_ = index; 179 *index_ = index;
181 *attributes = READ_ONLY; 180 *attributes = READ_ONLY;
182 return context; 181 return context;
183 } 182 }
(...skipping 25 matching lines...) Expand all
209 // before the global context and check that there are no context 208 // before the global context and check that there are no context
210 // extension objects (conservative check for with statements). 209 // extension objects (conservative check for with statements).
211 while (!context->IsGlobalContext()) { 210 while (!context->IsGlobalContext()) {
212 // Check if the context is a potentially a with context. 211 // Check if the context is a potentially a with context.
213 if (context->has_extension()) return false; 212 if (context->has_extension()) return false;
214 213
215 // Not a with context so it must be a function context. 214 // Not a with context so it must be a function context.
216 ASSERT(context->is_function_context()); 215 ASSERT(context->is_function_context());
217 216
218 // Check non-parameter locals. 217 // Check non-parameter locals.
219 Handle<Object> scope_info(context->closure()->shared()->scope_info()); 218 Handle<SerializedScopeInfo> scope_info(
219 context->closure()->shared()->scope_info());
220 Variable::Mode mode; 220 Variable::Mode mode;
221 int index = ScopeInfo<>::ContextSlotIndex(*scope_info, *name, &mode); 221 int index = scope_info->ContextSlotIndex(*name, &mode);
222 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); 222 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS);
223 if (index >= 0) return false; 223 if (index >= 0) return false;
224 224
225 // Check parameter locals. 225 // Check parameter locals.
226 int param_index = ScopeInfo<>::ParameterIndex(*scope_info, *name); 226 int param_index = scope_info->ParameterIndex(*name);
227 if (param_index >= 0) return false; 227 if (param_index >= 0) return false;
228 228
229 // Check context only holding the function name variable. 229 // Check context only holding the function name variable.
230 index = ScopeInfo<>::FunctionContextSlotIndex(*scope_info, *name); 230 index = scope_info->FunctionContextSlotIndex(*name);
231 if (index >= 0) return false; 231 if (index >= 0) return false;
232 context = Context::cast(context->closure()->context()); 232 context = Context::cast(context->closure()->context());
233 } 233 }
234 234
235 // No local or potential with statement found so the variable is 235 // No local or potential with statement found so the variable is
236 // global unless it is shadowed by an eval-introduced variable. 236 // global unless it is shadowed by an eval-introduced variable.
237 return true; 237 return true;
238 } 238 }
239 239
240 240
241 #ifdef DEBUG 241 #ifdef DEBUG
242 bool Context::IsBootstrappingOrContext(Object* object) { 242 bool Context::IsBootstrappingOrContext(Object* object) {
243 // During bootstrapping we allow all objects to pass as 243 // During bootstrapping we allow all objects to pass as
244 // contexts. This is necessary to fix circular dependencies. 244 // contexts. This is necessary to fix circular dependencies.
245 return Bootstrapper::IsActive() || object->IsContext(); 245 return Bootstrapper::IsActive() || object->IsContext();
246 } 246 }
247 247
248 248
249 bool Context::IsBootstrappingOrGlobalObject(Object* object) { 249 bool Context::IsBootstrappingOrGlobalObject(Object* object) {
250 // During bootstrapping we allow all objects to pass as global 250 // During bootstrapping we allow all objects to pass as global
251 // objects. This is necessary to fix circular dependencies. 251 // objects. This is necessary to fix circular dependencies.
252 return Bootstrapper::IsActive() || object->IsGlobalObject(); 252 return Bootstrapper::IsActive() || object->IsGlobalObject();
253 } 253 }
254 #endif 254 #endif
255 255
256 } } // namespace v8::internal 256 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/compiler.cc ('k') | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698