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

Side by Side Diff: src/contexts.h

Issue 10690043: Implement proper module linking. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Michael's comments. Created 8 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // function contexts, and non-NULL for 'with' contexts. 183 // function contexts, and non-NULL for 'with' contexts.
184 // Used to implement the 'with' statement. 184 // Used to implement the 'with' statement.
185 // 185 //
186 // [ extension ] A pointer to an extension JSObject, or NULL. Used to 186 // [ extension ] A pointer to an extension JSObject, or NULL. Used to
187 // implement 'with' statements and dynamic declarations 187 // implement 'with' statements and dynamic declarations
188 // (through 'eval'). The object in a 'with' statement is 188 // (through 'eval'). The object in a 'with' statement is
189 // stored in the extension slot of a 'with' context. 189 // stored in the extension slot of a 'with' context.
190 // Dynamically declared variables/functions are also added 190 // Dynamically declared variables/functions are also added
191 // to lazily allocated extension object. Context::Lookup 191 // to lazily allocated extension object. Context::Lookup
192 // searches the extension object for properties. 192 // searches the extension object for properties.
193 // For block contexts, contains the respective ScopeInfo.
194 // For module contexts, points back to the respective JSModule.
193 // 195 //
194 // [ global ] A pointer to the global object. Provided for quick 196 // [ global ] A pointer to the global object. Provided for quick
195 // access to the global object from inside the code (since 197 // access to the global object from inside the code (since
196 // we always have a context pointer). 198 // we always have a context pointer).
197 // 199 //
198 // In addition, function contexts may have statically allocated context slots 200 // In addition, function contexts may have statically allocated context slots
199 // to store local variables/functions that are accessed from inner functions 201 // to store local variables/functions that are accessed from inner functions
200 // (via static context addresses) or through 'eval' (dynamic context lookups). 202 // (via static context addresses) or through 'eval' (dynamic context lookups).
201 // Finally, the global context contains additional slots for fast access to 203 // Finally, the global context contains additional slots for fast access to
202 // global properties. 204 // global properties.
203 205
204 class Context: public FixedArray { 206 class Context: public FixedArray {
205 public: 207 public:
206 // Conversions. 208 // Conversions.
207 static Context* cast(Object* context) { 209 static Context* cast(Object* context) {
208 ASSERT(context->IsContext()); 210 ASSERT(context->IsContext());
209 return reinterpret_cast<Context*>(context); 211 return reinterpret_cast<Context*>(context);
210 } 212 }
211 213
212 // The default context slot layout; indices are FixedArray slot indices. 214 // The default context slot layout; indices are FixedArray slot indices.
213 enum { 215 enum {
214 // These slots are in all contexts. 216 // These slots are in all contexts.
215 CLOSURE_INDEX, 217 CLOSURE_INDEX,
216 PREVIOUS_INDEX, 218 PREVIOUS_INDEX,
217 // The extension slot is used for either the global object (in global 219 // The extension slot is used for either the global object (in global
218 // contexts), eval extension object (function contexts), subject of with 220 // contexts), eval extension object (function contexts), subject of with
219 // (with contexts), or the variable name (catch contexts), the serialized 221 // (with contexts), or the variable name (catch contexts), the serialized
220 // scope info (block contexts). 222 // scope info (block contexts), or the module instance (module contexts).
221 EXTENSION_INDEX, 223 EXTENSION_INDEX,
222 GLOBAL_INDEX, 224 GLOBAL_INDEX,
223 MIN_CONTEXT_SLOTS, 225 MIN_CONTEXT_SLOTS,
224 226
225 // This slot holds the thrown value in catch contexts. 227 // This slot holds the thrown value in catch contexts.
226 THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS, 228 THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS,
227 229
228 // These slots are only in global contexts. 230 // These slots are only in global contexts.
229 GLOBAL_PROXY_INDEX = MIN_CONTEXT_SLOTS, 231 GLOBAL_PROXY_INDEX = MIN_CONTEXT_SLOTS,
230 SECURITY_TOKEN_INDEX, 232 SECURITY_TOKEN_INDEX,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 298
297 FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST 299 FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST
298 }; 300 };
299 301
300 // Direct slot access. 302 // Direct slot access.
301 JSFunction* closure() { return JSFunction::cast(get(CLOSURE_INDEX)); } 303 JSFunction* closure() { return JSFunction::cast(get(CLOSURE_INDEX)); }
302 void set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); } 304 void set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); }
303 305
304 Context* previous() { 306 Context* previous() {
305 Object* result = unchecked_previous(); 307 Object* result = unchecked_previous();
306 ASSERT(IsBootstrappingOrContext(result)); 308 ASSERT(IsBootstrappingOrValidParentContext(result, this));
307 return reinterpret_cast<Context*>(result); 309 return reinterpret_cast<Context*>(result);
308 } 310 }
309 void set_previous(Context* context) { set(PREVIOUS_INDEX, context); } 311 void set_previous(Context* context) { set(PREVIOUS_INDEX, context); }
310 312
311 bool has_extension() { return extension() != NULL; } 313 bool has_extension() { return extension() != NULL; }
312 Object* extension() { return get(EXTENSION_INDEX); } 314 Object* extension() { return get(EXTENSION_INDEX); }
313 void set_extension(Object* object) { set(EXTENSION_INDEX, object); } 315 void set_extension(Object* object) { set(EXTENSION_INDEX, object); }
314 316
317 JSModule* module() { return JSModule::cast(get(EXTENSION_INDEX)); }
318 void set_module(JSModule* module) { set(EXTENSION_INDEX, module); }
319
315 // Get the context where var declarations will be hoisted to, which 320 // Get the context where var declarations will be hoisted to, which
316 // may be the context itself. 321 // may be the context itself.
317 Context* declaration_context(); 322 Context* declaration_context();
318 323
319 GlobalObject* global() { 324 GlobalObject* global() {
320 Object* result = get(GLOBAL_INDEX); 325 Object* result = get(GLOBAL_INDEX);
321 ASSERT(IsBootstrappingOrGlobalObject(result)); 326 ASSERT(IsBootstrappingOrGlobalObject(result));
322 return reinterpret_cast<GlobalObject*>(result); 327 return reinterpret_cast<GlobalObject*>(result);
323 } 328 }
324 void set_global(GlobalObject* global) { set(GLOBAL_INDEX, global); } 329 void set_global(GlobalObject* global) { set(GLOBAL_INDEX, global); }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 kHeaderSize, 424 kHeaderSize,
420 kHeaderSize + FIRST_WEAK_SLOT * kPointerSize, 425 kHeaderSize + FIRST_WEAK_SLOT * kPointerSize,
421 kSize> MarkCompactBodyDescriptor; 426 kSize> MarkCompactBodyDescriptor;
422 427
423 private: 428 private:
424 // Unchecked access to the slots. 429 // Unchecked access to the slots.
425 Object* unchecked_previous() { return get(PREVIOUS_INDEX); } 430 Object* unchecked_previous() { return get(PREVIOUS_INDEX); }
426 431
427 #ifdef DEBUG 432 #ifdef DEBUG
428 // Bootstrapping-aware type checks. 433 // Bootstrapping-aware type checks.
429 static bool IsBootstrappingOrContext(Object* object); 434 static bool IsBootstrappingOrValidParentContext(Object* object, Context* kid);
430 static bool IsBootstrappingOrGlobalObject(Object* object); 435 static bool IsBootstrappingOrGlobalObject(Object* object);
431 #endif 436 #endif
432 }; 437 };
433 438
434 } } // namespace v8::internal 439 } } // namespace v8::internal
435 440
436 #endif // V8_CONTEXTS_H_ 441 #endif // V8_CONTEXTS_H_
OLDNEW
« no previous file with comments | « src/compiler.cc ('k') | src/contexts.cc » ('j') | src/full-codegen.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698