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