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