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