• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ecmascript/global_env_constants.h"
17 
18 #include "ecmascript/accessor_data.h"
19 #include "ecmascript/builtins/builtins.h"
20 #include "ecmascript/builtins/builtins_global.h"
21 #include "ecmascript/ecma_vm.h"
22 #include "ecmascript/free_object.h"
23 #include "ecmascript/global_env.h"
24 #include "ecmascript/global_env_constants-inl.h"
25 #include "ecmascript/ic/ic_handler.h"
26 #include "ecmascript/ic/property_box.h"
27 #include "ecmascript/ic/proto_change_details.h"
28 #include "ecmascript/jobs/micro_job_queue.h"
29 #include "ecmascript/jobs/pending_job.h"
30 #include "ecmascript/js_api/js_api_arraylist_iterator.h"
31 #include "ecmascript/js_api/js_api_deque_iterator.h"
32 #include "ecmascript/js_api/js_api_lightweightmap_iterator.h"
33 #include "ecmascript/js_api/js_api_lightweightset_iterator.h"
34 #include "ecmascript/js_api/js_api_linked_list_iterator.h"
35 #include "ecmascript/js_api/js_api_list_iterator.h"
36 #include "ecmascript/js_api/js_api_plain_array_iterator.h"
37 #include "ecmascript/js_api/js_api_queue_iterator.h"
38 #include "ecmascript/js_api/js_api_stack_iterator.h"
39 #include "ecmascript/js_api/js_api_hashmap_iterator.h"
40 #include "ecmascript/js_api/js_api_hashset_iterator.h"
41 #include "ecmascript/js_api/js_api_tree_map_iterator.h"
42 #include "ecmascript/js_api/js_api_tree_set_iterator.h"
43 #include "ecmascript/js_api/js_api_vector_iterator.h"
44 #include "ecmascript/js_async_generator_object.h"
45 #include "ecmascript/jspandafile/class_info_extractor.h"
46 #include "ecmascript/jspandafile/class_literal.h"
47 #include "ecmascript/jspandafile/program_object.h"
48 #include "ecmascript/js_arguments.h"
49 #include "ecmascript/js_array.h"
50 #include "ecmascript/js_array_iterator.h"
51 #include "ecmascript/js_arraybuffer.h"
52 #include "ecmascript/js_finalization_registry.h"
53 #include "ecmascript/js_for_in_iterator.h"
54 #include "ecmascript/js_generator_object.h"
55 #include "ecmascript/js_hclass.h"
56 #include "ecmascript/js_iterator.h"
57 #include "ecmascript/js_map.h"
58 #include "ecmascript/js_map_iterator.h"
59 #include "ecmascript/js_primitive_ref.h"
60 #include "ecmascript/js_promise.h"
61 #include "ecmascript/js_proxy.h"
62 #include "ecmascript/js_realm.h"
63 #include "ecmascript/js_regexp.h"
64 #include "ecmascript/js_regexp_iterator.h"
65 #include "ecmascript/js_set.h"
66 #include "ecmascript/js_set_iterator.h"
67 #include "ecmascript/js_symbol.h"
68 #include "ecmascript/js_tagged_value.h"
69 #include "ecmascript/js_thread.h"
70 #include "ecmascript/method.h"
71 #include "ecmascript/module/js_module_source_text.h"
72 #include "ecmascript/object_factory.h"
73 #include "ecmascript/tagged_node.h"
74 #include "ecmascript/ts_types/ts_type.h"
75 
76 namespace panda::ecmascript {
Init(JSThread * thread,JSHClass * hClass)77 void GlobalEnvConstants::Init(JSThread *thread, JSHClass *hClass)
78 {
79     InitRootsClass(thread, hClass);
80     InitGlobalConstant(thread);
81 }
82 
InitRootsClass(JSThread * thread,JSHClass * hClass)83 void GlobalEnvConstants::InitRootsClass([[maybe_unused]] JSThread *thread, JSHClass *hClass)
84 {
85     // Global constants are readonly.
86     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
87 
88     SetConstant(ConstantIndex::HCLASS_CLASS_INDEX, JSTaggedValue(hClass));
89     SetConstant(ConstantIndex::FREE_OBJECT_WITH_NONE_FIELD_CLASS_INDEX,
90         factory->NewEcmaReadOnlyHClass(hClass, FreeObject::NEXT_OFFSET, JSType::FREE_OBJECT_WITH_NONE_FIELD));
91     SetConstant(ConstantIndex::FREE_OBJECT_WITH_ONE_FIELD_CLASS_INDEX,
92         factory->NewEcmaReadOnlyHClass(hClass, FreeObject::SIZE_OFFSET, JSType::FREE_OBJECT_WITH_ONE_FIELD));
93     SetConstant(ConstantIndex::FREE_OBJECT_WITH_TWO_FIELD_CLASS_INDEX,
94                 factory->NewEcmaReadOnlyHClass(hClass, FreeObject::SIZE, JSType::FREE_OBJECT_WITH_TWO_FIELD));
95     SetConstant(ConstantIndex::STRING_CLASS_INDEX, factory->NewEcmaReadOnlyHClass(hClass, 0, JSType::STRING));
96     SetConstant(ConstantIndex::ARRAY_CLASS_INDEX,
97                 factory->NewEcmaReadOnlyHClass(hClass, 0, JSType::TAGGED_ARRAY));
98     SetConstant(ConstantIndex::BYTE_ARRAY_CLASS_INDEX,
99                 factory->NewEcmaReadOnlyHClass(hClass, 0, JSType::BYTE_ARRAY));
100     SetConstant(ConstantIndex::CONSTANT_POOL_CLASS_INDEX,
101                 factory->NewEcmaReadOnlyHClass(hClass, 0, JSType::CONSTANT_POOL));
102     SetConstant(ConstantIndex::AOT_LITERAL_INFO_CLASS_INDEX,
103                 factory->NewEcmaReadOnlyHClass(hClass, 0, JSType::AOT_LITERAL_INFO));
104     InitGlobalConstantSpecial(thread);
105     SetConstant(ConstantIndex::DICTIONARY_CLASS_INDEX,
106                 factory->NewEcmaReadOnlyHClass(hClass, 0, JSType::TAGGED_DICTIONARY));
107     SetConstant(ConstantIndex::COW_ARRAY_CLASS_INDEX,
108                 factory->NewEcmaReadOnlyHClass(hClass, 0, JSType::COW_TAGGED_ARRAY));
109     SetConstant(ConstantIndex::BIGINT_CLASS_INDEX,
110                 factory->NewEcmaReadOnlyHClass(hClass, BigInt::SIZE, JSType::BIGINT));
111     SetConstant(ConstantIndex::JS_NATIVE_POINTER_CLASS_INDEX,
112                 factory->NewEcmaReadOnlyHClass(hClass, JSNativePointer::SIZE, JSType::JS_NATIVE_POINTER));
113     SetConstant(ConstantIndex::ENV_CLASS_INDEX,
114                 factory->NewEcmaReadOnlyHClass(hClass, 0, JSType::LEXICAL_ENV));
115     SetConstant(ConstantIndex::SYMBOL_CLASS_INDEX,
116                 factory->NewEcmaReadOnlyHClass(hClass, JSSymbol::SIZE, JSType::SYMBOL));
117     SetConstant(ConstantIndex::ACCESSOR_DATA_CLASS_INDEX,
118                 factory->NewEcmaReadOnlyHClass(hClass, AccessorData::SIZE, JSType::ACCESSOR_DATA));
119     SetConstant(ConstantIndex::INTERNAL_ACCESSOR_CLASS_INDEX,
120                 factory->NewEcmaReadOnlyHClass(hClass, AccessorData::SIZE, JSType::INTERNAL_ACCESSOR));
121     SetConstant(ConstantIndex::JS_PROXY_ORDINARY_CLASS_INDEX,
122                 factory->NewEcmaHClass(hClass, JSProxy::SIZE, JSType::JS_PROXY));
123     SetConstant(ConstantIndex::COMPLETION_RECORD_CLASS_INDEX,
124                 factory->NewEcmaReadOnlyHClass(hClass, CompletionRecord::SIZE, JSType::COMPLETION_RECORD));
125     SetConstant(ConstantIndex::GENERATOR_CONTEST_INDEX,
126                 factory->NewEcmaReadOnlyHClass(hClass, GeneratorContext::SIZE, JSType::JS_GENERATOR_CONTEXT));
127     SetConstant(ConstantIndex::ASYNC_GENERATOR_REQUEST_CLASS_INDEX,
128                 factory->NewEcmaReadOnlyHClass(hClass, AsyncGeneratorRequest::SIZE,
129                                                  JSType::ASYNC_GENERATOR_REQUEST));
130     SetConstant(ConstantIndex::ASYNC_ITERATOR_RECORD_CLASS_INDEX,
131                 factory->NewEcmaReadOnlyHClass(hClass, AsyncIteratorRecord::SIZE, JSType::ASYNC_ITERATOR_RECORD));
132     SetConstant(ConstantIndex::CAPABILITY_RECORD_CLASS_INDEX,
133                 factory->NewEcmaReadOnlyHClass(hClass, PromiseCapability::SIZE, JSType::PROMISE_CAPABILITY));
134     SetConstant(ConstantIndex::REACTIONS_RECORD_CLASS_INDEX,
135                 factory->NewEcmaReadOnlyHClass(hClass, PromiseReaction::SIZE, JSType::PROMISE_REACTIONS));
136     SetConstant(ConstantIndex::PROMISE_ITERATOR_RECORD_CLASS_INDEX,
137                 factory->NewEcmaReadOnlyHClass(hClass, PromiseIteratorRecord::SIZE,
138                                                  JSType::PROMISE_ITERATOR_RECORD));
139     SetConstant(ConstantIndex::PROMISE_RECORD_CLASS_INDEX,
140                 factory->NewEcmaReadOnlyHClass(hClass, PromiseRecord::SIZE, JSType::PROMISE_RECORD));
141     SetConstant(ConstantIndex::PROMISE_RESOLVING_FUNCTIONS_CLASS_INDEX,
142                 factory->NewEcmaReadOnlyHClass(hClass, ResolvingFunctionsRecord::SIZE,
143                                                  JSType::RESOLVING_FUNCTIONS_RECORD));
144     SetConstant(ConstantIndex::MICRO_JOB_QUEUE_CLASS_INDEX,
145                 factory->NewEcmaReadOnlyHClass(hClass, job::MicroJobQueue::SIZE, JSType::MICRO_JOB_QUEUE));
146     SetConstant(ConstantIndex::PENDING_JOB_CLASS_INDEX,
147                 factory->NewEcmaReadOnlyHClass(hClass, job::PendingJob::SIZE, JSType::PENDING_JOB));
148     SetConstant(ConstantIndex::PROTO_CHANGE_MARKER_CLASS_INDEX,
149                 factory->NewEcmaReadOnlyHClass(hClass, ProtoChangeMarker::SIZE, JSType::PROTO_CHANGE_MARKER));
150     SetConstant(ConstantIndex::PROTO_CHANGE_DETAILS_CLASS_INDEX,
151                 factory->NewEcmaReadOnlyHClass(hClass, ProtoChangeDetails::SIZE, JSType::PROTOTYPE_INFO));
152     SetConstant(ConstantIndex::PROTOTYPE_HANDLER_CLASS_INDEX,
153                 factory->NewEcmaReadOnlyHClass(hClass, PrototypeHandler::SIZE, JSType::PROTOTYPE_HANDLER));
154     SetConstant(ConstantIndex::TRANSITION_HANDLER_CLASS_INDEX,
155                 factory->NewEcmaReadOnlyHClass(hClass, TransitionHandler::SIZE, JSType::TRANSITION_HANDLER));
156     SetConstant(ConstantIndex::TRANS_WITH_PROTO_HANDLER_CLASS_INDEX,
157                 factory->NewEcmaReadOnlyHClass(hClass, TransWithProtoHandler::SIZE, JSType::TRANS_WITH_PROTO_HANDLER));
158     SetConstant(ConstantIndex::STORE_TS_HANDLER_CLASS_INDEX,
159                 factory->NewEcmaReadOnlyHClass(hClass, StoreTSHandler::SIZE, JSType::STORE_TS_HANDLER));
160     SetConstant(ConstantIndex::PROPERTY_BOX_CLASS_INDEX,
161                 factory->NewEcmaReadOnlyHClass(hClass, PropertyBox::SIZE, JSType::PROPERTY_BOX));
162     SetConstant(ConstantIndex::PROGRAM_CLASS_INDEX,
163                 factory->NewEcmaReadOnlyHClass(hClass, Program::SIZE, JSType::PROGRAM));
164     SetConstant(
165         ConstantIndex::IMPORT_ENTRY_CLASS_INDEX,
166         factory->NewEcmaReadOnlyHClass(hClass, ImportEntry::SIZE, JSType::IMPORTENTRY_RECORD));
167     SetConstant(
168         ConstantIndex::LOCAL_EXPORT_ENTRY_CLASS_INDEX,
169         factory->NewEcmaReadOnlyHClass(hClass, LocalExportEntry::SIZE, JSType::LOCAL_EXPORTENTRY_RECORD));
170     SetConstant(
171         ConstantIndex::INDIRECT_EXPORT_ENTRY_CLASS_INDEX,
172         factory->NewEcmaReadOnlyHClass(hClass, IndirectExportEntry::SIZE,
173                                        JSType::INDIRECT_EXPORTENTRY_RECORD));
174     SetConstant(
175         ConstantIndex::STAR_EXPORT_ENTRY_CLASS_INDEX,
176         factory->NewEcmaReadOnlyHClass(hClass, StarExportEntry::SIZE, JSType::STAR_EXPORTENTRY_RECORD));
177     SetConstant(
178         ConstantIndex::SOURCE_TEXT_MODULE_CLASS_INDEX,
179         factory->NewEcmaReadOnlyHClass(hClass, SourceTextModule::SIZE, JSType::SOURCE_TEXT_MODULE_RECORD));
180     SetConstant(
181         ConstantIndex::RESOLVED_BINDING_CLASS_INDEX,
182         factory->NewEcmaReadOnlyHClass(hClass, ResolvedBinding::SIZE, JSType::RESOLVEDBINDING_RECORD));
183     SetConstant(
184         ConstantIndex::RESOLVED_INDEX_BINDING_CLASS_INDEX,
185         factory->NewEcmaReadOnlyHClass(hClass, ResolvedIndexBinding::SIZE, JSType::RESOLVEDINDEXBINDING_RECORD));
186 
187     JSHClass *jsProxyCallableClass = *factory->NewEcmaHClass(hClass, JSProxy::SIZE, JSType::JS_PROXY);
188 
189     jsProxyCallableClass->SetCallable(true);
190     SetConstant(ConstantIndex::JS_PROXY_CALLABLE_CLASS_INDEX, JSTaggedValue(jsProxyCallableClass));
191 
192     JSHClass *jsProxyConstructClass = *factory->NewEcmaHClass(hClass, JSProxy::SIZE, JSType::JS_PROXY);
193 
194     jsProxyConstructClass->SetCallable(true);
195     jsProxyConstructClass->SetConstructor(true);
196     SetConstant(ConstantIndex::JS_PROXY_CONSTRUCT_CLASS_INDEX, JSTaggedValue(jsProxyConstructClass));
197 
198     SetConstant(ConstantIndex::JS_REALM_CLASS_INDEX,
199                 factory->NewEcmaHClass(hClass, JSRealm::SIZE, JSType::JS_REALM));
200     SetConstant(ConstantIndex::MACHINE_CODE_CLASS_INDEX,
201                 factory->NewEcmaReadOnlyHClass(hClass, 0, JSType::MACHINE_CODE_OBJECT));
202     SetConstant(ConstantIndex::CLASS_INFO_EXTRACTOR_HCLASS_INDEX,
203                 factory->NewEcmaReadOnlyHClass(hClass, ClassInfoExtractor::SIZE,
204                                                  JSType::CLASS_INFO_EXTRACTOR));
205     SetConstant(ConstantIndex::TS_OBJECT_TYPE_CLASS_INDEX,
206                 factory->NewEcmaReadOnlyHClass(hClass, TSObjectType::SIZE, JSType::TS_OBJECT_TYPE));
207     SetConstant(ConstantIndex::TS_CLASS_TYPE_CLASS_INDEX,
208                 factory->NewEcmaReadOnlyHClass(hClass, TSClassType::SIZE, JSType::TS_CLASS_TYPE));
209     SetConstant(ConstantIndex::TS_UNION_TYPE_CLASS_INDEX,
210                 factory->NewEcmaReadOnlyHClass(hClass, TSUnionType::SIZE, JSType::TS_UNION_TYPE));
211     SetConstant(ConstantIndex::TS_INTERFACE_TYPE_CLASS_INDEX,
212                 factory->NewEcmaReadOnlyHClass(hClass, TSInterfaceType::SIZE, JSType::TS_INTERFACE_TYPE));
213     SetConstant(ConstantIndex::TS_CLASS_INSTANCE_TYPE_CLASS_INDEX,
214                 factory->NewEcmaReadOnlyHClass(hClass, TSClassInstanceType::SIZE,
215                                                  JSType::TS_CLASS_INSTANCE_TYPE));
216     SetConstant(ConstantIndex::TS_FUNCTION_TYPE_CLASS_INDEX,
217                 factory->NewEcmaReadOnlyHClass(hClass, TSFunctionType::SIZE, JSType::TS_FUNCTION_TYPE));
218     SetConstant(ConstantIndex::TS_ARRAY_TYPE_CLASS_INDEX,
219                 factory->NewEcmaReadOnlyHClass(hClass, TSArrayType::SIZE, JSType::TS_ARRAY_TYPE));
220     SetConstant(ConstantIndex::TS_ITERATOR_INSTANCE_TYPE_CLASS_INDEX,
221                 factory->NewEcmaReadOnlyHClass(hClass, TSIteratorInstanceType::SIZE,
222                 JSType::TS_ITERATOR_INSTANCE_TYPE));
223     SetConstant(ConstantIndex::JS_REGEXP_ITERATOR_CLASS_INDEX,
224                 factory->NewEcmaHClass(hClass, JSRegExpIterator::SIZE, JSType::JS_REG_EXP_ITERATOR));
225     SetConstant(ConstantIndex::JS_SET_ITERATOR_CLASS_INDEX,
226                 factory->NewEcmaHClass(hClass, JSSetIterator::SIZE, JSType::JS_SET_ITERATOR));
227     SetConstant(ConstantIndex::JS_MAP_ITERATOR_CLASS_INDEX,
228                 factory->NewEcmaHClass(hClass, JSMapIterator::SIZE, JSType::JS_MAP_ITERATOR));
229     SetConstant(ConstantIndex::JS_ARRAY_ITERATOR_CLASS_INDEX,
230                 factory->NewEcmaHClass(hClass, JSArrayIterator::SIZE, JSType::JS_ARRAY_ITERATOR));
231     SetConstant(
232         ConstantIndex::JS_API_ARRAYLIST_ITERATOR_CLASS_INDEX,
233         factory->NewEcmaHClass(hClass, JSAPIArrayListIterator::SIZE, JSType::JS_API_ARRAYLIST_ITERATOR));
234     SetConstant(ConstantIndex::JS_API_DEQUE_ITERATOR_CLASS_INDEX,
235                 factory->NewEcmaHClass(hClass, JSAPIDequeIterator::SIZE, JSType::JS_API_DEQUE_ITERATOR));
236     SetConstant(ConstantIndex::JS_API_LIGHTWEIGHTMAP_ITERATOR_CLASS_INDEX,
237                 factory->NewEcmaHClass(hClass, JSAPILightWeightMapIterator::SIZE,
238                 JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR));
239     SetConstant(ConstantIndex::JS_API_LIGHTWEIGHTSET_ITERATOR_CLASS_INDEX,
240                 factory->NewEcmaHClass(hClass, JSAPILightWeightSetIterator::SIZE,
241                 JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR));
242     SetConstant(
243         ConstantIndex::JS_API_LINKED_LIST_ITERATOR_CLASS_INDEX,
244         factory->NewEcmaHClass(hClass, JSAPILinkedListIterator::SIZE, JSType::JS_API_LINKED_LIST_ITERATOR));
245     SetConstant(ConstantIndex::JS_API_LIST_ITERATOR_CLASS_INDEX,
246                 factory->NewEcmaHClass(hClass, JSAPIListIterator::SIZE, JSType::JS_API_LIST_ITERATOR));
247     SetConstant(
248         ConstantIndex::JS_API_PLAIN_ARRAY_ITERATOR_CLASS_INDEX,
249         factory->NewEcmaHClass(hClass, JSAPIPlainArrayIterator::SIZE, JSType::JS_API_PLAIN_ARRAY_ITERATOR));
250     SetConstant(ConstantIndex::JS_API_QUEUE_ITERATOR_CLASS_INDEX,
251                 factory->NewEcmaHClass(hClass, JSAPIQueueIterator::SIZE, JSType::JS_API_QUEUE_ITERATOR));
252     SetConstant(ConstantIndex::JS_API_STACK_ITERATOR_CLASS_INDEX,
253                 factory->NewEcmaHClass(hClass, JSAPIStackIterator::SIZE, JSType::JS_API_STACK_ITERATOR));
254     SetConstant(ConstantIndex::JS_API_VECTOR_ITERATOR_CLASS_INDEX,
255                 factory->NewEcmaHClass(hClass, JSAPIVectorIterator::SIZE, JSType::JS_API_VECTOR_ITERATOR));
256     SetConstant(ConstantIndex::JS_API_HASH_MAP_ITERATOR_CLASS_INDEX,
257                 factory->NewEcmaHClass(hClass, JSAPIHashMapIterator::SIZE, JSType::JS_API_HASHMAP_ITERATOR));
258     SetConstant(ConstantIndex::JS_API_HASH_SET_ITERATOR_CLASS_INDEX,
259                 factory->NewEcmaHClass(hClass, JSAPIHashSetIterator::SIZE, JSType::JS_API_HASHSET_ITERATOR));
260     SetConstant(ConstantIndex::JS_API_TREE_MAP_ITERATOR_CLASS_INDEX,
261                 factory->NewEcmaHClass(hClass, JSAPITreeMapIterator::SIZE, JSType::JS_API_TREEMAP_ITERATOR));
262     SetConstant(ConstantIndex::JS_API_TREE_SET_ITERATOR_CLASS_INDEX,
263                 factory->NewEcmaHClass(hClass, JSAPITreeSetIterator::SIZE, JSType::JS_API_TREESET_ITERATOR));
264     SetConstant(ConstantIndex::LINKED_NODE_CLASS_INDEX,
265                 factory->NewEcmaHClass(hClass, LinkedNode::SIZE, JSType::LINKED_NODE));
266     SetConstant(ConstantIndex::RB_TREENODE_CLASS_INDEX,
267                 factory->NewEcmaHClass(hClass, RBTreeNode::SIZE, JSType::RB_TREENODE));
268     SetConstant(ConstantIndex::CELL_RECORD_CLASS_INDEX,
269                 factory->NewEcmaReadOnlyHClass(hClass, CellRecord::SIZE, JSType::CELL_RECORD));
270     SetConstant(ConstantIndex::OBJECT_HCLASS_INDEX, factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_OBJECT));
271     SetConstant(ConstantIndex::JS_METHOD_CLASS_INDEX,
272                 factory->NewEcmaHClass(hClass, Method::SIZE, JSType::METHOD));
273     SetConstant(ConstantIndex::CLASS_LITERAL_HCLASS_INDEX,
274                 factory->NewEcmaHClass(hClass, ClassLiteral::SIZE, JSType::CLASS_LITERAL));
275 }
276 
InitGlobalConstantSpecial(JSThread * thread)277 void GlobalEnvConstants::InitGlobalConstantSpecial(JSThread *thread)
278 {
279     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
280     // SPECIAL INIT
281     SetConstant(ConstantIndex::UNDEFINED_INDEX, JSTaggedValue::Undefined());
282     SetConstant(ConstantIndex::NULL_INDEX, JSTaggedValue::Null());
283     auto vm = thread->GetEcmaVM();
284     SetConstant(ConstantIndex::EMPTY_STRING_OBJECT_INDEX, JSTaggedValue(EcmaStringAccessor::CreateEmptyString(vm)));
285     SetConstant(ConstantIndex::EMPTY_ARRAY_OBJECT_INDEX, factory->NewEmptyArray());
286     SetConstant(ConstantIndex::EMPTY_LAYOUT_INFO_OBJECT_INDEX, factory->CreateLayoutInfo(0));
287     SetConstant(ConstantIndex::EMPTY_TAGGED_QUEUE_OBJECT_INDEX, factory->NewTaggedQueue(0));
288 }
289 
290 // NOLINTNEXTLINE(readability-function-size)
InitGlobalConstant(JSThread * thread)291 void GlobalEnvConstants::InitGlobalConstant(JSThread *thread)
292 {
293     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
294     [[maybe_unused]] auto test = EcmaString::Cast(GetHandledEmptyString().GetObject<EcmaString>());
295     SetConstant(ConstantIndex::CONSTRUCTOR_STRING_INDEX, factory->NewFromASCIINonMovable("constructor"));
296     SetConstant(ConstantIndex::PROTOTYPE_STRING_INDEX, factory->NewFromASCIINonMovable("prototype"));
297     SetConstant(ConstantIndex::LENGTH_STRING_INDEX, factory->NewFromASCIINonMovable("length"));
298     SetConstant(ConstantIndex::VALUE_STRING_INDEX, factory->NewFromASCIINonMovable("value"));
299     SetConstant(ConstantIndex::SET_STRING_INDEX, factory->NewFromASCIINonMovable("set"));
300     SetConstant(ConstantIndex::GET_STRING_INDEX, factory->NewFromASCIINonMovable("get"));
301     SetConstant(ConstantIndex::WRITABLE_STRING_INDEX, factory->NewFromASCIINonMovable("writable"));
302     SetConstant(ConstantIndex::ENUMERABLE_STRING_INDEX, factory->NewFromASCIINonMovable("enumerable"));
303     SetConstant(ConstantIndex::CONFIGURABLE_STRING_INDEX, factory->NewFromASCIINonMovable("configurable"));
304     /* non ECMA standard jsapi containers iterators, init to Undefined first */
305     InitJSAPIContainers();
306     /* SymbolTable *RegisterSymbols */
307     SetConstant(ConstantIndex::NAME_STRING_INDEX, factory->NewFromASCIINonMovable("name"));
308     SetConstant(ConstantIndex::GETPROTOTYPEOF_STRING_INDEX, factory->NewFromASCIINonMovable("getPrototypeOf"));
309     SetConstant(ConstantIndex::SETPROTOTYPEOF_STRING_INDEX, factory->NewFromASCIINonMovable("setPrototypeOf"));
310     SetConstant(ConstantIndex::ISEXTENSIBLE_STRING_INDEX, factory->NewFromASCIINonMovable("isExtensible"));
311     SetConstant(ConstantIndex::PREVENTEXTENSIONS_STRING_INDEX,
312                 factory->NewFromASCIINonMovable("preventExtensions"));
313     SetConstant(ConstantIndex::GETOWNPROPERTYDESCRIPTOR_STRING_INDEX,
314                 factory->NewFromASCIINonMovable("getOwnPropertyDescriptor"));
315     SetConstant(ConstantIndex::DEFINEPROPERTY_STRING_INDEX, factory->NewFromASCIINonMovable("defineProperty"));
316     SetConstant(ConstantIndex::HAS_STRING_INDEX, factory->NewFromASCIINonMovable("has"));
317     SetConstant(ConstantIndex::DELETEPROPERTY_STRING_INDEX, factory->NewFromASCIINonMovable("deleteProperty"));
318     SetConstant(ConstantIndex::ENUMERATE_STRING_INDEX, factory->NewFromASCIINonMovable("enumerate"));
319     SetConstant(ConstantIndex::OWNKEYS_STRING_INDEX, factory->NewFromASCIINonMovable("ownKeys"));
320     SetConstant(ConstantIndex::APPLY_STRING_INDEX, factory->NewFromASCIINonMovable("apply"));
321     SetConstant(ConstantIndex::NEGATIVE_ZERO_STRING_INDEX, factory->NewFromASCIINonMovable("-0"));
322     SetConstant(ConstantIndex::DONE_STRING_INDEX, factory->NewFromASCIINonMovable("done"));
323     SetConstant(ConstantIndex::PROXY_STRING_INDEX, factory->NewFromASCIINonMovable("proxy"));
324     SetConstant(ConstantIndex::REVOKE_STRING_INDEX, factory->NewFromASCIINonMovable("revoke"));
325     SetConstant(ConstantIndex::NEXT_STRING_INDEX, factory->NewFromASCIINonMovable("next"));
326     SetConstant(ConstantIndex::TO_STRING_STRING_INDEX, factory->NewFromASCIINonMovable("toString"));
327     SetConstant(ConstantIndex::TO_LOCALE_STRING_STRING_INDEX, factory->NewFromASCIINonMovable("toLocaleString"));
328     SetConstant(ConstantIndex::VALUE_OF_STRING_INDEX, factory->NewFromASCIINonMovable("valueOf"));
329     SetConstant(ConstantIndex::UNDEFINED_STRING_INDEX, factory->NewFromASCIINonMovable("undefined"));
330     SetConstant(ConstantIndex::NULL_STRING_INDEX, factory->NewFromASCIINonMovable("null"));
331     SetConstant(ConstantIndex::BOOLEAN_STRING_INDEX, factory->NewFromASCIINonMovable("boolean"));
332     SetConstant(ConstantIndex::NUMBER_STRING_INDEX, factory->NewFromASCIINonMovable("number"));
333     SetConstant(ConstantIndex::BIGINT_STRING_INDEX, factory->NewFromASCIINonMovable("bigint"));
334     SetConstant(ConstantIndex::FUNCTION_STRING_INDEX, factory->NewFromASCIINonMovable("function"));
335     SetConstant(ConstantIndex::STRING_STRING_INDEX, factory->NewFromASCIINonMovable("string"));
336     SetConstant(ConstantIndex::SYMBOL_STRING_INDEX, factory->NewFromASCIINonMovable("symbol"));
337     SetConstant(ConstantIndex::OBJECT_STRING_INDEX, factory->NewFromASCIINonMovable("object"));
338     SetConstant(ConstantIndex::TRUE_STRING_INDEX, factory->NewFromASCIINonMovable("true"));
339     SetConstant(ConstantIndex::FALSE_STRING_INDEX, factory->NewFromASCIINonMovable("false"));
340     SetConstant(ConstantIndex::RETURN_STRING_INDEX, factory->NewFromASCIINonMovable("return"));
341     SetConstant(ConstantIndex::PROXY_CONSTRUCT_STRING_INDEX, factory->NewFromASCIINonMovable("construct"));
342     SetConstant(ConstantIndex::PROXY_CALL_STRING_INDEX, factory->NewFromASCIINonMovable("call"));
343     SetConstant(ConstantIndex::PROMISE_THEN_STRING_INDEX, factory->NewFromASCIINonMovable("then"));
344     SetConstant(ConstantIndex::PROMISE_CATCH_STRING_INDEX, factory->NewFromASCIINonMovable("catch"));
345     SetConstant(ConstantIndex::PROMISE_FINALLY_STRING_INDEX, factory->NewFromASCII("finally"));
346     SetConstant(ConstantIndex::PROMISE_STATUS_STRING_INDEX, factory->NewFromASCII("status"));
347     SetConstant(ConstantIndex::PROMISE_FULFILLED_STRING_INDEX, factory->NewFromASCII("fulfilled"));
348     SetConstant(ConstantIndex::PROMISE_REJECTED_STRING_INDEX, factory->NewFromASCII("rejected"));
349     SetConstant(ConstantIndex::PROMISE_REASON_STRING_INDEX, factory->NewFromASCII("reason"));
350     SetConstant(ConstantIndex::SCRIPT_JOB_STRING_INDEX, factory->NewFromASCIINonMovable("ScriptJobs"));
351     SetConstant(ConstantIndex::PROMISE_STRING_INDEX, factory->NewFromASCIINonMovable("PrimiseJobs"));
352     SetConstant(ConstantIndex::THROWER_STRING_INDEX, factory->NewFromASCIINonMovable("Thrower"));
353     SetConstant(ConstantIndex::IDENTITY_STRING_INDEX, factory->NewFromASCIINonMovable("Identity"));
354     SetConstant(ConstantIndex::CALLER_STRING_INDEX, factory->NewFromASCIINonMovable("caller"));
355     SetConstant(ConstantIndex::CALLEE_STRING_INDEX, factory->NewFromASCIINonMovable("callee"));
356     SetConstant(ConstantIndex::INT8_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Int8Array"));
357     SetConstant(ConstantIndex::UINT8_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Uint8Array"));
358     SetConstant(ConstantIndex::UINT8_CLAMPED_ARRAY_STRING_INDEX,
359                 factory->NewFromASCIINonMovable("Uint8ClampedArray"));
360     SetConstant(ConstantIndex::INT16_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Int16Array"));
361     SetConstant(ConstantIndex::UINT16_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Uint16Array"));
362     SetConstant(ConstantIndex::INT32_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Int32Array"));
363     SetConstant(ConstantIndex::UINT32_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Uint32Array"));
364     SetConstant(ConstantIndex::FLOAT32_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Float32Array"));
365     SetConstant(ConstantIndex::FLOAT64_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("Float64Array"));
366     SetConstant(ConstantIndex::BIGINT64_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("BigInt64Array"));
367     SetConstant(ConstantIndex::BIGUINT64_ARRAY_STRING_INDEX, factory->NewFromASCIINonMovable("BigUint64Array"));
368     SetConstant(ConstantIndex::ASYNC_FUNCTION_STRING_INDEX, factory->NewFromASCIINonMovable("AsyncFunction"));
369     SetConstant(ConstantIndex::PROMISE_RESOLVE_STRING_INDEX, factory->NewFromASCIINonMovable("resolve"));
370     SetConstant(ConstantIndex::ID_STRING_INDEX, factory->NewFromASCIINonMovable("id"));
371     SetConstant(ConstantIndex::METHOD_STRING_INDEX, factory->NewFromASCIINonMovable("method"));
372     SetConstant(ConstantIndex::PARAMS_STRING_INDEX, factory->NewFromASCIINonMovable("params"));
373     SetConstant(ConstantIndex::RESULT_STRING_INDEX, factory->NewFromASCIINonMovable("result"));
374     SetConstant(ConstantIndex::TO_JSON_STRING_INDEX, factory->NewFromASCIINonMovable("toJSON"));
375     SetConstant(ConstantIndex::GLOBAL_STRING_INDEX, factory->NewFromASCIINonMovable("global"));
376     SetConstant(ConstantIndex::MESSAGE_STRING_INDEX, factory->NewFromASCIINonMovable("message"));
377     SetConstant(ConstantIndex::ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("Error"));
378     SetConstant(ConstantIndex::ERRORS_STRING_INDEX, factory->NewFromASCII("errors"));
379     SetConstant(ConstantIndex::AGGREGATE_ERROR_STRING_INDEX, factory->NewFromASCII("AggregateError"));
380     SetConstant(ConstantIndex::RANGE_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("RangeError"));
381     SetConstant(ConstantIndex::REFERENCE_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("ReferenceError"));
382     SetConstant(ConstantIndex::TYPE_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("TypeError"));
383     SetConstant(ConstantIndex::URI_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("URIError"));
384     SetConstant(ConstantIndex::SYNTAX_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("SyntaxError"));
385     SetConstant(ConstantIndex::EVAL_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("EvalError"));
386     SetConstant(ConstantIndex::OOM_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("OutOfMemoryError"));
387     SetConstant(ConstantIndex::ERROR_FUNC_STRING_INDEX, factory->NewFromASCIINonMovable("errorfunc"));
388     SetConstant(ConstantIndex::STACK_STRING_INDEX, factory->NewFromASCIINonMovable("stack"));
389     SetConstant(ConstantIndex::STACK_EMPTY_STRING_INDEX, factory->NewFromASCIINonMovable("stackisempty"));
390     SetConstant(ConstantIndex::OBJ_NOT_COERCIBLE_STRING_INDEX,
391                 factory->NewFromASCIINonMovable("objectnotcoercible"));
392     /* for Intl. */
393     SetConstant(ConstantIndex::LANGUAGE_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("language"));
394     SetConstant(ConstantIndex::SCRIPT_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("script"));
395     SetConstant(ConstantIndex::REGION_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("region"));
396     SetConstant(ConstantIndex::BASE_NAME_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("baseName"));
397     SetConstant(ConstantIndex::CALENDAR_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("calendar"));
398     SetConstant(ConstantIndex::COLLATION_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("collation"));
399     SetConstant(ConstantIndex::HOUR_CYCLE_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("hourCycle"));
400     SetConstant(ConstantIndex::CASE_FIRST_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("caseFirst"));
401     SetConstant(ConstantIndex::NUMERIC_STRING_CLASS_INDEX, factory->NewFromASCIINonMovable("numeric"));
402     SetConstant(ConstantIndex::NUMBERING_SYSTEM_STRING_CLASS_INDEX,
403                 factory->NewFromASCIINonMovable("numberingSystem"));
404     SetConstant(ConstantIndex::TYPE_STRING_INDEX, factory->NewFromASCIINonMovable("type"));
405     SetConstant(ConstantIndex::LOCALE_MATCHER_STRING_INDEX, factory->NewFromASCIINonMovable("localeMatcher"));
406     SetConstant(ConstantIndex::FORMAT_MATCHER_STRING_INDEX, factory->NewFromASCIINonMovable("formatMatcher"));
407     SetConstant(ConstantIndex::HOUR12_STRING_INDEX, factory->NewFromASCIINonMovable("hour12"));
408     SetConstant(ConstantIndex::H11_STRING_INDEX, factory->NewFromASCIINonMovable("h11"));
409     SetConstant(ConstantIndex::H12_STRING_INDEX, factory->NewFromASCIINonMovable("h12"));
410     SetConstant(ConstantIndex::H23_STRING_INDEX, factory->NewFromASCIINonMovable("h23"));
411     SetConstant(ConstantIndex::H24_STRING_INDEX, factory->NewFromASCIINonMovable("h24"));
412     SetConstant(ConstantIndex::WEEK_DAY_STRING_INDEX, factory->NewFromASCIINonMovable("weekday"));
413     SetConstant(ConstantIndex::ERA_STRING_INDEX, factory->NewFromASCIINonMovable("era"));
414     SetConstant(ConstantIndex::YEAR_STRING_INDEX, factory->NewFromASCIINonMovable("year"));
415     SetConstant(ConstantIndex::QUARTER_STRING_INDEX, factory->NewFromASCIINonMovable("quarter"));
416     SetConstant(ConstantIndex::MONTH_STRING_INDEX, factory->NewFromASCIINonMovable("month"));
417     SetConstant(ConstantIndex::DAY_STRING_INDEX, factory->NewFromASCIINonMovable("day"));
418     SetConstant(ConstantIndex::HOUR_STRING_INDEX, factory->NewFromASCIINonMovable("hour"));
419     SetConstant(ConstantIndex::MINUTE_STRING_INDEX, factory->NewFromASCIINonMovable("minute"));
420     SetConstant(ConstantIndex::SECOND_STRING_INDEX, factory->NewFromASCIINonMovable("second"));
421     SetConstant(ConstantIndex::YEARS_STRING_INDEX, factory->NewFromASCIINonMovable("years"));
422     SetConstant(ConstantIndex::QUARTERS_STRING_INDEX, factory->NewFromASCIINonMovable("quarters"));
423     SetConstant(ConstantIndex::MONTHS_STRING_INDEX, factory->NewFromASCIINonMovable("months"));
424     SetConstant(ConstantIndex::DAYS_STRING_INDEX, factory->NewFromASCIINonMovable("days"));
425     SetConstant(ConstantIndex::HOURS_STRING_INDEX, factory->NewFromASCIINonMovable("hours"));
426     SetConstant(ConstantIndex::MINUTES_STRING_INDEX, factory->NewFromASCIINonMovable("minutes"));
427     SetConstant(ConstantIndex::SECONDS_STRING_INDEX, factory->NewFromASCIINonMovable("seconds"));
428     SetConstant(ConstantIndex::TIME_ZONE_NAME_STRING_INDEX, factory->NewFromASCIINonMovable("timeZoneName"));
429     SetConstant(ConstantIndex::LOCALE_STRING_INDEX, factory->NewFromASCIINonMovable("locale"));
430     SetConstant(ConstantIndex::TIME_ZONE_STRING_INDEX, factory->NewFromASCIINonMovable("timeZone"));
431     SetConstant(ConstantIndex::LITERAL_STRING_INDEX, factory->NewFromASCIINonMovable("literal"));
432     SetConstant(ConstantIndex::YEAR_NAME_STRING_INDEX, factory->NewFromASCIINonMovable("yearName"));
433     SetConstant(ConstantIndex::DAY_PERIOD_STRING_INDEX, factory->NewFromASCIINonMovable("dayPeriod"));
434     SetConstant(ConstantIndex::FRACTIONAL_SECOND_DIGITS_STRING_INDEX,
435                 factory->NewFromASCIINonMovable("fractionalSecondDigits"));
436     SetConstant(ConstantIndex::FRACTIONAL_SECOND_STRING_INDEX, factory->NewFromASCIINonMovable("fractionalSecond"));
437     SetConstant(ConstantIndex::RELATED_YEAR_STRING_INDEX, factory->NewFromASCIINonMovable("relatedYear"));
438     SetConstant(ConstantIndex::LOOK_UP_STRING_INDEX, factory->NewFromASCIINonMovable("lookup"));
439     SetConstant(ConstantIndex::BEST_FIT_STRING_INDEX, factory->NewFromASCIINonMovable("bestfit"));
440     SetConstant(ConstantIndex::DATE_STYLE_STRING_INDEX, factory->NewFromASCIINonMovable("dateStyle"));
441     SetConstant(ConstantIndex::TIME_STYLE_STRING_INDEX, factory->NewFromASCIINonMovable("timeStyle"));
442     SetConstant(ConstantIndex::UTC_STRING_INDEX, factory->NewFromASCIINonMovable("UTC"));
443     SetConstant(ConstantIndex::WEEK_STRING_INDEX, factory->NewFromASCIINonMovable("week"));
444     SetConstant(ConstantIndex::WEEKS_STRING_INDEX, factory->NewFromASCIINonMovable("weeks"));
445     SetConstant(ConstantIndex::SOURCE_STRING_INDEX, factory->NewFromASCIINonMovable("source"));
446     SetConstant(ConstantIndex::FORMAT_STRING_INDEX, factory->NewFromASCIINonMovable("format"));
447     SetConstant(ConstantIndex::EN_US_STRING_INDEX, factory->NewFromASCIINonMovable("en-US"));
448     SetConstant(ConstantIndex::UND_STRING_INDEX, factory->NewFromASCIINonMovable("und"));
449     SetConstant(ConstantIndex::LATN_STRING_INDEX, factory->NewFromASCIINonMovable("latn"));
450     SetConstant(ConstantIndex::STYLE_STRING_INDEX, factory->NewFromASCIINonMovable("style"));
451     SetConstant(ConstantIndex::UNIT_STRING_INDEX, factory->NewFromASCIINonMovable("unit"));
452     SetConstant(ConstantIndex::INTEGER_STRING_INDEX, factory->NewFromASCIINonMovable("integer"));
453     SetConstant(ConstantIndex::NAN_STRING_INDEX, factory->NewFromASCIINonMovable("nan"));
454     SetConstant(ConstantIndex::INFINITY_STRING_INDEX, factory->NewFromASCIINonMovable("infinity"));
455     SetConstant(ConstantIndex::FRACTION_STRING_INDEX, factory->NewFromASCIINonMovable("fraction"));
456     SetConstant(ConstantIndex::DECIMAL_STRING_INDEX, factory->NewFromASCIINonMovable("decimal"));
457     SetConstant(ConstantIndex::GROUP_STRING_INDEX, factory->NewFromASCIINonMovable("group"));
458     SetConstant(ConstantIndex::GROUPS_STRING_INDEX, factory->NewFromASCIINonMovable("groups"));
459     SetConstant(ConstantIndex::CURRENCY_STRING_INDEX, factory->NewFromASCIINonMovable("currency"));
460     SetConstant(ConstantIndex::CURRENCY_SIGN_STRING_INDEX, factory->NewFromASCIINonMovable("currencySign"));
461     SetConstant(ConstantIndex::CURRENCY_DISPLAY_STRING_INDEX, factory->NewFromASCIINonMovable("currencyDisplay"));
462     SetConstant(ConstantIndex::PERCENT_SIGN_STRING_INDEX, factory->NewFromASCIINonMovable("percentSign"));
463     SetConstant(ConstantIndex::PERCENT_STRING_INDEX, factory->NewFromASCIINonMovable("percent"));
464     SetConstant(ConstantIndex::MINUS_SIGN_STRING_INDEX, factory->NewFromASCIINonMovable("minusSign"));
465     SetConstant(ConstantIndex::PLUS_SIGN_STRING_INDEX, factory->NewFromASCIINonMovable("plusSign"));
466     SetConstant(ConstantIndex::EXPONENT_SEPARATOR_STRING_INDEX,
467                 factory->NewFromASCIINonMovable("exponentSeparator"));
468     SetConstant(ConstantIndex::EXPONENT_MINUS_SIGN_INDEX, factory->NewFromASCIINonMovable("exponentMinusSign"));
469     SetConstant(ConstantIndex::EXPONENT_INTEGER_STRING_INDEX, factory->NewFromASCIINonMovable("exponentInteger"));
470     SetConstant(ConstantIndex::LONG_STRING_INDEX, factory->NewFromASCIINonMovable("long"));
471     SetConstant(ConstantIndex::SHORT_STRING_INDEX, factory->NewFromASCIINonMovable("short"));
472     SetConstant(ConstantIndex::FULL_STRING_INDEX, factory->NewFromASCIINonMovable("full"));
473     SetConstant(ConstantIndex::MEDIUM_STRING_INDEX, factory->NewFromASCIINonMovable("medium"));
474     SetConstant(ConstantIndex::NARROW_STRING_INDEX, factory->NewFromASCIINonMovable("narrow"));
475     SetConstant(ConstantIndex::ALWAYS_STRING_INDEX, factory->NewFromASCIINonMovable("always"));
476     SetConstant(ConstantIndex::AUTO_STRING_INDEX, factory->NewFromASCIINonMovable("auto"));
477     SetConstant(ConstantIndex::THROW_STRING_INDEX, factory->NewFromASCIINonMovable("throw"));
478     SetConstant(ConstantIndex::UNIT_DISPLAY_INDEX, factory->NewFromASCIINonMovable("unitDisplay"));
479     SetConstant(ConstantIndex::NOTATION_INDEX, factory->NewFromASCIINonMovable("notation"));
480     SetConstant(ConstantIndex::COMPACT_DISPALY_INDEX, factory->NewFromASCIINonMovable("compactDisplay"));
481     SetConstant(ConstantIndex::USER_GROUPING_INDEX, factory->NewFromASCIINonMovable("useGrouping"));
482     SetConstant(ConstantIndex::SIGN_DISPLAY_INDEX, factory->NewFromASCIINonMovable("signDisplay"));
483     SetConstant(ConstantIndex::CODE_INDEX, factory->NewFromASCIINonMovable("code"));
484     SetConstant(ConstantIndex::NARROW_SYMBOL_INDEX, factory->NewFromASCIINonMovable("narrowSymbol"));
485     SetConstant(ConstantIndex::STANDARD_INDEX, factory->NewFromASCIINonMovable("standard"));
486     SetConstant(ConstantIndex::ACCOUNTING_INDEX, factory->NewFromASCIINonMovable("accounting"));
487     SetConstant(ConstantIndex::SCIENTIFIC_INDEX, factory->NewFromASCIINonMovable("scientific"));
488     SetConstant(ConstantIndex::ENGINEERING_INDEX, factory->NewFromASCIINonMovable("engineering"));
489     SetConstant(ConstantIndex::COMPACT_STRING_INDEX, factory->NewFromASCIINonMovable("compact"));
490     SetConstant(ConstantIndex::NEVER_INDEX, factory->NewFromASCIINonMovable("never"));
491     SetConstant(ConstantIndex::EXPECT_ZERO_INDEX, factory->NewFromASCIINonMovable("exceptZero"));
492     SetConstant(ConstantIndex::MINIMUM_INTEGER_DIGITS_INDEX,
493                 factory->NewFromASCIINonMovable("minimumIntegerDigits"));
494     SetConstant(ConstantIndex::MINIMUM_FRACTIONDIGITS_INDEX,
495                 factory->NewFromASCIINonMovable("minimumFractionDigits"));
496     SetConstant(ConstantIndex::MAXIMUM_FRACTIONDIGITS_INDEX,
497                 factory->NewFromASCIINonMovable("maximumFractionDigits"));
498     SetConstant(ConstantIndex::MINIMUM_SIGNIFICANTDIGITS_INDEX,
499                 factory->NewFromASCIINonMovable("minimumSignificantDigits"));
500     SetConstant(ConstantIndex::MAXIMUM_SIGNIFICANTDIGITS_INDEX,
501                 factory->NewFromASCIINonMovable("maximumSignificantDigits"));
502     SetConstant(ConstantIndex::INVALID_DATE_INDEX, factory->NewFromASCIINonMovable("Invalid Date"));
503     SetConstant(ConstantIndex::USAGE_INDEX, factory->NewFromASCIINonMovable("usage"));
504     SetConstant(ConstantIndex::COMPARE_INDEX, factory->NewFromASCIINonMovable("compare"));
505     SetConstant(ConstantIndex::SENSITIVITY_INDEX, factory->NewFromASCIINonMovable("sensitivity"));
506     SetConstant(ConstantIndex::IGNORE_PUNCTUATION_INDEX, factory->NewFromASCIINonMovable("ignorePunctuation"));
507     SetConstant(ConstantIndex::CARDINAL_INDEX, factory->NewFromASCIINonMovable("cardinal"));
508     SetConstant(ConstantIndex::ORDINAL_INDEX, factory->NewFromASCIINonMovable("ordinal"));
509     SetConstant(ConstantIndex::EXEC_INDEX, factory->NewFromASCIINonMovable("exec"));
510     SetConstant(ConstantIndex::LAST_INDEX_INDEX, factory->NewFromASCIINonMovable("lastIndex"));
511     SetConstant(ConstantIndex::PLURAL_CATEGORIES_INDEX, factory->NewFromASCIINonMovable("pluralCategories"));
512     SetConstant(ConstantIndex::SORT_INDEX, factory->NewFromASCIINonMovable("sort"));
513     SetConstant(ConstantIndex::SEARCH_INDEX, factory->NewFromASCIINonMovable("search"));
514     SetConstant(ConstantIndex::BASE_INDEX, factory->NewFromASCIINonMovable("base"));
515     SetConstant(ConstantIndex::ACCENT_INDEX, factory->NewFromASCIINonMovable("accent"));
516     SetConstant(ConstantIndex::CASE_INDEX, factory->NewFromASCIINonMovable("case"));
517     SetConstant(ConstantIndex::VARIANT_INDEX, factory->NewFromASCIINonMovable("variant"));
518     SetConstant(ConstantIndex::EN_US_POSIX_STRING_INDEX, factory->NewFromASCIINonMovable("en-US-POSIX"));
519     SetConstant(ConstantIndex::UPPER_INDEX, factory->NewFromASCIINonMovable("upper"));
520     SetConstant(ConstantIndex::LOWER_INDEX, factory->NewFromASCIINonMovable("lower"));
521     SetConstant(ConstantIndex::DEFAULT_INDEX, factory->NewFromASCIINonMovable("default"));
522     SetConstant(ConstantIndex::SHARED_INDEX, factory->NewFromASCIINonMovable("shared"));
523     SetConstant(ConstantIndex::START_RANGE_INDEX, factory->NewFromASCIINonMovable("startRange"));
524     SetConstant(ConstantIndex::END_RANGE_INDEX, factory->NewFromASCIINonMovable("endRange"));
525     SetConstant(ConstantIndex::ISO8601_INDEX, factory->NewFromASCIINonMovable("iso8601"));
526     SetConstant(ConstantIndex::GREGORY_INDEX, factory->NewFromASCIINonMovable("gregory"));
527     SetConstant(ConstantIndex::ETHIOAA_INDEX, factory->NewFromASCIINonMovable("ethioaa"));
528     SetConstant(ConstantIndex::STICKY_INDEX, factory->NewFromASCIINonMovable("sticky"));
529     SetConstant(ConstantIndex::U_INDEX, factory->NewFromASCIINonMovable("u"));
530     SetConstant(ConstantIndex::INDEX_INDEX, factory->NewFromASCIINonMovable("index"));
531     SetConstant(ConstantIndex::INPUT_INDEX, factory->NewFromASCIINonMovable("input"));
532     SetConstant(ConstantIndex::UNICODE_INDEX, factory->NewFromASCIINonMovable("unicode"));
533     SetConstant(ConstantIndex::ZERO_INDEX, factory->NewFromASCIINonMovable("0"));
534     SetConstant(ConstantIndex::VALUES_INDEX, factory->NewFromASCIINonMovable("values"));
535     SetConstant(ConstantIndex::ADD_INDEX, factory->NewFromASCIINonMovable("add"));
536     SetConstant(ConstantIndex::AMBIGUOUS_INDEX, factory->NewFromASCIINonMovable("ambiguous"));
537     SetConstant(ConstantIndex::MODULE_INDEX, factory->NewFromASCIINonMovable("Module"));
538     SetConstant(ConstantIndex::STAR_INDEX, factory->NewFromASCIINonMovable("*"));
539     SetConstant(ConstantIndex::DATETIMEFIELD_INDEX, factory->NewFromASCIINonMovable("datetimefield"));
540     SetConstant(ConstantIndex::CONJUNCTION_INDEX, factory->NewFromASCIINonMovable("conjunction"));
541     SetConstant(ConstantIndex::NONE_INDEX, factory->NewFromASCIINonMovable("none"));
542     SetConstant(ConstantIndex::FALLBACK_INDEX, factory->NewFromASCIINonMovable("fallback"));
543     SetConstant(ConstantIndex::DISJUNCTION_INDEX, factory->NewFromASCIINonMovable("disjunction"));
544     SetConstant(ConstantIndex::ELEMENT_INDEX, factory->NewFromASCIINonMovable("element"));
545     SetConstant(ConstantIndex::FLAGS_INDEX, factory->NewFromASCIINonMovable("flags"));
546     SetConstant(ConstantIndex::G_INDEX, factory->NewFromASCIINonMovable("g"));
547     SetConstant(ConstantIndex::NFC_INDEX, factory->NewFromASCIINonMovable("NFC"));
548     SetConstant(ConstantIndex::ENTRIES_INDEX, factory->NewFromASCIINonMovable("entries"));
549     SetConstant(ConstantIndex::LEFT_SQUARE_BRACKET_INDEX, factory->NewFromASCIINonMovable("["));
550     SetConstant(ConstantIndex::RIGHT_SQUARE_BRACKET_INDEX, factory->NewFromASCIINonMovable("]"));
551     SetConstant(ConstantIndex::Y_INDEX, factory->NewFromASCIINonMovable("y"));
552     SetConstant(ConstantIndex::DOLLAR_INDEX, factory->NewFromASCIINonMovable("$"));
553     SetConstant(ConstantIndex::COMMA_INDEX, factory->NewFromASCIINonMovable(","));
554     SetConstant(ConstantIndex::JOIN_INDEX, factory->NewFromASCIINonMovable("join"));
555     SetConstant(ConstantIndex::COPY_WITHIN_INDEX, factory->NewFromASCIINonMovable("copyWithin"));
556     SetConstant(ConstantIndex::FILL_INDEX, factory->NewFromASCIINonMovable("fill"));
557     SetConstant(ConstantIndex::FIND_INDEX, factory->NewFromASCIINonMovable("find"));
558     SetConstant(ConstantIndex::FIND_INDEX_INDEX, factory->NewFromASCIINonMovable("findIndex"));
559     SetConstant(ConstantIndex::FLAT_INDEX, factory->NewFromASCIINonMovable("flat"));
560     SetConstant(ConstantIndex::FLATMAP_INDEX, factory->NewFromASCIINonMovable("flatMap"));
561     SetConstant(ConstantIndex::INCLUDES_INDEX, factory->NewFromASCIINonMovable("includes"));
562     SetConstant(ConstantIndex::KEYS_INDEX, factory->NewFromASCIINonMovable("keys"));
563     SetConstant(ConstantIndex::BOUND_INDEX, factory->NewFromASCIINonMovable("bound"));
564     SetConstant(ConstantIndex::BACKSLASH_INDEX, factory->NewFromASCIINonMovable("/"));
565     SetConstant(ConstantIndex::SPACE_INDEX, factory->NewFromASCIINonMovable(" "));
566     SetConstant(ConstantIndex::NAN_INDEX, factory->NewFromASCIINonMovable("NaN"));
567     SetConstant(ConstantIndex::NOT_EQUAL_INDEX, factory->NewFromASCIINonMovable("not-equal"));
568     SetConstant(ConstantIndex::OK_INDEX, factory->NewFromASCIINonMovable("ok"));
569     SetConstant(ConstantIndex::TIMEOUT_INDEX, factory->NewFromASCIINonMovable("timed-out"));
570     SetConstant(ConstantIndex::CJS_EXPORTS_INDEX, factory->NewFromASCIINonMovable("exports"));
571     SetConstant(ConstantIndex::CJS_CACHE_INDEX, factory->NewFromASCIINonMovable("_cache"));
572     SetConstant(ConstantIndex::NAPI_WRAPPER_INDEX, factory->NewFromASCIINonMovable("_napiwrapper"));
573     // for require native module
574     SetConstant(ConstantIndex::REQUIRE_NATIVE_MOUDULE_FUNC_INDEX,
575                 factory->NewFromASCIINonMovable("requireNativeModule"));
576     SetConstant(ConstantIndex::REQUIRE_NAPI_FUNC_INDEX, factory->NewFromASCIINonMovable("requireNapi"));
577     SetConstant(ConstantIndex::DOLLAR_STRING_ONE_INDEX, factory->NewFromASCIINonMovable("$1"));
578     SetConstant(ConstantIndex::DOLLAR_STRING_TWO_INDEX, factory->NewFromASCIINonMovable("$2"));
579     SetConstant(ConstantIndex::DOLLAR_STRING_THREE_INDEX, factory->NewFromASCIINonMovable("$3"));
580     SetConstant(ConstantIndex::DOLLAR_STRING_FOUR_INDEX, factory->NewFromASCIINonMovable("$4"));
581     SetConstant(ConstantIndex::DOLLAR_STRING_FIVE_INDEX, factory->NewFromASCIINonMovable("$5"));
582     SetConstant(ConstantIndex::DOLLAR_STRING_SIX_INDEX, factory->NewFromASCIINonMovable("$6"));
583     SetConstant(ConstantIndex::DOLLAR_STRING_SEVEN_INDEX, factory->NewFromASCIINonMovable("$7"));
584     SetConstant(ConstantIndex::DOLLAR_STRING_EIGHT_INDEX, factory->NewFromASCIINonMovable("$8"));
585     SetConstant(ConstantIndex::DOLLAR_STRING_NINE_INDEX, factory->NewFromASCIINonMovable("$9"));
586 
587     auto accessor = factory->NewInternalAccessor(reinterpret_cast<void *>(JSFunction::PrototypeSetter),
588                                                  reinterpret_cast<void *>(JSFunction::PrototypeGetter));
589     SetConstant(ConstantIndex::FUNCTION_PROTOTYPE_ACCESSOR, accessor);
590     accessor = factory->NewInternalAccessor(nullptr, reinterpret_cast<void *>(JSFunction::NameGetter));
591     SetConstant(ConstantIndex::FUNCTION_NAME_ACCESSOR, accessor);
592     accessor = factory->NewInternalAccessor(reinterpret_cast<void *>(JSArray::LengthSetter),
593                                             reinterpret_cast<void *>(JSArray::LengthGetter));
594     SetConstant(ConstantIndex::ARRAY_LENGTH_ACCESSOR, accessor);
595     SetConstant(ConstantIndex::CLASS_PROTOTYPE_HCLASS_INDEX,
596                 factory->CreateDefaultClassPrototypeHClass(JSHClass::Cast(GetHClassClass().GetTaggedObject())));
597     SetConstant(ConstantIndex::CLASS_CONSTRUCTOR_HCLASS_INDEX,
598                 factory->CreateDefaultClassConstructorHClass(JSHClass::Cast(GetHClassClass().GetTaggedObject())));
599 }
600 
InitJSAPIContainers()601 void GlobalEnvConstants::InitJSAPIContainers()
602 {
603     for (size_t i = GetJSAPIContainersBegin(); i <= GetJSAPIContainersEnd(); i++) {
604         SetConstant(static_cast<ConstantIndex>(i), JSTaggedValue::Undefined());
605     }
606 }
607 
InitSpecialForSnapshot()608 void GlobalEnvConstants::InitSpecialForSnapshot()
609 {
610     SetConstant(ConstantIndex::UNDEFINED_INDEX, JSTaggedValue::Undefined());
611     SetConstant(ConstantIndex::NULL_INDEX, JSTaggedValue::Null());
612     InitJSAPIContainers();
613 }
614 }  // namespace panda::ecmascript
615