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(TYPED_ARRAY_FUN_INDEX, JSFunction, typed_array_function) \
306 : V(TYPED_ARRAY_PROTOTYPE_INDEX, JSObject, typed_array_prototype) \
307 : V(UINT16_ARRAY_FUN_INDEX, JSFunction, uint16_array_fun) \
308 : V(UINT32_ARRAY_FUN_INDEX, JSFunction, uint32_array_fun) \
309 : V(UINT8_ARRAY_FUN_INDEX, JSFunction, uint8_array_fun) \
310 : V(UINT8_CLAMPED_ARRAY_FUN_INDEX, JSFunction, uint8_clamped_array_fun) \
311 : V(ARRAY_ENTRIES_ITERATOR_INDEX, JSFunction, array_entries_iterator) \
312 : V(ARRAY_FOR_EACH_ITERATOR_INDEX, JSFunction, array_for_each_iterator) \
313 : V(ARRAY_KEYS_ITERATOR_INDEX, JSFunction, array_keys_iterator) \
314 : V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \
315 : V(ERROR_FUNCTION_INDEX, JSFunction, error_function) \
316 : V(ERROR_TO_STRING, JSFunction, error_to_string) \
317 : V(EVAL_ERROR_FUNCTION_INDEX, JSFunction, eval_error_function) \
318 : V(GLOBAL_EVAL_FUN_INDEX, JSFunction, global_eval_fun) \
319 : V(GLOBAL_PROXY_FUNCTION_INDEX, JSFunction, global_proxy_function) \
320 : V(MAP_DELETE_INDEX, JSFunction, map_delete) \
321 : V(MAP_GET_INDEX, JSFunction, map_get) \
322 : V(MAP_HAS_INDEX, JSFunction, map_has) \
323 : V(MAP_SET_INDEX, JSFunction, map_set) \
324 : V(FUNCTION_HAS_INSTANCE_INDEX, JSFunction, function_has_instance) \
325 : V(OBJECT_TO_STRING, JSFunction, object_to_string) \
326 : V(PROMISE_ALL_INDEX, JSFunction, promise_all) \
327 : V(PROMISE_CATCH_INDEX, JSFunction, promise_catch) \
328 : V(PROMISE_FUNCTION_INDEX, JSFunction, promise_function) \
329 : V(RANGE_ERROR_FUNCTION_INDEX, JSFunction, range_error_function) \
330 : V(REFERENCE_ERROR_FUNCTION_INDEX, JSFunction, reference_error_function) \
331 : V(SET_ADD_INDEX, JSFunction, set_add) \
332 : V(SET_DELETE_INDEX, JSFunction, set_delete) \
333 : V(SET_HAS_INDEX, JSFunction, set_has) \
334 : V(SYNTAX_ERROR_FUNCTION_INDEX, JSFunction, syntax_error_function) \
335 : V(TYPE_ERROR_FUNCTION_INDEX, JSFunction, type_error_function) \
336 : V(URI_ERROR_FUNCTION_INDEX, JSFunction, uri_error_function) \
337 : V(WASM_COMPILE_ERROR_FUNCTION_INDEX, JSFunction, \
338 : wasm_compile_error_function) \
339 : V(WASM_LINK_ERROR_FUNCTION_INDEX, JSFunction, wasm_link_error_function) \
340 : V(WASM_RUNTIME_ERROR_FUNCTION_INDEX, JSFunction, \
341 : wasm_runtime_error_function) \
342 : V(WEAKMAP_SET_INDEX, JSFunction, weakmap_set) \
343 : V(WEAKMAP_GET_INDEX, JSFunction, weakmap_get) \
344 : V(WEAKSET_ADD_INDEX, JSFunction, weakset_add) \
345 : NATIVE_CONTEXT_INTRINSIC_FUNCTIONS(V)
346 :
347 : // A table of all script contexts. Every loaded top-level script with top-level
348 : // lexical declarations contributes its ScriptContext into this table.
349 : //
350 : // The table is a fixed array, its first slot is the current used count and
351 : // the subsequent slots 1..used contain ScriptContexts.
352 : class ScriptContextTable : public FixedArray {
353 : public:
354 : DECL_CAST(ScriptContextTable)
355 :
356 : struct LookupResult {
357 : int context_index;
358 : int slot_index;
359 : VariableMode mode;
360 : InitializationFlag init_flag;
361 : MaybeAssignedFlag maybe_assigned_flag;
362 : };
363 :
364 : inline int used() const;
365 : inline void set_used(int used);
366 :
367 : static inline Handle<Context> GetContext(Isolate* isolate,
368 : Handle<ScriptContextTable> table,
369 : int i);
370 : inline Context get_context(int i) const;
371 :
372 : // Lookup a variable `name` in a ScriptContextTable.
373 : // If it returns true, the variable is found and `result` contains
374 : // valid information about its location.
375 : // If it returns false, `result` is untouched.
376 : V8_WARN_UNUSED_RESULT
377 : static bool Lookup(Isolate* isolate, ScriptContextTable table, String name,
378 : LookupResult* result);
379 :
380 : V8_WARN_UNUSED_RESULT
381 : static Handle<ScriptContextTable> Extend(Handle<ScriptContextTable> table,
382 : Handle<Context> script_context);
383 :
384 : static const int kUsedSlotIndex = 0;
385 : static const int kFirstContextSlotIndex = 1;
386 : static const int kMinLength = kFirstContextSlotIndex;
387 :
388 : OBJECT_CONSTRUCTORS(ScriptContextTable, FixedArray);
389 : };
390 :
391 : // JSFunctions are pairs (context, function code), sometimes also called
392 : // closures. A Context object is used to represent function contexts and
393 : // dynamically pushed 'with' contexts (or 'scopes' in ECMA-262 speak).
394 : //
395 : // At runtime, the contexts build a stack in parallel to the execution
396 : // stack, with the top-most context being the current context. All contexts
397 : // have the following slots:
398 : //
399 : // [ scope_info ] This is the scope info describing the current context. It
400 : // contains the names of statically allocated context slots,
401 : // and stack-allocated locals. The names are needed for
402 : // dynamic lookups in the presence of 'with' or 'eval', and
403 : // for the debugger.
404 : //
405 : // [ previous ] A pointer to the previous context.
406 : //
407 : // [ extension ] Additional data.
408 : //
409 : // For native contexts, it contains the global object.
410 : // For module contexts, it contains the module object.
411 : // For await contexts, it contains the generator object.
412 : // For block contexts, it may contain an "extension object".
413 : // For with contexts, it contains an "extension object".
414 : //
415 : // An "extension object" is used to dynamically extend a
416 : // context with additional variables, namely in the
417 : // implementation of the 'with' construct and the 'eval'
418 : // construct. For instance, Context::Lookup also searches
419 : // the extension object for properties. (Storing the
420 : // extension object is the original purpose of this context
421 : // slot, hence the name.)
422 : //
423 : // [ native_context ] A pointer to the native context.
424 : //
425 : // In addition, function contexts may have statically allocated context slots
426 : // to store local variables/functions that are accessed from inner functions
427 : // (via static context addresses) or through 'eval' (dynamic context lookups).
428 : // The native context contains additional slots for fast access to native
429 : // properties.
430 : //
431 : // Finally, with Harmony scoping, the JSFunction representing a top level
432 : // script will have the ScriptContext rather than a FunctionContext.
433 : // Script contexts from all top-level scripts are gathered in
434 : // ScriptContextTable.
435 :
436 : class Context : public HeapObject {
437 : public:
438 : NEVER_READ_ONLY_SPACE
439 :
440 : DECL_CAST(Context)
441 :
442 : // [length]: length of the context.
443 : V8_INLINE int length() const;
444 : V8_INLINE void set_length(int value);
445 :
446 : // Setter and getter for elements.
447 : V8_INLINE Object get(int index) const;
448 : V8_INLINE void set(int index, Object value);
449 : // Setter with explicit barrier mode.
450 : V8_INLINE void set(int index, Object value, WriteBarrierMode mode);
451 :
452 : // Layout description.
453 : #define CONTEXT_FIELDS(V) \
454 : V(kLengthOffset, kTaggedSize) \
455 : /* TODO(ishell): remove this fixedArray-like header size. */ \
456 : V(kHeaderSize, 0) \
457 : V(kStartOfTaggedFieldsOffset, 0) \
458 : V(kStartOfStrongFieldsOffset, 0) \
459 : /* Tagged fields. */ \
460 : V(kScopeInfoOffset, kTaggedSize) \
461 : V(kPreviousOffset, kTaggedSize) \
462 : V(kExtensionOffset, kTaggedSize) \
463 : V(kNativeContextOffset, kTaggedSize) \
464 : /* Header size. */ \
465 : /* TODO(ishell): use this as header size once MIN_CONTEXT_SLOTS */ \
466 : /* is removed in favour of offset-based access to common fields. */ \
467 : V(kTodoHeaderSize, 0)
468 :
469 : DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, CONTEXT_FIELDS)
470 : #undef CONTEXT_FIELDS
471 :
472 : // Garbage collection support.
473 : V8_INLINE static constexpr int SizeFor(int length) {
474 : // TODO(ishell): switch to kTodoHeaderSize based approach once we no longer
475 : // reference common Context fields via index
476 56254753 : return kHeaderSize + length * kTaggedSize;
477 : }
478 :
479 : // Code Generation support.
480 : // Offset of the element from the beginning of object.
481 : V8_INLINE static constexpr int OffsetOfElementAt(int index) {
482 : return SizeFor(index);
483 : }
484 : // Offset of the element from the heap object pointer.
485 : V8_INLINE static constexpr int SlotOffset(int index) {
486 89772 : return SizeFor(index) - kHeapObjectTag;
487 : }
488 :
489 : // TODO(ishell): eventually migrate to the offset based access instead of
490 : // index-based.
491 : // The default context slot layout; indices are FixedArray slot indices.
492 : enum Field {
493 : // TODO(shell): use offset-based approach for accessing common values.
494 : // These slots are in all contexts.
495 : SCOPE_INFO_INDEX,
496 : PREVIOUS_INDEX,
497 : EXTENSION_INDEX,
498 : NATIVE_CONTEXT_INDEX,
499 :
500 : // These slots are only in native contexts.
501 : #define NATIVE_CONTEXT_SLOT(index, type, name) index,
502 : NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_SLOT)
503 : #undef NATIVE_CONTEXT_SLOT
504 :
505 : // Properties from here are treated as weak references by the full GC.
506 : // Scavenge treats them as strong references.
507 : OPTIMIZED_CODE_LIST, // Weak.
508 : DEOPTIMIZED_CODE_LIST, // Weak.
509 : NEXT_CONTEXT_LINK, // Weak.
510 :
511 : // Total number of slots.
512 : NATIVE_CONTEXT_SLOTS,
513 : FIRST_WEAK_SLOT = OPTIMIZED_CODE_LIST,
514 : FIRST_JS_ARRAY_MAP_SLOT = JS_ARRAY_PACKED_SMI_ELEMENTS_MAP_INDEX,
515 :
516 : // TODO(shell): Remove, once it becomes zero
517 : MIN_CONTEXT_SLOTS = GLOBAL_PROXY_INDEX,
518 :
519 : // This slot holds the thrown value in catch contexts.
520 : THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS,
521 :
522 : // These slots hold values in debug evaluate contexts.
523 : WRAPPED_CONTEXT_INDEX = MIN_CONTEXT_SLOTS,
524 : WHITE_LIST_INDEX = MIN_CONTEXT_SLOTS + 1
525 : };
526 :
527 : // A region of native context entries containing maps for functions created
528 : // by Builtins::kFastNewClosure.
529 : static const int FIRST_FUNCTION_MAP_INDEX = SLOPPY_FUNCTION_MAP_INDEX;
530 : static const int LAST_FUNCTION_MAP_INDEX = CLASS_FUNCTION_MAP_INDEX;
531 :
532 : static const int kNoContext = 0;
533 : static const int kInvalidContext = 1;
534 :
535 : void ResetErrorsThrown();
536 : void IncrementErrorsThrown();
537 : int GetErrorsThrown();
538 :
539 : // Direct slot access.
540 : inline void set_scope_info(ScopeInfo scope_info);
541 : inline Context previous();
542 : inline void set_previous(Context context);
543 :
544 : inline Object next_context_link();
545 :
546 : inline bool has_extension();
547 : inline HeapObject extension();
548 : inline void set_extension(HeapObject object);
549 : JSObject extension_object();
550 : JSReceiver extension_receiver();
551 : ScopeInfo scope_info();
552 :
553 : // Find the module context (assuming there is one) and return the associated
554 : // module object.
555 : Module module();
556 :
557 : // Get the context where var declarations will be hoisted to, which
558 : // may be the context itself.
559 : Context declaration_context();
560 : bool is_declaration_context();
561 :
562 : // Get the next closure's context on the context chain.
563 : Context closure_context();
564 :
565 : // Returns a JSGlobalProxy object or null.
566 : JSGlobalProxy global_proxy();
567 : void set_global_proxy(JSGlobalProxy global);
568 :
569 : // Get the JSGlobalObject object.
570 : V8_EXPORT_PRIVATE JSGlobalObject global_object();
571 :
572 : // Get the script context by traversing the context chain.
573 : Context script_context();
574 :
575 : // Compute the native context.
576 : inline NativeContext native_context() const;
577 : inline void set_native_context(NativeContext context);
578 :
579 : // Predicates for context types. IsNativeContext is already defined on
580 : // Object.
581 : inline bool IsFunctionContext() const;
582 : inline bool IsCatchContext() const;
583 : inline bool IsWithContext() const;
584 : inline bool IsDebugEvaluateContext() const;
585 : inline bool IsAwaitContext() const;
586 : inline bool IsBlockContext() const;
587 : inline bool IsModuleContext() const;
588 : inline bool IsEvalContext() const;
589 : inline bool IsScriptContext() const;
590 :
591 : inline bool HasSameSecurityTokenAs(Context that) const;
592 :
593 : // The native context also stores a list of all optimized code and a
594 : // list of all deoptimized code, which are needed by the deoptimizer.
595 : void AddOptimizedCode(Code code);
596 : void SetOptimizedCodeListHead(Object head);
597 : Object OptimizedCodeListHead();
598 : void SetDeoptimizedCodeListHead(Object head);
599 : Object DeoptimizedCodeListHead();
600 :
601 : Handle<Object> ErrorMessageForCodeGenerationFromStrings();
602 :
603 : static int IntrinsicIndexForName(Handle<String> name);
604 : static int IntrinsicIndexForName(const unsigned char* name, int length);
605 :
606 : #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \
607 : inline void set_##name(type value); \
608 : inline bool is_##name(type value) const; \
609 : inline type name() const;
610 : NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS)
611 : #undef NATIVE_CONTEXT_FIELD_ACCESSORS
612 :
613 : // Lookup the slot called name, starting with the current context.
614 : // There are three possibilities:
615 : //
616 : // 1) result->IsContext():
617 : // The binding was found in a context. *index is always the
618 : // non-negative slot index. *attributes is NONE for var and let
619 : // declarations, READ_ONLY for const declarations (never ABSENT).
620 : //
621 : // 2) result->IsJSObject():
622 : // The binding was found as a named property in a context extension
623 : // object (i.e., was introduced via eval), as a property on the subject
624 : // of with, or as a property of the global object. *index is -1 and
625 : // *attributes is not ABSENT.
626 : //
627 : // 3) result->IsModule():
628 : // The binding was found in module imports or exports.
629 : // *attributes is never ABSENT. imports are READ_ONLY.
630 : //
631 : // 4) result.is_null():
632 : // There was no binding found, *index is always -1 and *attributes is
633 : // always ABSENT.
634 : static Handle<Object> Lookup(Handle<Context> context, Handle<String> name,
635 : ContextLookupFlags flags, int* index,
636 : PropertyAttributes* attributes,
637 : InitializationFlag* init_flag,
638 : VariableMode* variable_mode,
639 : bool* is_sloppy_function_name = nullptr);
640 :
641 : static inline int FunctionMapIndex(LanguageMode language_mode,
642 : FunctionKind kind, bool has_shared_name,
643 : bool needs_home_object);
644 :
645 9968 : static int ArrayMapIndex(ElementsKind elements_kind) {
646 : DCHECK(IsFastElementsKind(elements_kind));
647 3165025 : return elements_kind + FIRST_JS_ARRAY_MAP_SLOT;
648 : }
649 :
650 : inline Map GetInitialJSArrayMap(ElementsKind kind) const;
651 :
652 : static const int kNotFound = -1;
653 :
654 : // Dispatched behavior.
655 : DECL_PRINTER(Context)
656 : DECL_VERIFIER(Context)
657 :
658 : typedef FlexibleBodyDescriptor<kStartOfTaggedFieldsOffset> BodyDescriptor;
659 :
660 : private:
661 : #ifdef DEBUG
662 : // Bootstrapping-aware type checks.
663 : V8_EXPORT_PRIVATE static bool IsBootstrappingOrNativeContext(Isolate* isolate,
664 : Object object);
665 : static bool IsBootstrappingOrValidParentContext(Object object, Context kid);
666 : #endif
667 :
668 12123222 : OBJECT_CONSTRUCTORS(Context, HeapObject);
669 : };
670 :
671 : class NativeContext : public Context {
672 : public:
673 : DECL_CAST(NativeContext)
674 : // TODO(neis): Move some stuff from Context here.
675 :
676 : // [microtask_queue]: pointer to the MicrotaskQueue object.
677 : DECL_PRIMITIVE_ACCESSORS(microtask_queue, MicrotaskQueue*)
678 :
679 : // Dispatched behavior.
680 : DECL_PRINTER(NativeContext)
681 : DECL_VERIFIER(NativeContext)
682 :
683 : // Layout description.
684 : #define NATIVE_CONTEXT_FIELDS_DEF(V) \
685 : /* TODO(ishell): move definition of common context offsets to Context. */ \
686 : V(kStartOfNativeContextFieldsOffset, \
687 : (FIRST_WEAK_SLOT - MIN_CONTEXT_SLOTS) * kTaggedSize) \
688 : V(kEndOfStrongFieldsOffset, 0) \
689 : V(kStartOfWeakFieldsOffset, \
690 : (NATIVE_CONTEXT_SLOTS - FIRST_WEAK_SLOT) * kTaggedSize) \
691 : V(kEndOfWeakFieldsOffset, 0) \
692 : V(kEndOfNativeContextFieldsOffset, 0) \
693 : V(kEndOfTaggedFieldsOffset, 0) \
694 : /* Raw data. */ \
695 : V(kMicrotaskQueueOffset, kSystemPointerSize) \
696 : /* Total size. */ \
697 : V(kSize, 0)
698 :
699 : DEFINE_FIELD_OFFSET_CONSTANTS(Context::kTodoHeaderSize,
700 : NATIVE_CONTEXT_FIELDS_DEF)
701 : #undef NATIVE_CONTEXT_FIELDS_DEF
702 :
703 : class BodyDescriptor;
704 :
705 : private:
706 : STATIC_ASSERT(OffsetOfElementAt(EMBEDDER_DATA_INDEX) ==
707 : Internals::kNativeContextEmbedderDataOffset);
708 :
709 2677618 : OBJECT_CONSTRUCTORS(NativeContext, Context);
710 : };
711 :
712 : typedef Context::Field ContextField;
713 :
714 : } // namespace internal
715 : } // namespace v8
716 :
717 : #include "src/objects/object-macros-undef.h"
718 :
719 : #endif // V8_CONTEXTS_H_
|