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

Side by Side Diff: src/contexts.cc

Issue 2918001: Move serialized scope info from Code object to SharedFunctionInfo. (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<Code> code(context->closure()->code()); 123 Handle<Object> scope_info(context->closure()->shared()->scope_info());
124 Variable::Mode mode; 124 Variable::Mode mode;
125 int index = ScopeInfo<>::ContextSlotIndex(*code, *name, &mode); 125 int index = ScopeInfo<>::ContextSlotIndex(*scope_info, *name, &mode);
126 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); 126 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS);
127 if (index >= 0) { 127 if (index >= 0) {
128 // slot found 128 // slot found
129 if (FLAG_trace_contexts) { 129 if (FLAG_trace_contexts) {
130 PrintF("=> found local in context slot %d (mode = %d)\n", 130 PrintF("=> found local in context slot %d (mode = %d)\n",
131 index, mode); 131 index, mode);
132 } 132 }
133 *index_ = index; 133 *index_ = index;
134 // Note: Fixed context slots are statically allocated by the compiler. 134 // Note: Fixed context slots are statically allocated by the compiler.
135 // Statically allocated variables always have a statically known mode, 135 // Statically allocated variables always have a statically known mode,
136 // which is the mode with which they were declared when added to the 136 // which is the mode with which they were declared when added to the
137 // scope. Thus, the DYNAMIC mode (which corresponds to dynamically 137 // scope. Thus, the DYNAMIC mode (which corresponds to dynamically
138 // declared variables that were introduced through declaration nodes) 138 // declared variables that were introduced through declaration nodes)
139 // must not appear here. 139 // must not appear here.
140 switch (mode) { 140 switch (mode) {
141 case Variable::INTERNAL: // fall through 141 case Variable::INTERNAL: // fall through
142 case Variable::VAR: *attributes = NONE; break; 142 case Variable::VAR: *attributes = NONE; break;
143 case Variable::CONST: *attributes = READ_ONLY; break; 143 case Variable::CONST: *attributes = READ_ONLY; break;
144 case Variable::DYNAMIC: UNREACHABLE(); break; 144 case Variable::DYNAMIC: UNREACHABLE(); break;
145 case Variable::DYNAMIC_GLOBAL: UNREACHABLE(); break; 145 case Variable::DYNAMIC_GLOBAL: UNREACHABLE(); break;
146 case Variable::DYNAMIC_LOCAL: UNREACHABLE(); break; 146 case Variable::DYNAMIC_LOCAL: UNREACHABLE(); break;
147 case Variable::TEMPORARY: UNREACHABLE(); break; 147 case Variable::TEMPORARY: UNREACHABLE(); break;
148 } 148 }
149 return context; 149 return context;
150 } 150 }
151 151
152 // check parameter locals in context 152 // check parameter locals in context
153 int param_index = ScopeInfo<>::ParameterIndex(*code, *name); 153 int param_index = ScopeInfo<>::ParameterIndex(*scope_info, *name);
154 if (param_index >= 0) { 154 if (param_index >= 0) {
155 // slot found. 155 // slot found.
156 int index = 156 int index =
157 ScopeInfo<>::ContextSlotIndex(*code, 157 ScopeInfo<>::ContextSlotIndex(*scope_info,
158 Heap::arguments_shadow_symbol(), 158 Heap::arguments_shadow_symbol(),
159 NULL); 159 NULL);
160 ASSERT(index >= 0); // arguments must exist and be in the heap context 160 ASSERT(index >= 0); // arguments must exist and be in the heap context
161 Handle<JSObject> arguments(JSObject::cast(context->get(index))); 161 Handle<JSObject> arguments(JSObject::cast(context->get(index)));
162 ASSERT(arguments->HasLocalProperty(Heap::length_symbol())); 162 ASSERT(arguments->HasLocalProperty(Heap::length_symbol()));
163 if (FLAG_trace_contexts) { 163 if (FLAG_trace_contexts) {
164 PrintF("=> found parameter %d in arguments object\n", param_index); 164 PrintF("=> found parameter %d in arguments object\n", param_index);
165 } 165 }
166 *index_ = param_index; 166 *index_ = param_index;
167 *attributes = NONE; 167 *attributes = NONE;
168 return arguments; 168 return arguments;
169 } 169 }
170 170
171 // check intermediate context (holding only the function name variable) 171 // check intermediate context (holding only the function name variable)
172 if (follow_context_chain) { 172 if (follow_context_chain) {
173 int index = ScopeInfo<>::FunctionContextSlotIndex(*code, *name); 173 int index = ScopeInfo<>::FunctionContextSlotIndex(*scope_info, *name);
174 if (index >= 0) { 174 if (index >= 0) {
175 // slot found 175 // slot found
176 if (FLAG_trace_contexts) { 176 if (FLAG_trace_contexts) {
177 PrintF("=> found intermediate function in context slot %d\n", 177 PrintF("=> found intermediate function in context slot %d\n",
178 index); 178 index);
179 } 179 }
180 *index_ = index; 180 *index_ = index;
181 *attributes = READ_ONLY; 181 *attributes = READ_ONLY;
182 return context; 182 return context;
183 } 183 }
(...skipping 25 matching lines...) Expand all
209 // before the global context and check that there are no context 209 // before the global context and check that there are no context
210 // extension objects (conservative check for with statements). 210 // extension objects (conservative check for with statements).
211 while (!context->IsGlobalContext()) { 211 while (!context->IsGlobalContext()) {
212 // Check if the context is a potentially a with context. 212 // Check if the context is a potentially a with context.
213 if (context->has_extension()) return false; 213 if (context->has_extension()) return false;
214 214
215 // Not a with context so it must be a function context. 215 // Not a with context so it must be a function context.
216 ASSERT(context->is_function_context()); 216 ASSERT(context->is_function_context());
217 217
218 // Check non-parameter locals. 218 // Check non-parameter locals.
219 Handle<Code> code(context->closure()->code()); 219 Handle<Object> scope_info(context->closure()->shared()->scope_info());
220 Variable::Mode mode; 220 Variable::Mode mode;
221 int index = ScopeInfo<>::ContextSlotIndex(*code, *name, &mode); 221 int index = ScopeInfo<>::ContextSlotIndex(*scope_info, *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(*code, *name); 226 int param_index = ScopeInfo<>::ParameterIndex(*scope_info, *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(*code, *name); 230 index = ScopeInfo<>::FunctionContextSlotIndex(*scope_info, *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