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