Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_CONTEXTS_H_ |
| 6 | #define V8_CONTEXTS_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/heap/heap.h" |
| 9 | #include "src/objects.h" |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 10 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | |
| 14 | |
| 15 | enum ContextLookupFlags { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 16 | FOLLOW_CONTEXT_CHAIN = 1 << 0, |
| 17 | FOLLOW_PROTOTYPE_CHAIN = 1 << 1, |
| 18 | STOP_AT_DECLARATION_SCOPE = 1 << 2, |
| 19 | SKIP_WITH_CONTEXT = 1 << 3, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 20 | |
| 21 | DONT_FOLLOW_CHAINS = 0, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 22 | FOLLOW_CHAINS = FOLLOW_CONTEXT_CHAIN | FOLLOW_PROTOTYPE_CHAIN, |
| 23 | LEXICAL_TEST = |
| 24 | FOLLOW_CONTEXT_CHAIN | STOP_AT_DECLARATION_SCOPE | SKIP_WITH_CONTEXT, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 28 | // ES5 10.2 defines lexical environments with mutable and immutable bindings. |
| 29 | // Immutable bindings have two states, initialized and uninitialized, and |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 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 MUTABLE_IS_INITIALIZED. |
| 34 | // |
| 35 | // There are two possibilities for 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 |
| 40 | // initialized when entering the function and thus does not need to be |
| 41 | // checked. it gets the BindingFlag IMMUTABLE_IS_INITIALIZED. |
| 42 | // Accessing an uninitialized binding produces the undefined value. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 43 | // |
| 44 | // The harmony proposal for block scoped bindings also introduces the |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 45 | // uninitialized state for mutable bindings. |
| 46 | // * A 'let' declared variable. They are initialized when evaluating the |
| 47 | // corresponding declaration statement. They need to be checked for being |
| 48 | // initialized and thus get the flag MUTABLE_CHECK_INITIALIZED. |
| 49 | // * A 'var' declared variable. It is initialized immediately upon creation |
| 50 | // and thus doesn't need to be checked. It gets the flag |
| 51 | // MUTABLE_IS_INITIALIZED. |
| 52 | // * Catch bound variables, function parameters and variables introduced by |
| 53 | // function declarations are initialized immediately and do not need to be |
| 54 | // checked. Thus they get the flag MUTABLE_IS_INITIALIZED. |
| 55 | // Immutable bindings in harmony mode get the _HARMONY flag variants. Accessing |
| 56 | // an uninitialized binding produces a reference error. |
| 57 | // |
| 58 | // In V8 uninitialized bindings are set to the hole value upon creation and set |
| 59 | // to a different value upon initialization. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 60 | enum BindingFlags { |
| 61 | MUTABLE_IS_INITIALIZED, |
| 62 | MUTABLE_CHECK_INITIALIZED, |
| 63 | IMMUTABLE_IS_INITIALIZED, |
| 64 | IMMUTABLE_CHECK_INITIALIZED, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 65 | IMMUTABLE_IS_INITIALIZED_HARMONY, |
| 66 | IMMUTABLE_CHECK_INITIALIZED_HARMONY, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 67 | MISSING_BINDING |
| 68 | }; |
| 69 | |
| 70 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 71 | // Heap-allocated activation contexts. |
| 72 | // |
| 73 | // Contexts are implemented as FixedArray objects; the Context |
| 74 | // class is a convenience interface casted on a FixedArray object. |
| 75 | // |
| 76 | // Note: Context must have no virtual functions and Context objects |
| 77 | // must always be allocated via Heap::AllocateContext() or |
| 78 | // Factory::NewContext. |
| 79 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 80 | #define NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V) \ |
| 81 | V(IS_ARRAYLIKE, JSFunction, is_arraylike) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 82 | V(GET_TEMPLATE_CALL_SITE_INDEX, JSFunction, get_template_call_site) \ |
| 83 | V(MAKE_RANGE_ERROR_INDEX, JSFunction, make_range_error) \ |
| 84 | V(MAKE_TYPE_ERROR_INDEX, JSFunction, make_type_error) \ |
| 85 | V(OBJECT_FREEZE, JSFunction, object_freeze) \ |
| 86 | V(OBJECT_IS_EXTENSIBLE, JSFunction, object_is_extensible) \ |
| 87 | V(OBJECT_IS_FROZEN, JSFunction, object_is_frozen) \ |
| 88 | V(OBJECT_IS_SEALED, JSFunction, object_is_sealed) \ |
| 89 | V(OBJECT_KEYS, JSFunction, object_keys) \ |
| 90 | V(REFLECT_APPLY_INDEX, JSFunction, reflect_apply) \ |
| 91 | V(REFLECT_CONSTRUCT_INDEX, JSFunction, reflect_construct) \ |
| 92 | V(REFLECT_DEFINE_PROPERTY_INDEX, JSFunction, reflect_define_property) \ |
| 93 | V(REFLECT_DELETE_PROPERTY_INDEX, JSFunction, reflect_delete_property) \ |
| 94 | V(SPREAD_ARGUMENTS_INDEX, JSFunction, spread_arguments) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 95 | V(SPREAD_ITERABLE_INDEX, JSFunction, spread_iterable) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 96 | V(ORDINARY_HAS_INSTANCE_INDEX, JSFunction, ordinary_has_instance) \ |
| 97 | V(MATH_FLOOR, JSFunction, math_floor) \ |
| 98 | V(MATH_SQRT, JSFunction, math_sqrt) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 99 | |
| 100 | #define NATIVE_CONTEXT_IMPORTED_FIELDS(V) \ |
| 101 | V(ARRAY_CONCAT_INDEX, JSFunction, array_concat) \ |
| 102 | V(ARRAY_POP_INDEX, JSFunction, array_pop) \ |
| 103 | V(ARRAY_PUSH_INDEX, JSFunction, array_push) \ |
| 104 | V(ARRAY_SHIFT_INDEX, JSFunction, array_shift) \ |
| 105 | V(ARRAY_SPLICE_INDEX, JSFunction, array_splice) \ |
| 106 | V(ARRAY_SLICE_INDEX, JSFunction, array_slice) \ |
| 107 | V(ARRAY_UNSHIFT_INDEX, JSFunction, array_unshift) \ |
| 108 | V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \ |
| 109 | V(DERIVED_GET_TRAP_INDEX, JSFunction, derived_get_trap) \ |
| 110 | V(ERROR_FUNCTION_INDEX, JSFunction, error_function) \ |
| 111 | V(EVAL_ERROR_FUNCTION_INDEX, JSFunction, eval_error_function) \ |
| 112 | V(GET_STACK_TRACE_LINE_INDEX, JSFunction, get_stack_trace_line_fun) \ |
| 113 | V(GLOBAL_EVAL_FUN_INDEX, JSFunction, global_eval_fun) \ |
| 114 | V(JSON_SERIALIZE_ADAPTER_INDEX, JSFunction, json_serialize_adapter) \ |
| 115 | V(MAKE_ERROR_FUNCTION_INDEX, JSFunction, make_error_function) \ |
| 116 | V(MAP_DELETE_METHOD_INDEX, JSFunction, map_delete) \ |
| 117 | V(MAP_GET_METHOD_INDEX, JSFunction, map_get) \ |
| 118 | V(MAP_HAS_METHOD_INDEX, JSFunction, map_has) \ |
| 119 | V(MAP_SET_METHOD_INDEX, JSFunction, map_set) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 120 | V(MATH_POW_METHOD_INDEX, JSFunction, math_pow) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 121 | V(MESSAGE_GET_COLUMN_NUMBER_INDEX, JSFunction, message_get_column_number) \ |
| 122 | V(MESSAGE_GET_LINE_NUMBER_INDEX, JSFunction, message_get_line_number) \ |
| 123 | V(MESSAGE_GET_SOURCE_LINE_INDEX, JSFunction, message_get_source_line) \ |
| 124 | V(NATIVE_OBJECT_GET_NOTIFIER_INDEX, JSFunction, native_object_get_notifier) \ |
| 125 | V(NATIVE_OBJECT_NOTIFIER_PERFORM_CHANGE, JSFunction, \ |
| 126 | native_object_notifier_perform_change) \ |
| 127 | V(NATIVE_OBJECT_OBSERVE_INDEX, JSFunction, native_object_observe) \ |
| 128 | V(NO_SIDE_EFFECTS_TO_STRING_FUN_INDEX, JSFunction, \ |
| 129 | no_side_effects_to_string_fun) \ |
| 130 | V(OBJECT_VALUE_OF, JSFunction, object_value_of) \ |
| 131 | V(OBJECT_TO_STRING, JSFunction, object_to_string) \ |
| 132 | V(OBSERVERS_BEGIN_SPLICE_INDEX, JSFunction, observers_begin_perform_splice) \ |
| 133 | V(OBSERVERS_END_SPLICE_INDEX, JSFunction, observers_end_perform_splice) \ |
| 134 | V(OBSERVERS_ENQUEUE_SPLICE_INDEX, JSFunction, observers_enqueue_splice) \ |
| 135 | V(OBSERVERS_NOTIFY_CHANGE_INDEX, JSFunction, observers_notify_change) \ |
| 136 | V(PROMISE_CATCH_INDEX, JSFunction, promise_catch) \ |
| 137 | V(PROMISE_CHAIN_INDEX, JSFunction, promise_chain) \ |
| 138 | V(PROMISE_CREATE_INDEX, JSFunction, promise_create) \ |
| 139 | V(PROMISE_FUNCTION_INDEX, JSFunction, promise_function) \ |
| 140 | V(PROMISE_HAS_USER_DEFINED_REJECT_HANDLER_INDEX, JSFunction, \ |
| 141 | promise_has_user_defined_reject_handler) \ |
| 142 | V(PROMISE_REJECT_INDEX, JSFunction, promise_reject) \ |
| 143 | V(PROMISE_RESOLVE_INDEX, JSFunction, promise_resolve) \ |
| 144 | V(PROMISE_THEN_INDEX, JSFunction, promise_then) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 145 | V(RANGE_ERROR_FUNCTION_INDEX, JSFunction, range_error_function) \ |
| 146 | V(REFERENCE_ERROR_FUNCTION_INDEX, JSFunction, reference_error_function) \ |
| 147 | V(SET_ADD_METHOD_INDEX, JSFunction, set_add) \ |
| 148 | V(SET_DELETE_METHOD_INDEX, JSFunction, set_delete) \ |
| 149 | V(SET_HAS_METHOD_INDEX, JSFunction, set_has) \ |
| 150 | V(STACK_OVERFLOW_BOILERPLATE_INDEX, JSObject, stack_overflow_boilerplate) \ |
| 151 | V(SYNTAX_ERROR_FUNCTION_INDEX, JSFunction, syntax_error_function) \ |
| 152 | V(TYPE_ERROR_FUNCTION_INDEX, JSFunction, type_error_function) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 153 | V(URI_ERROR_FUNCTION_INDEX, JSFunction, uri_error_function) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 154 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 155 | #define NATIVE_CONTEXT_FIELDS(V) \ |
| 156 | V(GLOBAL_PROXY_INDEX, JSObject, global_proxy_object) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 157 | V(EMBEDDER_DATA_INDEX, FixedArray, embedder_data) \ |
| 158 | /* Below is alpha-sorted */ \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 159 | V(ACCESSOR_PROPERTY_DESCRIPTOR_MAP_INDEX, Map, \ |
| 160 | accessor_property_descriptor_map) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 161 | V(ALLOW_CODE_GEN_FROM_STRINGS_INDEX, Object, allow_code_gen_from_strings) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 162 | V(ARRAY_BUFFER_FUN_INDEX, JSFunction, array_buffer_fun) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 163 | V(ARRAY_BUFFER_MAP_INDEX, Map, array_buffer_map) \ |
| 164 | V(ARRAY_FUNCTION_INDEX, JSFunction, array_function) \ |
| 165 | V(BOOL16X8_FUNCTION_INDEX, JSFunction, bool16x8_function) \ |
| 166 | V(BOOL32X4_FUNCTION_INDEX, JSFunction, bool32x4_function) \ |
| 167 | V(BOOL8X16_FUNCTION_INDEX, JSFunction, bool8x16_function) \ |
| 168 | V(BOOLEAN_FUNCTION_INDEX, JSFunction, boolean_function) \ |
| 169 | V(BOUND_FUNCTION_WITH_CONSTRUCTOR_MAP_INDEX, Map, \ |
| 170 | bound_function_with_constructor_map) \ |
| 171 | V(BOUND_FUNCTION_WITHOUT_CONSTRUCTOR_MAP_INDEX, Map, \ |
| 172 | bound_function_without_constructor_map) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 173 | V(CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, JSFunction, \ |
| 174 | call_as_constructor_delegate) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 175 | V(CALL_AS_FUNCTION_DELEGATE_INDEX, JSFunction, call_as_function_delegate) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 176 | V(CONTEXT_EXTENSION_FUNCTION_INDEX, JSFunction, context_extension_function) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 177 | V(DATA_PROPERTY_DESCRIPTOR_MAP_INDEX, Map, data_property_descriptor_map) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 178 | V(DATA_VIEW_FUN_INDEX, JSFunction, data_view_fun) \ |
| 179 | V(DATE_FUNCTION_INDEX, JSFunction, date_function) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 180 | V(ERROR_MESSAGE_FOR_CODE_GEN_FROM_STRINGS_INDEX, Object, \ |
| 181 | error_message_for_code_gen_from_strings) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 182 | V(ERRORS_THROWN_INDEX, Smi, errors_thrown) \ |
| 183 | V(EXTRAS_EXPORTS_OBJECT_INDEX, JSObject, extras_binding_object) \ |
| 184 | V(EXTRAS_UTILS_OBJECT_INDEX, JSObject, extras_utils_object) \ |
| 185 | V(FAST_ALIASED_ARGUMENTS_MAP_INDEX, Map, fast_aliased_arguments_map) \ |
| 186 | V(FLOAT32_ARRAY_FUN_INDEX, JSFunction, float32_array_fun) \ |
| 187 | V(FLOAT32X4_FUNCTION_INDEX, JSFunction, float32x4_function) \ |
| 188 | V(FLOAT64_ARRAY_FUN_INDEX, JSFunction, float64_array_fun) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 189 | V(TEMPLATE_INSTANTIATIONS_CACHE_INDEX, UnseededNumberDictionary, \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 190 | template_instantiations_cache) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 191 | V(FUNCTION_FUNCTION_INDEX, JSFunction, function_function) \ |
| 192 | V(GENERATOR_FUNCTION_FUNCTION_INDEX, JSFunction, \ |
| 193 | generator_function_function) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 194 | V(GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX, Map, generator_object_prototype_map) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 195 | V(INITIAL_ARRAY_PROTOTYPE_INDEX, JSObject, initial_array_prototype) \ |
| 196 | V(INITIAL_OBJECT_PROTOTYPE_INDEX, JSObject, initial_object_prototype) \ |
| 197 | V(INT16_ARRAY_FUN_INDEX, JSFunction, int16_array_fun) \ |
| 198 | V(INT16X8_FUNCTION_INDEX, JSFunction, int16x8_function) \ |
| 199 | V(INT32_ARRAY_FUN_INDEX, JSFunction, int32_array_fun) \ |
| 200 | V(INT32X4_FUNCTION_INDEX, JSFunction, int32x4_function) \ |
| 201 | V(INT8_ARRAY_FUN_INDEX, JSFunction, int8_array_fun) \ |
| 202 | V(INT8X16_FUNCTION_INDEX, JSFunction, int8x16_function) \ |
| 203 | V(INTERNAL_ARRAY_FUNCTION_INDEX, JSFunction, internal_array_function) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 204 | V(ITERATOR_RESULT_MAP_INDEX, Map, iterator_result_map) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 205 | V(JS_ARRAY_FAST_SMI_ELEMENTS_MAP_INDEX, Map, \ |
| 206 | js_array_fast_smi_elements_map_index) \ |
| 207 | V(JS_ARRAY_FAST_HOLEY_SMI_ELEMENTS_MAP_INDEX, Map, \ |
| 208 | js_array_fast_holey_smi_elements_map_index) \ |
| 209 | V(JS_ARRAY_FAST_ELEMENTS_MAP_INDEX, Map, js_array_fast_elements_map_index) \ |
| 210 | V(JS_ARRAY_FAST_HOLEY_ELEMENTS_MAP_INDEX, Map, \ |
| 211 | js_array_fast_holey_elements_map_index) \ |
| 212 | V(JS_ARRAY_FAST_DOUBLE_ELEMENTS_MAP_INDEX, Map, \ |
| 213 | js_array_fast_double_elements_map_index) \ |
| 214 | V(JS_ARRAY_FAST_HOLEY_DOUBLE_ELEMENTS_MAP_INDEX, Map, \ |
| 215 | js_array_fast_holey_double_elements_map_index) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 216 | V(JS_MAP_FUN_INDEX, JSFunction, js_map_fun) \ |
| 217 | V(JS_MAP_MAP_INDEX, Map, js_map_map) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 218 | V(JS_SET_FUN_INDEX, JSFunction, js_set_fun) \ |
| 219 | V(JS_SET_MAP_INDEX, Map, js_set_map) \ |
| 220 | V(JS_WEAK_MAP_FUN_INDEX, JSFunction, js_weak_map_fun) \ |
| 221 | V(JS_WEAK_SET_FUN_INDEX, JSFunction, js_weak_set_fun) \ |
| 222 | V(MAP_CACHE_INDEX, Object, map_cache) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 223 | V(MAP_ITERATOR_MAP_INDEX, Map, map_iterator_map) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 224 | V(STRING_ITERATOR_MAP_INDEX, Map, string_iterator_map) \ |
| 225 | V(MESSAGE_LISTENERS_INDEX, JSObject, message_listeners) \ |
| 226 | V(NATIVES_UTILS_OBJECT_INDEX, Object, natives_utils_object) \ |
| 227 | V(NORMALIZED_MAP_CACHE_INDEX, Object, normalized_map_cache) \ |
| 228 | V(NUMBER_FUNCTION_INDEX, JSFunction, number_function) \ |
| 229 | V(OBJECT_FUNCTION_INDEX, JSFunction, object_function) \ |
| 230 | V(OBJECT_FUNCTION_PROTOTYPE_MAP_INDEX, Map, object_function_prototype_map) \ |
| 231 | V(OPAQUE_REFERENCE_FUNCTION_INDEX, JSFunction, opaque_reference_function) \ |
| 232 | V(PROXY_CALLABLE_MAP_INDEX, Map, proxy_callable_map) \ |
| 233 | V(PROXY_CONSTRUCTOR_MAP_INDEX, Map, proxy_constructor_map) \ |
| 234 | V(PROXY_FUNCTION_INDEX, JSFunction, proxy_function) \ |
| 235 | V(PROXY_FUNCTION_MAP_INDEX, Map, proxy_function_map) \ |
| 236 | V(PROXY_MAP_INDEX, Map, proxy_map) \ |
| 237 | V(REGEXP_FUNCTION_INDEX, JSFunction, regexp_function) \ |
| 238 | V(REGEXP_RESULT_MAP_INDEX, Map, regexp_result_map) \ |
| 239 | V(SCRIPT_CONTEXT_TABLE_INDEX, ScriptContextTable, script_context_table) \ |
| 240 | V(SCRIPT_FUNCTION_INDEX, JSFunction, script_function) \ |
| 241 | V(SECURITY_TOKEN_INDEX, Object, security_token) \ |
| 242 | V(SELF_WEAK_CELL_INDEX, WeakCell, self_weak_cell) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 243 | V(SET_ITERATOR_MAP_INDEX, Map, set_iterator_map) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 244 | V(SHARED_ARRAY_BUFFER_FUN_INDEX, JSFunction, shared_array_buffer_fun) \ |
| 245 | V(SLOPPY_ARGUMENTS_MAP_INDEX, Map, sloppy_arguments_map) \ |
| 246 | V(SLOPPY_FUNCTION_MAP_INDEX, Map, sloppy_function_map) \ |
| 247 | V(SLOPPY_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, \ |
| 248 | sloppy_function_without_prototype_map) \ |
| 249 | V(SLOPPY_FUNCTION_WITH_READONLY_PROTOTYPE_MAP_INDEX, Map, \ |
| 250 | sloppy_function_with_readonly_prototype_map) \ |
| 251 | V(WASM_FUNCTION_MAP_INDEX, Map, wasm_function_map) \ |
| 252 | V(SLOPPY_GENERATOR_FUNCTION_MAP_INDEX, Map, sloppy_generator_function_map) \ |
| 253 | V(SLOW_ALIASED_ARGUMENTS_MAP_INDEX, Map, slow_aliased_arguments_map) \ |
| 254 | V(STRICT_ARGUMENTS_MAP_INDEX, Map, strict_arguments_map) \ |
| 255 | V(STRICT_FUNCTION_MAP_INDEX, Map, strict_function_map) \ |
| 256 | V(STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, \ |
| 257 | strict_function_without_prototype_map) \ |
| 258 | V(STRICT_GENERATOR_FUNCTION_MAP_INDEX, Map, strict_generator_function_map) \ |
| 259 | V(STRING_FUNCTION_INDEX, JSFunction, string_function) \ |
| 260 | V(STRING_FUNCTION_PROTOTYPE_MAP_INDEX, Map, string_function_prototype_map) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 261 | V(SYMBOL_FUNCTION_INDEX, JSFunction, symbol_function) \ |
| 262 | V(UINT16_ARRAY_FUN_INDEX, JSFunction, uint16_array_fun) \ |
| 263 | V(UINT16X8_FUNCTION_INDEX, JSFunction, uint16x8_function) \ |
| 264 | V(UINT32_ARRAY_FUN_INDEX, JSFunction, uint32_array_fun) \ |
| 265 | V(UINT32X4_FUNCTION_INDEX, JSFunction, uint32x4_function) \ |
| 266 | V(UINT8_ARRAY_FUN_INDEX, JSFunction, uint8_array_fun) \ |
| 267 | V(UINT8_CLAMPED_ARRAY_FUN_INDEX, JSFunction, uint8_clamped_array_fun) \ |
| 268 | V(UINT8X16_FUNCTION_INDEX, JSFunction, uint8x16_function) \ |
| 269 | NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V) \ |
| 270 | NATIVE_CONTEXT_IMPORTED_FIELDS(V) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 271 | |
| 272 | // A table of all script contexts. Every loaded top-level script with top-level |
| 273 | // lexical declarations contributes its ScriptContext into this table. |
| 274 | // |
| 275 | // The table is a fixed array, its first slot is the current used count and |
| 276 | // the subsequent slots 1..used contain ScriptContexts. |
| 277 | class ScriptContextTable : public FixedArray { |
| 278 | public: |
| 279 | // Conversions. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 280 | static inline ScriptContextTable* cast(Object* context); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 281 | |
| 282 | struct LookupResult { |
| 283 | int context_index; |
| 284 | int slot_index; |
| 285 | VariableMode mode; |
| 286 | InitializationFlag init_flag; |
| 287 | MaybeAssignedFlag maybe_assigned_flag; |
| 288 | }; |
| 289 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 290 | inline int used() const; |
| 291 | inline void set_used(int used); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 292 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 293 | static inline Handle<Context> GetContext(Handle<ScriptContextTable> table, |
| 294 | int i); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 295 | |
| 296 | // Lookup a variable `name` in a ScriptContextTable. |
| 297 | // If it returns true, the variable is found and `result` contains |
| 298 | // valid information about its location. |
| 299 | // If it returns false, `result` is untouched. |
| 300 | MUST_USE_RESULT |
| 301 | static bool Lookup(Handle<ScriptContextTable> table, Handle<String> name, |
| 302 | LookupResult* result); |
| 303 | |
| 304 | MUST_USE_RESULT |
| 305 | static Handle<ScriptContextTable> Extend(Handle<ScriptContextTable> table, |
| 306 | Handle<Context> script_context); |
| 307 | |
| 308 | static int GetContextOffset(int context_index) { |
| 309 | return kFirstContextOffset + context_index * kPointerSize; |
| 310 | } |
| 311 | |
| 312 | private: |
| 313 | static const int kUsedSlot = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 314 | static const int kFirstContextSlot = kUsedSlot + 1; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 315 | static const int kFirstContextOffset = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 316 | FixedArray::kHeaderSize + kFirstContextSlot * kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 317 | |
| 318 | DISALLOW_IMPLICIT_CONSTRUCTORS(ScriptContextTable); |
| 319 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 320 | |
| 321 | // JSFunctions are pairs (context, function code), sometimes also called |
| 322 | // closures. A Context object is used to represent function contexts and |
| 323 | // dynamically pushed 'with' contexts (or 'scopes' in ECMA-262 speak). |
| 324 | // |
| 325 | // At runtime, the contexts build a stack in parallel to the execution |
| 326 | // stack, with the top-most context being the current context. All contexts |
| 327 | // have the following slots: |
| 328 | // |
| 329 | // [ closure ] This is the current function. It is the same for all |
| 330 | // contexts inside a function. It provides access to the |
| 331 | // incoming context (i.e., the outer context, which may |
| 332 | // or may not become the current function's context), and |
| 333 | // it provides access to the functions code and thus it's |
| 334 | // scope information, which in turn contains the names of |
| 335 | // statically allocated context slots. The names are needed |
| 336 | // for dynamic lookups in the presence of 'with' or 'eval'. |
| 337 | // |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 338 | // [ previous ] A pointer to the previous context. It is NULL for |
| 339 | // function contexts, and non-NULL for 'with' contexts. |
| 340 | // Used to implement the 'with' statement. |
| 341 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 342 | // [ extension ] A pointer to an extension JSObject, or "the hole". Used to |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 343 | // implement 'with' statements and dynamic declarations |
| 344 | // (through 'eval'). The object in a 'with' statement is |
| 345 | // stored in the extension slot of a 'with' context. |
| 346 | // Dynamically declared variables/functions are also added |
| 347 | // to lazily allocated extension object. Context::Lookup |
| 348 | // searches the extension object for properties. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 349 | // For script and block contexts, contains the respective |
| 350 | // ScopeInfo. For block contexts representing sloppy declaration |
| 351 | // block scopes, it may also be a struct being a |
| 352 | // SloppyBlockWithEvalContextExtension, pairing the ScopeInfo |
| 353 | // with an extension object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 354 | // For module contexts, points back to the respective JSModule. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 355 | // |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 356 | // [ global_object ] A pointer to the global object. Provided for quick |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 357 | // access to the global object from inside the code (since |
| 358 | // we always have a context pointer). |
| 359 | // |
| 360 | // In addition, function contexts may have statically allocated context slots |
| 361 | // to store local variables/functions that are accessed from inner functions |
| 362 | // (via static context addresses) or through 'eval' (dynamic context lookups). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 363 | // The native context contains additional slots for fast access to native |
| 364 | // properties. |
| 365 | // |
| 366 | // Finally, with Harmony scoping, the JSFunction representing a top level |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 367 | // script will have the ScriptContext rather than a FunctionContext. |
| 368 | // Script contexts from all top-level scripts are gathered in |
| 369 | // ScriptContextTable. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 370 | |
| 371 | class Context: public FixedArray { |
| 372 | public: |
| 373 | // Conversions. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 374 | static inline Context* cast(Object* context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 375 | |
| 376 | // The default context slot layout; indices are FixedArray slot indices. |
| 377 | enum { |
| 378 | // These slots are in all contexts. |
| 379 | CLOSURE_INDEX, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 380 | PREVIOUS_INDEX, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 381 | // The extension slot is used for either the global object (in native |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 382 | // contexts), eval extension object (function contexts), subject of with |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 383 | // (with contexts), or the variable name (catch contexts), the serialized |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 384 | // scope info (block contexts), or the module instance (module contexts). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 385 | EXTENSION_INDEX, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 386 | NATIVE_CONTEXT_INDEX, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 387 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 388 | // These slots are only in native contexts. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 389 | #define NATIVE_CONTEXT_SLOT(index, type, name) index, |
| 390 | NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_SLOT) |
| 391 | #undef NATIVE_CONTEXT_SLOT |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 392 | |
| 393 | // Properties from here are treated as weak references by the full GC. |
| 394 | // Scavenge treats them as strong references. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 395 | OPTIMIZED_FUNCTIONS_LIST, // Weak. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 396 | OPTIMIZED_CODE_LIST, // Weak. |
| 397 | DEOPTIMIZED_CODE_LIST, // Weak. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 398 | NEXT_CONTEXT_LINK, // Weak. |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 399 | |
| 400 | // Total number of slots. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 401 | NATIVE_CONTEXT_SLOTS, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 402 | FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST, |
| 403 | FIRST_JS_ARRAY_MAP_SLOT = JS_ARRAY_FAST_SMI_ELEMENTS_MAP_INDEX, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 404 | |
| 405 | MIN_CONTEXT_SLOTS = GLOBAL_PROXY_INDEX, |
| 406 | // This slot holds the thrown value in catch contexts. |
| 407 | THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 408 | |
| 409 | // These slots hold values in debug evaluate contexts. |
| 410 | WRAPPED_CONTEXT_INDEX = MIN_CONTEXT_SLOTS, |
| 411 | WHITE_LIST_INDEX = MIN_CONTEXT_SLOTS + 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 412 | }; |
| 413 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 414 | void IncrementErrorsThrown(); |
| 415 | int GetErrorsThrown(); |
| 416 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 417 | // Direct slot access. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 418 | inline JSFunction* closure(); |
| 419 | inline void set_closure(JSFunction* closure); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 420 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 421 | inline Context* previous(); |
| 422 | inline void set_previous(Context* context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 423 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 424 | inline bool has_extension(); |
| 425 | inline HeapObject* extension(); |
| 426 | inline void set_extension(HeapObject* object); |
| 427 | JSObject* extension_object(); |
| 428 | JSReceiver* extension_receiver(); |
| 429 | ScopeInfo* scope_info(); |
| 430 | String* catch_name(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 431 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 432 | inline JSModule* module(); |
| 433 | inline void set_module(JSModule* module); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 434 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 435 | // Get the context where var declarations will be hoisted to, which |
| 436 | // may be the context itself. |
| 437 | Context* declaration_context(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 438 | bool is_declaration_context(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 439 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 440 | // Get the next closure's context on the context chain. |
| 441 | Context* closure_context(); |
| 442 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 443 | // Returns a JSGlobalProxy object or null. |
| 444 | JSObject* global_proxy(); |
| 445 | void set_global_proxy(JSObject* global); |
| 446 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 447 | // Get the JSGlobalObject object. |
| 448 | JSGlobalObject* global_object(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 449 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 450 | // Get the script context by traversing the context chain. |
| 451 | Context* script_context(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 452 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 453 | // Compute the native context. |
| 454 | inline Context* native_context(); |
| 455 | inline void set_native_context(Context* context); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 456 | |
| 457 | // Predicates for context types. IsNativeContext is also defined on Object |
| 458 | // because we frequently have to know if arbitrary objects are natives |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 459 | // contexts. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 460 | inline bool IsNativeContext(); |
| 461 | inline bool IsFunctionContext(); |
| 462 | inline bool IsCatchContext(); |
| 463 | inline bool IsWithContext(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 464 | inline bool IsDebugEvaluateContext(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 465 | inline bool IsBlockContext(); |
| 466 | inline bool IsModuleContext(); |
| 467 | inline bool IsScriptContext(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 468 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 469 | inline bool HasSameSecurityTokenAs(Context* that); |
| 470 | |
| 471 | // Initializes global variable bindings in given script context. |
| 472 | void InitializeGlobalSlots(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 473 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 474 | // A native context holds a list of all functions with optimized code. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 475 | void AddOptimizedFunction(JSFunction* function); |
| 476 | void RemoveOptimizedFunction(JSFunction* function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 477 | void SetOptimizedFunctionsListHead(Object* head); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 478 | Object* OptimizedFunctionsListHead(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 479 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 480 | // The native context also stores a list of all optimized code and a |
| 481 | // list of all deoptimized code, which are needed by the deoptimizer. |
| 482 | void AddOptimizedCode(Code* code); |
| 483 | void SetOptimizedCodeListHead(Object* head); |
| 484 | Object* OptimizedCodeListHead(); |
| 485 | void SetDeoptimizedCodeListHead(Object* head); |
| 486 | Object* DeoptimizedCodeListHead(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 487 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 488 | Handle<Object> ErrorMessageForCodeGenerationFromStrings(); |
| 489 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 490 | static int ImportedFieldIndexForName(Handle<String> name); |
| 491 | static int IntrinsicIndexForName(Handle<String> name); |
| 492 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 493 | #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 494 | inline void set_##name(type* value); \ |
| 495 | inline bool is_##name(type* value); \ |
| 496 | inline type* name(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 497 | NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS) |
| 498 | #undef NATIVE_CONTEXT_FIELD_ACCESSORS |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 499 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 500 | // Lookup the slot called name, starting with the current context. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 501 | // There are three possibilities: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 502 | // |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 503 | // 1) result->IsContext(): |
| 504 | // The binding was found in a context. *index is always the |
| 505 | // non-negative slot index. *attributes is NONE for var and let |
| 506 | // declarations, READ_ONLY for const declarations (never ABSENT). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 507 | // |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 508 | // 2) result->IsJSObject(): |
| 509 | // The binding was found as a named property in a context extension |
| 510 | // object (i.e., was introduced via eval), as a property on the subject |
| 511 | // of with, or as a property of the global object. *index is -1 and |
| 512 | // *attributes is not ABSENT. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 513 | // |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 514 | // 3) result.is_null(): |
| 515 | // There was no binding found, *index is always -1 and *attributes is |
| 516 | // always ABSENT. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 517 | Handle<Object> Lookup(Handle<String> name, |
| 518 | ContextLookupFlags flags, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 519 | int* index, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 520 | PropertyAttributes* attributes, |
| 521 | BindingFlags* binding_flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 522 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 523 | // Code generation support. |
| 524 | static int SlotOffset(int index) { |
| 525 | return kHeaderSize + index * kPointerSize - kHeapObjectTag; |
| 526 | } |
| 527 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 528 | static int FunctionMapIndex(LanguageMode language_mode, FunctionKind kind) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 529 | if (IsGeneratorFunction(kind)) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 530 | return is_strict(language_mode) ? STRICT_GENERATOR_FUNCTION_MAP_INDEX |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 531 | : SLOPPY_GENERATOR_FUNCTION_MAP_INDEX; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 534 | if (IsClassConstructor(kind)) { |
| 535 | // Use strict function map (no own "caller" / "arguments") |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 536 | return STRICT_FUNCTION_MAP_INDEX; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | if (IsArrowFunction(kind) || IsConciseMethod(kind) || |
| 540 | IsAccessorFunction(kind)) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 541 | return STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 544 | return is_strict(language_mode) ? STRICT_FUNCTION_MAP_INDEX |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 545 | : SLOPPY_FUNCTION_MAP_INDEX; |
| 546 | } |
| 547 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 548 | static int ArrayMapIndex(ElementsKind elements_kind) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 549 | DCHECK(IsFastElementsKind(elements_kind)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 550 | return elements_kind + FIRST_JS_ARRAY_MAP_SLOT; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | static const int kSize = kHeaderSize + NATIVE_CONTEXT_SLOTS * kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 554 | static const int kNotFound = -1; |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 555 | |
| 556 | // GC support. |
| 557 | typedef FixedBodyDescriptor< |
| 558 | kHeaderSize, kSize, kSize> ScavengeBodyDescriptor; |
| 559 | |
| 560 | typedef FixedBodyDescriptor< |
| 561 | kHeaderSize, |
| 562 | kHeaderSize + FIRST_WEAK_SLOT * kPointerSize, |
| 563 | kSize> MarkCompactBodyDescriptor; |
| 564 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 565 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 566 | #ifdef DEBUG |
| 567 | // Bootstrapping-aware type checks. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 568 | static bool IsBootstrappingOrNativeContext(Isolate* isolate, Object* object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 569 | static bool IsBootstrappingOrValidParentContext(Object* object, Context* kid); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 570 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 571 | |
| 572 | STATIC_ASSERT(kHeaderSize == Internals::kContextHeaderSize); |
| 573 | STATIC_ASSERT(EMBEDDER_DATA_INDEX == Internals::kContextEmbedderDataIndex); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 574 | }; |
| 575 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 576 | } // namespace internal |
| 577 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 578 | |
| 579 | #endif // V8_CONTEXTS_H_ |