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