OLD | NEW |
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_CONTEXTS_H_ | 5 #ifndef V8_CONTEXTS_H_ |
6 #define V8_CONTEXTS_H_ | 6 #define V8_CONTEXTS_H_ |
7 | 7 |
8 #include "src/heap/heap.h" | 8 #include "src/heap/heap.h" |
9 #include "src/objects.h" | 9 #include "src/objects.h" |
10 | 10 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 // contexts inside a function. It provides access to the | 291 // contexts inside a function. It provides access to the |
292 // incoming context (i.e., the outer context, which may | 292 // incoming context (i.e., the outer context, which may |
293 // or may not become the current function's context), and | 293 // or may not become the current function's context), and |
294 // it provides access to the functions code and thus it's | 294 // it provides access to the functions code and thus it's |
295 // scope information, which in turn contains the names of | 295 // scope information, which in turn contains the names of |
296 // statically allocated context slots. The names are needed | 296 // statically allocated context slots. The names are needed |
297 // for dynamic lookups in the presence of 'with' or 'eval'. | 297 // for dynamic lookups in the presence of 'with' or 'eval'. |
298 // | 298 // |
299 // [ previous ] A pointer to the previous context. | 299 // [ previous ] A pointer to the previous context. |
300 // | 300 // |
301 // [ extension ] A pointer to a ContextExtension object, or "the hole". Used | 301 // [ extension ] Additional data. |
302 // to implement 'with' statements and dynamic declarations | 302 // |
303 // (through 'eval'). The object in a 'with' statement is | 303 // For script contexts, it contains the respective ScopeInfo. |
304 // stored in the extension slot of a 'with' context. | 304 // |
305 // Dynamically declared variables/functions are also added | 305 // For catch contexts, it contains a ContextExtension object |
306 // to lazily allocated extension object. Context::Lookup | 306 // consisting of the ScopeInfo and the name of the catch |
307 // searches the extension object for properties. | 307 // variable. |
308 // For script and block contexts, contains the respective | 308 // |
309 // ScopeInfo. For block contexts representing sloppy declaration | 309 // For module contexts, it contains the module object. |
310 // block scopes, it may also be a struct being a | 310 // |
311 // ContextExtension, pairing the ScopeInfo with an extension | 311 // For block contexts, it contains either the respective |
312 // object. | 312 // ScopeInfo or a ContextExtension object consisting of the |
| 313 // ScopeInfo and an "extension object" (see below). |
| 314 // |
| 315 // For with contexts, it contains a ContextExtension object |
| 316 // consisting of the ScopeInfo and an "extension object". |
| 317 // |
| 318 // An "extension object" is used to dynamically extend a context |
| 319 // with additional variables, namely in the implementation of the |
| 320 // 'with' construct and the 'eval' construct. For instance, |
| 321 // Context::Lookup also searches the extension object for |
| 322 // properties. (Storing the extension object is the original |
| 323 // purpose of this context slot, hence the name.) |
313 // | 324 // |
314 // [ native_context ] A pointer to the native context. | 325 // [ native_context ] A pointer to the native context. |
315 // | 326 // |
316 // In addition, function contexts may have statically allocated context slots | 327 // In addition, function contexts may have statically allocated context slots |
317 // to store local variables/functions that are accessed from inner functions | 328 // to store local variables/functions that are accessed from inner functions |
318 // (via static context addresses) or through 'eval' (dynamic context lookups). | 329 // (via static context addresses) or through 'eval' (dynamic context lookups). |
319 // The native context contains additional slots for fast access to native | 330 // The native context contains additional slots for fast access to native |
320 // properties. | 331 // properties. |
321 // | 332 // |
322 // Finally, with Harmony scoping, the JSFunction representing a top level | 333 // Finally, with Harmony scoping, the JSFunction representing a top level |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 #endif | 538 #endif |
528 | 539 |
529 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); | 540 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); |
530 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); | 541 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); |
531 }; | 542 }; |
532 | 543 |
533 } // namespace internal | 544 } // namespace internal |
534 } // namespace v8 | 545 } // namespace v8 |
535 | 546 |
536 #endif // V8_CONTEXTS_H_ | 547 #endif // V8_CONTEXTS_H_ |
OLD | NEW |