| 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 12 matching lines...) Expand all Loading... |
| 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. | 28 // ES5 10.2 defines lexical environments with mutable and immutable bindings. |
| 29 // Immutable bindings have two states, initialized and uninitialized, and | 29 // Immutable bindings have two states, initialized and uninitialized, and |
| 30 // their state is changed by the InitializeImmutableBinding method. The | 30 // their state is changed by the InitializeImmutableBinding method. The |
| 31 // BindingFlags enum represents information if a binding has definitely been | 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 | 32 // initialized. A mutable binding does not need to be checked and thus has |
| 33 // the BindingFlag MUTABLE_IS_INITIALIZED. | 33 // the BindingFlag BINDING_IS_INITIALIZED. |
| 34 // | 34 // |
| 35 // There are two possibilities for immutable bindings | 35 // There is one possibility for legacy immutable bindings: |
| 36 // * 'const' declared variables. They are initialized when evaluating the | |
| 37 // corresponding declaration statement. They need to be checked for being | |
| 38 // initialized and thus get the flag IMMUTABLE_CHECK_INITIALIZED. | |
| 39 // * The function name of a named function literal. The binding is immediately | 36 // * The function name of a named function literal. The binding is immediately |
| 40 // initialized when entering the function and thus does not need to be | 37 // initialized when entering the function and thus does not need to be |
| 41 // checked. it gets the BindingFlag IMMUTABLE_IS_INITIALIZED. | 38 // checked. it gets the BindingFlag BINDING_IS_INITIALIZED. |
| 42 // Accessing an uninitialized binding produces the undefined value. | |
| 43 // | 39 // |
| 44 // The harmony proposal for block scoped bindings also introduces the | 40 // The harmony proposal for block scoped bindings also introduces the |
| 45 // uninitialized state for mutable bindings. | 41 // uninitialized state for mutable bindings. |
| 46 // * A 'let' declared variable. They are initialized when evaluating the | 42 // * A 'let' declared variable. They are initialized when evaluating the |
| 47 // corresponding declaration statement. They need to be checked for being | 43 // corresponding declaration statement. They need to be checked for being |
| 48 // initialized and thus get the flag MUTABLE_CHECK_INITIALIZED. | 44 // initialized and thus get the flag BINDING_CHECK_INITIALIZED. |
| 49 // * A 'var' declared variable. It is initialized immediately upon creation | 45 // * A 'var' declared variable. It is initialized immediately upon creation |
| 50 // and thus doesn't need to be checked. It gets the flag | 46 // and thus doesn't need to be checked. It gets the flag |
| 51 // MUTABLE_IS_INITIALIZED. | 47 // BINDING_IS_INITIALIZED. |
| 52 // * Catch bound variables, function parameters and variables introduced by | 48 // * Catch bound variables, function parameters and variables introduced by |
| 53 // function declarations are initialized immediately and do not need to be | 49 // function declarations are initialized immediately and do not need to be |
| 54 // checked. Thus they get the flag MUTABLE_IS_INITIALIZED. | 50 // checked. Thus they get the flag BINDING_IS_INITIALIZED. |
| 55 // Immutable bindings in harmony mode get the _HARMONY flag variants. Accessing | 51 // Accessing an uninitialized binding produces a reference error. |
| 56 // an uninitialized binding produces a reference error. | |
| 57 // | 52 // |
| 58 // In V8 uninitialized bindings are set to the hole value upon creation and set | 53 // In V8 uninitialized bindings are set to the hole value upon creation and set |
| 59 // to a different value upon initialization. | 54 // to a different value upon initialization. |
| 60 enum BindingFlags { | 55 enum BindingFlags { |
| 61 MUTABLE_IS_INITIALIZED, | 56 BINDING_IS_INITIALIZED, |
| 62 MUTABLE_CHECK_INITIALIZED, | 57 BINDING_CHECK_INITIALIZED, |
| 63 IMMUTABLE_IS_INITIALIZED, | |
| 64 IMMUTABLE_CHECK_INITIALIZED, | |
| 65 IMMUTABLE_IS_INITIALIZED_HARMONY, | |
| 66 IMMUTABLE_CHECK_INITIALIZED_HARMONY, | |
| 67 MISSING_BINDING | 58 MISSING_BINDING |
| 68 }; | 59 }; |
| 69 | 60 |
| 70 | |
| 71 // Heap-allocated activation contexts. | 61 // Heap-allocated activation contexts. |
| 72 // | 62 // |
| 73 // Contexts are implemented as FixedArray objects; the Context | 63 // Contexts are implemented as FixedArray objects; the Context |
| 74 // class is a convenience interface casted on a FixedArray object. | 64 // class is a convenience interface casted on a FixedArray object. |
| 75 // | 65 // |
| 76 // Note: Context must have no virtual functions and Context objects | 66 // Note: Context must have no virtual functions and Context objects |
| 77 // must always be allocated via Heap::AllocateContext() or | 67 // must always be allocated via Heap::AllocateContext() or |
| 78 // Factory::NewContext. | 68 // Factory::NewContext. |
| 79 | 69 |
| 80 #define NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V) \ | 70 #define NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V) \ |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 #endif | 560 #endif |
| 571 | 561 |
| 572 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); | 562 STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); |
| 573 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); | 563 STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); |
| 574 }; | 564 }; |
| 575 | 565 |
| 576 } // namespace internal | 566 } // namespace internal |
| 577 } // namespace v8 | 567 } // namespace v8 |
| 578 | 568 |
| 579 #endif // V8_CONTEXTS_H_ | 569 #endif // V8_CONTEXTS_H_ |
| OLD | NEW |