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 #ifndef ECMASCRIPT_TAGGED_VALUE_INL_H
17 #define ECMASCRIPT_TAGGED_VALUE_INL_H
18
19 #include "ecmascript/js_tagged_value.h"
20
21 #include "ecmascript/accessor_data.h"
22 #include "ecmascript/base/error_helper.h"
23 #include "ecmascript/base/number_helper.h"
24 #include "ecmascript/base/string_helper.h"
25 #include "ecmascript/ecma_macros.h"
26 #include "ecmascript/ecma_runtime_call_info.h"
27 #include "ecmascript/ecma_string-inl.h"
28 #include "ecmascript/js_bigint.h"
29 #include "ecmascript/js_hclass-inl.h"
30 #include "ecmascript/js_object.h"
31 #include "ecmascript/js_proxy.h"
32 #include "ecmascript/js_symbol.h"
33 #include "ecmascript/js_tagged_number.h"
34 #include "ecmascript/js_thread.h"
35 #include "ecmascript/mem/c_containers.h"
36 #include "ecmascript/mem/tagged_object-inl.h"
37 #include "ecmascript/module/js_module_namespace.h"
38 #include "ecmascript/object_factory.h"
39
40 namespace panda::ecmascript {
41 // ecma6 7.1 Type Conversion
42 static constexpr double SAFE_NUMBER = 9007199254740991LL;
43 static constexpr uint32_t MAX_ELEMENT_INDEX_LEN = 10;
44
ToBoolean()45 inline bool JSTaggedValue::ToBoolean() const
46 {
47 if (IsInt()) {
48 return GetInt() != 0;
49 }
50 if (IsDouble()) {
51 double d = GetDouble();
52 return !std::isnan(d) && d != 0;
53 }
54 switch (GetRawData()) {
55 case JSTaggedValue::VALUE_UNDEFINED:
56 [[fallthrough]];
57 case JSTaggedValue::VALUE_HOLE:
58 [[fallthrough]];
59 case JSTaggedValue::VALUE_NULL:
60 [[fallthrough]];
61 case JSTaggedValue::VALUE_FALSE: {
62 return false;
63 }
64 case JSTaggedValue::VALUE_TRUE: {
65 return true;
66 }
67 default: {
68 break;
69 }
70 }
71
72 if (IsBigInt()) {
73 BigInt *bigint = BigInt::Cast(GetTaggedObject());
74 return !bigint->IsZero();
75 }
76 if (IsHeapObject()) {
77 TaggedObject *obj = GetTaggedObject();
78 if (IsString()) {
79 auto str = static_cast<EcmaString *>(obj);
80 return EcmaStringAccessor(str).GetLength() != 0;
81 }
82 return true;
83 }
84
85 UNREACHABLE();
86 }
87
ToNumber(JSThread * thread,const JSHandle<JSTaggedValue> & tagged)88 inline JSTaggedNumber JSTaggedValue::ToNumber(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)
89 {
90 if (tagged->IsInt() || tagged->IsDouble()) {
91 return JSTaggedNumber(tagged.GetTaggedValue());
92 }
93
94 switch (tagged->GetRawData()) {
95 case JSTaggedValue::VALUE_UNDEFINED:
96 case JSTaggedValue::VALUE_HOLE: {
97 return JSTaggedNumber(base::NAN_VALUE);
98 }
99 case JSTaggedValue::VALUE_TRUE: {
100 return JSTaggedNumber(1);
101 }
102 case JSTaggedValue::VALUE_FALSE:
103 case JSTaggedValue::VALUE_NULL: {
104 return JSTaggedNumber(0);
105 }
106 default: {
107 break;
108 }
109 }
110
111 if (tagged->IsString()) {
112 return StringToDouble(tagged.GetTaggedValue());
113 }
114 if (tagged->IsECMAObject()) {
115 JSHandle<JSTaggedValue> primValue(thread, ToPrimitive(thread, tagged, PREFER_NUMBER));
116 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedNumber::Exception());
117 return ToNumber(thread, primValue);
118 }
119 if (tagged->IsSymbol()) {
120 THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a Symbol value to a number", JSTaggedNumber::Exception());
121 }
122 if (tagged->IsBigInt()) {
123 THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a BigInt value to a number", JSTaggedNumber::Exception());
124 }
125 THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a Unknown value to a number", JSTaggedNumber::Exception());
126 }
127
ToBigInt(JSThread * thread,const JSHandle<JSTaggedValue> & tagged)128 inline JSTaggedValue JSTaggedValue::ToBigInt(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)
129 {
130 JSHandle<JSTaggedValue> primValue(thread, ToPrimitive(thread, tagged));
131 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
132 switch (primValue->GetRawData()) {
133 case JSTaggedValue::VALUE_UNDEFINED:
134 case JSTaggedValue::VALUE_NULL: {
135 THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a undefine or null value to a BigInt",
136 JSTaggedValue::Exception());
137 }
138 case JSTaggedValue::VALUE_TRUE: {
139 return BigInt::Int32ToBigInt(thread, 1).GetTaggedValue();
140 }
141 case JSTaggedValue::VALUE_FALSE: {
142 return BigInt::Int32ToBigInt(thread, 0).GetTaggedValue();
143 }
144 default: {
145 break;
146 }
147 }
148
149 if (primValue->IsNumber()) {
150 THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a Number value to a BigInt", JSTaggedNumber::Exception());
151 }
152 if (primValue->IsString()) {
153 JSHandle<JSTaggedValue> value(thread, base::NumberHelper::StringToBigInt(thread, primValue));
154 if (value->IsBigInt()) {
155 return value.GetTaggedValue();
156 }
157 THROW_SYNTAX_ERROR_AND_RETURN(thread, "Cannot convert string to a BigInt,"
158 "because not allow Infinity, decimal points, or exponents",
159 JSTaggedValue::Exception());
160 }
161 if (primValue->IsSymbol()) {
162 THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a Symbol value to a BigInt", JSTaggedNumber::Exception());
163 }
164 if (primValue->IsBigInt()) {
165 return primValue.GetTaggedValue();
166 }
167 THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a Unknown value to a BigInt", JSTaggedNumber::Exception());
168 }
169
ToBigInt64(JSThread * thread,const JSHandle<JSTaggedValue> & tagged)170 inline JSTaggedValue JSTaggedValue::ToBigInt64(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)
171 {
172 JSHandle<BigInt> value(thread, ToBigInt(thread, tagged));
173 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
174 JSHandle<BigInt> tVal = BigInt::GetUint64MaxBigint(thread);
175 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
176 JSHandle<BigInt> int64bitVal = BigInt::FloorMod(thread, value, tVal);
177 JSHandle<BigInt> resValue = BigInt::GetInt64MaxBigint(thread);
178 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
179 if (!BigInt::LessThan(int64bitVal.GetTaggedValue(), resValue.GetTaggedValue())) {
180 return BigInt::Subtract(thread, int64bitVal, tVal).GetTaggedValue();
181 } else {
182 return int64bitVal.GetTaggedValue();
183 }
184 }
185
ToBigUint64(JSThread * thread,const JSHandle<JSTaggedValue> & tagged)186 inline JSTaggedValue JSTaggedValue::ToBigUint64(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)
187 {
188 JSHandle<BigInt> value(thread, ToBigInt(thread, tagged));
189 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
190 bool signFlag = value->GetSign();
191 uint32_t len = value->GetLength();
192 if (!signFlag && len <= 2) { // 2:2 int equal int64
193 return value.GetTaggedValue();
194 }
195 JSHandle<BigInt> tVal = BigInt::GetUint64MaxBigint(thread);
196 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
197 return BigInt::FloorMod(thread, value, tVal).GetTaggedValue();
198 }
199
ToInteger(JSThread * thread,const JSHandle<JSTaggedValue> & tagged)200 inline JSTaggedNumber JSTaggedValue::ToInteger(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)
201 {
202 JSTaggedNumber number = ToNumber(thread, tagged);
203 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedNumber::Exception());
204
205 return JSTaggedNumber(base::NumberHelper::TruncateDouble(number.GetNumber()));
206 }
207
ToInt32(JSThread * thread,const JSHandle<JSTaggedValue> & tagged)208 inline int32_t JSTaggedValue::ToInt32(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)
209 {
210 JSTaggedNumber number = ToNumber(thread, tagged);
211 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0);
212 return base::NumberHelper::DoubleToInt(number.GetNumber(), base::INT32_BITS);
213 }
214
ToUint32(JSThread * thread,const JSHandle<JSTaggedValue> & tagged)215 inline uint32_t JSTaggedValue::ToUint32(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)
216 {
217 return ToInt32(thread, tagged);
218 }
219
ToInt16(JSThread * thread,const JSHandle<JSTaggedValue> & tagged)220 inline int16_t JSTaggedValue::ToInt16(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)
221 {
222 JSTaggedNumber number = ToNumber(thread, tagged);
223 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0);
224
225 return base::NumberHelper::DoubleToInt(number.GetNumber(), base::INT16_BITS);
226 }
227
ToUint16(JSThread * thread,const JSHandle<JSTaggedValue> & tagged)228 inline uint16_t JSTaggedValue::ToUint16(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)
229 {
230 return ToInt16(thread, tagged);
231 }
232
ToInt8(JSThread * thread,const JSHandle<JSTaggedValue> & tagged)233 inline int8_t JSTaggedValue::ToInt8(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)
234 {
235 JSTaggedNumber number = ToNumber(thread, tagged);
236 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0);
237
238 return base::NumberHelper::DoubleToInt(number.GetNumber(), base::INT8_BITS);
239 }
240
ToUint8(JSThread * thread,const JSHandle<JSTaggedValue> & tagged)241 inline uint8_t JSTaggedValue::ToUint8(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)
242 {
243 return ToInt8(thread, tagged);
244 }
245
ToUint8Clamp(JSThread * thread,const JSHandle<JSTaggedValue> & tagged)246 inline uint8_t JSTaggedValue::ToUint8Clamp(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)
247 {
248 JSTaggedNumber number = ToNumber(thread, tagged);
249 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0);
250
251 double d = number.GetNumber();
252 if (std::isnan(d) || d <= 0) {
253 return 0;
254 }
255 if (d >= UINT8_MAX) {
256 return UINT8_MAX;
257 }
258
259 return lrint(d);
260 }
261
ToLength(JSThread * thread,const JSHandle<JSTaggedValue> & tagged)262 inline JSTaggedNumber JSTaggedValue::ToLength(JSThread *thread, const JSHandle<JSTaggedValue> &tagged)
263 {
264 JSTaggedNumber len = ToInteger(thread, tagged);
265 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedNumber::Exception());
266 if (len.GetNumber() < 0.0) {
267 return JSTaggedNumber(static_cast<double>(0));
268 }
269 if (len.GetNumber() > SAFE_NUMBER) {
270 return JSTaggedNumber(static_cast<double>(SAFE_NUMBER));
271 }
272 return len;
273 }
274
275 // ecma6 7.2 Testing and Comparison Operations
RequireObjectCoercible(JSThread * thread,const JSHandle<JSTaggedValue> & tagged,const char * message)276 inline JSHandle<JSTaggedValue> JSTaggedValue::RequireObjectCoercible(JSThread *thread,
277 const JSHandle<JSTaggedValue> &tagged,
278 const char *message)
279 {
280 if (tagged->IsUndefined() || tagged->IsNull()) {
281 THROW_TYPE_ERROR_AND_RETURN(thread, message, JSHandle<JSTaggedValue>(thread, JSTaggedValue::Exception()));
282 }
283 return tagged;
284 }
285
IsCallable()286 inline bool JSTaggedValue::IsCallable() const
287 {
288 return IsHeapObject() && GetTaggedObject()->GetClass()->IsCallable();
289 }
290
IsConstructor()291 inline bool JSTaggedValue::IsConstructor() const
292 {
293 return IsHeapObject() && GetTaggedObject()->GetClass()->IsConstructor();
294 }
295
IsExtensible(JSThread * thread)296 inline bool JSTaggedValue::IsExtensible(JSThread *thread) const
297 {
298 if (UNLIKELY(IsJSProxy())) {
299 return JSProxy::IsExtensible(thread, JSHandle<JSProxy>(thread, *this));
300 }
301 if (UNLIKELY(IsModuleNamespace())) {
302 ModuleNamespace* ns = ModuleNamespace::Cast(this->GetTaggedObject());
303 return ns->IsExtensible();
304 }
305
306 return IsHeapObject() && GetTaggedObject()->GetClass()->IsExtensible();
307 }
308
IsClassConstructor()309 inline bool JSTaggedValue::IsClassConstructor() const
310 {
311 return IsHeapObject() && GetTaggedObject()->GetClass()->IsClassConstructor();
312 }
313
IsClassPrototype()314 inline bool JSTaggedValue::IsClassPrototype() const
315 {
316 return IsHeapObject() && GetTaggedObject()->GetClass()->IsClassPrototype();
317 }
318
IsPropertyKey(const JSHandle<JSTaggedValue> & key)319 inline bool JSTaggedValue::IsPropertyKey(const JSHandle<JSTaggedValue> &key)
320 {
321 return key->IsStringOrSymbol() || key->IsNumber();
322 }
323
SameValue(const JSTaggedValue & x,const JSTaggedValue & y)324 inline bool JSTaggedValue::SameValue(const JSTaggedValue &x, const JSTaggedValue &y)
325 {
326 // same object or special type must be same value
327 if (x == y) {
328 return true;
329 }
330 if (x.IsInt() && y.IsInt()) {
331 // same value should be returned above
332 return false;
333 }
334 if (x.IsNumber() && y.IsNumber()) {
335 return SameValueNumberic(x, y);
336 }
337 if (x.IsString() && y.IsString()) {
338 return StringCompare(EcmaString::Cast(x.GetTaggedObject()), EcmaString::Cast(y.GetTaggedObject()));
339 }
340 if (x.IsBigInt() && y.IsBigInt()) {
341 return BigInt::SameValue(x, y);
342 }
343 return false;
344 }
345
SameValue(const JSHandle<JSTaggedValue> & xHandle,const JSHandle<JSTaggedValue> & yHandle)346 inline bool JSTaggedValue::SameValue(const JSHandle<JSTaggedValue> &xHandle, const JSHandle<JSTaggedValue> &yHandle)
347 {
348 return SameValue(xHandle.GetTaggedValue(), yHandle.GetTaggedValue());
349 }
350
SameValueZero(const JSTaggedValue & x,const JSTaggedValue & y)351 inline bool JSTaggedValue::SameValueZero(const JSTaggedValue &x, const JSTaggedValue &y)
352 {
353 if (x == y) {
354 return true;
355 }
356
357 if (x.IsNumber() && y.IsNumber()) {
358 double xValue = x.ExtractNumber();
359 double yValue = y.ExtractNumber();
360 // Compare xValue with yValue to deal with -0.0
361 return (xValue == yValue) || (std::isnan(xValue) && std::isnan(yValue));
362 }
363
364 if (x.IsString() && y.IsString()) {
365 auto xStr = static_cast<EcmaString *>(x.GetTaggedObject());
366 auto yStr = static_cast<EcmaString *>(y.GetTaggedObject());
367 return EcmaStringAccessor::StringsAreEqual(xStr, yStr);
368 }
369 if (x.IsBigInt() && y.IsBigInt()) {
370 return BigInt::SameValueZero(x, y);
371 }
372 return false;
373 }
374
SameValueNumberic(const JSTaggedValue & x,const JSTaggedValue & y)375 inline bool JSTaggedValue::SameValueNumberic(const JSTaggedValue &x, const JSTaggedValue &y)
376 {
377 double xValue = x.ExtractNumber();
378 double yValue = y.ExtractNumber();
379 // SameNumberValue(NaN, NaN) is true.
380 if (xValue != yValue) {
381 return std::isnan(xValue) && std::isnan(yValue);
382 }
383 // SameNumberValue(0.0, -0.0) is false.
384 return (std::signbit(xValue) == std::signbit(yValue));
385 }
386
Less(JSThread * thread,const JSHandle<JSTaggedValue> & x,const JSHandle<JSTaggedValue> & y)387 inline bool JSTaggedValue::Less(JSThread *thread, const JSHandle<JSTaggedValue> &x, const JSHandle<JSTaggedValue> &y)
388 {
389 ComparisonResult result = Compare(thread, x, y);
390 return result == ComparisonResult::LESS;
391 }
392
StrictNumberEquals(double x,double y)393 inline bool JSTaggedValue::StrictNumberEquals(double x, double y)
394 {
395 // Must check explicitly for NaN's on Windows, but -0 works fine.
396 if (std::isnan(x) || std::isnan(y)) {
397 return false;
398 }
399 return x == y;
400 }
401
StrictIntEquals(int x,int y)402 inline bool JSTaggedValue::StrictIntEquals(int x, int y)
403 {
404 return x == y;
405 }
406
StrictEqual(const JSThread * thread,const JSHandle<JSTaggedValue> & x,const JSHandle<JSTaggedValue> & y)407 inline bool JSTaggedValue::StrictEqual([[maybe_unused]] const JSThread *thread, const JSHandle<JSTaggedValue> &x,
408 const JSHandle<JSTaggedValue> &y)
409 {
410 return StrictEqual(x.GetTaggedValue(), y.GetTaggedValue());
411 }
412
StrictEqual(const JSTaggedValue & x,const JSTaggedValue & y)413 inline bool JSTaggedValue::StrictEqual(const JSTaggedValue &x, const JSTaggedValue &y)
414 {
415 if (x.IsInt() && y.IsInt()) {
416 return StrictIntEquals(x.GetInt(), y.GetInt());
417 }
418
419 if (x.IsDouble() && y.IsDouble()) {
420 return StrictNumberEquals(x.GetDouble(), y.GetDouble());
421 }
422
423 if (x.IsNumber() && y.IsNumber()) {
424 return StrictNumberEquals(x.GetNumber(), y.GetNumber());
425 }
426
427 if (x == y) {
428 return true;
429 }
430
431 if (x.IsString() && y.IsString()) {
432 return StringCompare(EcmaString::Cast(x.GetTaggedObject()), EcmaString::Cast(y.GetTaggedObject()));
433 }
434
435 if (x.IsBigInt() && y.IsBigInt()) {
436 return BigInt::Equal(x, y);
437 }
438 return false;
439 }
440
StrictNumberCompare(double x,double y)441 inline ComparisonResult JSTaggedValue::StrictNumberCompare(double x, double y)
442 {
443 if (std::isnan(x) || std::isnan(y)) {
444 return ComparisonResult::UNDEFINED;
445 }
446 if (x < y) {
447 return ComparisonResult::LESS;
448 }
449 if (x > y) {
450 return ComparisonResult::GREAT;
451 }
452 return ComparisonResult::EQUAL;
453 }
454
IsNumber()455 inline bool JSTaggedValue::IsNumber() const
456 {
457 return IsInt() || IsDouble();
458 }
459
IsString()460 inline bool JSTaggedValue::IsString() const
461 {
462 return IsHeapObject() && GetTaggedObject()->GetClass()->IsString();
463 }
464
IsBigInt()465 inline bool JSTaggedValue::IsBigInt() const
466 {
467 return IsHeapObject() && GetTaggedObject()->GetClass()->IsBigInt();
468 }
469
IsStringOrSymbol()470 inline bool JSTaggedValue::IsStringOrSymbol() const
471 {
472 return IsHeapObject() && GetTaggedObject()->GetClass()->IsStringOrSymbol();
473 }
474
IsTaggedArray()475 inline bool JSTaggedValue::IsTaggedArray() const
476 {
477 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTaggedArray();
478 }
479
IsByteArray()480 inline bool JSTaggedValue::IsByteArray() const
481 {
482 return IsHeapObject() && GetTaggedObject()->GetClass()->IsByteArray();
483 }
484
IsConstantPool()485 inline bool JSTaggedValue::IsConstantPool() const
486 {
487 return IsHeapObject() && GetTaggedObject()->GetClass()->IsConstantPool();
488 }
489
IsAOTLiteralInfo()490 inline bool JSTaggedValue::IsAOTLiteralInfo() const
491 {
492 return IsHeapObject() && GetTaggedObject()->GetClass()->IsAOTLiteralInfo();
493 }
494
IsLinkedNode()495 inline bool JSTaggedValue::IsLinkedNode() const
496 {
497 return IsHeapObject() && GetTaggedObject()->GetClass()->IsLinkedNode();
498 }
499
IsRBTreeNode()500 inline bool JSTaggedValue::IsRBTreeNode() const
501 {
502 return IsHeapObject() && GetTaggedObject()->GetClass()->IsRBTreeNode();
503 }
504
IsNativePointer()505 inline bool JSTaggedValue::IsNativePointer() const
506 {
507 return IsJSNativePointer();
508 }
509
IsJSNativePointer()510 inline bool JSTaggedValue::IsJSNativePointer() const
511 {
512 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSNativePointer();
513 }
514
CheckIsJSNativePointer()515 inline bool JSTaggedValue::CheckIsJSNativePointer() const
516 {
517 return IsHeapObject() && GetTaggedObject() != nullptr && GetTaggedObject()->GetClass()->IsJSNativePointer();
518 }
519
IsSymbol()520 inline bool JSTaggedValue::IsSymbol() const
521 {
522 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSSymbol();
523 }
524
IsJSProxy()525 inline bool JSTaggedValue::IsJSProxy() const
526 {
527 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSProxy();
528 }
529
CheckIsJSProxy()530 inline bool JSTaggedValue::CheckIsJSProxy() const
531 {
532 return IsHeapObject() && GetTaggedObject() != nullptr && GetTaggedObject()->GetClass()->IsJSProxy();
533 }
534
IsBoolean()535 inline bool JSTaggedValue::IsBoolean() const
536 {
537 return ((value_ & TAG_HEAPOBJECT_MASK) == TAG_BOOLEAN_MASK);
538 }
539
IsJSObject()540 inline bool JSTaggedValue::IsJSObject() const
541 {
542 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSObject();
543 }
544
IsECMAObject()545 inline bool JSTaggedValue::IsECMAObject() const
546 {
547 return IsHeapObject() && GetTaggedObject()->GetClass()->IsECMAObject();
548 }
549
IsJSPromise()550 inline bool JSTaggedValue::IsJSPromise() const
551 {
552 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPromise();
553 }
554
IsRecord()555 inline bool JSTaggedValue::IsRecord() const
556 {
557 return IsHeapObject() && GetTaggedObject()->GetClass()->IsRecord();
558 }
559
IsPromiseReaction()560 inline bool JSTaggedValue::IsPromiseReaction() const
561 {
562 return IsHeapObject() && GetTaggedObject()->GetClass()->IsPromiseReaction();
563 }
564
IsJSPromiseReactionFunction()565 inline bool JSTaggedValue::IsJSPromiseReactionFunction() const
566 {
567 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPromiseReactionFunction();
568 }
569
IsProgram()570 inline bool JSTaggedValue::IsProgram() const
571 {
572 return IsHeapObject() && GetTaggedObject()->GetClass()->IsProgram();
573 }
574
IsJSPromiseExecutorFunction()575 inline bool JSTaggedValue::IsJSPromiseExecutorFunction() const
576 {
577 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPromiseExecutorFunction();
578 }
579
IsJSAsyncFromSyncIterUnwarpFunction()580 inline bool JSTaggedValue::IsJSAsyncFromSyncIterUnwarpFunction() const
581 {
582 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAsyncFromSyncIterUnwarpFunction();
583 }
584
IsJSPromiseAllResolveElementFunction()585 inline bool JSTaggedValue::IsJSPromiseAllResolveElementFunction() const
586 {
587 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPromiseAllResolveElementFunction();
588 }
589
IsJSAsyncGeneratorResNextRetProRstFtn()590 inline bool JSTaggedValue::IsJSAsyncGeneratorResNextRetProRstFtn() const
591 {
592 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAsyncGeneratorResNextRetProRstFtn();
593 }
594
IsCompletionRecord()595 inline bool JSTaggedValue::IsCompletionRecord() const
596 {
597 return IsHeapObject() && GetTaggedObject()->GetClass()->IsCompletionRecord();
598 }
599
IsResolvingFunctionsRecord()600 inline bool JSTaggedValue::IsResolvingFunctionsRecord() const
601 {
602 return IsHeapObject() && GetTaggedObject()->GetClass()->IsResolvingFunctionsRecord();
603 }
604
IsPromiseRecord()605 inline bool JSTaggedValue::IsPromiseRecord() const
606 {
607 return IsHeapObject() && GetTaggedObject()->GetClass()->IsPromiseRecord();
608 }
609
IsJSLocale()610 inline bool JSTaggedValue::IsJSLocale() const
611 {
612 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSLocale();
613 }
614
IsJSIntl()615 inline bool JSTaggedValue::IsJSIntl() const
616 {
617 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSIntl();
618 }
619
IsJSDateTimeFormat()620 inline bool JSTaggedValue::IsJSDateTimeFormat() const
621 {
622 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSDateTimeFormat();
623 }
624
IsJSRelativeTimeFormat()625 inline bool JSTaggedValue::IsJSRelativeTimeFormat() const
626 {
627 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSRelativeTimeFormat();
628 }
629
IsJSNumberFormat()630 inline bool JSTaggedValue::IsJSNumberFormat() const
631 {
632 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSNumberFormat();
633 }
634
IsJSCollator()635 inline bool JSTaggedValue::IsJSCollator() const
636 {
637 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSCollator();
638 }
639
IsJSPluralRules()640 inline bool JSTaggedValue::IsJSPluralRules() const
641 {
642 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPluralRules();
643 }
644
IsJSDisplayNames()645 inline bool JSTaggedValue::IsJSDisplayNames() const
646 {
647 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSDisplayNames();
648 }
649
IsJSListFormat()650 inline bool JSTaggedValue::IsJSListFormat() const
651 {
652 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSListFormat();
653 }
654
IsMethod()655 inline bool JSTaggedValue::IsMethod() const
656 {
657 return IsHeapObject() && GetTaggedObject()->GetClass()->IsMethod();
658 }
659
IsClassLiteral()660 inline bool JSTaggedValue::IsClassLiteral() const
661 {
662 return IsHeapObject() && GetTaggedObject()->GetClass()->IsClassLiteral();
663 }
664
IsJSAPIArrayList()665 inline bool JSTaggedValue::IsJSAPIArrayList() const
666 {
667 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIArrayList();
668 }
669
IsJSAPIHashMap()670 inline bool JSTaggedValue::IsJSAPIHashMap() const
671 {
672 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIHashMap();
673 }
674
IsJSAPIHashSet()675 inline bool JSTaggedValue::IsJSAPIHashSet() const
676 {
677 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIHashSet();
678 }
679
IsJSAPITreeMap()680 inline bool JSTaggedValue::IsJSAPITreeMap() const
681 {
682 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPITreeMap();
683 }
684
IsJSAPITreeSet()685 inline bool JSTaggedValue::IsJSAPITreeSet() const
686 {
687 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPITreeSet();
688 }
689
IsJSAPIPlainArray()690 inline bool JSTaggedValue::IsJSAPIPlainArray() const
691 {
692 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIPlainArray();
693 }
694
IsJSAPIPlainArrayIterator()695 inline bool JSTaggedValue::IsJSAPIPlainArrayIterator() const
696 {
697 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIPlainArrayIterator();
698 }
699
IsJSAPIQueue()700 inline bool JSTaggedValue::IsJSAPIQueue() const
701 {
702 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIQueue();
703 }
704
IsJSAPIDeque()705 inline bool JSTaggedValue::IsJSAPIDeque() const
706 {
707 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIDeque();
708 }
709
IsJSAPILightWeightMap()710 inline bool JSTaggedValue::IsJSAPILightWeightMap() const
711 {
712 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPILightWeightMap();
713 }
714
IsJSAPILightWeightSet()715 inline bool JSTaggedValue::IsJSAPILightWeightSet() const
716 {
717 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPILightWeightSet();
718 }
719
IsJSAPIStack()720 inline bool JSTaggedValue::IsJSAPIStack() const
721 {
722 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIStack();
723 }
724
IsJSAPIVector()725 inline bool JSTaggedValue::IsJSAPIVector() const
726 {
727 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIVector();
728 }
729
IsJSAPIList()730 inline bool JSTaggedValue::IsJSAPIList() const
731 {
732 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIList();
733 }
734
IsJSAPILinkedList()735 inline bool JSTaggedValue::IsJSAPILinkedList() const
736 {
737 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPILinkedList();
738 }
739
IsJSAPILinkedListIterator()740 inline bool JSTaggedValue::IsJSAPILinkedListIterator() const
741 {
742 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPILinkedListIterator();
743 }
744
IsJSAPIListIterator()745 inline bool JSTaggedValue::IsJSAPIListIterator() const
746 {
747 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIListIterator();
748 }
749
IsSpecialContainer()750 inline bool JSTaggedValue::IsSpecialContainer() const
751 {
752 return IsHeapObject() && GetTaggedObject()->GetClass()->IsSpecialContainer();
753 }
754
HasOrdinaryGet()755 inline bool JSTaggedValue::HasOrdinaryGet() const
756 {
757 return IsHeapObject() && GetTaggedObject()->GetClass()->HasOrdinaryGet();
758 }
759
IsPromiseIteratorRecord()760 inline bool JSTaggedValue::IsPromiseIteratorRecord() const
761 {
762 return IsHeapObject() && GetTaggedObject()->GetClass()->IsPromiseIteratorRecord();
763 }
764
IsPromiseCapability()765 inline bool JSTaggedValue::IsPromiseCapability() const
766 {
767 return IsHeapObject() && GetTaggedObject()->GetClass()->IsPromiseCapability();
768 }
769
IsJSPromiseAnyRejectElementFunction()770 inline bool JSTaggedValue::IsJSPromiseAnyRejectElementFunction() const
771 {
772 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPromiseAnyRejectElementFunction();
773 }
774
IsJSPromiseAllSettledElementFunction()775 inline bool JSTaggedValue::IsJSPromiseAllSettledElementFunction() const
776 {
777 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPromiseAllSettledElementFunction();
778 }
779
IsJSPromiseFinallyFunction()780 inline bool JSTaggedValue::IsJSPromiseFinallyFunction() const
781 {
782 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPromiseFinallyFunction();
783 }
784
IsJSPromiseValueThunkOrThrowerFunction()785 inline bool JSTaggedValue::IsJSPromiseValueThunkOrThrowerFunction() const
786 {
787 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPromiseValueThunkOrThrowerFunction();
788 }
789
IsJSError()790 inline bool JSTaggedValue::IsJSError() const
791 {
792 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSError();
793 }
794
IsMicroJobQueue()795 inline bool JSTaggedValue::IsMicroJobQueue() const
796 {
797 return IsHeapObject() && GetTaggedObject()->GetClass()->IsMicroJobQueue();
798 }
799
IsPendingJob()800 inline bool JSTaggedValue::IsPendingJob() const
801 {
802 return IsHeapObject() && GetTaggedObject()->GetClass()->IsPendingJob();
803 }
804
IsArguments()805 inline bool JSTaggedValue::IsArguments() const
806 {
807 return IsHeapObject() && GetTaggedObject()->GetClass()->IsArguments();
808 }
809
IsDate()810 inline bool JSTaggedValue::IsDate() const
811 {
812 return IsHeapObject() && GetTaggedObject()->GetClass()->IsDate();
813 }
814
IsArray(JSThread * thread)815 inline bool JSTaggedValue::IsArray(JSThread *thread) const
816 {
817 if (!IsHeapObject()) {
818 return false;
819 }
820 JSHClass *jsHclass = GetTaggedObject()->GetClass();
821 if (jsHclass->IsJSArray()) {
822 return true;
823 }
824
825 if (jsHclass->IsJSProxy()) {
826 return JSProxy::Cast(GetTaggedObject())->IsArray(thread);
827 }
828 return false;
829 }
830
IsCOWArray()831 inline bool JSTaggedValue::IsCOWArray() const
832 {
833 return IsHeapObject() && GetTaggedObject()->GetClass()->IsCOWArray();
834 }
835
IsJSArray()836 inline bool JSTaggedValue::IsJSArray() const
837 {
838 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSArray();
839 }
840
IsStableJSArray(JSThread * thread)841 inline bool JSTaggedValue::IsStableJSArray(JSThread *thread) const
842 {
843 return IsHeapObject() && GetTaggedObject()->GetClass()->IsStableJSArray() &&
844 !thread->IsStableArrayElementsGuardiansInvalid();
845 }
846
IsStableJSArguments(JSThread * thread)847 inline bool JSTaggedValue::IsStableJSArguments(JSThread *thread) const
848 {
849 return IsHeapObject() && GetTaggedObject()->GetClass()->IsStableJSArguments() &&
850 !thread->IsStableArrayElementsGuardiansInvalid();
851 }
852
HasStableElements(JSThread * thread)853 inline bool JSTaggedValue::HasStableElements(JSThread *thread) const
854 {
855 return IsHeapObject() && GetTaggedObject()->GetClass()->IsStableElements() &&
856 !thread->IsStableArrayElementsGuardiansInvalid();
857 }
858
IsTypedArray()859 inline bool JSTaggedValue::IsTypedArray() const
860 {
861 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTypedArray();
862 }
863
IsJSTypedArray()864 inline bool JSTaggedValue::IsJSTypedArray() const
865 {
866 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSTypedArray();
867 }
868
IsJSInt8Array()869 inline bool JSTaggedValue::IsJSInt8Array() const
870 {
871 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSInt8Array();
872 }
873
IsJSUint8Array()874 inline bool JSTaggedValue::IsJSUint8Array() const
875 {
876 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSUint8Array();
877 }
878
IsJSUint8ClampedArray()879 inline bool JSTaggedValue::IsJSUint8ClampedArray() const
880 {
881 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSUint8ClampedArray();
882 }
883
IsJSInt16Array()884 inline bool JSTaggedValue::IsJSInt16Array() const
885 {
886 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSInt16Array();
887 }
888
IsJSUint16Array()889 inline bool JSTaggedValue::IsJSUint16Array() const
890 {
891 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSUint16Array();
892 }
893
IsJSInt32Array()894 inline bool JSTaggedValue::IsJSInt32Array() const
895 {
896 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSInt32Array();
897 }
898
IsJSUint32Array()899 inline bool JSTaggedValue::IsJSUint32Array() const
900 {
901 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSUint32Array();
902 }
903
IsJSFloat32Array()904 inline bool JSTaggedValue::IsJSFloat32Array() const
905 {
906 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSFloat32Array();
907 }
908
IsJSFloat64Array()909 inline bool JSTaggedValue::IsJSFloat64Array() const
910 {
911 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSFloat64Array();
912 }
913
IsJSBigInt64Array()914 inline bool JSTaggedValue::IsJSBigInt64Array() const
915 {
916 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSBigInt64Array();
917 }
918
IsJSBigUint64Array()919 inline bool JSTaggedValue::IsJSBigUint64Array() const
920 {
921 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSBigUint64Array();
922 }
923
IsJSMap()924 inline bool JSTaggedValue::IsJSMap() const
925 {
926 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSMap();
927 }
928
IsJSWeakMap()929 inline bool JSTaggedValue::IsJSWeakMap() const
930 {
931 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSWeakMap();
932 }
933
IsJSWeakSet()934 inline bool JSTaggedValue::IsJSWeakSet() const
935 {
936 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSWeakSet();
937 }
938
IsJSSet()939 inline bool JSTaggedValue::IsJSSet() const
940 {
941 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSSet();
942 }
943
IsJSWeakRef()944 inline bool JSTaggedValue::IsJSWeakRef() const
945 {
946 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSWeakRef();
947 }
948
IsJSFinalizationRegistry()949 inline bool JSTaggedValue::IsJSFinalizationRegistry() const
950 {
951 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSFinalizationRegistry();
952 }
953
IsCellRecord()954 inline bool JSTaggedValue::IsCellRecord() const
955 {
956 return IsHeapObject() && GetTaggedObject()->GetClass()->IsCellRecord();
957 }
958
IsJSRegExp()959 inline bool JSTaggedValue::IsJSRegExp() const
960 {
961 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSRegExp();
962 }
963
IsJSFunction()964 inline bool JSTaggedValue::IsJSFunction() const
965 {
966 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSFunction();
967 }
968
IsJSFunctionBase()969 inline bool JSTaggedValue::IsJSFunctionBase() const
970 {
971 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSFunctionBase();
972 }
973
CheckIsJSFunctionBase()974 inline bool JSTaggedValue::CheckIsJSFunctionBase() const
975 {
976 return IsHeapObject() && GetTaggedObject() != nullptr && GetTaggedObject()->GetClass()->IsJSFunctionBase();
977 }
978
IsBoundFunction()979 inline bool JSTaggedValue::IsBoundFunction() const
980 {
981 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJsBoundFunction();
982 }
983
IsJSIntlBoundFunction()984 inline bool JSTaggedValue::IsJSIntlBoundFunction() const
985 {
986 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSIntlBoundFunction();
987 }
988
IsProxyRevocFunction()989 inline bool JSTaggedValue::IsProxyRevocFunction() const
990 {
991 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSProxyRevocFunction();
992 }
993
IsJSAsyncFunction()994 inline bool JSTaggedValue::IsJSAsyncFunction() const
995 {
996 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAsyncFunction();
997 }
998
IsJSAsyncAwaitStatusFunction()999 inline bool JSTaggedValue::IsJSAsyncAwaitStatusFunction() const
1000 {
1001 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAsyncAwaitStatusFunction();
1002 }
1003
IsJSPrimitiveRef()1004 inline bool JSTaggedValue::IsJSPrimitiveRef() const
1005 {
1006 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJsPrimitiveRef();
1007 }
1008
IsJSPrimitive()1009 inline bool JSTaggedValue::IsJSPrimitive() const
1010 {
1011 return IsNumber() || IsStringOrSymbol() || IsBoolean();
1012 }
1013
IsAccessorData()1014 inline bool JSTaggedValue::IsAccessorData() const
1015 {
1016 return IsHeapObject() && GetTaggedObject()->GetClass()->IsAccessorData();
1017 }
1018
IsInternalAccessor()1019 inline bool JSTaggedValue::IsInternalAccessor() const
1020 {
1021 return IsHeapObject() && GetTaggedObject()->GetClass()->IsInternalAccessor();
1022 }
1023
IsAccessor()1024 inline bool JSTaggedValue::IsAccessor() const
1025 {
1026 if (IsHeapObject()) {
1027 auto *jshclass = GetTaggedObject()->GetClass();
1028 return jshclass->IsAccessorData() || jshclass->IsInternalAccessor();
1029 }
1030
1031 return false;
1032 }
1033
IsPrototypeHandler()1034 inline bool JSTaggedValue::IsPrototypeHandler() const
1035 {
1036 return IsHeapObject() && GetTaggedObject()->GetClass()->IsPrototypeHandler();
1037 }
1038
IsTransitionHandler()1039 inline bool JSTaggedValue::IsTransitionHandler() const
1040 {
1041 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTransitionHandler();
1042 }
1043
IsTransWithProtoHandler()1044 inline bool JSTaggedValue::IsTransWithProtoHandler() const
1045 {
1046 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTransWithProtoHandler();
1047 }
1048
IsStoreTSHandler()1049 inline bool JSTaggedValue::IsStoreTSHandler() const
1050 {
1051 return IsHeapObject() && GetTaggedObject()->GetClass()->IsStoreTSHandler();
1052 }
1053
IsPropertyBox()1054 inline bool JSTaggedValue::IsPropertyBox() const
1055 {
1056 return IsHeapObject() && GetTaggedObject()->GetClass()->IsPropertyBox();
1057 }
1058
IsProtoChangeDetails()1059 inline bool JSTaggedValue::IsProtoChangeDetails() const
1060 {
1061 return IsHeapObject() && GetTaggedObject()->GetClass()->IsProtoChangeDetails();
1062 }
IsProtoChangeMarker()1063 inline bool JSTaggedValue::IsProtoChangeMarker() const
1064 {
1065 return IsHeapObject() && GetTaggedObject()->GetClass()->IsProtoChangeMarker();
1066 }
1067
IsJSGlobalEnv()1068 inline bool JSTaggedValue::IsJSGlobalEnv() const
1069 {
1070 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJsGlobalEnv();
1071 }
1072
IsForinIterator()1073 inline bool JSTaggedValue::IsForinIterator() const
1074 {
1075 return IsHeapObject() && GetTaggedObject()->GetClass()->IsForinIterator();
1076 }
1077
IsJSSetIterator()1078 inline bool JSTaggedValue::IsJSSetIterator() const
1079 {
1080 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSSetIterator();
1081 }
1082
IsJSRegExpIterator()1083 inline bool JSTaggedValue::IsJSRegExpIterator() const
1084 {
1085 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSRegExpIterator();
1086 }
1087
IsJSMapIterator()1088 inline bool JSTaggedValue::IsJSMapIterator() const
1089 {
1090 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSMapIterator();
1091 }
1092
IsJSAPIHashMapIterator()1093 inline bool JSTaggedValue::IsJSAPIHashMapIterator() const
1094 {
1095 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIHashMapIterator();
1096 }
1097
IsJSAPIHashSetIterator()1098 inline bool JSTaggedValue::IsJSAPIHashSetIterator() const
1099 {
1100 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIHashSetIterator();
1101 }
1102
IsJSAPITreeMapIterator()1103 inline bool JSTaggedValue::IsJSAPITreeMapIterator() const
1104 {
1105 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPITreeMapIterator();
1106 }
1107
IsJSAPITreeSetIterator()1108 inline bool JSTaggedValue::IsJSAPITreeSetIterator() const
1109 {
1110 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPITreeSetIterator();
1111 }
1112
IsJSArrayIterator()1113 inline bool JSTaggedValue::IsJSArrayIterator() const
1114 {
1115 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSArrayIterator();
1116 }
1117
IsJSAPIArrayListIterator()1118 inline bool JSTaggedValue::IsJSAPIArrayListIterator() const
1119 {
1120 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIArrayListIterator();
1121 }
1122
IsJSAPIQueueIterator()1123 inline bool JSTaggedValue::IsJSAPIQueueIterator() const
1124 {
1125 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIQueueIterator();
1126 }
1127
IsJSAPIDequeIterator()1128 inline bool JSTaggedValue::IsJSAPIDequeIterator() const
1129 {
1130 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIDequeIterator();
1131 }
1132
IsJSAPILightWeightMapIterator()1133 inline bool JSTaggedValue::IsJSAPILightWeightMapIterator() const
1134 {
1135 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPILightWeightMapIterator();
1136 }
1137
IsJSAPILightWeightSetIterator()1138 inline bool JSTaggedValue::IsJSAPILightWeightSetIterator() const
1139 {
1140 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPILightWeightSetIterator();
1141 }
1142
IsJSAPIStackIterator()1143 inline bool JSTaggedValue::IsJSAPIStackIterator() const
1144 {
1145 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIStackIterator();
1146 }
1147
IsJSAPIVectorIterator()1148 inline bool JSTaggedValue::IsJSAPIVectorIterator() const
1149 {
1150 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIVectorIterator();
1151 }
1152
IsIterator()1153 inline bool JSTaggedValue::IsIterator() const
1154 {
1155 return IsHeapObject() && GetTaggedObject()->GetClass()->IsIterator();
1156 }
1157
IsAsyncIterator()1158 inline bool JSTaggedValue::IsAsyncIterator() const
1159 {
1160 return IsHeapObject() && GetTaggedObject()->GetClass()->IsAsyncIterator();
1161 }
1162
IsAsyncFromSyncIterator()1163 inline bool JSTaggedValue::IsAsyncFromSyncIterator() const
1164 {
1165 return IsHeapObject() && GetTaggedObject()->GetClass()->IsAsyncFromSyncIterator();
1166 }
1167
IsGeneratorFunction()1168 inline bool JSTaggedValue::IsGeneratorFunction() const
1169 {
1170 return IsHeapObject() && GetTaggedObject()->GetClass()->IsGeneratorFunction();
1171 }
1172
IsAsyncGeneratorFunction()1173 inline bool JSTaggedValue::IsAsyncGeneratorFunction() const
1174 {
1175 return IsHeapObject() && GetTaggedObject()->GetClass()->IsAsyncGeneratorFunction();
1176 }
1177
IsGeneratorObject()1178 inline bool JSTaggedValue::IsGeneratorObject() const
1179 {
1180 return IsHeapObject() && GetTaggedObject()->GetClass()->IsGeneratorObject();
1181 }
1182
IsGeneratorContext()1183 inline bool JSTaggedValue::IsGeneratorContext() const
1184 {
1185 return IsHeapObject() && GetTaggedObject()->GetClass()->IsGeneratorContext();
1186 }
1187
IsAsyncGeneratorRequest()1188 inline bool JSTaggedValue::IsAsyncGeneratorRequest() const
1189 {
1190 return IsHeapObject() && GetTaggedObject()->GetClass()->IsAsyncGeneratorRequest();
1191 }
1192
IsAsyncIteratorRecord()1193 inline bool JSTaggedValue::IsAsyncIteratorRecord() const
1194 {
1195 return IsHeapObject() && GetTaggedObject()->GetClass()->IsAsyncIteratorRecord();
1196 }
1197
IsAsyncGeneratorObject()1198 inline bool JSTaggedValue::IsAsyncGeneratorObject() const
1199 {
1200 return IsHeapObject() && GetTaggedObject()->GetClass()->IsAsyncGeneratorObject();
1201 }
1202
IsAsyncFuncObject()1203 inline bool JSTaggedValue::IsAsyncFuncObject() const
1204 {
1205 return IsHeapObject() && GetTaggedObject()->GetClass()->IsAsyncFuncObject();
1206 }
1207
IsJSHClass()1208 inline bool JSTaggedValue::IsJSHClass() const
1209 {
1210 return IsHeapObject() && GetTaggedObject()->GetClass()->IsHClass();
1211 }
1212
IsStringIterator()1213 inline bool JSTaggedValue::IsStringIterator() const
1214 {
1215 return IsHeapObject() && GetTaggedObject()->GetClass()->IsStringIterator();
1216 }
1217
IsArrayBuffer()1218 inline bool JSTaggedValue::IsArrayBuffer() const
1219 {
1220 return IsHeapObject() && GetTaggedObject()->GetClass()->IsArrayBuffer();
1221 }
1222
IsSharedArrayBuffer()1223 inline bool JSTaggedValue::IsSharedArrayBuffer() const
1224 {
1225 return IsHeapObject() && GetTaggedObject()->GetClass()->IsSharedArrayBuffer();
1226 }
1227
IsDataView()1228 inline bool JSTaggedValue::IsDataView() const
1229 {
1230 return IsHeapObject() && GetTaggedObject()->GetClass()->IsDataView();
1231 }
1232
IsTemplateMap()1233 inline bool JSTaggedValue::IsTemplateMap() const
1234 {
1235 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTemplateMap();
1236 }
1237
IsJSGlobalObject()1238 inline bool JSTaggedValue::IsJSGlobalObject() const
1239 {
1240 return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSGlobalObject();
1241 }
1242
IsMachineCodeObject()1243 inline bool JSTaggedValue::IsMachineCodeObject() const
1244 {
1245 return IsHeapObject() && GetTaggedObject()->GetClass()->IsMachineCodeObject();
1246 }
1247
IsClassInfoExtractor()1248 inline bool JSTaggedValue::IsClassInfoExtractor() const
1249 {
1250 return IsHeapObject() && GetTaggedObject()->GetClass()->IsClassInfoExtractor();
1251 }
1252
IsTSType()1253 inline bool JSTaggedValue::IsTSType() const
1254 {
1255 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSType();
1256 }
1257
IsTSObjectType()1258 inline bool JSTaggedValue::IsTSObjectType() const
1259 {
1260 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSObjectType();
1261 }
1262
IsTSClassType()1263 inline bool JSTaggedValue::IsTSClassType() const
1264 {
1265 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSClassType();
1266 }
1267
IsTSInterfaceType()1268 inline bool JSTaggedValue::IsTSInterfaceType() const
1269 {
1270 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSInterfaceType();
1271 }
1272
IsTSUnionType()1273 inline bool JSTaggedValue::IsTSUnionType() const
1274 {
1275 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSUnionType();
1276 }
1277
IsTSClassInstanceType()1278 inline bool JSTaggedValue::IsTSClassInstanceType() const
1279 {
1280 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSClassInstanceType();
1281 }
1282
IsCjsExports()1283 inline bool JSTaggedValue::IsCjsExports() const
1284 {
1285 return IsHeapObject() && GetTaggedObject()->GetClass()->IsCjsExports();
1286 }
1287
IsCjsModule()1288 inline bool JSTaggedValue::IsCjsModule() const
1289 {
1290 return IsHeapObject() && GetTaggedObject()->GetClass()->IsCjsModule();
1291 }
1292
IsCjsRequire()1293 inline bool JSTaggedValue::IsCjsRequire() const
1294 {
1295 return IsHeapObject() && GetTaggedObject()->GetClass()->IsCjsRequire();
1296 }
1297
IsTSFunctionType()1298 inline bool JSTaggedValue::IsTSFunctionType() const
1299 {
1300 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSFunctionType();
1301 }
1302
IsTSArrayType()1303 inline bool JSTaggedValue::IsTSArrayType() const
1304 {
1305 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSArrayType();
1306 }
1307
IsTSIteratorInstanceType()1308 inline bool JSTaggedValue::IsTSIteratorInstanceType() const
1309 {
1310 return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSIteratorInstanceType();
1311 }
1312
IsModuleRecord()1313 inline bool JSTaggedValue::IsModuleRecord() const
1314 {
1315 return IsHeapObject() && GetTaggedObject()->GetClass()->IsModuleRecord();
1316 }
1317
IsSourceTextModule()1318 inline bool JSTaggedValue::IsSourceTextModule() const
1319 {
1320 return IsHeapObject() && GetTaggedObject()->GetClass()->IsSourceTextModule();
1321 }
1322
IsImportEntry()1323 inline bool JSTaggedValue::IsImportEntry() const
1324 {
1325 return IsHeapObject() && GetTaggedObject()->GetClass()->IsImportEntry();
1326 }
1327
IsLocalExportEntry()1328 inline bool JSTaggedValue::IsLocalExportEntry() const
1329 {
1330 return IsHeapObject() && GetTaggedObject()->GetClass()->IsLocalExportEntry();
1331 }
1332
IsIndirectExportEntry()1333 inline bool JSTaggedValue::IsIndirectExportEntry() const
1334 {
1335 return IsHeapObject() && GetTaggedObject()->GetClass()->IsIndirectExportEntry();
1336 }
1337
IsStarExportEntry()1338 inline bool JSTaggedValue::IsStarExportEntry() const
1339 {
1340 return IsHeapObject() && GetTaggedObject()->GetClass()->IsStarExportEntry();
1341 }
1342
IsResolvedBinding()1343 inline bool JSTaggedValue::IsResolvedBinding() const
1344 {
1345 return IsHeapObject() && GetTaggedObject()->GetClass()->IsResolvedBinding();
1346 }
1347
IsResolvedIndexBinding()1348 inline bool JSTaggedValue::IsResolvedIndexBinding() const
1349 {
1350 return IsHeapObject() && GetTaggedObject()->GetClass()->IsResolvedIndexBinding();
1351 }
1352
IsModuleNamespace()1353 inline bool JSTaggedValue::IsModuleNamespace() const
1354 {
1355 return IsHeapObject() && GetTaggedObject()->GetClass()->IsModuleNamespace();
1356 }
1357
ExtractNumber()1358 inline double JSTaggedValue::ExtractNumber() const
1359 {
1360 ASSERT(IsNumber());
1361 return GetNumber();
1362 }
1363
1364 // 9.4.2.4 ArraySetLength 3 to 7
ToArrayLength(JSThread * thread,const JSHandle<JSTaggedValue> & tagged,uint32_t * output)1365 inline bool JSTaggedValue::ToArrayLength(JSThread *thread, const JSHandle<JSTaggedValue> &tagged, uint32_t *output)
1366 {
1367 // 3. Let newLen be ToUint32(Desc.[[Value]]).
1368 uint32_t newLen = ToUint32(thread, tagged);
1369 // 4. ReturnIfAbrupt(newLen).
1370 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false);
1371
1372 // 5. Let numberLen be ToNumber(Desc.[[Value]]).
1373 JSTaggedNumber numberLen = ToNumber(thread, tagged);
1374 // 6. ReturnIfAbrupt(newLen).
1375 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false);
1376
1377 // 7. If newLen != numberLen, throw a RangeError exception.
1378 if (JSTaggedNumber(newLen) != numberLen) {
1379 THROW_RANGE_ERROR_AND_RETURN(thread, "Not a valid array length", false);
1380 }
1381
1382 *output = newLen;
1383 return true;
1384 }
1385
GetArrayLength()1386 inline uint32_t JSTaggedValue::GetArrayLength() const
1387 {
1388 ASSERT(IsNumber());
1389 if (IsInt()) {
1390 return static_cast<uint32_t>(GetInt());
1391 }
1392 if (IsDouble()) {
1393 ASSERT(GetDouble() <= TaggedArray::MAX_ARRAY_INDEX);
1394 return static_cast<uint32_t>(GetDouble());
1395 }
1396 UNREACHABLE();
1397 }
1398
ToElementIndex(JSTaggedValue key,uint32_t * output)1399 inline bool JSTaggedValue::ToElementIndex(JSTaggedValue key, uint32_t *output)
1400 {
1401 if (key.IsInt()) {
1402 int index = key.GetInt();
1403 if (index >= 0) {
1404 *output = index;
1405 return true;
1406 }
1407 } else if (key.IsDouble()) {
1408 double d = key.GetDouble();
1409 uint32_t index = static_cast<uint32_t>(base::NumberHelper::DoubleToInt(d, base::INT32_BITS));
1410 if (d - static_cast<double>(index) == 0.0) {
1411 *output = index;
1412 return true;
1413 }
1414 } else if (key.IsString()) {
1415 return StringToElementIndex(key, output);
1416 }
1417 return false;
1418 }
1419
StringToElementIndex(JSTaggedValue key,uint32_t * output)1420 inline bool JSTaggedValue::StringToElementIndex(JSTaggedValue key, uint32_t *output)
1421 {
1422 ASSERT(key.IsString());
1423 auto strObj = static_cast<EcmaString *>(key.GetTaggedObject());
1424 return EcmaStringAccessor(strObj).ToElementIndex(output);
1425 }
1426
GetKeyHashCode()1427 inline uint32_t JSTaggedValue::GetKeyHashCode() const
1428 {
1429 ASSERT(IsStringOrSymbol());
1430 if (IsString()) {
1431 return EcmaStringAccessor(GetTaggedObject()).GetHashcode();
1432 }
1433
1434 return JSSymbol::Cast(GetTaggedObject())->GetHashField();
1435 }
1436
StringToDouble(JSTaggedValue tagged)1437 inline JSTaggedNumber JSTaggedValue::StringToDouble(JSTaggedValue tagged)
1438 {
1439 auto strObj = static_cast<EcmaString *>(tagged.GetTaggedObject());
1440 size_t strLen = EcmaStringAccessor(strObj).GetLength();
1441 if (strLen == 0) {
1442 return JSTaggedNumber(0);
1443 }
1444 [[maybe_unused]] CVector<uint8_t> buf;
1445 Span<const uint8_t> str = EcmaStringAccessor(strObj).ToUtf8Span(buf);
1446 double d = base::NumberHelper::StringToDouble(str.begin(), str.end(), 0,
1447 base::ALLOW_BINARY + base::ALLOW_OCTAL + base::ALLOW_HEX);
1448 return JSTaggedNumber(d);
1449 }
1450
StringCompare(EcmaString * xStr,EcmaString * yStr)1451 inline bool JSTaggedValue::StringCompare(EcmaString *xStr, EcmaString *yStr)
1452 {
1453 if (EcmaStringAccessor(xStr).IsInternString() && EcmaStringAccessor(yStr).IsInternString()) {
1454 return xStr == yStr;
1455 }
1456 return EcmaStringAccessor::StringsAreEqual(xStr, yStr);
1457 }
1458
TryCastDoubleToInt32(double d)1459 inline JSTaggedValue JSTaggedValue::TryCastDoubleToInt32(double d)
1460 {
1461 if (UNLIKELY(static_cast<int32_t>(d) != d)) {
1462 return JSTaggedValue(d);
1463 }
1464 return JSTaggedValue(static_cast<int32_t>(d));
1465 }
1466 } // namespace panda::ecmascript
1467 #endif // ECMASCRIPT_TAGGED_VALUE_INL_H
1468