| 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 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 | 14 |
| 15 enum ContextLookupFlags { | 15 enum ContextLookupFlags { |
| 16 FOLLOW_CONTEXT_CHAIN = 1 << 0, | 16 FOLLOW_CONTEXT_CHAIN = 1 << 0, |
| 17 FOLLOW_PROTOTYPE_CHAIN = 1 << 1, | 17 FOLLOW_PROTOTYPE_CHAIN = 1 << 1, |
| 18 STOP_AT_DECLARATION_SCOPE = 1 << 2, | 18 STOP_AT_DECLARATION_SCOPE = 1 << 2, |
| 19 SKIP_WITH_CONTEXT = 1 << 3, | 19 SKIP_WITH_CONTEXT = 1 << 3, |
| 20 | 20 |
| 21 DONT_FOLLOW_CHAINS = 0, | 21 DONT_FOLLOW_CHAINS = 0, |
| 22 FOLLOW_CHAINS = FOLLOW_CONTEXT_CHAIN | FOLLOW_PROTOTYPE_CHAIN, | 22 FOLLOW_CHAINS = FOLLOW_CONTEXT_CHAIN | FOLLOW_PROTOTYPE_CHAIN, |
| 23 LEXICAL_TEST = | 23 LEXICAL_TEST = |
| 24 FOLLOW_CONTEXT_CHAIN | STOP_AT_DECLARATION_SCOPE | SKIP_WITH_CONTEXT, | 24 FOLLOW_CONTEXT_CHAIN | STOP_AT_DECLARATION_SCOPE | SKIP_WITH_CONTEXT, |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 | 27 |
| 28 // ES5 10.2 defines lexical environments with mutable and immutable bindings. | |
| 29 // Immutable bindings have two states, initialized and uninitialized, and | |
| 30 // their state is changed by the InitializeImmutableBinding method. The | |
| 31 // BindingFlags enum represents information if a binding has definitely been | |
| 32 // initialized. A mutable binding does not need to be checked and thus has | |
| 33 // the BindingFlag BINDING_IS_INITIALIZED. | |
| 34 // | |
| 35 // There is one possibility for legacy immutable bindings: | |
| 36 // * The function name of a named function literal. The binding is immediately | |
| 37 // initialized when entering the function and thus does not need to be | |
| 38 // checked. it gets the BindingFlag BINDING_IS_INITIALIZED. | |
| 39 // | |
| 40 // The harmony proposal for block scoped bindings also introduces the | |
| 41 // uninitialized state for mutable bindings. | |
| 42 // * A 'let' declared variable. They are initialized when evaluating the | |
| 43 // corresponding declaration statement. They need to be checked for being | |
| 44 // initialized and thus get the flag BINDING_CHECK_INITIALIZED. | |
| 45 // * A 'var' declared variable. It is initialized immediately upon creation | |
| 46 // and thus doesn't need to be checked. It gets the flag | |
| 47 // BINDING_IS_INITIALIZED. | |
| 48 // * Catch bound variables, function parameters and variables introduced by | |
| 49 // function declarations are initialized immediately and do not need to be | |
| 50 // checked. Thus they get the flag BINDING_IS_INITIALIZED. | |
| 51 // Accessing an uninitialized binding produces a reference error. | |
| 52 // | |
| 53 // In V8 uninitialized bindings are set to the hole value upon creation and set | |
| 54 // to a different value upon initialization. | |
| 55 enum BindingFlags { | |
| 56 BINDING_IS_INITIALIZED, | |
| 57 BINDING_CHECK_INITIALIZED, | |
| 58 MISSING_BINDING | |
| 59 }; | |
| 60 | |
| 61 // Heap-allocated activation contexts. | 28 // Heap-allocated activation contexts. |
| 62 // | 29 // |
| 63 // Contexts are implemented as FixedArray objects; the Context | 30 // Contexts are implemented as FixedArray objects; the Context |
| 64 // class is a convenience interface casted on a FixedArray object. | 31 // class is a convenience interface casted on a FixedArray object. |
| 65 // | 32 // |
| 66 // Note: Context must have no virtual functions and Context objects | 33 // Note: Context must have no virtual functions and Context objects |
| 67 // must always be allocated via Heap::AllocateContext() or | 34 // must always be allocated via Heap::AllocateContext() or |
| 68 // Factory::NewContext. | 35 // Factory::NewContext. |
| 69 | 36 |
| 70 #define NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V) \ | 37 #define NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V) \ |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 // The binding was found as a named property in a context extension | 467 // The binding was found as a named property in a context extension |
| 501 // object (i.e., was introduced via eval), as a property on the subject | 468 // object (i.e., was introduced via eval), as a property on the subject |
| 502 // of with, or as a property of the global object. *index is -1 and | 469 // of with, or as a property of the global object. *index is -1 and |
| 503 // *attributes is not ABSENT. | 470 // *attributes is not ABSENT. |
| 504 // | 471 // |
| 505 // 3) result.is_null(): | 472 // 3) result.is_null(): |
| 506 // There was no binding found, *index is always -1 and *attributes is | 473 // There was no binding found, *index is always -1 and *attributes is |
| 507 // always ABSENT. | 474 // always ABSENT. |
| 508 Handle<Object> Lookup(Handle<String> name, ContextLookupFlags flags, | 475 Handle<Object> Lookup(Handle<String> name, ContextLookupFlags flags, |
| 509 int* index, PropertyAttributes* attributes, | 476 int* index, PropertyAttributes* attributes, |
| 510 BindingFlags* binding_flags, | 477 InitializationFlag* init_flag, |
| 511 VariableMode* variable_mode); | 478 VariableMode* variable_mode); |
| 512 | 479 |
| 513 // Code generation support. | 480 // Code generation support. |
| 514 static int SlotOffset(int index) { | 481 static int SlotOffset(int index) { |
| 515 return kHeaderSize + index * kPointerSize - kHeapObjectTag; | 482 return kHeaderSize + index * kPointerSize - kHeapObjectTag; |
| 516 } | 483 } |
| 517 | 484 |
| 518 static int FunctionMapIndex(LanguageMode language_mode, FunctionKind kind) { | 485 static int FunctionMapIndex(LanguageMode language_mode, FunctionKind kind) { |
| 519 // Note: Must be kept in sync with FastNewClosureStub::Generate. | 486 // Note: Must be kept in sync with FastNewClosureStub::Generate. |
| 520 if (IsGeneratorFunction(kind)) { | 487 if (IsGeneratorFunction(kind)) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 #endif | 533 #endif |
| 567 | 534 |
| 568 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); | 535 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); |
| 569 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); | 536 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); |
| 570 }; | 537 }; |
| 571 | 538 |
| 572 } // namespace internal | 539 } // namespace internal |
| 573 } // namespace v8 | 540 } // namespace v8 |
| 574 | 541 |
| 575 #endif // V8_CONTEXTS_H_ | 542 #endif // V8_CONTEXTS_H_ |
| OLD | NEW |