Line data Source code
1 : // Copyright 2012 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_CONTEXTS_H_
6 : #define V8_CONTEXTS_H_
7 :
8 : #include "src/objects/fixed-array.h"
9 :
10 : // Has to be the last include (doesn't have include guards):
11 : #include "src/objects/object-macros.h"
12 :
13 : namespace v8 {
14 : namespace internal {
15 :
16 : class JSGlobalObject;
17 : class JSGlobalProxy;
18 : class MicrotaskQueue;
19 : class NativeContext;
20 : class RegExpMatchInfo;
21 :
22 : enum ContextLookupFlags {
23 : FOLLOW_CONTEXT_CHAIN = 1 << 0,
24 : FOLLOW_PROTOTYPE_CHAIN = 1 << 1,
25 :
26 : DONT_FOLLOW_CHAINS = 0,
27 : FOLLOW_CHAINS = FOLLOW_CONTEXT_CHAIN | FOLLOW_PROTOTYPE_CHAIN,
28 : };
29 :
30 : // Heap-allocated activation contexts.
31 : //
32 : // Contexts are implemented as FixedArray-like objects having a fixed
33 : // header with a set of common fields.
34 : //
35 : // Note: Context must have no virtual functions and Context objects
36 : // must always be allocated via Heap::AllocateContext() or
37 : // Factory::NewContext.
38 :
39 : #define NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V) \
40 : V(ASYNC_FUNCTION_PROMISE_CREATE_INDEX, JSFunction, \
41 : async_function_promise_create) \
42 : V(IS_ARRAYLIKE, JSFunction, is_arraylike) \
43 : V(GENERATOR_NEXT_INTERNAL, JSFunction, generator_next_internal) \
44 : V(MAKE_ERROR_INDEX, JSFunction, make_error) \
45 : V(MAKE_RANGE_ERROR_INDEX, JSFunction, make_range_error) \
46 : V(MAKE_SYNTAX_ERROR_INDEX, JSFunction, make_syntax_error) \
47 : V(MAKE_TYPE_ERROR_INDEX, JSFunction, make_type_error) \
48 : V(MAKE_URI_ERROR_INDEX, JSFunction, make_uri_error) \
49 : V(OBJECT_CREATE, JSFunction, object_create) \
50 : V(OBJECT_DEFINE_PROPERTIES, JSFunction, object_define_properties) \
51 : V(OBJECT_DEFINE_PROPERTY, JSFunction, object_define_property) \
52 : V(OBJECT_GET_PROTOTYPE_OF, JSFunction, object_get_prototype_of) \
53 : V(OBJECT_IS_EXTENSIBLE, JSFunction, object_is_extensible) \
54 : V(OBJECT_IS_FROZEN, JSFunction, object_is_frozen) \
55 : V(OBJECT_IS_SEALED, JSFunction, object_is_sealed) \
56 : V(OBJECT_KEYS, JSFunction, object_keys) \
57 : V(REGEXP_INTERNAL_MATCH, JSFunction, regexp_internal_match) \
58 : V(REFLECT_APPLY_INDEX, JSFunction, reflect_apply) \
59 : V(REFLECT_CONSTRUCT_INDEX, JSFunction, reflect_construct) \
60 : V(REFLECT_DEFINE_PROPERTY_INDEX, JSFunction, reflect_define_property) \
61 : V(REFLECT_DELETE_PROPERTY_INDEX, JSFunction, reflect_delete_property) \
62 : V(MATH_FLOOR_INDEX, JSFunction, math_floor) \
63 : V(MATH_POW_INDEX, JSFunction, math_pow) \
64 : V(NEW_PROMISE_CAPABILITY_INDEX, JSFunction, new_promise_capability) \
65 : V(PROMISE_INTERNAL_CONSTRUCTOR_INDEX, JSFunction, \
66 : promise_internal_constructor) \
67 : V(IS_PROMISE_INDEX, JSFunction, is_promise) \
68 : V(PROMISE_THEN_INDEX, JSFunction, promise_then)
69 :
70 : #define NATIVE_CONTEXT_FIELDS(V) \
71 : V(GLOBAL_PROXY_INDEX, JSGlobalProxy, global_proxy_object) \
72 : /* TODO(ishell): Actually we store exactly EmbedderDataArray here but */ \
73 : /* it's already UBSan-fiendly and doesn't require a star... So declare */ \
74 : /* it as a HeapObject for now. */ \
75 : V(EMBEDDER_DATA_INDEX, HeapObject, embedder_data) \
76 : /* Below is alpha-sorted */ \
77 : V(ACCESSOR_PROPERTY_DESCRIPTOR_MAP_INDEX, Map, \
78 : accessor_property_descriptor_map) \
79 : V(ALLOW_CODE_GEN_FROM_STRINGS_INDEX, Object, allow_code_gen_from_strings) \
80 : V(ARRAY_BUFFER_FUN_INDEX, JSFunction, array_buffer_fun) \
81 : V(ARRAY_BUFFER_MAP_INDEX, Map, array_buffer_map) \
82 : V(ARRAY_BUFFER_NOINIT_FUN_INDEX, JSFunction, array_buffer_noinit_fun) \
83 : V(ARRAY_FUNCTION_INDEX, JSFunction, array_function) \
84 : V(ARRAY_JOIN_STACK_INDEX, HeapObject, array_join_stack) \
85 : V(ASYNC_FROM_SYNC_ITERATOR_MAP_INDEX, Map, async_from_sync_iterator_map) \
86 : V(ASYNC_FUNCTION_AWAIT_REJECT_SHARED_FUN, SharedFunctionInfo, \
87 : async_function_await_reject_shared_fun) \
88 : V(ASYNC_FUNCTION_AWAIT_RESOLVE_SHARED_FUN, SharedFunctionInfo, \
89 : async_function_await_resolve_shared_fun) \
90 : V(ASYNC_FUNCTION_FUNCTION_INDEX, JSFunction, async_function_constructor) \
91 : V(ASYNC_FUNCTION_OBJECT_MAP_INDEX, Map, async_function_object_map) \
92 : V(ASYNC_GENERATOR_FUNCTION_FUNCTION_INDEX, JSFunction, \
93 : async_generator_function_function) \
94 : V(ASYNC_ITERATOR_VALUE_UNWRAP_SHARED_FUN, SharedFunctionInfo, \
95 : async_iterator_value_unwrap_shared_fun) \
96 : V(ASYNC_GENERATOR_AWAIT_REJECT_SHARED_FUN, SharedFunctionInfo, \
97 : async_generator_await_reject_shared_fun) \
98 : V(ASYNC_GENERATOR_AWAIT_RESOLVE_SHARED_FUN, SharedFunctionInfo, \
99 : async_generator_await_resolve_shared_fun) \
100 : V(ASYNC_GENERATOR_YIELD_RESOLVE_SHARED_FUN, SharedFunctionInfo, \
101 : async_generator_yield_resolve_shared_fun) \
102 : V(ASYNC_GENERATOR_RETURN_RESOLVE_SHARED_FUN, SharedFunctionInfo, \
103 : async_generator_return_resolve_shared_fun) \
104 : V(ASYNC_GENERATOR_RETURN_CLOSED_RESOLVE_SHARED_FUN, SharedFunctionInfo, \
105 : async_generator_return_closed_resolve_shared_fun) \
106 : V(ASYNC_GENERATOR_RETURN_CLOSED_REJECT_SHARED_FUN, SharedFunctionInfo, \
107 : async_generator_return_closed_reject_shared_fun) \
108 : V(ATOMICS_OBJECT, JSObject, atomics_object) \
109 : V(BIGINT_FUNCTION_INDEX, JSFunction, bigint_function) \
110 : V(BIGINT64_ARRAY_FUN_INDEX, JSFunction, bigint64_array_fun) \
111 : V(BIGUINT64_ARRAY_FUN_INDEX, JSFunction, biguint64_array_fun) \
112 : V(BOOLEAN_FUNCTION_INDEX, JSFunction, boolean_function) \
113 : V(BOUND_FUNCTION_WITH_CONSTRUCTOR_MAP_INDEX, Map, \
114 : bound_function_with_constructor_map) \
115 : V(BOUND_FUNCTION_WITHOUT_CONSTRUCTOR_MAP_INDEX, Map, \
116 : bound_function_without_constructor_map) \
117 : V(CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, JSFunction, \
118 : call_as_constructor_delegate) \
119 : V(CALL_AS_FUNCTION_DELEGATE_INDEX, JSFunction, call_as_function_delegate) \
120 : V(CALLSITE_FUNCTION_INDEX, JSFunction, callsite_function) \
121 : V(CONTEXT_EXTENSION_FUNCTION_INDEX, JSFunction, context_extension_function) \
122 : V(DATA_PROPERTY_DESCRIPTOR_MAP_INDEX, Map, data_property_descriptor_map) \
123 : V(DATA_VIEW_FUN_INDEX, JSFunction, data_view_fun) \
124 : V(DATE_FUNCTION_INDEX, JSFunction, date_function) \
125 : V(DEBUG_CONTEXT_ID_INDEX, Object, debug_context_id) \
126 : V(EMPTY_FUNCTION_INDEX, JSFunction, empty_function) \
127 : V(ERROR_MESSAGE_FOR_CODE_GEN_FROM_STRINGS_INDEX, Object, \
128 : error_message_for_code_gen_from_strings) \
129 : V(ERRORS_THROWN_INDEX, Smi, errors_thrown) \
130 : V(EXTRAS_EXPORTS_OBJECT_INDEX, JSObject, extras_binding_object) \
131 : V(EXTRAS_UTILS_OBJECT_INDEX, Object, extras_utils_object) \
132 : V(FAST_ALIASED_ARGUMENTS_MAP_INDEX, Map, fast_aliased_arguments_map) \
133 : V(FAST_TEMPLATE_INSTANTIATIONS_CACHE_INDEX, FixedArray, \
134 : fast_template_instantiations_cache) \
135 : V(FLOAT32_ARRAY_FUN_INDEX, JSFunction, float32_array_fun) \
136 : V(FLOAT64_ARRAY_FUN_INDEX, JSFunction, float64_array_fun) \
137 : V(FUNCTION_FUNCTION_INDEX, JSFunction, function_function) \
138 : V(GENERATOR_FUNCTION_FUNCTION_INDEX, JSFunction, \
139 : generator_function_function) \
140 : V(GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX, Map, generator_object_prototype_map) \
141 : V(ASYNC_GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX, Map, \
142 : async_generator_object_prototype_map) \
143 : V(INITIAL_ARRAY_ITERATOR_MAP_INDEX, Map, initial_array_iterator_map) \
144 : V(INITIAL_ARRAY_ITERATOR_PROTOTYPE_INDEX, JSObject, \
145 : initial_array_iterator_prototype) \
146 : V(INITIAL_ARRAY_PROTOTYPE_INDEX, JSObject, initial_array_prototype) \
147 : V(INITIAL_ERROR_PROTOTYPE_INDEX, JSObject, initial_error_prototype) \
148 : V(INITIAL_GENERATOR_PROTOTYPE_INDEX, JSObject, initial_generator_prototype) \
149 : V(INITIAL_ASYNC_GENERATOR_PROTOTYPE_INDEX, JSObject, \
150 : initial_async_generator_prototype) \
151 : V(INITIAL_ITERATOR_PROTOTYPE_INDEX, JSObject, initial_iterator_prototype) \
152 : V(INITIAL_MAP_ITERATOR_PROTOTYPE_INDEX, JSObject, \
153 : initial_map_iterator_prototype) \
154 : V(INITIAL_MAP_PROTOTYPE_MAP_INDEX, Map, initial_map_prototype_map) \
155 : V(INITIAL_OBJECT_PROTOTYPE_INDEX, JSObject, initial_object_prototype) \
156 : V(INITIAL_SET_ITERATOR_PROTOTYPE_INDEX, JSObject, \
157 : initial_set_iterator_prototype) \
158 : V(INITIAL_SET_PROTOTYPE_INDEX, JSObject, initial_set_prototype) \
159 : V(INITIAL_SET_PROTOTYPE_MAP_INDEX, Map, initial_set_prototype_map) \
160 : V(INITIAL_STRING_ITERATOR_MAP_INDEX, Map, initial_string_iterator_map) \
161 : V(INITIAL_STRING_ITERATOR_PROTOTYPE_INDEX, JSObject, \
162 : initial_string_iterator_prototype) \
163 : V(INITIAL_STRING_PROTOTYPE_INDEX, JSObject, initial_string_prototype) \
164 : V(INITIAL_WEAKMAP_PROTOTYPE_MAP_INDEX, Map, initial_weakmap_prototype_map) \
165 : V(INITIAL_WEAKSET_PROTOTYPE_MAP_INDEX, Map, initial_weakset_prototype_map) \
166 : V(INT16_ARRAY_FUN_INDEX, JSFunction, int16_array_fun) \
167 : V(INT32_ARRAY_FUN_INDEX, JSFunction, int32_array_fun) \
168 : V(INT8_ARRAY_FUN_INDEX, JSFunction, int8_array_fun) \
169 : V(INTL_COLLATOR_FUNCTION_INDEX, JSFunction, intl_collator_function) \
170 : V(INTL_DATE_TIME_FORMAT_FUNCTION_INDEX, JSFunction, \
171 : intl_date_time_format_function) \
172 : V(INTL_NUMBER_FORMAT_FUNCTION_INDEX, JSFunction, \
173 : intl_number_format_function) \
174 : V(INTL_LOCALE_FUNCTION_INDEX, JSFunction, intl_locale_function) \
175 : V(INTL_SEGMENT_ITERATOR_MAP_INDEX, Map, intl_segment_iterator_map) \
176 : V(ITERATOR_RESULT_MAP_INDEX, Map, iterator_result_map) \
177 : V(JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX, Map, \
178 : js_array_packed_smi_elements_map) \
179 : V(JS_ARRAY_HOLEY_SMI_ELEMENTS_MAP_INDEX, Map, \
180 : js_array_holey_smi_elements_map) \
181 : V(JS_ARRAY_PACKED_ELEMENTS_MAP_INDEX, Map, js_array_packed_elements_map) \
182 : V(JS_ARRAY_HOLEY_ELEMENTS_MAP_INDEX, Map, js_array_holey_elements_map) \
183 : V(JS_ARRAY_PACKED_DOUBLE_ELEMENTS_MAP_INDEX, Map, \
184 : js_array_packed_double_elements_map) \
185 : V(JS_ARRAY_HOLEY_DOUBLE_ELEMENTS_MAP_INDEX, Map, \
186 : js_array_holey_double_elements_map) \
187 : V(JS_MAP_FUN_INDEX, JSFunction, js_map_fun) \
188 : V(JS_MAP_MAP_INDEX, Map, js_map_map) \
189 : V(JS_MODULE_NAMESPACE_MAP, Map, js_module_namespace_map) \
190 : V(JS_SET_FUN_INDEX, JSFunction, js_set_fun) \
191 : V(JS_SET_MAP_INDEX, Map, js_set_map) \
192 : V(JS_WEAK_CELL_MAP_INDEX, Map, js_weak_cell_map) \
193 : V(JS_WEAK_FACTORY_CLEANUP_ITERATOR_MAP_INDEX, Map, \
194 : js_weak_factory_cleanup_iterator_map) \
195 : V(JS_WEAK_MAP_FUN_INDEX, JSFunction, js_weak_map_fun) \
196 : V(JS_WEAK_REF_MAP_INDEX, Map, js_weak_ref_map) \
197 : V(JS_WEAK_SET_FUN_INDEX, JSFunction, js_weak_set_fun) \
198 : V(MAP_CACHE_INDEX, Object, map_cache) \
199 : V(MAP_KEY_ITERATOR_MAP_INDEX, Map, map_key_iterator_map) \
200 : V(MAP_KEY_VALUE_ITERATOR_MAP_INDEX, Map, map_key_value_iterator_map) \
201 : V(MAP_VALUE_ITERATOR_MAP_INDEX, Map, map_value_iterator_map) \
202 : V(MATH_RANDOM_INDEX_INDEX, Smi, math_random_index) \
203 : V(MATH_RANDOM_STATE_INDEX, ByteArray, math_random_state) \
204 : V(MATH_RANDOM_CACHE_INDEX, FixedDoubleArray, math_random_cache) \
205 : V(MESSAGE_LISTENERS_INDEX, TemplateList, message_listeners) \
206 : V(NORMALIZED_MAP_CACHE_INDEX, Object, normalized_map_cache) \
207 : V(NUMBER_FUNCTION_INDEX, JSFunction, number_function) \
208 : V(OBJECT_FUNCTION_INDEX, JSFunction, object_function) \
209 : V(OBJECT_FUNCTION_PROTOTYPE_MAP_INDEX, Map, object_function_prototype_map) \
210 : V(OPAQUE_REFERENCE_FUNCTION_INDEX, JSFunction, opaque_reference_function) \
211 : V(PROXY_CALLABLE_MAP_INDEX, Map, proxy_callable_map) \
212 : V(PROXY_CONSTRUCTOR_MAP_INDEX, Map, proxy_constructor_map) \
213 : V(PROXY_FUNCTION_INDEX, JSFunction, proxy_function) \
214 : V(PROXY_MAP_INDEX, Map, proxy_map) \
215 : V(PROXY_REVOCABLE_RESULT_MAP_INDEX, Map, proxy_revocable_result_map) \
216 : V(PROXY_REVOKE_SHARED_FUN, SharedFunctionInfo, proxy_revoke_shared_fun) \
217 : V(PROMISE_GET_CAPABILITIES_EXECUTOR_SHARED_FUN, SharedFunctionInfo, \
218 : promise_get_capabilities_executor_shared_fun) \
219 : V(PROMISE_CAPABILITY_DEFAULT_REJECT_SHARED_FUN_INDEX, SharedFunctionInfo, \
220 : promise_capability_default_reject_shared_fun) \
221 : V(PROMISE_CAPABILITY_DEFAULT_RESOLVE_SHARED_FUN_INDEX, SharedFunctionInfo, \
222 : promise_capability_default_resolve_shared_fun) \
223 : V(PROMISE_THEN_FINALLY_SHARED_FUN, SharedFunctionInfo, \
224 : promise_then_finally_shared_fun) \
225 : V(PROMISE_CATCH_FINALLY_SHARED_FUN, SharedFunctionInfo, \
226 : promise_catch_finally_shared_fun) \
227 : V(PROMISE_VALUE_THUNK_FINALLY_SHARED_FUN, SharedFunctionInfo, \
228 : promise_value_thunk_finally_shared_fun) \
229 : V(PROMISE_THROWER_FINALLY_SHARED_FUN, SharedFunctionInfo, \
230 : promise_thrower_finally_shared_fun) \
231 : V(PROMISE_ALL_RESOLVE_ELEMENT_SHARED_FUN, SharedFunctionInfo, \
232 : promise_all_resolve_element_shared_fun) \
233 : V(PROMISE_PROTOTYPE_INDEX, JSObject, promise_prototype) \
234 : V(REGEXP_EXEC_FUNCTION_INDEX, JSFunction, regexp_exec_function) \
235 : V(REGEXP_FUNCTION_INDEX, JSFunction, regexp_function) \
236 : V(REGEXP_LAST_MATCH_INFO_INDEX, RegExpMatchInfo, regexp_last_match_info) \
237 : V(REGEXP_INTERNAL_MATCH_INFO_INDEX, RegExpMatchInfo, \
238 : regexp_internal_match_info) \
239 : V(REGEXP_PROTOTYPE_MAP_INDEX, Map, regexp_prototype_map) \
240 : V(INITIAL_REGEXP_STRING_ITERATOR_PROTOTYPE_MAP_INDEX, Map, \
241 : initial_regexp_string_iterator_prototype_map) \
242 : V(REGEXP_RESULT_MAP_INDEX, Map, regexp_result_map) \
243 : V(REGEXP_PROTOTYPE_INDEX, JSObject, regexp_prototype) \
244 : V(SCRIPT_CONTEXT_TABLE_INDEX, ScriptContextTable, script_context_table) \
245 : V(SECURITY_TOKEN_INDEX, Object, security_token) \
246 : V(SERIALIZED_OBJECTS, FixedArray, serialized_objects) \
247 : V(SET_VALUE_ITERATOR_MAP_INDEX, Map, set_value_iterator_map) \
248 : V(SET_KEY_VALUE_ITERATOR_MAP_INDEX, Map, set_key_value_iterator_map) \
249 : V(SHARED_ARRAY_BUFFER_FUN_INDEX, JSFunction, shared_array_buffer_fun) \
250 : V(SLOPPY_ARGUMENTS_MAP_INDEX, Map, sloppy_arguments_map) \
251 : V(SLOW_ALIASED_ARGUMENTS_MAP_INDEX, Map, slow_aliased_arguments_map) \
252 : V(STRICT_ARGUMENTS_MAP_INDEX, Map, strict_arguments_map) \
253 : V(SLOW_OBJECT_WITH_NULL_PROTOTYPE_MAP, Map, \
254 : slow_object_with_null_prototype_map) \
255 : V(SLOW_OBJECT_WITH_OBJECT_PROTOTYPE_MAP, Map, \
256 : slow_object_with_object_prototype_map) \
257 : V(SLOW_TEMPLATE_INSTANTIATIONS_CACHE_INDEX, SimpleNumberDictionary, \
258 : slow_template_instantiations_cache) \
259 : /* All *_FUNCTION_MAP_INDEX definitions used by Context::FunctionMapIndex */ \
260 : /* must remain together. */ \
261 : V(SLOPPY_FUNCTION_MAP_INDEX, Map, sloppy_function_map) \
262 : V(SLOPPY_FUNCTION_WITH_NAME_MAP_INDEX, Map, sloppy_function_with_name_map) \
263 : V(SLOPPY_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, \
264 : sloppy_function_without_prototype_map) \
265 : V(SLOPPY_FUNCTION_WITH_READONLY_PROTOTYPE_MAP_INDEX, Map, \
266 : sloppy_function_with_readonly_prototype_map) \
267 : V(STRICT_FUNCTION_MAP_INDEX, Map, strict_function_map) \
268 : V(STRICT_FUNCTION_WITH_NAME_MAP_INDEX, Map, strict_function_with_name_map) \
269 : V(STRICT_FUNCTION_WITH_READONLY_PROTOTYPE_MAP_INDEX, Map, \
270 : strict_function_with_readonly_prototype_map) \
271 : V(STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, \
272 : strict_function_without_prototype_map) \
273 : V(METHOD_WITH_NAME_MAP_INDEX, Map, method_with_name_map) \
274 : V(METHOD_WITH_HOME_OBJECT_MAP_INDEX, Map, method_with_home_object_map) \
275 : V(METHOD_WITH_NAME_AND_HOME_OBJECT_MAP_INDEX, Map, \
276 : method_with_name_and_home_object_map) \
277 : V(ASYNC_FUNCTION_MAP_INDEX, Map, async_function_map) \
278 : V(ASYNC_FUNCTION_WITH_NAME_MAP_INDEX, Map, async_function_with_name_map) \
279 : V(ASYNC_FUNCTION_WITH_HOME_OBJECT_MAP_INDEX, Map, \
280 : async_function_with_home_object_map) \
281 : V(ASYNC_FUNCTION_WITH_NAME_AND_HOME_OBJECT_MAP_INDEX, Map, \
282 : async_function_with_name_and_home_object_map) \
283 : V(GENERATOR_FUNCTION_MAP_INDEX, Map, generator_function_map) \
284 : V(GENERATOR_FUNCTION_WITH_NAME_MAP_INDEX, Map, \
285 : generator_function_with_name_map) \
286 : V(GENERATOR_FUNCTION_WITH_HOME_OBJECT_MAP_INDEX, Map, \
287 : generator_function_with_home_object_map) \
288 : V(GENERATOR_FUNCTION_WITH_NAME_AND_HOME_OBJECT_MAP_INDEX, Map, \
289 : generator_function_with_name_and_home_object_map) \
290 : V(ASYNC_GENERATOR_FUNCTION_MAP_INDEX, Map, async_generator_function_map) \
291 : V(ASYNC_GENERATOR_FUNCTION_WITH_NAME_MAP_INDEX, Map, \
292 : async_generator_function_with_name_map) \
293 : V(ASYNC_GENERATOR_FUNCTION_WITH_HOME_OBJECT_MAP_INDEX, Map, \
294 : async_generator_function_with_home_object_map) \
295 : V(ASYNC_GENERATOR_FUNCTION_WITH_NAME_AND_HOME_OBJECT_MAP_INDEX, Map, \
296 : async_generator_function_with_name_and_home_object_map) \
297 : V(CLASS_FUNCTION_MAP_INDEX, Map, class_function_map) \
298 : V(STRING_FUNCTION_INDEX, JSFunction, string_function) \
299 : V(STRING_FUNCTION_PROTOTYPE_MAP_INDEX, Map, string_function_prototype_map) \
300 : V(SYMBOL_FUNCTION_INDEX, JSFunction, symbol_function) \
301 : V(NATIVE_FUNCTION_MAP_INDEX, Map, native_function_map) \
302 : V(WASM_EXCEPTION_CONSTRUCTOR_INDEX, JSFunction, wasm_exception_constructor) \
303 : V(WASM_GLOBAL_CONSTRUCTOR_INDEX, JSFunction, wasm_global_constructor) \
304 : V(WASM_INSTANCE_CONSTRUCTOR_INDEX, JSFunction, wasm_instance_constructor) \
305 : V(WASM_MEMORY_CONSTRUCTOR_INDEX, JSFunction, wasm_memory_constructor) \
306 : V(WASM_MODULE_CONSTRUCTOR_INDEX, JSFunction, wasm_module_constructor) \
307 : V(WASM_TABLE_CONSTRUCTOR_INDEX, JSFunction, wasm_table_constructor) \
308 : V(TYPED_ARRAY_FUN_INDEX, JSFunction, typed_array_function) \
309 : V(TYPED_ARRAY_PROTOTYPE_INDEX, JSObject, typed_array_prototype) \
310 : V(UINT16_ARRAY_FUN_INDEX, JSFunction, uint16_array_fun) \
311 : V(UINT32_ARRAY_FUN_INDEX, JSFunction, uint32_array_fun) \
312 : V(UINT8_ARRAY_FUN_INDEX, JSFunction, uint8_array_fun) \
313 : V(UINT8_CLAMPED_ARRAY_FUN_INDEX, JSFunction, uint8_clamped_array_fun) \
314 : V(ARRAY_ENTRIES_ITERATOR_INDEX, JSFunction, array_entries_iterator) \
315 : V(ARRAY_FOR_EACH_ITERATOR_INDEX, JSFunction, array_for_each_iterator) \
316 : V(ARRAY_KEYS_ITERATOR_INDEX, JSFunction, array_keys_iterator) \
317 : V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \
318 : V(ERROR_FUNCTION_INDEX, JSFunction, error_function) \
319 : V(ERROR_TO_STRING, JSFunction, error_to_string) \
320 : V(EVAL_ERROR_FUNCTION_INDEX, JSFunction, eval_error_function) \
321 : V(GLOBAL_EVAL_FUN_INDEX, JSFunction, global_eval_fun) \
322 : V(GLOBAL_PROXY_FUNCTION_INDEX, JSFunction, global_proxy_function) \
323 : V(MAP_DELETE_INDEX, JSFunction, map_delete) \
324 : V(MAP_GET_INDEX, JSFunction, map_get) \
325 : V(MAP_HAS_INDEX, JSFunction, map_has) \
326 : V(MAP_SET_INDEX, JSFunction, map_set) \
327 : V(FUNCTION_HAS_INSTANCE_INDEX, JSFunction, function_has_instance) \
328 : V(OBJECT_TO_STRING, JSFunction, object_to_string) \
329 : V(PROMISE_ALL_INDEX, JSFunction, promise_all) \
330 : V(PROMISE_CATCH_INDEX, JSFunction, promise_catch) \
331 : V(PROMISE_FUNCTION_INDEX, JSFunction, promise_function) \
332 : V(RANGE_ERROR_FUNCTION_INDEX, JSFunction, range_error_function) \
333 : V(REFERENCE_ERROR_FUNCTION_INDEX, JSFunction, reference_error_function) \
334 : V(SET_ADD_INDEX, JSFunction, set_add) \
335 : V(SET_DELETE_INDEX, JSFunction, set_delete) \
336 : V(SET_HAS_INDEX, JSFunction, set_has) \
337 : V(SYNTAX_ERROR_FUNCTION_INDEX, JSFunction, syntax_error_function) \
338 : V(TYPE_ERROR_FUNCTION_INDEX, JSFunction, type_error_function) \
339 : V(URI_ERROR_FUNCTION_INDEX, JSFunction, uri_error_function) \
340 : V(WASM_COMPILE_ERROR_FUNCTION_INDEX, JSFunction, \
341 : wasm_compile_error_function) \
342 : V(WASM_LINK_ERROR_FUNCTION_INDEX, JSFunction, wasm_link_error_function) \
343 : V(WASM_RUNTIME_ERROR_FUNCTION_INDEX, JSFunction, \
344 : wasm_runtime_error_function) \
345 : V(WEAKMAP_SET_INDEX, JSFunction, weakmap_set) \
346 : V(WEAKMAP_GET_INDEX, JSFunction, weakmap_get) \
347 : V(WEAKSET_ADD_INDEX, JSFunction, weakset_add) \
348 : NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V)
349 :
350 : // A table of all script contexts. Every loaded top-level script with top-level
351 : // lexical declarations contributes its ScriptContext into this table.
352 : //
353 : // The table is a fixed array, its first slot is the current used count and
354 : // the subsequent slots 1..used contain ScriptContexts.
355 : class ScriptContextTable : public FixedArray {
356 : public:
357 : DECL_CAST(ScriptContextTable)
358 :
359 : struct LookupResult {
360 : int context_index;
361 : int slot_index;
362 : VariableMode mode;
363 : InitializationFlag init_flag;
364 : MaybeAssignedFlag maybe_assigned_flag;
365 : };
366 :
367 : inline int used() const;
368 : inline void set_used(int used);
369 :
370 : static inline Handle<Context> GetContext(Isolate* isolate,
371 : Handle<ScriptContextTable> table,
372 : int i);
373 :
374 : // Lookup a variable `name` in a ScriptContextTable.
375 : // If it returns true, the variable is found and `result` contains
376 : // valid information about its location.
377 : // If it returns false, `result` is untouched.
378 : V8_WARN_UNUSED_RESULT
379 : static bool Lookup(Isolate* isolate, Handle<ScriptContextTable> table,
380 : Handle<String> name, LookupResult* result);
381 :
382 : V8_WARN_UNUSED_RESULT
383 : static Handle<ScriptContextTable> Extend(Handle<ScriptContextTable> table,
384 : Handle<Context> script_context);
385 :
386 : static const int kUsedSlotIndex = 0;
387 : static const int kFirstContextSlotIndex = 1;
388 : static const int kMinLength = kFirstContextSlotIndex;
389 :
390 : OBJECT_CONSTRUCTORS(ScriptContextTable, FixedArray);
391 : };
392 :
393 : // JSFunctions are pairs (context, function code), sometimes also called
394 : // closures. A Context object is used to represent function contexts and
395 : // dynamically pushed 'with' contexts (or 'scopes' in ECMA-262 speak).
396 : //
397 : // At runtime, the contexts build a stack in parallel to the execution
398 : // stack, with the top-most context being the current context. All contexts
399 : // have the following slots:
400 : //
401 : // [ scope_info ] This is the scope info describing the current context. It
402 : // contains the names of statically allocated context slots,
403 : // and stack-allocated locals. The names are needed for
404 : // dynamic lookups in the presence of 'with' or 'eval', and
405 : // for the debugger.
406 : //
407 : // [ previous ] A pointer to the previous context.
408 : //
409 : // [ extension ] Additional data.
410 : //
411 : // For native contexts, it contains the global object.
412 : // For module contexts, it contains the module object.
413 : // For await contexts, it contains the generator object.
414 : // For block contexts, it may contain an "extension object".
415 : // For with contexts, it contains an "extension object".
416 : //
417 : // An "extension object" is used to dynamically extend a
418 : // context with additional variables, namely in the
419 : // implementation of the 'with' construct and the 'eval'
420 : // construct. For instance, Context::Lookup also searches
421 : // the extension object for properties. (Storing the
422 : // extension object is the original purpose of this context
423 : // slot, hence the name.)
424 : //
425 : // [ native_context ] A pointer to the native context.
426 : //
427 : // In addition, function contexts may have statically allocated context slots
428 : // to store local variables/functions that are accessed from inner functions
429 : // (via static context addresses) or through 'eval' (dynamic context lookups).
430 : // The native context contains additional slots for fast access to native
431 : // properties.
432 : //
433 : // Finally, with Harmony scoping, the JSFunction representing a top level
434 : // script will have the ScriptContext rather than a FunctionContext.
435 : // Script contexts from all top-level scripts are gathered in
436 : // ScriptContextTable.
437 :
438 : class Context : public HeapObject {
439 : public:
440 : NEVER_READ_ONLY_SPACE
441 :
442 : DECL_CAST(Context)
443 :
444 : // [length]: length of the context.
445 : V8_INLINE int length() const;
446 : V8_INLINE void set_length(int value);
447 :
448 : // Setter and getter for elements.
449 : V8_INLINE Object get(int index) const;
450 : V8_INLINE void set(int index, Object value);
451 : // Setter with explicit barrier mode.
452 : V8_INLINE void set(int index, Object value, WriteBarrierMode mode);
453 :
454 : // Layout description.
455 : #define CONTEXT_FIELDS(V) \
456 : V(kLengthOffset, kTaggedSize) \
457 : /* TODO(ishell): remove this fixedArray-like header size. */ \
458 : V(kHeaderSize, 0) \
459 : V(kStartOfTaggedFieldsOffset, 0) \
460 : V(kStartOfStrongFieldsOffset, 0) \
461 : /* Tagged fields. */ \
462 : V(kScopeInfoOffset, kTaggedSize) \
463 : V(kPreviousOffset, kTaggedSize) \
464 : V(kExtensionOffset, kTaggedSize) \
465 : V(kNativeContextOffset, kTaggedSize) \
466 : /* Header size. */ \
467 : /* TODO(ishell): use this as header size once MIN_CONTEXT_SLOTS */ \
468 : /* is removed in favour of offset-based access to common fields. */ \
469 : V(kTodoHeaderSize, 0)
470 :
471 : DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, CONTEXT_FIELDS)
472 : #undef CONTEXT_FIELDS
473 :
474 : // Garbage collection support.
475 : V8_INLINE static constexpr int SizeFor(int length) {
476 : // TODO(ishell): switch to kTodoHeaderSize based approach once we no longer
477 : // reference common Context fields via index
478 60320853 : return kHeaderSize + length * kTaggedSize;
479 : }
480 :
481 : // Code Generation support.
482 : // Offset of the element from the beginning of object.
483 : V8_INLINE static constexpr int OffsetOfElementAt(int index) {
484 : return SizeFor(index);
485 : }
486 : // Offset of the element from the heap object pointer.
487 : V8_INLINE static constexpr int SlotOffset(int index) {
488 82707 : return SizeFor(index) - kHeapObjectTag;
489 : }
490 :
491 : // TODO(ishell): eventually migrate to the offset based access instead of
492 : // index-based.
493 : // The default context slot layout; indices are FixedArray slot indices.
494 : enum Field {
495 : // TODO(shell): use offset-based approach for accessing common values.
496 : // These slots are in all contexts.
497 : SCOPE_INFO_INDEX,
498 : PREVIOUS_INDEX,
499 : EXTENSION_INDEX,
500 : NATIVE_CONTEXT_INDEX,
501 :
502 : // These slots are only in native contexts.
503 : #define NATIVE_CONTEXT_SLOT(index, type, name) index,
504 : NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_SLOT)
505 : #undef NATIVE_CONTEXT_SLOT
506 :
507 : // Properties from here are treated as weak references by the full GC.
508 : // Scavenge treats them as strong references.
509 : OPTIMIZED_CODE_LIST, // Weak.
510 : DEOPTIMIZED_CODE_LIST, // Weak.
511 : NEXT_CONTEXT_LINK, // Weak.
512 :
513 : // Total number of slots.
514 : NATIVE_CONTEXT_SLOTS,
515 : FIRST_WEAK_SLOT = OPTIMIZED_CODE_LIST,
516 : FIRST_JS_ARRAY_MAP_SLOT = JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX,
517 :
518 : // TODO(shell): Remove, once it becomes zero
519 : MIN_CONTEXT_SLOTS = GLOBAL_PROXY_INDEX,
520 :
521 : // This slot holds the thrown value in catch contexts.
522 : THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS,
523 :
524 : // These slots hold values in debug evaluate contexts.
525 : WRAPPED_CONTEXT_INDEX = MIN_CONTEXT_SLOTS,
526 : WHITE_LIST_INDEX = MIN_CONTEXT_SLOTS + 1
527 : };
528 :
529 : // A region of native context entries containing maps for functions created
530 : // by Builtins::kFastNewClosure.
531 : static const int FIRST_FUNCTION_MAP_INDEX = SLOPPY_FUNCTION_MAP_INDEX;
532 : static const int LAST_FUNCTION_MAP_INDEX = CLASS_FUNCTION_MAP_INDEX;
533 :
534 : static const int kNoContext = 0;
535 : static const int kInvalidContext = 1;
536 :
537 : void ResetErrorsThrown();
538 : void IncrementErrorsThrown();
539 : int GetErrorsThrown();
540 :
541 : // Direct slot access.
542 : inline void set_scope_info(ScopeInfo scope_info);
543 : inline Context previous();
544 : inline void set_previous(Context context);
545 :
546 : inline Object next_context_link();
547 :
548 : inline bool has_extension();
549 : inline HeapObject extension();
550 : inline void set_extension(HeapObject object);
551 : JSObject extension_object();
552 : JSReceiver extension_receiver();
553 : ScopeInfo scope_info();
554 :
555 : // Find the module context (assuming there is one) and return the associated
556 : // module object.
557 : Module module();
558 :
559 : // Get the context where var declarations will be hoisted to, which
560 : // may be the context itself.
561 : Context declaration_context();
562 : bool is_declaration_context();
563 :
564 : // Get the next closure's context on the context chain.
565 : Context closure_context();
566 :
567 : // Returns a JSGlobalProxy object or null.
568 : JSGlobalProxy global_proxy();
569 : void set_global_proxy(JSGlobalProxy global);
570 :
571 : // Get the JSGlobalObject object.
572 : V8_EXPORT_PRIVATE JSGlobalObject global_object();
573 :
574 : // Get the script context by traversing the context chain.
575 : Context script_context();
576 :
577 : // Compute the native context.
578 : inline NativeContext native_context() const;
579 : inline void set_native_context(NativeContext context);
580 :
581 : // Predicates for context types. IsNativeContext is already defined on
582 : // Object.
583 : inline bool IsFunctionContext() const;
584 : inline bool IsCatchContext() const;
585 : inline bool IsWithContext() const;
586 : inline bool IsDebugEvaluateContext() const;
587 : inline bool IsAwaitContext() const;
588 : inline bool IsBlockContext() const;
589 : inline bool IsModuleContext() const;
590 : inline bool IsEvalContext() const;
591 : inline bool IsScriptContext() const;
592 :
593 : inline bool HasSameSecurityTokenAs(Context that) const;
594 :
595 : // The native context also stores a list of all optimized code and a
596 : // list of all deoptimized code, which are needed by the deoptimizer.
597 : void AddOptimizedCode(Code code);
598 : void SetOptimizedCodeListHead(Object head);
599 : Object OptimizedCodeListHead();
600 : void SetDeoptimizedCodeListHead(Object head);
601 : Object DeoptimizedCodeListHead();
602 :
603 : Handle<Object> ErrorMessageForCodeGenerationFromStrings();
604 :
605 : static int IntrinsicIndexForName(Handle<String> name);
606 : static int IntrinsicIndexForName(const unsigned char* name, int length);
607 :
608 : #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \
609 : inline void set_##name(type value); \
610 : inline bool is_##name(type value) const; \
611 : inline type name() const;
612 : NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS)
613 : #undef NATIVE_CONTEXT_FIELD_ACCESSORS
614 :
615 : // Lookup the slot called name, starting with the current context.
616 : // There are three possibilities:
617 : //
618 : // 1) result->IsContext():
619 : // The binding was found in a context. *index is always the
620 : // non-negative slot index. *attributes is NONE for var and let
621 : // declarations, READ_ONLY for const declarations (never ABSENT).
622 : //
623 : // 2) result->IsJSObject():
624 : // The binding was found as a named property in a context extension
625 : // object (i.e., was introduced via eval), as a property on the subject
626 : // of with, or as a property of the global object. *index is -1 and
627 : // *attributes is not ABSENT.
628 : //
629 : // 3) result->IsModule():
630 : // The binding was found in module imports or exports.
631 : // *attributes is never ABSENT. imports are READ_ONLY.
632 : //
633 : // 4) result.is_null():
634 : // There was no binding found, *index is always -1 and *attributes is
635 : // always ABSENT.
636 : static Handle<Object> Lookup(Handle<Context> context, Handle<String> name,
637 : ContextLookupFlags flags, int* index,
638 : PropertyAttributes* attributes,
639 : InitializationFlag* init_flag,
640 : VariableMode* variable_mode,
641 : bool* is_sloppy_function_name = nullptr);
642 :
643 : static inline int FunctionMapIndex(LanguageMode language_mode,
644 : FunctionKind kind, bool has_prototype_slot,
645 : bool has_shared_name,
646 : bool needs_home_object);
647 :
648 : static int ArrayMapIndex(ElementsKind elements_kind) {
649 : DCHECK(IsFastElementsKind(elements_kind));
650 4351283 : return elements_kind + FIRST_JS_ARRAY_MAP_SLOT;
651 : }
652 :
653 : inline Map GetInitialJSArrayMap(ElementsKind kind) const;
654 :
655 : static const int kNotFound = -1;
656 :
657 : // Dispatched behavior.
658 : DECL_PRINTER(Context)
659 : DECL_VERIFIER(Context)
660 :
661 : typedef FlexibleBodyDescriptor<kStartOfTaggedFieldsOffset> BodyDescriptor;
662 :
663 : private:
664 : #ifdef DEBUG
665 : // Bootstrapping-aware type checks.
666 : V8_EXPORT_PRIVATE static bool IsBootstrappingOrNativeContext(Isolate* isolate,
667 : Object object);
668 : static bool IsBootstrappingOrValidParentContext(Object object, Context kid);
669 : #endif
670 :
671 427177168 : OBJECT_CONSTRUCTORS(Context, HeapObject)
672 : };
673 :
674 : class NativeContext : public Context {
675 : public:
676 : DECL_CAST(NativeContext)
677 : // TODO(neis): Move some stuff from Context here.
678 :
679 : // [microtask_queue]: pointer to the MicrotaskQueue object.
680 : DECL_PRIMITIVE_ACCESSORS(microtask_queue, MicrotaskQueue*)
681 :
682 : // Dispatched behavior.
683 : DECL_PRINTER(NativeContext)
684 : DECL_VERIFIER(NativeContext)
685 :
686 : // Layout description.
687 : #define NATIVE_CONTEXT_FIELDS_DEF(V) \
688 : /* TODO(ishell): move definition of common context offsets to Context. */ \
689 : V(kStartOfNativeContextFieldsOffset, \
690 : (FIRST_WEAK_SLOT - MIN_CONTEXT_SLOTS) * kTaggedSize) \
691 : V(kEndOfStrongFieldsOffset, 0) \
692 : V(kStartOfWeakFieldsOffset, \
693 : (NATIVE_CONTEXT_SLOTS - FIRST_WEAK_SLOT) * kTaggedSize) \
694 : V(kEndOfWeakFieldsOffset, 0) \
695 : V(kEndOfNativeContextFieldsOffset, 0) \
696 : V(kEndOfTaggedFieldsOffset, 0) \
697 : /* Raw data. */ \
698 : V(kMicrotaskQueueOffset, kSystemPointerSize) \
699 : /* Total size. */ \
700 : V(kSize, 0)
701 :
702 : DEFINE_FIELD_OFFSET_CONSTANTS(Context::kTodoHeaderSize,
703 : NATIVE_CONTEXT_FIELDS_DEF)
704 : #undef NATIVE_CONTEXT_FIELDS_DEF
705 :
706 : class BodyDescriptor;
707 :
708 : private:
709 : STATIC_ASSERT(OffsetOfElementAt(EMBEDDER_DATA_INDEX) ==
710 : Internals::kNativeContextEmbedderDataOffset);
711 :
712 2565441 : OBJECT_CONSTRUCTORS(NativeContext, Context);
713 : };
714 :
715 : typedef Context::Field ContextField;
716 :
717 : } // namespace internal
718 : } // namespace v8
719 :
720 : #include "src/objects/object-macros-undef.h"
721 :
722 : #endif // V8_CONTEXTS_H_
|