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