1 /*
2 * Copyright (c) 2021 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.h"
20 #include "ecmascript/builtins/builtins_global.h"
21 #include "ecmascript/class_info_extractor.h"
22 #include "ecmascript/jspandafile/program_object.h"
23 #include "ecmascript/ecma_module.h"
24 #include "ecmascript/ecma_vm.h"
25 #include "ecmascript/free_object.h"
26 #include "ecmascript/global_env.h"
27 #include "ecmascript/global_env_constants-inl.h"
28 #include "ecmascript/ic/ic_handler.h"
29 #include "ecmascript/ic/property_box.h"
30 #include "ecmascript/ic/proto_change_details.h"
31 #include "ecmascript/jobs/micro_job_queue.h"
32 #include "ecmascript/jobs/pending_job.h"
33 #include "ecmascript/js_arguments.h"
34 #include "ecmascript/js_array.h"
35 #include "ecmascript/js_array_iterator.h"
36 #include "ecmascript/js_arraybuffer.h"
37 #include "ecmascript/js_for_in_iterator.h"
38 #include "ecmascript/js_generator_object.h"
39 #include "ecmascript/js_hclass.h"
40 #include "ecmascript/js_iterator.h"
41 #include "ecmascript/js_map.h"
42 #include "ecmascript/js_map_iterator.h"
43 #include "ecmascript/js_primitive_ref.h"
44 #include "ecmascript/js_promise.h"
45 #include "ecmascript/js_proxy.h"
46 #include "ecmascript/js_realm.h"
47 #include "ecmascript/js_regexp.h"
48 #include "ecmascript/js_set.h"
49 #include "ecmascript/js_set_iterator.h"
50 #include "ecmascript/js_symbol.h"
51 #include "ecmascript/js_tagged_value.h"
52 #include "ecmascript/js_thread.h"
53 #include "ecmascript/object_factory.h"
54 #include "ecmascript/ts_types/ts_type.h"
55
56 namespace panda::ecmascript {
InitRootsClass(JSThread * thread,JSHClass * dynClassClass)57 void GlobalEnvConstants::InitRootsClass([[maybe_unused]] JSThread *thread, JSHClass *dynClassClass)
58 {
59 // Global constants are readonly.
60 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
61
62 SetConstant(ConstantIndex::HCLASS_CLASS_INDEX, JSTaggedValue(dynClassClass));
63 SetConstant(ConstantIndex::FREE_OBJECT_WITH_NONE_FIELD_CLASS_INDEX,
64 factory->NewEcmaDynClass(dynClassClass, FreeObject::NEXT_OFFSET, JSType::FREE_OBJECT_WITH_NONE_FIELD));
65 SetConstant(ConstantIndex::FREE_OBJECT_WITH_ONE_FIELD_CLASS_INDEX,
66 factory->NewEcmaDynClass(dynClassClass, FreeObject::SIZE_OFFSET, JSType::FREE_OBJECT_WITH_ONE_FIELD));
67 SetConstant(ConstantIndex::FREE_OBJECT_WITH_TWO_FIELD_CLASS_INDEX,
68 factory->NewEcmaDynClass(dynClassClass, FreeObject::SIZE, JSType::FREE_OBJECT_WITH_TWO_FIELD));
69 SetConstant(ConstantIndex::STRING_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, 0, JSType::STRING));
70 SetConstant(ConstantIndex::ARRAY_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, 0, JSType::TAGGED_ARRAY));
71 SetConstant(ConstantIndex::DICTIONARY_CLASS_INDEX,
72 factory->NewEcmaDynClass(dynClassClass, 0, JSType::TAGGED_DICTIONARY));
73 SetConstant(ConstantIndex::BIGINT_CLASS_INDEX,
74 factory->NewEcmaDynClass(dynClassClass, BigInt::SIZE, JSType::BIGINT));
75 SetConstant(ConstantIndex::JS_NATIVE_POINTER_CLASS_INDEX,
76 factory->NewEcmaDynClass(dynClassClass, JSNativePointer::SIZE, JSType::JS_NATIVE_POINTER));
77 SetConstant(ConstantIndex::ENV_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, 0, JSType::TAGGED_ARRAY));
78 SetConstant(ConstantIndex::SYMBOL_CLASS_INDEX,
79 factory->NewEcmaDynClass(dynClassClass, JSSymbol::SIZE, JSType::SYMBOL));
80 SetConstant(ConstantIndex::ACCESSOE_DATA_CLASS_INDEX,
81 factory->NewEcmaDynClass(dynClassClass, AccessorData::SIZE, JSType::ACCESSOR_DATA));
82 SetConstant(ConstantIndex::INTERNAL_ACCESSOR_CLASS_INDEX,
83 factory->NewEcmaDynClass(dynClassClass, AccessorData::SIZE, JSType::INTERNAL_ACCESSOR));
84 SetConstant(ConstantIndex::JS_PROXY_ORDINARY_CLASS_INDEX,
85 factory->NewEcmaDynClass(dynClassClass, JSProxy::SIZE, JSType::JS_PROXY));
86 SetConstant(ConstantIndex::COMPLETION_RECORD_CLASS_INDEX,
87 factory->NewEcmaDynClass(dynClassClass, CompletionRecord::SIZE, JSType::COMPLETION_RECORD));
88 SetConstant(ConstantIndex::GENERATOR_CONTEST_INDEX,
89 factory->NewEcmaDynClass(dynClassClass, GeneratorContext::SIZE, JSType::JS_GENERATOR_CONTEXT));
90 SetConstant(ConstantIndex::CAPABILITY_RECORD_CLASS_INDEX,
91 factory->NewEcmaDynClass(dynClassClass, PromiseCapability::SIZE, JSType::PROMISE_CAPABILITY));
92 SetConstant(ConstantIndex::REACTIONS_RECORD_CLASS_INDEX,
93 factory->NewEcmaDynClass(dynClassClass, PromiseReaction::SIZE, JSType::PROMISE_REACTIONS));
94 SetConstant(ConstantIndex::PROMISE_ITERATOR_RECORD_CLASS_INDEX,
95 factory->NewEcmaDynClass(dynClassClass, PromiseIteratorRecord::SIZE, JSType::PROMISE_ITERATOR_RECORD));
96 SetConstant(ConstantIndex::PROMISE_RECORD_CLASS_INDEX,
97 factory->NewEcmaDynClass(dynClassClass, PromiseRecord::SIZE, JSType::PROMISE_RECORD));
98 SetConstant(ConstantIndex::PROMISE_RESOLVING_FUNCTIONS_CLASS_INDEX,
99 factory->NewEcmaDynClass(dynClassClass, ResolvingFunctionsRecord::SIZE,
100 JSType::RESOLVING_FUNCTIONS_RECORD));
101 SetConstant(ConstantIndex::MICRO_JOB_QUEUE_CLASS_INDEX,
102 factory->NewEcmaDynClass(dynClassClass, job::MicroJobQueue::SIZE, JSType::MICRO_JOB_QUEUE));
103 SetConstant(ConstantIndex::PENDING_JOB_CLASS_INDEX,
104 factory->NewEcmaDynClass(dynClassClass, job::PendingJob::SIZE, JSType::PENDING_JOB));
105 SetConstant(ConstantIndex::PROTO_CHANGE_MARKER_CLASS_INDEX,
106 factory->NewEcmaDynClass(dynClassClass, ProtoChangeMarker::SIZE, JSType::PROTO_CHANGE_MARKER));
107 SetConstant(ConstantIndex::PROTO_CHANGE_DETAILS_CLASS_INDEX,
108 factory->NewEcmaDynClass(dynClassClass, ProtoChangeDetails::SIZE, JSType::PROTOTYPE_INFO));
109 SetConstant(ConstantIndex::PROTOTYPE_HANDLER_CLASS_INDEX,
110 factory->NewEcmaDynClass(dynClassClass, PrototypeHandler::SIZE, JSType::PROTOTYPE_HANDLER));
111 SetConstant(ConstantIndex::TRANSITION_HANDLER_CLASS_INDEX,
112 factory->NewEcmaDynClass(dynClassClass, TransitionHandler::SIZE, JSType::TRANSITION_HANDLER));
113 SetConstant(ConstantIndex::PROPERTY_BOX_CLASS_INDEX,
114 factory->NewEcmaDynClass(dynClassClass, PropertyBox::SIZE, JSType::PROPERTY_BOX));
115 SetConstant(ConstantIndex::PROGRAM_CLASS_INDEX,
116 factory->NewEcmaDynClass(dynClassClass, Program::SIZE, JSType::PROGRAM));
117 SetConstant(ConstantIndex::ECMA_MODULE_CLASS_INDEX,
118 factory->NewEcmaDynClass(dynClassClass, EcmaModule::SIZE, JSType::ECMA_MODULE));
119
120 JSHClass *jsProxyCallableClass = *factory->NewEcmaDynClass(dynClassClass, JSProxy::SIZE, JSType::JS_PROXY);
121
122 jsProxyCallableClass->SetCallable(true);
123 SetConstant(ConstantIndex::JS_PROXY_CALLABLE_CLASS_INDEX, JSTaggedValue(jsProxyCallableClass));
124
125 JSHClass *jsProxyConstructClass = *factory->NewEcmaDynClass(dynClassClass, JSProxy::SIZE, JSType::JS_PROXY);
126
127 jsProxyConstructClass->SetCallable(true);
128 jsProxyConstructClass->SetConstructor(true);
129 SetConstant(ConstantIndex::JS_PROXY_CONSTRUCT_CLASS_INDEX, JSTaggedValue(jsProxyConstructClass));
130
131 SetConstant(ConstantIndex::JS_REALM_CLASS_INDEX,
132 factory->NewEcmaDynClass(dynClassClass, JSRealm::SIZE, JSType::JS_REALM));
133 SetConstant(ConstantIndex::MACHINE_CODE_CLASS_INDEX,
134 factory->NewEcmaDynClass(dynClassClass, 0, JSType::MACHINE_CODE_OBJECT));
135 SetConstant(ConstantIndex::CLASS_INFO_EXTRACTOR_HCLASS_INDEX,
136 factory->NewEcmaDynClass(dynClassClass, ClassInfoExtractor::SIZE, JSType::CLASS_INFO_EXTRACTOR));
137 SetConstant(ConstantIndex::TS_OBJECT_TYPE_CLASS_INDEX,
138 factory->NewEcmaDynClass(dynClassClass, TSObjectType::SIZE, JSType::TS_OBJECT_TYPE));
139 SetConstant(ConstantIndex::TS_CLASS_TYPE_CLASS_INDEX,
140 factory->NewEcmaDynClass(dynClassClass, TSClassType::SIZE, JSType::TS_CLASS_TYPE));
141 SetConstant(ConstantIndex::TS_UNION_TYPE_CLASS_INDEX,
142 factory->NewEcmaDynClass(dynClassClass, TSClassType::SIZE, JSType::TS_UNION_TYPE));
143 SetConstant(ConstantIndex::TS_INTERFACE_TYPE_CLASS_INDEX,
144 factory->NewEcmaDynClass(dynClassClass, TSInterfaceType::SIZE, JSType::TS_INTERFACE_TYPE));
145 SetConstant(ConstantIndex::TS_CLASS_INSTANCE_TYPE_CLASS_INDEX,
146 factory->NewEcmaDynClass(dynClassClass, TSClassInstanceType::SIZE, JSType::TS_CLASS_INSTANCE_TYPE));
147 SetConstant(ConstantIndex::TS_IMPORT_TYPE_CLASS_INDEX,
148 factory->NewEcmaDynClass(dynClassClass, TSImportType::SIZE, JSType::TS_IMPORT_TYPE));
149 }
150
151 // NOLINTNEXTLINE(readability-function-size)
InitGlobalConstant(JSThread * thread)152 void GlobalEnvConstants::InitGlobalConstant(JSThread *thread)
153 {
154 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
155 // SPECIAL INIT
156 SetConstant(ConstantIndex::UNDEFINED_INDEX, JSTaggedValue::Undefined());
157 SetConstant(ConstantIndex::NULL_INDEX, JSTaggedValue::Null());
158 auto vm = thread->GetEcmaVM();
159 SetConstant(ConstantIndex::EMPTY_STRING_OBJECT_INDEX, JSTaggedValue(EcmaString::CreateEmptyString(vm)));
160 [[maybe_unused]] auto test = EcmaString::Cast(GetHandledEmptyString().GetObject<EcmaString>());
161 SetConstant(ConstantIndex::CONSTRUCTOR_STRING_INDEX, factory->NewFromCanBeCompressString("constructor"));
162 SetConstant(ConstantIndex::PROTOTYPE_STRING_INDEX, factory->NewFromCanBeCompressString("prototype"));
163 SetConstant(ConstantIndex::LENGTH_STRING_INDEX, factory->NewFromCanBeCompressString("length"));
164 SetConstant(ConstantIndex::VALUE_STRING_INDEX, factory->NewFromCanBeCompressString("value"));
165 SetConstant(ConstantIndex::SET_STRING_INDEX, factory->NewFromCanBeCompressString("set"));
166 SetConstant(ConstantIndex::GET_STRING_INDEX, factory->NewFromCanBeCompressString("get"));
167 SetConstant(ConstantIndex::WRITABLE_STRING_INDEX, factory->NewFromCanBeCompressString("writable"));
168 SetConstant(ConstantIndex::ENUMERABLE_STRING_INDEX, factory->NewFromCanBeCompressString("enumerable"));
169 SetConstant(ConstantIndex::CONFIGURABLE_STRING_INDEX, factory->NewFromCanBeCompressString("configurable"));
170 /* SymbolTable *RegisterSymbols */
171 SetConstant(ConstantIndex::NAME_STRING_INDEX, factory->NewFromCanBeCompressString("name"));
172 SetConstant(ConstantIndex::GETPROTOTYPEOF_STRING_INDEX, factory->NewFromCanBeCompressString("getPrototypeOf"));
173 SetConstant(ConstantIndex::SETPROTOTYPEOF_STRING_INDEX, factory->NewFromCanBeCompressString("setPrototypeOf"));
174 SetConstant(ConstantIndex::ISEXTENSIBLE_STRING_INDEX, factory->NewFromCanBeCompressString("isExtensible"));
175 SetConstant(ConstantIndex::PREVENTEXTENSIONS_STRING_INDEX,
176 factory->NewFromCanBeCompressString("preventExtensions"));
177 SetConstant(ConstantIndex::GETOWNPROPERTYDESCRIPTOR_STRING_INDEX,
178 factory->NewFromCanBeCompressString("getOwnPropertyDescriptor"));
179 SetConstant(ConstantIndex::DEFINEPROPERTY_STRING_INDEX, factory->NewFromCanBeCompressString("defineProperty"));
180 SetConstant(ConstantIndex::HAS_STRING_INDEX, factory->NewFromCanBeCompressString("has"));
181 SetConstant(ConstantIndex::DELETEPROPERTY_STRING_INDEX, factory->NewFromCanBeCompressString("deleteProperty"));
182 SetConstant(ConstantIndex::ENUMERATE_STRING_INDEX, factory->NewFromCanBeCompressString("enumerate"));
183 SetConstant(ConstantIndex::OWNKEYS_STRING_INDEX, factory->NewFromCanBeCompressString("ownKeys"));
184 SetConstant(ConstantIndex::APPLY_STRING_INDEX, factory->NewFromCanBeCompressString("apply"));
185 SetConstant(ConstantIndex::NEGATIVE_ZERO_STRING_INDEX, factory->NewFromCanBeCompressString("-0"));
186 SetConstant(ConstantIndex::DONE_STRING_INDEX, factory->NewFromCanBeCompressString("done"));
187 SetConstant(ConstantIndex::PROXY_STRING_INDEX, factory->NewFromCanBeCompressString("proxy"));
188 SetConstant(ConstantIndex::REVOKE_STRING_INDEX, factory->NewFromCanBeCompressString("revoke"));
189 SetConstant(ConstantIndex::NEXT_STRING_INDEX, factory->NewFromCanBeCompressString("next"));
190 SetConstant(ConstantIndex::TO_STRING_STRING_INDEX, factory->NewFromCanBeCompressString("toString"));
191 SetConstant(ConstantIndex::TO_LOCALE_STRING_STRING_INDEX, factory->NewFromCanBeCompressString("toLocaleString"));
192 SetConstant(ConstantIndex::VALUE_OF_STRING_INDEX, factory->NewFromCanBeCompressString("valueOf"));
193 SetConstant(ConstantIndex::UNDEFINED_STRING_INDEX, factory->NewFromCanBeCompressString("undefined"));
194 SetConstant(ConstantIndex::NULL_STRING_INDEX, factory->NewFromCanBeCompressString("null"));
195 SetConstant(ConstantIndex::BOOLEAN_STRING_INDEX, factory->NewFromCanBeCompressString("boolean"));
196 SetConstant(ConstantIndex::NUMBER_STRING_INDEX, factory->NewFromCanBeCompressString("number"));
197 SetConstant(ConstantIndex::BIGINT_STRING_INDEX, factory->NewFromCanBeCompressString("bigint"));
198 SetConstant(ConstantIndex::FUNCTION_STRING_INDEX, factory->NewFromCanBeCompressString("function"));
199 SetConstant(ConstantIndex::STRING_STRING_INDEX, factory->NewFromCanBeCompressString("string"));
200 SetConstant(ConstantIndex::SYMBOL_STRING_INDEX, factory->NewFromCanBeCompressString("symbol"));
201 SetConstant(ConstantIndex::OBJECT_STRING_INDEX, factory->NewFromCanBeCompressString("object"));
202 SetConstant(ConstantIndex::TRUE_STRING_INDEX, factory->NewFromCanBeCompressString("true"));
203 SetConstant(ConstantIndex::FALSE_STRING_INDEX, factory->NewFromCanBeCompressString("false"));
204 SetConstant(ConstantIndex::RETURN_STRING_INDEX, factory->NewFromCanBeCompressString("return"));
205 SetConstant(ConstantIndex::PROXY_CONSTRUCT_STRING_INDEX, factory->NewFromCanBeCompressString("construct"));
206 SetConstant(ConstantIndex::PROXY_CALL_STRING_INDEX, factory->NewFromCanBeCompressString("call"));
207 SetConstant(ConstantIndex::PROMISE_THEN_STRING_INDEX, factory->NewFromCanBeCompressString("then"));
208 SetConstant(ConstantIndex::PROMISE_CATCH_STRING_INDEX, factory->NewFromCanBeCompressString("catch"));
209 SetConstant(ConstantIndex::SCRIPT_JOB_STRING_INDEX, factory->NewFromCanBeCompressString("ScriptJobs"));
210 SetConstant(ConstantIndex::PROMISE_STRING_INDEX, factory->NewFromCanBeCompressString("PrimiseJobs"));
211 SetConstant(ConstantIndex::THROWER_STRING_INDEX, factory->NewFromCanBeCompressString("Thrower"));
212 SetConstant(ConstantIndex::IDENTITY_STRING_INDEX, factory->NewFromCanBeCompressString("Identity"));
213 SetConstant(ConstantIndex::CALLER_STRING_INDEX, factory->NewFromCanBeCompressString("caller"));
214 SetConstant(ConstantIndex::CALLEE_STRING_INDEX, factory->NewFromCanBeCompressString("callee"));
215 SetConstant(ConstantIndex::INT8_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Int8Array"));
216 SetConstant(ConstantIndex::UINT8_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Uint8Array"));
217 SetConstant(ConstantIndex::UINT8_CLAMPED_ARRAY_STRING_INDEX,
218 factory->NewFromCanBeCompressString("Uint8ClampedArray"));
219 SetConstant(ConstantIndex::INT16_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Int16Array"));
220 SetConstant(ConstantIndex::UINT16_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Uint16Array"));
221 SetConstant(ConstantIndex::INT32_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Int32Array"));
222 SetConstant(ConstantIndex::UINT32_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Uint32Array"));
223 SetConstant(ConstantIndex::FLOAT32_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Float32Array"));
224 SetConstant(ConstantIndex::FLOAT64_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Float64Array"));
225 SetConstant(ConstantIndex::ASYNC_FUNCTION_STRING_INDEX, factory->NewFromCanBeCompressString("AsyncFunction"));
226 SetConstant(ConstantIndex::PROMISE_RESOLVE_STRING_INDEX, factory->NewFromCanBeCompressString("resolve"));
227 SetConstant(ConstantIndex::ID_STRING_INDEX, factory->NewFromCanBeCompressString("id"));
228 SetConstant(ConstantIndex::METHOD_STRING_INDEX, factory->NewFromCanBeCompressString("method"));
229 SetConstant(ConstantIndex::PARAMS_STRING_INDEX, factory->NewFromCanBeCompressString("params"));
230 SetConstant(ConstantIndex::RESULT_STRING_INDEX, factory->NewFromCanBeCompressString("result"));
231 SetConstant(ConstantIndex::TO_JSON_STRING_INDEX, factory->NewFromCanBeCompressString("toJSON"));
232 SetConstant(ConstantIndex::GLOBAL_STRING_INDEX, factory->NewFromCanBeCompressString("global"));
233 SetConstant(ConstantIndex::MESSAGE_STRING_INDEX, factory->NewFromCanBeCompressString("message"));
234 SetConstant(ConstantIndex::ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("Error"));
235 SetConstant(ConstantIndex::RANGE_ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("RangeError"));
236 SetConstant(ConstantIndex::REFERENCE_ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("ReferenceError"));
237 SetConstant(ConstantIndex::TYPE_ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("TypeError"));
238 SetConstant(ConstantIndex::URI_ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("URIError"));
239 SetConstant(ConstantIndex::SYNTAX_ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("SyntaxError"));
240 SetConstant(ConstantIndex::EVAL_ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("EvalError"));
241 SetConstant(ConstantIndex::STACK_STRING_INDEX, factory->NewFromCanBeCompressString("stack"));
242 SetConstant(ConstantIndex::STACK_EMPTY_STRING_INDEX, factory->NewFromCanBeCompressString("stackisempty"));
243 SetConstant(ConstantIndex::OBJ_NOT_COERCIBLE_STRING_INDEX,
244 factory->NewFromCanBeCompressString("objectnotcoercible"));
245 /* for Intl. */
246 SetConstant(ConstantIndex::LANGUAGE_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("language"));
247 SetConstant(ConstantIndex::SCRIPT_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("script"));
248 SetConstant(ConstantIndex::REGION_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("region"));
249 SetConstant(ConstantIndex::BASE_NAME_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("baseName"));
250 SetConstant(ConstantIndex::CALENDAR_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("calendar"));
251 SetConstant(ConstantIndex::COLLATION_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("collation"));
252 SetConstant(ConstantIndex::HOUR_CYCLE_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("hourCycle"));
253 SetConstant(ConstantIndex::CASE_FIRST_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("caseFirst"));
254 SetConstant(ConstantIndex::NUMERIC_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("numeric"));
255 SetConstant(ConstantIndex::NUMBERING_SYSTEM_STRING_CLASS_INDEX,
256 factory->NewFromCanBeCompressString("numberingSystem"));
257 SetConstant(ConstantIndex::TYPE_STRING_INDEX, factory->NewFromCanBeCompressString("type"));
258 SetConstant(ConstantIndex::LOCALE_MATCHER_STRING_INDEX, factory->NewFromCanBeCompressString("localeMatcher"));
259 SetConstant(ConstantIndex::FORMAT_MATCHER_STRING_INDEX, factory->NewFromCanBeCompressString("formatMatcher"));
260 SetConstant(ConstantIndex::HOUR12_STRING_INDEX, factory->NewFromCanBeCompressString("hour12"));
261 SetConstant(ConstantIndex::H11_STRING_INDEX, factory->NewFromCanBeCompressString("h11"));
262 SetConstant(ConstantIndex::H12_STRING_INDEX, factory->NewFromCanBeCompressString("h12"));
263 SetConstant(ConstantIndex::H23_STRING_INDEX, factory->NewFromCanBeCompressString("h23"));
264 SetConstant(ConstantIndex::H24_STRING_INDEX, factory->NewFromCanBeCompressString("h24"));
265 SetConstant(ConstantIndex::WEEK_DAY_STRING_INDEX, factory->NewFromCanBeCompressString("weekday"));
266 SetConstant(ConstantIndex::ERA_STRING_INDEX, factory->NewFromCanBeCompressString("era"));
267 SetConstant(ConstantIndex::YEAR_STRING_INDEX, factory->NewFromCanBeCompressString("year"));
268 SetConstant(ConstantIndex::QUARTER_STRING_INDEX, factory->NewFromCanBeCompressString("quarter"));
269 SetConstant(ConstantIndex::MONTH_STRING_INDEX, factory->NewFromCanBeCompressString("month"));
270 SetConstant(ConstantIndex::DAY_STRING_INDEX, factory->NewFromCanBeCompressString("day"));
271 SetConstant(ConstantIndex::HOUR_STRING_INDEX, factory->NewFromCanBeCompressString("hour"));
272 SetConstant(ConstantIndex::MINUTE_STRING_INDEX, factory->NewFromCanBeCompressString("minute"));
273 SetConstant(ConstantIndex::SECOND_STRING_INDEX, factory->NewFromCanBeCompressString("second"));
274 SetConstant(ConstantIndex::YEARS_STRING_INDEX, factory->NewFromCanBeCompressString("years"));
275 SetConstant(ConstantIndex::QUARTERS_STRING_INDEX, factory->NewFromCanBeCompressString("quarters"));
276 SetConstant(ConstantIndex::MONTHS_STRING_INDEX, factory->NewFromCanBeCompressString("months"));
277 SetConstant(ConstantIndex::DAYS_STRING_INDEX, factory->NewFromCanBeCompressString("days"));
278 SetConstant(ConstantIndex::HOURS_STRING_INDEX, factory->NewFromCanBeCompressString("hours"));
279 SetConstant(ConstantIndex::MINUTES_STRING_INDEX, factory->NewFromCanBeCompressString("minutes"));
280 SetConstant(ConstantIndex::SECONDS_STRING_INDEX, factory->NewFromCanBeCompressString("seconds"));
281 SetConstant(ConstantIndex::TIME_ZONE_NAME_STRING_INDEX, factory->NewFromCanBeCompressString("timeZoneName"));
282 SetConstant(ConstantIndex::LOCALE_STRING_INDEX, factory->NewFromCanBeCompressString("locale"));
283 SetConstant(ConstantIndex::TIME_ZONE_STRING_INDEX, factory->NewFromCanBeCompressString("timeZone"));
284 SetConstant(ConstantIndex::LITERAL_STRING_INDEX, factory->NewFromCanBeCompressString("literal"));
285 SetConstant(ConstantIndex::YEAR_NAME_STRING_INDEX, factory->NewFromCanBeCompressString("yearName"));
286 SetConstant(ConstantIndex::DAY_PERIOD_STRING_INDEX, factory->NewFromCanBeCompressString("dayPeriod"));
287 SetConstant(ConstantIndex::FRACTIONAL_SECOND_DIGITS_STRING_INDEX,
288 factory->NewFromCanBeCompressString("fractionalSecondDigits"));
289 SetConstant(ConstantIndex::FRACTIONAL_SECOND_STRING_INDEX, factory->NewFromCanBeCompressString("fractionalSecond"));
290 SetConstant(ConstantIndex::RELATED_YEAR_STRING_INDEX, factory->NewFromCanBeCompressString("relatedYear"));
291 SetConstant(ConstantIndex::LOOK_UP_STRING_INDEX, factory->NewFromCanBeCompressString("lookup"));
292 SetConstant(ConstantIndex::BEST_FIT_STRING_INDEX, factory->NewFromCanBeCompressString("bestfit"));
293 SetConstant(ConstantIndex::DATE_STYLE_STRING_INDEX, factory->NewFromCanBeCompressString("dateStyle"));
294 SetConstant(ConstantIndex::TIME_STYLE_STRING_INDEX, factory->NewFromCanBeCompressString("timeStyle"));
295 SetConstant(ConstantIndex::UTC_STRING_INDEX, factory->NewFromCanBeCompressString("UTC"));
296 SetConstant(ConstantIndex::INITIALIZED_RELATIVE_INDEX, factory->NewFromCanBeCompressString("true"));
297 SetConstant(ConstantIndex::WEEK_STRING_INDEX, factory->NewFromCanBeCompressString("week"));
298 SetConstant(ConstantIndex::WEEKS_STRING_INDEX, factory->NewFromCanBeCompressString("weeks"));
299 SetConstant(ConstantIndex::SOURCE_STRING_INDEX, factory->NewFromCanBeCompressString("source"));
300 SetConstant(ConstantIndex::FORMAT_STRING_INDEX, factory->NewFromCanBeCompressString("format"));
301 SetConstant(ConstantIndex::EN_US_STRING_INDEX, factory->NewFromCanBeCompressString("en-US"));
302 SetConstant(ConstantIndex::UND_STRING_INDEX, factory->NewFromCanBeCompressString("und"));
303 SetConstant(ConstantIndex::LATN_STRING_INDEX, factory->NewFromCanBeCompressString("latn"));
304 SetConstant(ConstantIndex::STYLE_STRING_INDEX, factory->NewFromCanBeCompressString("style"));
305 SetConstant(ConstantIndex::UNIT_STRING_INDEX, factory->NewFromCanBeCompressString("unit"));
306 SetConstant(ConstantIndex::INTEGER_STRING_INDEX, factory->NewFromCanBeCompressString("integer"));
307 SetConstant(ConstantIndex::NAN_STRING_INDEX, factory->NewFromCanBeCompressString("nan"));
308 SetConstant(ConstantIndex::INFINITY_STRING_INDEX, factory->NewFromCanBeCompressString("infinity"));
309 SetConstant(ConstantIndex::FRACTION_STRING_INDEX, factory->NewFromCanBeCompressString("fraction"));
310 SetConstant(ConstantIndex::DECIMAL_STRING_INDEX, factory->NewFromCanBeCompressString("decimal"));
311 SetConstant(ConstantIndex::GROUP_STRING_INDEX, factory->NewFromCanBeCompressString("group"));
312 SetConstant(ConstantIndex::CURRENCY_STRING_INDEX, factory->NewFromCanBeCompressString("currency"));
313 SetConstant(ConstantIndex::CURRENCY_SIGN_STRING_INDEX, factory->NewFromCanBeCompressString("currencySign"));
314 SetConstant(ConstantIndex::CURRENCY_DISPLAY_STRING_INDEX, factory->NewFromCanBeCompressString("currencyDisplay"));
315 SetConstant(ConstantIndex::PERCENT_SIGN_STRING_INDEX, factory->NewFromCanBeCompressString("percentSign"));
316 SetConstant(ConstantIndex::PERCENT_STRING_INDEX, factory->NewFromCanBeCompressString("percent"));
317 SetConstant(ConstantIndex::MINUS_SIGN_STRING_INDEX, factory->NewFromCanBeCompressString("minusSign"));
318 SetConstant(ConstantIndex::PLUS_SIGN_STRING_INDEX, factory->NewFromCanBeCompressString("plusSign"));
319 SetConstant(ConstantIndex::EXPONENT_SEPARATOR_STRING_INDEX,
320 factory->NewFromCanBeCompressString("exponentSeparator"));
321 SetConstant(ConstantIndex::EXPONENT_MINUS_SIGN_INDEX, factory->NewFromCanBeCompressString("exponentMinusSign"));
322 SetConstant(ConstantIndex::EXPONENT_INTEGER_STRING_INDEX, factory->NewFromCanBeCompressString("exponentInteger"));
323 SetConstant(ConstantIndex::LONG_STRING_INDEX, factory->NewFromCanBeCompressString("long"));
324 SetConstant(ConstantIndex::SHORT_STRING_INDEX, factory->NewFromCanBeCompressString("short"));
325 SetConstant(ConstantIndex::FULL_STRING_INDEX, factory->NewFromCanBeCompressString("full"));
326 SetConstant(ConstantIndex::MEDIUM_STRING_INDEX, factory->NewFromCanBeCompressString("medium"));
327 SetConstant(ConstantIndex::NARROW_STRING_INDEX, factory->NewFromCanBeCompressString("narrow"));
328 SetConstant(ConstantIndex::ALWAYS_STRING_INDEX, factory->NewFromCanBeCompressString("always"));
329 SetConstant(ConstantIndex::AUTO_STRING_INDEX, factory->NewFromCanBeCompressString("auto"));
330 SetConstant(ConstantIndex::UNIT_DISPLAY_INDEX, factory->NewFromCanBeCompressString("unitDisplay"));
331 SetConstant(ConstantIndex::NOTATION_INDEX, factory->NewFromCanBeCompressString("notation"));
332 SetConstant(ConstantIndex::COMPACT_DISPALY_INDEX, factory->NewFromCanBeCompressString("compactDisplay"));
333 SetConstant(ConstantIndex::USER_GROUPING_INDEX, factory->NewFromCanBeCompressString("useGrouping"));
334 SetConstant(ConstantIndex::SIGN_DISPLAY_INDEX, factory->NewFromCanBeCompressString("signDisplay"));
335 SetConstant(ConstantIndex::CODE_INDEX, factory->NewFromCanBeCompressString("code"));
336 SetConstant(ConstantIndex::NARROW_SYMBOL_INDEX, factory->NewFromCanBeCompressString("narrowSymbol"));
337 SetConstant(ConstantIndex::STANDARD_INDEX, factory->NewFromCanBeCompressString("standard"));
338 SetConstant(ConstantIndex::ACCOUNTING_INDEX, factory->NewFromCanBeCompressString("accounting"));
339 SetConstant(ConstantIndex::SCIENTIFIC_INDEX, factory->NewFromCanBeCompressString("scientific"));
340 SetConstant(ConstantIndex::ENGINEERING_INDEX, factory->NewFromCanBeCompressString("engineering"));
341 SetConstant(ConstantIndex::COMPACT_STRING_INDEX, factory->NewFromCanBeCompressString("compact"));
342 SetConstant(ConstantIndex::NEVER_INDEX, factory->NewFromCanBeCompressString("never"));
343 SetConstant(ConstantIndex::EXPECT_ZERO_INDEX, factory->NewFromCanBeCompressString("exceptZero"));
344 SetConstant(ConstantIndex::MINIMUM_INTEGER_DIGITS_INDEX,
345 factory->NewFromCanBeCompressString("minimumIntegerDigits"));
346 SetConstant(ConstantIndex::MINIMUM_FRACTIONDIGITS_INDEX,
347 factory->NewFromCanBeCompressString("minimumFractionDigits"));
348 SetConstant(ConstantIndex::MAXIMUM_FRACTIONDIGITS_INDEX,
349 factory->NewFromCanBeCompressString("maximumFractionDigits"));
350 SetConstant(ConstantIndex::MINIMUM_SIGNIFICANTDIGITS_INDEX,
351 factory->NewFromCanBeCompressString("minimumSignificantDigits"));
352 SetConstant(ConstantIndex::MAXIMUM_SIGNIFICANTDIGITS_INDEX,
353 factory->NewFromCanBeCompressString("maximumSignificantDigits"));
354 SetConstant(ConstantIndex::INVALID_DATE_INDEX, factory->NewFromCanBeCompressString("Invalid Date"));
355 SetConstant(ConstantIndex::USAGE_INDEX, factory->NewFromCanBeCompressString("usage"));
356 SetConstant(ConstantIndex::COMPARE_INDEX, factory->NewFromCanBeCompressString("compare"));
357 SetConstant(ConstantIndex::SENSITIVITY_INDEX, factory->NewFromCanBeCompressString("sensitivity"));
358 SetConstant(ConstantIndex::IGNORE_PUNCTUATION_INDEX, factory->NewFromCanBeCompressString("ignorePunctuation"));
359 SetConstant(ConstantIndex::CARDINAL_INDEX, factory->NewFromCanBeCompressString("cardinal"));
360 SetConstant(ConstantIndex::ORDINAL_INDEX, factory->NewFromCanBeCompressString("ordinal"));
361 SetConstant(ConstantIndex::EXEC_INDEX, factory->NewFromCanBeCompressString("exec"));
362 SetConstant(ConstantIndex::LAST_INDEX_INDEX, factory->NewFromCanBeCompressString("lastIndex"));
363 SetConstant(ConstantIndex::PLURAL_CATEGORIES_INDEX, factory->NewFromCanBeCompressString("pluralCategories"));
364 SetConstant(ConstantIndex::SORT_INDEX, factory->NewFromCanBeCompressString("sort"));
365 SetConstant(ConstantIndex::SEARCH_INDEX, factory->NewFromCanBeCompressString("search"));
366 SetConstant(ConstantIndex::BASE_INDEX, factory->NewFromCanBeCompressString("base"));
367 SetConstant(ConstantIndex::ACCENT_INDEX, factory->NewFromCanBeCompressString("accent"));
368 SetConstant(ConstantIndex::CASE_INDEX, factory->NewFromCanBeCompressString("case"));
369 SetConstant(ConstantIndex::VARIANT_INDEX, factory->NewFromCanBeCompressString("variant"));
370 SetConstant(ConstantIndex::EN_US_POSIX_STRING_INDEX, factory->NewFromCanBeCompressString("en-US-POSIX"));
371 SetConstant(ConstantIndex::UPPER_INDEX, factory->NewFromCanBeCompressString("upper"));
372 SetConstant(ConstantIndex::LOWER_INDEX, factory->NewFromCanBeCompressString("lower"));
373 SetConstant(ConstantIndex::DEFAULT_INDEX, factory->NewFromCanBeCompressString("default"));
374 SetConstant(ConstantIndex::SHARED_INDEX, factory->NewFromCanBeCompressString("shared"));
375 SetConstant(ConstantIndex::START_RANGE_INDEX, factory->NewFromCanBeCompressString("startRange"));
376 SetConstant(ConstantIndex::END_RANGE_INDEX, factory->NewFromCanBeCompressString("endRange"));
377 SetConstant(ConstantIndex::ISO8601_INDEX, factory->NewFromCanBeCompressString("iso8601"));
378 SetConstant(ConstantIndex::GREGORY_INDEX, factory->NewFromCanBeCompressString("gregory"));
379 SetConstant(ConstantIndex::ETHIOAA_INDEX, factory->NewFromCanBeCompressString("ethioaa"));
380 SetConstant(ConstantIndex::STICKY_INDEX, factory->NewFromCanBeCompressString("sticky"));
381 SetConstant(ConstantIndex::U_INDEX, factory->NewFromCanBeCompressString("u"));
382 SetConstant(ConstantIndex::INDEX_INDEX, factory->NewFromCanBeCompressString("index"));
383 SetConstant(ConstantIndex::INPUT_INDEX, factory->NewFromCanBeCompressString("input"));
384 SetConstant(ConstantIndex::UNICODE_INDEX, factory->NewFromCanBeCompressString("unicode"));
385 SetConstant(ConstantIndex::ZERO_INDEX, factory->NewFromCanBeCompressString("0"));
386 SetConstant(ConstantIndex::VALUES_INDEX, factory->NewFromCanBeCompressString("values"));
387
388 auto accessor = factory->NewInternalAccessor(reinterpret_cast<void *>(JSFunction::PrototypeSetter),
389 reinterpret_cast<void *>(JSFunction::PrototypeGetter));
390 SetConstant(ConstantIndex::FUNCTION_PROTOTYPE_ACCESSOR, accessor);
391 accessor = factory->NewInternalAccessor(nullptr, reinterpret_cast<void *>(JSFunction::NameGetter));
392 SetConstant(ConstantIndex::FUNCTION_NAME_ACCESSOR, accessor);
393 accessor = factory->NewInternalAccessor(reinterpret_cast<void *>(JSArray::LengthSetter),
394 reinterpret_cast<void *>(JSArray::LengthGetter));
395 SetConstant(ConstantIndex::ARRAY_LENGTH_ACCESSOR, accessor);
396 }
397
InitGlobalUndefined()398 void GlobalEnvConstants::InitGlobalUndefined()
399 {
400 SetConstant(ConstantIndex::UNDEFINED_INDEX, JSTaggedValue::Undefined());
401 }
402 } // namespace panda::ecmascript
403