danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_CONTEXTS_H_ |
| 29 | #define V8_CONTEXTS_H_ |
| 30 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 31 | #include "heap.h" |
| 32 | #include "objects.h" |
| 33 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 34 | namespace v8 { |
| 35 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | |
| 37 | |
| 38 | enum ContextLookupFlags { |
| 39 | FOLLOW_CONTEXT_CHAIN = 1, |
| 40 | FOLLOW_PROTOTYPE_CHAIN = 2, |
| 41 | |
| 42 | DONT_FOLLOW_CHAINS = 0, |
| 43 | FOLLOW_CHAINS = FOLLOW_CONTEXT_CHAIN | FOLLOW_PROTOTYPE_CHAIN |
| 44 | }; |
| 45 | |
| 46 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 47 | // ES5 10.2 defines lexical environments with mutable and immutable bindings. |
| 48 | // Immutable bindings have two states, initialized and uninitialized, and |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 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. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 62 | // |
| 63 | // The harmony proposal for block scoped bindings also introduces the |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 64 | // uninitialized state for mutable bindings. |
| 65 | // * A 'let' declared variable. They are initialized when evaluating the |
| 66 | // corresponding declaration statement. They need to be checked for being |
| 67 | // initialized and thus get the flag MUTABLE_CHECK_INITIALIZED. |
| 68 | // * A 'var' declared variable. It is initialized immediately upon creation |
| 69 | // and thus doesn't need to be checked. It gets the flag |
| 70 | // MUTABLE_IS_INITIALIZED. |
| 71 | // * Catch bound variables, function parameters and variables introduced by |
| 72 | // function declarations are initialized immediately and do not need to be |
| 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. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 79 | enum BindingFlags { |
| 80 | MUTABLE_IS_INITIALIZED, |
| 81 | MUTABLE_CHECK_INITIALIZED, |
| 82 | IMMUTABLE_IS_INITIALIZED, |
| 83 | IMMUTABLE_CHECK_INITIALIZED, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 84 | IMMUTABLE_IS_INITIALIZED_HARMONY, |
| 85 | IMMUTABLE_CHECK_INITIALIZED_HARMONY, |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 86 | MISSING_BINDING |
| 87 | }; |
| 88 | |
| 89 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 90 | // Heap-allocated activation contexts. |
| 91 | // |
| 92 | // Contexts are implemented as FixedArray objects; the Context |
| 93 | // class is a convenience interface casted on a FixedArray object. |
| 94 | // |
| 95 | // Note: Context must have no virtual functions and Context objects |
| 96 | // must always be allocated via Heap::AllocateContext() or |
| 97 | // Factory::NewContext. |
| 98 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 99 | #define NATIVE_CONTEXT_FIELDS(V) \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 100 | V(GLOBAL_PROXY_INDEX, JSObject, global_proxy_object) \ |
| 101 | V(SECURITY_TOKEN_INDEX, Object, security_token) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 102 | V(BOOLEAN_FUNCTION_INDEX, JSFunction, boolean_function) \ |
| 103 | V(NUMBER_FUNCTION_INDEX, JSFunction, number_function) \ |
| 104 | V(STRING_FUNCTION_INDEX, JSFunction, string_function) \ |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 105 | V(STRING_FUNCTION_PROTOTYPE_MAP_INDEX, Map, string_function_prototype_map) \ |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 106 | V(SYMBOL_FUNCTION_INDEX, JSFunction, symbol_function) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 107 | V(OBJECT_FUNCTION_INDEX, JSFunction, object_function) \ |
svenpanne@chromium.org | 3c93e77 | 2012-01-02 09:26:59 +0000 | [diff] [blame] | 108 | V(INTERNAL_ARRAY_FUNCTION_INDEX, JSFunction, internal_array_function) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 109 | V(ARRAY_FUNCTION_INDEX, JSFunction, array_function) \ |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 110 | V(JS_ARRAY_MAPS_INDEX, Object, js_array_maps) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 111 | V(DATE_FUNCTION_INDEX, JSFunction, date_function) \ |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 112 | V(JSON_OBJECT_INDEX, JSObject, json_object) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | V(REGEXP_FUNCTION_INDEX, JSFunction, regexp_function) \ |
| 114 | V(INITIAL_OBJECT_PROTOTYPE_INDEX, JSObject, initial_object_prototype) \ |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 115 | V(INITIAL_ARRAY_PROTOTYPE_INDEX, JSObject, initial_array_prototype) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 116 | V(CREATE_DATE_FUN_INDEX, JSFunction, create_date_fun) \ |
| 117 | V(TO_NUMBER_FUN_INDEX, JSFunction, to_number_fun) \ |
| 118 | V(TO_STRING_FUN_INDEX, JSFunction, to_string_fun) \ |
| 119 | V(TO_DETAIL_STRING_FUN_INDEX, JSFunction, to_detail_string_fun) \ |
| 120 | V(TO_OBJECT_FUN_INDEX, JSFunction, to_object_fun) \ |
| 121 | V(TO_INTEGER_FUN_INDEX, JSFunction, to_integer_fun) \ |
| 122 | V(TO_UINT32_FUN_INDEX, JSFunction, to_uint32_fun) \ |
| 123 | V(TO_INT32_FUN_INDEX, JSFunction, to_int32_fun) \ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 124 | V(GLOBAL_EVAL_FUN_INDEX, JSFunction, global_eval_fun) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 125 | V(INSTANTIATE_FUN_INDEX, JSFunction, instantiate_fun) \ |
| 126 | V(CONFIGURE_INSTANCE_FUN_INDEX, JSFunction, configure_instance_fun) \ |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 127 | V(ARRAY_BUFFER_FUN_INDEX, JSFunction, array_buffer_fun) \ |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 128 | V(UINT8_ARRAY_FUN_INDEX, JSFunction, uint8_array_fun) \ |
| 129 | V(INT8_ARRAY_FUN_INDEX, JSFunction, int8_array_fun) \ |
| 130 | V(UINT16_ARRAY_FUN_INDEX, JSFunction, uint16_array_fun) \ |
| 131 | V(INT16_ARRAY_FUN_INDEX, JSFunction, int16_array_fun) \ |
| 132 | V(UINT32_ARRAY_FUN_INDEX, JSFunction, uint32_array_fun) \ |
| 133 | V(INT32_ARRAY_FUN_INDEX, JSFunction, int32_array_fun) \ |
| 134 | V(FLOAT_ARRAY_FUN_INDEX, JSFunction, float_array_fun) \ |
| 135 | V(DOUBLE_ARRAY_FUN_INDEX, JSFunction, double_array_fun) \ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 136 | V(UINT8C_ARRAY_FUN_INDEX, JSFunction, uint8c_array_fun) \ |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 137 | V(DATA_VIEW_FUN_INDEX, JSFunction, data_view_fun) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 138 | V(FUNCTION_MAP_INDEX, Map, function_map) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 139 | V(STRICT_MODE_FUNCTION_MAP_INDEX, Map, strict_mode_function_map) \ |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 140 | V(FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, function_without_prototype_map) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 141 | V(STRICT_MODE_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, \ |
| 142 | strict_mode_function_without_prototype_map) \ |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 143 | V(REGEXP_RESULT_MAP_INDEX, Map, regexp_result_map)\ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 144 | V(ARGUMENTS_BOILERPLATE_INDEX, JSObject, arguments_boilerplate) \ |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 145 | V(ALIASED_ARGUMENTS_BOILERPLATE_INDEX, JSObject, \ |
| 146 | aliased_arguments_boilerplate) \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 147 | V(STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX, JSObject, \ |
| 148 | strict_mode_arguments_boilerplate) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 149 | V(MESSAGE_LISTENERS_INDEX, JSObject, message_listeners) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 150 | V(MAKE_MESSAGE_FUN_INDEX, JSFunction, make_message_fun) \ |
| 151 | V(GET_STACK_TRACE_LINE_INDEX, JSFunction, get_stack_trace_line_fun) \ |
| 152 | V(CONFIGURE_GLOBAL_INDEX, JSFunction, configure_global_fun) \ |
| 153 | V(FUNCTION_CACHE_INDEX, JSObject, function_cache) \ |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 154 | V(JSFUNCTION_RESULT_CACHES_INDEX, FixedArray, jsfunction_result_caches) \ |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 155 | V(NORMALIZED_MAP_CACHE_INDEX, NormalizedMapCache, normalized_map_cache) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 156 | V(RUNTIME_CONTEXT_INDEX, Context, runtime_context) \ |
| 157 | V(CALL_AS_FUNCTION_DELEGATE_INDEX, JSFunction, call_as_function_delegate) \ |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 158 | V(CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, JSFunction, \ |
| 159 | call_as_constructor_delegate) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 160 | V(SCRIPT_FUNCTION_INDEX, JSFunction, script_function) \ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 161 | V(OPAQUE_REFERENCE_FUNCTION_INDEX, JSFunction, opaque_reference_function) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 162 | V(CONTEXT_EXTENSION_FUNCTION_INDEX, JSFunction, context_extension_function) \ |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 163 | V(OUT_OF_MEMORY_INDEX, Object, out_of_memory) \ |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 164 | V(MAP_CACHE_INDEX, Object, map_cache) \ |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 165 | V(EMBEDDER_DATA_INDEX, FixedArray, embedder_data) \ |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 166 | V(ALLOW_CODE_GEN_FROM_STRINGS_INDEX, Object, allow_code_gen_from_strings) \ |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 167 | V(ERROR_MESSAGE_FOR_CODE_GEN_FROM_STRINGS_INDEX, Object, \ |
| 168 | error_message_for_code_gen_from_strings) \ |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 169 | V(TO_COMPLETE_PROPERTY_DESCRIPTOR_INDEX, JSFunction, \ |
| 170 | to_complete_property_descriptor) \ |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 171 | V(DERIVED_HAS_TRAP_INDEX, JSFunction, derived_has_trap) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 172 | V(DERIVED_GET_TRAP_INDEX, JSFunction, derived_get_trap) \ |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 173 | V(DERIVED_SET_TRAP_INDEX, JSFunction, derived_set_trap) \ |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 174 | V(PROXY_ENUMERATE_INDEX, JSFunction, proxy_enumerate) \ |
| 175 | V(OBSERVERS_NOTIFY_CHANGE_INDEX, JSFunction, observers_notify_change) \ |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 176 | V(OBSERVERS_ENQUEUE_SPLICE_INDEX, JSFunction, observers_enqueue_splice) \ |
| 177 | V(OBSERVERS_BEGIN_SPLICE_INDEX, JSFunction, \ |
| 178 | observers_begin_perform_splice) \ |
| 179 | V(OBSERVERS_END_SPLICE_INDEX, JSFunction, \ |
| 180 | observers_end_perform_splice) \ |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 181 | V(OBSERVERS_DELIVER_CHANGES_INDEX, JSFunction, observers_deliver_changes) \ |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 182 | V(GENERATOR_FUNCTION_MAP_INDEX, Map, generator_function_map) \ |
| 183 | V(STRICT_MODE_GENERATOR_FUNCTION_MAP_INDEX, Map, \ |
| 184 | strict_mode_generator_function_map) \ |
| 185 | V(GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX, Map, \ |
| 186 | generator_object_prototype_map) \ |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 187 | V(GENERATOR_RESULT_MAP_INDEX, Map, generator_result_map) \ |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 188 | V(RANDOM_SEED_INDEX, ByteArray, random_seed) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 189 | |
| 190 | // JSFunctions are pairs (context, function code), sometimes also called |
| 191 | // closures. A Context object is used to represent function contexts and |
| 192 | // dynamically pushed 'with' contexts (or 'scopes' in ECMA-262 speak). |
| 193 | // |
| 194 | // At runtime, the contexts build a stack in parallel to the execution |
| 195 | // stack, with the top-most context being the current context. All contexts |
| 196 | // have the following slots: |
| 197 | // |
| 198 | // [ closure ] This is the current function. It is the same for all |
| 199 | // contexts inside a function. It provides access to the |
| 200 | // incoming context (i.e., the outer context, which may |
| 201 | // or may not become the current function's context), and |
| 202 | // it provides access to the functions code and thus it's |
| 203 | // scope information, which in turn contains the names of |
| 204 | // statically allocated context slots. The names are needed |
| 205 | // for dynamic lookups in the presence of 'with' or 'eval'. |
| 206 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 207 | // [ previous ] A pointer to the previous context. It is NULL for |
| 208 | // function contexts, and non-NULL for 'with' contexts. |
| 209 | // Used to implement the 'with' statement. |
| 210 | // |
| 211 | // [ extension ] A pointer to an extension JSObject, or NULL. Used to |
| 212 | // implement 'with' statements and dynamic declarations |
| 213 | // (through 'eval'). The object in a 'with' statement is |
| 214 | // stored in the extension slot of a 'with' context. |
| 215 | // Dynamically declared variables/functions are also added |
| 216 | // to lazily allocated extension object. Context::Lookup |
| 217 | // searches the extension object for properties. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 218 | // For global and block contexts, contains the respective |
| 219 | // ScopeInfo. |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 220 | // For module contexts, points back to the respective JSModule. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 221 | // |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 222 | // [ global_object ] A pointer to the global object. Provided for quick |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | // access to the global object from inside the code (since |
| 224 | // we always have a context pointer). |
| 225 | // |
| 226 | // In addition, function contexts may have statically allocated context slots |
| 227 | // to store local variables/functions that are accessed from inner functions |
| 228 | // (via static context addresses) or through 'eval' (dynamic context lookups). |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 229 | // Finally, the native context contains additional slots for fast access to |
| 230 | // native properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 231 | |
| 232 | class Context: public FixedArray { |
| 233 | public: |
| 234 | // Conversions. |
| 235 | static Context* cast(Object* context) { |
| 236 | ASSERT(context->IsContext()); |
| 237 | return reinterpret_cast<Context*>(context); |
| 238 | } |
| 239 | |
| 240 | // The default context slot layout; indices are FixedArray slot indices. |
| 241 | enum { |
| 242 | // These slots are in all contexts. |
| 243 | CLOSURE_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 244 | PREVIOUS_INDEX, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 245 | // The extension slot is used for either the global object (in global |
| 246 | // contexts), eval extension object (function contexts), subject of with |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 247 | // (with contexts), or the variable name (catch contexts), the serialized |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 248 | // scope info (block contexts), or the module instance (module contexts). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 249 | EXTENSION_INDEX, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 250 | GLOBAL_OBJECT_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 251 | MIN_CONTEXT_SLOTS, |
| 252 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 253 | // This slot holds the thrown value in catch contexts. |
| 254 | THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS, |
| 255 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 256 | // These slots are only in native contexts. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 257 | GLOBAL_PROXY_INDEX = MIN_CONTEXT_SLOTS, |
| 258 | SECURITY_TOKEN_INDEX, |
| 259 | ARGUMENTS_BOILERPLATE_INDEX, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 260 | ALIASED_ARGUMENTS_BOILERPLATE_INDEX, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 261 | STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX, |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 262 | REGEXP_RESULT_MAP_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 263 | FUNCTION_MAP_INDEX, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 264 | STRICT_MODE_FUNCTION_MAP_INDEX, |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 265 | FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 266 | STRICT_MODE_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 267 | INITIAL_OBJECT_PROTOTYPE_INDEX, |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 268 | INITIAL_ARRAY_PROTOTYPE_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 269 | BOOLEAN_FUNCTION_INDEX, |
| 270 | NUMBER_FUNCTION_INDEX, |
| 271 | STRING_FUNCTION_INDEX, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 272 | STRING_FUNCTION_PROTOTYPE_MAP_INDEX, |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 273 | SYMBOL_FUNCTION_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 274 | OBJECT_FUNCTION_INDEX, |
svenpanne@chromium.org | 3c93e77 | 2012-01-02 09:26:59 +0000 | [diff] [blame] | 275 | INTERNAL_ARRAY_FUNCTION_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 276 | ARRAY_FUNCTION_INDEX, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 277 | JS_ARRAY_MAPS_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 278 | DATE_FUNCTION_INDEX, |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 279 | JSON_OBJECT_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 280 | REGEXP_FUNCTION_INDEX, |
| 281 | CREATE_DATE_FUN_INDEX, |
| 282 | TO_NUMBER_FUN_INDEX, |
| 283 | TO_STRING_FUN_INDEX, |
| 284 | TO_DETAIL_STRING_FUN_INDEX, |
| 285 | TO_OBJECT_FUN_INDEX, |
| 286 | TO_INTEGER_FUN_INDEX, |
| 287 | TO_UINT32_FUN_INDEX, |
| 288 | TO_INT32_FUN_INDEX, |
| 289 | TO_BOOLEAN_FUN_INDEX, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 290 | GLOBAL_EVAL_FUN_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 291 | INSTANTIATE_FUN_INDEX, |
| 292 | CONFIGURE_INSTANCE_FUN_INDEX, |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 293 | ARRAY_BUFFER_FUN_INDEX, |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 294 | UINT8_ARRAY_FUN_INDEX, |
| 295 | INT8_ARRAY_FUN_INDEX, |
| 296 | UINT16_ARRAY_FUN_INDEX, |
| 297 | INT16_ARRAY_FUN_INDEX, |
| 298 | UINT32_ARRAY_FUN_INDEX, |
| 299 | INT32_ARRAY_FUN_INDEX, |
| 300 | FLOAT_ARRAY_FUN_INDEX, |
| 301 | DOUBLE_ARRAY_FUN_INDEX, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 302 | UINT8C_ARRAY_FUN_INDEX, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 303 | DATA_VIEW_FUN_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 304 | MESSAGE_LISTENERS_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 305 | MAKE_MESSAGE_FUN_INDEX, |
| 306 | GET_STACK_TRACE_LINE_INDEX, |
| 307 | CONFIGURE_GLOBAL_INDEX, |
| 308 | FUNCTION_CACHE_INDEX, |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 309 | JSFUNCTION_RESULT_CACHES_INDEX, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 310 | NORMALIZED_MAP_CACHE_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 311 | RUNTIME_CONTEXT_INDEX, |
| 312 | CALL_AS_FUNCTION_DELEGATE_INDEX, |
sgjesse@chromium.org | 05521fc | 2009-05-21 07:37:44 +0000 | [diff] [blame] | 313 | CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 314 | SCRIPT_FUNCTION_INDEX, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 315 | OPAQUE_REFERENCE_FUNCTION_INDEX, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 316 | CONTEXT_EXTENSION_FUNCTION_INDEX, |
| 317 | OUT_OF_MEMORY_INDEX, |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 318 | EMBEDDER_DATA_INDEX, |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 319 | ALLOW_CODE_GEN_FROM_STRINGS_INDEX, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 320 | ERROR_MESSAGE_FOR_CODE_GEN_FROM_STRINGS_INDEX, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 321 | TO_COMPLETE_PROPERTY_DESCRIPTOR_INDEX, |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 322 | DERIVED_HAS_TRAP_INDEX, |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 323 | DERIVED_GET_TRAP_INDEX, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 324 | DERIVED_SET_TRAP_INDEX, |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 325 | PROXY_ENUMERATE_INDEX, |
| 326 | OBSERVERS_NOTIFY_CHANGE_INDEX, |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 327 | OBSERVERS_ENQUEUE_SPLICE_INDEX, |
| 328 | OBSERVERS_BEGIN_SPLICE_INDEX, |
| 329 | OBSERVERS_END_SPLICE_INDEX, |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 330 | OBSERVERS_DELIVER_CHANGES_INDEX, |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 331 | GENERATOR_FUNCTION_MAP_INDEX, |
| 332 | STRICT_MODE_GENERATOR_FUNCTION_MAP_INDEX, |
| 333 | GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 334 | GENERATOR_RESULT_MAP_INDEX, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 335 | RANDOM_SEED_INDEX, |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 336 | |
| 337 | // Properties from here are treated as weak references by the full GC. |
| 338 | // Scavenge treats them as strong references. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 339 | OPTIMIZED_FUNCTIONS_LIST, // Weak. |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 340 | OPTIMIZED_CODE_LIST, // Weak. |
| 341 | DEOPTIMIZED_CODE_LIST, // Weak. |
| 342 | MAP_CACHE_INDEX, // Weak. |
| 343 | NEXT_CONTEXT_LINK, // Weak. |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 344 | |
| 345 | // Total number of slots. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 346 | NATIVE_CONTEXT_SLOTS, |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 347 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 348 | FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 349 | }; |
| 350 | |
| 351 | // Direct slot access. |
| 352 | JSFunction* closure() { return JSFunction::cast(get(CLOSURE_INDEX)); } |
| 353 | void set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); } |
| 354 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 355 | Context* previous() { |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 356 | Object* result = unchecked_previous(); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 357 | ASSERT(IsBootstrappingOrValidParentContext(result, this)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 358 | return reinterpret_cast<Context*>(result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 359 | } |
| 360 | void set_previous(Context* context) { set(PREVIOUS_INDEX, context); } |
| 361 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 362 | bool has_extension() { return extension() != NULL; } |
| 363 | Object* extension() { return get(EXTENSION_INDEX); } |
| 364 | void set_extension(Object* object) { set(EXTENSION_INDEX, object); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 365 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 366 | JSModule* module() { return JSModule::cast(get(EXTENSION_INDEX)); } |
| 367 | void set_module(JSModule* module) { set(EXTENSION_INDEX, module); } |
| 368 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 369 | // Get the context where var declarations will be hoisted to, which |
| 370 | // may be the context itself. |
| 371 | Context* declaration_context(); |
| 372 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 373 | GlobalObject* global_object() { |
| 374 | Object* result = get(GLOBAL_OBJECT_INDEX); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 375 | ASSERT(IsBootstrappingOrGlobalObject(this->GetIsolate(), result)); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 376 | return reinterpret_cast<GlobalObject*>(result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 377 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 378 | void set_global_object(GlobalObject* object) { |
| 379 | set(GLOBAL_OBJECT_INDEX, object); |
| 380 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 381 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 382 | // Returns a JSGlobalProxy object or null. |
| 383 | JSObject* global_proxy(); |
| 384 | void set_global_proxy(JSObject* global); |
| 385 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 386 | // The builtins object. |
| 387 | JSBuiltinsObject* builtins(); |
| 388 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 389 | // Get the innermost global context by traversing the context chain. |
| 390 | Context* global_context(); |
| 391 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 392 | // Compute the native context by traversing the context chain. |
| 393 | Context* native_context(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 394 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 395 | // Predicates for context types. IsNativeContext is also defined on Object |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 396 | // because we frequently have to know if arbitrary objects are natives |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 397 | // contexts. |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 398 | bool IsNativeContext() { |
| 399 | Map* map = this->map(); |
| 400 | return map == map->GetHeap()->native_context_map(); |
| 401 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 402 | bool IsFunctionContext() { |
| 403 | Map* map = this->map(); |
| 404 | return map == map->GetHeap()->function_context_map(); |
| 405 | } |
| 406 | bool IsCatchContext() { |
| 407 | Map* map = this->map(); |
| 408 | return map == map->GetHeap()->catch_context_map(); |
| 409 | } |
| 410 | bool IsWithContext() { |
| 411 | Map* map = this->map(); |
| 412 | return map == map->GetHeap()->with_context_map(); |
| 413 | } |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 414 | bool IsBlockContext() { |
| 415 | Map* map = this->map(); |
| 416 | return map == map->GetHeap()->block_context_map(); |
| 417 | } |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 418 | bool IsModuleContext() { |
| 419 | Map* map = this->map(); |
| 420 | return map == map->GetHeap()->module_context_map(); |
| 421 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 422 | bool IsGlobalContext() { |
| 423 | Map* map = this->map(); |
| 424 | return map == map->GetHeap()->global_context_map(); |
| 425 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 426 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 427 | // Tells whether the native context is marked with out of memory. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 428 | inline bool has_out_of_memory(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 429 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 430 | // Mark the native context with out of memory. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 431 | inline void mark_out_of_memory(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 432 | |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 433 | // A native context holds a list of all functions with optimized code. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 434 | void AddOptimizedFunction(JSFunction* function); |
| 435 | void RemoveOptimizedFunction(JSFunction* function); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 436 | void SetOptimizedFunctionsListHead(Object* head); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 437 | Object* OptimizedFunctionsListHead(); |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 438 | |
| 439 | // The native context also stores a list of all optimized code and a |
| 440 | // list of all deoptimized code, which are needed by the deoptimizer. |
| 441 | void AddOptimizedCode(Code* code); |
| 442 | void SetOptimizedCodeListHead(Object* head); |
| 443 | Object* OptimizedCodeListHead(); |
| 444 | void SetDeoptimizedCodeListHead(Object* head); |
| 445 | Object* DeoptimizedCodeListHead(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 446 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 447 | Handle<Object> ErrorMessageForCodeGenerationFromStrings(); |
| 448 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 449 | #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 450 | void set_##name(type* value) { \ |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 451 | ASSERT(IsNativeContext()); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 452 | set(index, value); \ |
| 453 | } \ |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 454 | bool is_##name(type* value) { \ |
| 455 | ASSERT(IsNativeContext()); \ |
| 456 | return type::cast(get(index)) == value; \ |
| 457 | } \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 458 | type* name() { \ |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 459 | ASSERT(IsNativeContext()); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 460 | return type::cast(get(index)); \ |
| 461 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 462 | NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS) |
| 463 | #undef NATIVE_CONTEXT_FIELD_ACCESSORS |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 464 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 465 | // Lookup the slot called name, starting with the current context. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 466 | // There are three possibilities: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 467 | // |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 468 | // 1) result->IsContext(): |
| 469 | // The binding was found in a context. *index is always the |
| 470 | // non-negative slot index. *attributes is NONE for var and let |
| 471 | // declarations, READ_ONLY for const declarations (never ABSENT). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 472 | // |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 473 | // 2) result->IsJSObject(): |
| 474 | // The binding was found as a named property in a context extension |
| 475 | // object (i.e., was introduced via eval), as a property on the subject |
| 476 | // of with, or as a property of the global object. *index is -1 and |
| 477 | // *attributes is not ABSENT. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 478 | // |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 479 | // 3) result.is_null(): |
| 480 | // There was no binding found, *index is always -1 and *attributes is |
| 481 | // always ABSENT. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 482 | Handle<Object> Lookup(Handle<String> name, |
| 483 | ContextLookupFlags flags, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 484 | int* index, |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 485 | PropertyAttributes* attributes, |
| 486 | BindingFlags* binding_flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 487 | |
| 488 | // Code generation support. |
| 489 | static int SlotOffset(int index) { |
| 490 | return kHeaderSize + index * kPointerSize - kHeapObjectTag; |
| 491 | } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 492 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 493 | static int FunctionMapIndex(LanguageMode language_mode, bool is_generator) { |
| 494 | return is_generator |
| 495 | ? (language_mode == CLASSIC_MODE |
| 496 | ? GENERATOR_FUNCTION_MAP_INDEX |
| 497 | : STRICT_MODE_GENERATOR_FUNCTION_MAP_INDEX) |
| 498 | : (language_mode == CLASSIC_MODE |
| 499 | ? FUNCTION_MAP_INDEX |
| 500 | : STRICT_MODE_FUNCTION_MAP_INDEX); |
| 501 | } |
| 502 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 503 | static const int kSize = kHeaderSize + NATIVE_CONTEXT_SLOTS * kPointerSize; |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 504 | |
| 505 | // GC support. |
| 506 | typedef FixedBodyDescriptor< |
| 507 | kHeaderSize, kSize, kSize> ScavengeBodyDescriptor; |
| 508 | |
| 509 | typedef FixedBodyDescriptor< |
| 510 | kHeaderSize, |
| 511 | kHeaderSize + FIRST_WEAK_SLOT * kPointerSize, |
| 512 | kSize> MarkCompactBodyDescriptor; |
| 513 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 514 | private: |
| 515 | // Unchecked access to the slots. |
| 516 | Object* unchecked_previous() { return get(PREVIOUS_INDEX); } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 517 | |
| 518 | #ifdef DEBUG |
| 519 | // Bootstrapping-aware type checks. |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 520 | static bool IsBootstrappingOrValidParentContext(Object* object, Context* kid); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 521 | static bool IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 522 | #endif |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 523 | |
| 524 | STATIC_CHECK(kHeaderSize == Internals::kContextHeaderSize); |
| 525 | STATIC_CHECK(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 526 | }; |
| 527 | |
| 528 | } } // namespace v8::internal |
| 529 | |
| 530 | #endif // V8_CONTEXTS_H_ |