OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 28 matching lines...) Expand all Loading... |
39 FOLLOW_CONTEXT_CHAIN = 1, | 39 FOLLOW_CONTEXT_CHAIN = 1, |
40 FOLLOW_PROTOTYPE_CHAIN = 2, | 40 FOLLOW_PROTOTYPE_CHAIN = 2, |
41 | 41 |
42 DONT_FOLLOW_CHAINS = 0, | 42 DONT_FOLLOW_CHAINS = 0, |
43 FOLLOW_CHAINS = FOLLOW_CONTEXT_CHAIN | FOLLOW_PROTOTYPE_CHAIN | 43 FOLLOW_CHAINS = FOLLOW_CONTEXT_CHAIN | FOLLOW_PROTOTYPE_CHAIN |
44 }; | 44 }; |
45 | 45 |
46 | 46 |
47 // ES5 10.2 defines lexical environments with mutable and immutable bindings. | 47 // ES5 10.2 defines lexical environments with mutable and immutable bindings. |
48 // Immutable bindings have two states, initialized and uninitialized, and | 48 // Immutable bindings have two states, initialized and uninitialized, and |
49 // their state is changed by the InitializeImmutableBinding method. | 49 // their state is changed by the InitializeImmutableBinding method. The |
| 50 // BindingFlags enum represents information if a binding has definitely been |
| 51 // initialized. A mutable binding does not need to be checked and thus has |
| 52 // the BindingFlag MUTABLE_IS_INITIALIZED. |
| 53 // |
| 54 // There are two possibilities for immutable bindings |
| 55 // * 'const' declared variables. They are initialized when evaluating the |
| 56 // corresponding declaration statement. They need to be checked for being |
| 57 // initialized and thus get the flag IMMUTABLE_CHECK_INITIALIZED. |
| 58 // * The function name of a named function literal. The binding is immediately |
| 59 // initialized when entering the function and thus does not need to be |
| 60 // checked. it gets the BindingFlag IMMUTABLE_IS_INITIALIZED. |
| 61 // Accessing an uninitialized binding produces the undefined value. |
50 // | 62 // |
51 // The harmony proposal for block scoped bindings also introduces the | 63 // The harmony proposal for block scoped bindings also introduces the |
52 // uninitialized state for mutable bindings. A 'let' declared variable | 64 // uninitialized state for mutable bindings. |
53 // is a mutable binding that is created uninitalized upon activation of its | 65 // * A 'let' declared variable. They are initialized when evaluating the |
54 // lexical environment and it is initialized when evaluating its declaration | 66 // corresponding declaration statement. They need to be checked for being |
55 // statement. Var declared variables are mutable bindings that are | 67 // initialized and thus get the flag MUTABLE_CHECK_INITIALIZED. |
56 // immediately initialized upon creation. The BindingFlags enum represents | 68 // * A 'var' declared variable. It is initialized immediately upon creation |
57 // information if a binding has definitely been initialized. 'const' declared | 69 // and thus doesn't need to be checked. It gets the flag |
58 // variables are created as uninitialized immutable bindings. | 70 // MUTABLE_IS_INITIALIZED. |
59 | 71 // * Catch bound variables, function parameters and variables introduced by |
60 // In harmony mode accessing an uninitialized binding produces a reference | 72 // function declarations are initialized immediately and do not need to be |
61 // error. | 73 // checked. Thus they get the flag MUTABLE_IS_INITIALIZED. |
| 74 // Immutable bindings in harmony mode get the _HARMONY flag variants. Accessing |
| 75 // an uninitialized binding produces a reference error. |
| 76 // |
| 77 // In V8 uninitialized bindings are set to the hole value upon creation and set |
| 78 // to a different value upon initialization. |
62 enum BindingFlags { | 79 enum BindingFlags { |
63 MUTABLE_IS_INITIALIZED, | 80 MUTABLE_IS_INITIALIZED, |
64 MUTABLE_CHECK_INITIALIZED, | 81 MUTABLE_CHECK_INITIALIZED, |
65 IMMUTABLE_IS_INITIALIZED, | 82 IMMUTABLE_IS_INITIALIZED, |
66 IMMUTABLE_CHECK_INITIALIZED, | 83 IMMUTABLE_CHECK_INITIALIZED, |
| 84 IMMUTABLE_IS_INITIALIZED_HARMONY, |
| 85 IMMUTABLE_CHECK_INITIALIZED_HARMONY, |
67 MISSING_BINDING | 86 MISSING_BINDING |
68 }; | 87 }; |
69 | 88 |
70 | 89 |
71 // Heap-allocated activation contexts. | 90 // Heap-allocated activation contexts. |
72 // | 91 // |
73 // Contexts are implemented as FixedArray objects; the Context | 92 // Contexts are implemented as FixedArray objects; the Context |
74 // class is a convenience interface casted on a FixedArray object. | 93 // class is a convenience interface casted on a FixedArray object. |
75 // | 94 // |
76 // Note: Context must have no virtual functions and Context objects | 95 // Note: Context must have no virtual functions and Context objects |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 V(OPAQUE_REFERENCE_FUNCTION_INDEX, JSFunction, opaque_reference_function) \ | 150 V(OPAQUE_REFERENCE_FUNCTION_INDEX, JSFunction, opaque_reference_function) \ |
132 V(CONTEXT_EXTENSION_FUNCTION_INDEX, JSFunction, context_extension_function) \ | 151 V(CONTEXT_EXTENSION_FUNCTION_INDEX, JSFunction, context_extension_function) \ |
133 V(OUT_OF_MEMORY_INDEX, Object, out_of_memory) \ | 152 V(OUT_OF_MEMORY_INDEX, Object, out_of_memory) \ |
134 V(MAP_CACHE_INDEX, Object, map_cache) \ | 153 V(MAP_CACHE_INDEX, Object, map_cache) \ |
135 V(CONTEXT_DATA_INDEX, Object, data) \ | 154 V(CONTEXT_DATA_INDEX, Object, data) \ |
136 V(ALLOW_CODE_GEN_FROM_STRINGS_INDEX, Object, allow_code_gen_from_strings) \ | 155 V(ALLOW_CODE_GEN_FROM_STRINGS_INDEX, Object, allow_code_gen_from_strings) \ |
137 V(TO_COMPLETE_PROPERTY_DESCRIPTOR_INDEX, JSFunction, \ | 156 V(TO_COMPLETE_PROPERTY_DESCRIPTOR_INDEX, JSFunction, \ |
138 to_complete_property_descriptor) \ | 157 to_complete_property_descriptor) \ |
139 V(DERIVED_HAS_TRAP_INDEX, JSFunction, derived_has_trap) \ | 158 V(DERIVED_HAS_TRAP_INDEX, JSFunction, derived_has_trap) \ |
140 V(DERIVED_GET_TRAP_INDEX, JSFunction, derived_get_trap) \ | 159 V(DERIVED_GET_TRAP_INDEX, JSFunction, derived_get_trap) \ |
141 V(DERIVED_SET_TRAP_INDEX, JSFunction, derived_set_trap) | 160 V(DERIVED_SET_TRAP_INDEX, JSFunction, derived_set_trap) \ |
| 161 V(PROXY_ENUMERATE, JSFunction, proxy_enumerate) \ |
| 162 V(RANDOM_SEED_INDEX, ByteArray, random_seed) |
142 | 163 |
143 // JSFunctions are pairs (context, function code), sometimes also called | 164 // JSFunctions are pairs (context, function code), sometimes also called |
144 // closures. A Context object is used to represent function contexts and | 165 // closures. A Context object is used to represent function contexts and |
145 // dynamically pushed 'with' contexts (or 'scopes' in ECMA-262 speak). | 166 // dynamically pushed 'with' contexts (or 'scopes' in ECMA-262 speak). |
146 // | 167 // |
147 // At runtime, the contexts build a stack in parallel to the execution | 168 // At runtime, the contexts build a stack in parallel to the execution |
148 // stack, with the top-most context being the current context. All contexts | 169 // stack, with the top-most context being the current context. All contexts |
149 // have the following slots: | 170 // have the following slots: |
150 // | 171 // |
151 // [ closure ] This is the current function. It is the same for all | 172 // [ closure ] This is the current function. It is the same for all |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 return reinterpret_cast<Context*>(context); | 208 return reinterpret_cast<Context*>(context); |
188 } | 209 } |
189 | 210 |
190 // The default context slot layout; indices are FixedArray slot indices. | 211 // The default context slot layout; indices are FixedArray slot indices. |
191 enum { | 212 enum { |
192 // These slots are in all contexts. | 213 // These slots are in all contexts. |
193 CLOSURE_INDEX, | 214 CLOSURE_INDEX, |
194 PREVIOUS_INDEX, | 215 PREVIOUS_INDEX, |
195 // The extension slot is used for either the global object (in global | 216 // The extension slot is used for either the global object (in global |
196 // contexts), eval extension object (function contexts), subject of with | 217 // contexts), eval extension object (function contexts), subject of with |
197 // (with contexts), or the variable name (catch contexts). | 218 // (with contexts), or the variable name (catch contexts), the serialized |
| 219 // scope info (block contexts). |
198 EXTENSION_INDEX, | 220 EXTENSION_INDEX, |
199 GLOBAL_INDEX, | 221 GLOBAL_INDEX, |
200 MIN_CONTEXT_SLOTS, | 222 MIN_CONTEXT_SLOTS, |
201 | 223 |
202 // This slot holds the thrown value in catch contexts. | 224 // This slot holds the thrown value in catch contexts. |
203 THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS, | 225 THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS, |
204 | 226 |
205 // These slots are only in global contexts. | 227 // These slots are only in global contexts. |
206 GLOBAL_PROXY_INDEX = MIN_CONTEXT_SLOTS, | 228 GLOBAL_PROXY_INDEX = MIN_CONTEXT_SLOTS, |
207 SECURITY_TOKEN_INDEX, | 229 SECURITY_TOKEN_INDEX, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 SCRIPT_FUNCTION_INDEX, | 273 SCRIPT_FUNCTION_INDEX, |
252 OPAQUE_REFERENCE_FUNCTION_INDEX, | 274 OPAQUE_REFERENCE_FUNCTION_INDEX, |
253 CONTEXT_EXTENSION_FUNCTION_INDEX, | 275 CONTEXT_EXTENSION_FUNCTION_INDEX, |
254 OUT_OF_MEMORY_INDEX, | 276 OUT_OF_MEMORY_INDEX, |
255 CONTEXT_DATA_INDEX, | 277 CONTEXT_DATA_INDEX, |
256 ALLOW_CODE_GEN_FROM_STRINGS_INDEX, | 278 ALLOW_CODE_GEN_FROM_STRINGS_INDEX, |
257 TO_COMPLETE_PROPERTY_DESCRIPTOR_INDEX, | 279 TO_COMPLETE_PROPERTY_DESCRIPTOR_INDEX, |
258 DERIVED_HAS_TRAP_INDEX, | 280 DERIVED_HAS_TRAP_INDEX, |
259 DERIVED_GET_TRAP_INDEX, | 281 DERIVED_GET_TRAP_INDEX, |
260 DERIVED_SET_TRAP_INDEX, | 282 DERIVED_SET_TRAP_INDEX, |
| 283 PROXY_ENUMERATE, |
| 284 RANDOM_SEED_INDEX, |
261 | 285 |
262 // Properties from here are treated as weak references by the full GC. | 286 // Properties from here are treated as weak references by the full GC. |
263 // Scavenge treats them as strong references. | 287 // Scavenge treats them as strong references. |
264 OPTIMIZED_FUNCTIONS_LIST, // Weak. | 288 OPTIMIZED_FUNCTIONS_LIST, // Weak. |
265 MAP_CACHE_INDEX, // Weak. | 289 MAP_CACHE_INDEX, // Weak. |
266 NEXT_CONTEXT_LINK, // Weak. | 290 NEXT_CONTEXT_LINK, // Weak. |
267 | 291 |
268 // Total number of slots. | 292 // Total number of slots. |
269 GLOBAL_CONTEXT_SLOTS, | 293 GLOBAL_CONTEXT_SLOTS, |
270 | 294 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 // context. Do not consider context extension objects. This is | 402 // context. Do not consider context extension objects. This is |
379 // used for compiling code using eval. If the context surrounding | 403 // used for compiling code using eval. If the context surrounding |
380 // the eval call does not have a local variable with this name and | 404 // the eval call does not have a local variable with this name and |
381 // does not contain a with statement the property is global unless | 405 // does not contain a with statement the property is global unless |
382 // it is shadowed by a property in an extension object introduced by | 406 // it is shadowed by a property in an extension object introduced by |
383 // eval. | 407 // eval. |
384 bool GlobalIfNotShadowedByEval(Handle<String> name); | 408 bool GlobalIfNotShadowedByEval(Handle<String> name); |
385 | 409 |
386 // Determine if any function scope in the context call eval and if | 410 // Determine if any function scope in the context call eval and if |
387 // any of those calls are in non-strict mode. | 411 // any of those calls are in non-strict mode. |
388 void ComputeEvalScopeInfo(bool* outer_scope_calls_eval, | 412 void ComputeEvalScopeInfo(bool* outer_scope_calls_non_strict_eval); |
389 bool* outer_scope_calls_non_strict_eval); | |
390 | 413 |
391 // Code generation support. | 414 // Code generation support. |
392 static int SlotOffset(int index) { | 415 static int SlotOffset(int index) { |
393 return kHeaderSize + index * kPointerSize - kHeapObjectTag; | 416 return kHeaderSize + index * kPointerSize - kHeapObjectTag; |
394 } | 417 } |
395 | 418 |
396 static const int kSize = kHeaderSize + GLOBAL_CONTEXT_SLOTS * kPointerSize; | 419 static const int kSize = kHeaderSize + GLOBAL_CONTEXT_SLOTS * kPointerSize; |
397 | 420 |
398 // GC support. | 421 // GC support. |
399 typedef FixedBodyDescriptor< | 422 typedef FixedBodyDescriptor< |
(...skipping 11 matching lines...) Expand all Loading... |
411 #ifdef DEBUG | 434 #ifdef DEBUG |
412 // Bootstrapping-aware type checks. | 435 // Bootstrapping-aware type checks. |
413 static bool IsBootstrappingOrContext(Object* object); | 436 static bool IsBootstrappingOrContext(Object* object); |
414 static bool IsBootstrappingOrGlobalObject(Object* object); | 437 static bool IsBootstrappingOrGlobalObject(Object* object); |
415 #endif | 438 #endif |
416 }; | 439 }; |
417 | 440 |
418 } } // namespace v8::internal | 441 } } // namespace v8::internal |
419 | 442 |
420 #endif // V8_CONTEXTS_H_ | 443 #endif // V8_CONTEXTS_H_ |
OLD | NEW |