• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_JS_TAGGED_VALUE_H
17 #define ECMASCRIPT_JS_TAGGED_VALUE_H
18 
19 #include "ecmascript/base/bit_helper.h"
20 #include "ecmascript/base/config.h"
21 #include "ecmascript/mem/c_string.h"
22 #include "ecmascript/mem/mem_common.h"
23 #include "ecmascript/js_tagged_value_internals.h"
24 namespace panda::ecmascript {
25 class JSArray;
26 class JSObject;
27 class JSTaggedNumber;
28 template<typename T>
29 class JSHandle;
30 class TaggedArray;
31 class LinkedHashMap;
32 class LinkedHashSet;
33 class PropertyDescriptor;
34 class OperationResult;
35 class EcmaString;
36 class JSThread;
37 struct Reference;
38 
39 static constexpr double SAFE_NUMBER = 9007199254740991LL;
40 
41 // Don't switch the order!
42 enum PreferredPrimitiveType : uint8_t { PREFER_NUMBER = 0, PREFER_STRING, NO_PREFERENCE };
43 
44 // Result of an abstract relational comparison of x and y, implemented according
45 // to ES6 section 7.2.11 Abstract Relational Comparison.
46 enum class ComparisonResult {
47     LESS,      // x < y
48     EQUAL,     // x = y
49     GREAT,     // x > y
50     UNDEFINED  // at least one of x or y was undefined or NaN
51 };
52 
53 enum class ClassKind : uint8_t { SENDABLE = 0, NON_SENDABLE };
54 class JSTaggedValue : public JSTaggedValueInternals {
55 public:
Cast(TaggedObject * object)56     static JSTaggedValue Cast(TaggedObject *object)
57     {
58         return JSTaggedValue(object);
59     }
60 
61     static const JSTaggedType NULL_POINTER = VALUE_HOLE;
62     static const JSTaggedType INVALID_VALUE_LIMIT = 0x40000ULL;
63 
CastDoubleToTagged(double value)64     static inline JSTaggedType CastDoubleToTagged(double value)
65     {
66         return base::bit_cast<JSTaggedType>(value);
67     }
68 
CastTaggedToDouble(JSTaggedType value)69     static inline double CastTaggedToDouble(JSTaggedType value)
70     {
71         return base::bit_cast<double>(value);
72     }
73 
TaggedTypeSize()74     static inline constexpr size_t TaggedTypeSize()
75     {
76         return sizeof(JSTaggedType);
77     }
78 
79     static constexpr size_t SizeArch32 = sizeof(JSTaggedType);
80 
81     static constexpr size_t SizeArch64 = sizeof(JSTaggedType);
82 
83     explicit JSTaggedValue(void *) = delete;
84 
JSTaggedValue()85     ARK_INLINE constexpr JSTaggedValue() : value_(JSTaggedValue::NULL_POINTER) {}
86 
JSTaggedValue(JSTaggedType v)87     ARK_INLINE constexpr explicit JSTaggedValue(JSTaggedType v) : value_(v) {}
88 
JSTaggedValue(int v)89     ARK_INLINE constexpr explicit JSTaggedValue(int v) : value_(static_cast<JSTaggedType>(v) | TAG_INT) {}
90 
JSTaggedValue(unsigned int v)91     ARK_INLINE explicit JSTaggedValue(unsigned int v)
92     {
93         if (static_cast<int32_t>(v) < 0) {
94             value_ = JSTaggedValue(static_cast<double>(v)).GetRawData();
95             return;
96         }
97         value_ = JSTaggedValue(static_cast<int32_t>(v)).GetRawData();
98     }
99 
JSTaggedValue(bool v)100     ARK_INLINE constexpr explicit JSTaggedValue(bool v)
101         : value_(static_cast<JSTaggedType>(v) | TAG_BOOLEAN_MASK) {}
102 
JSTaggedValue(double v)103     ARK_INLINE explicit JSTaggedValue(double v)
104     {
105         ASSERT_PRINT(!IsImpureNaN(v), "pureNaN will break the encoding of tagged double: "
106                                           << std::hex << CastDoubleToTagged(v));
107         value_ = CastDoubleToTagged(v) + DOUBLE_ENCODE_OFFSET;
108     }
109 
JSTaggedValue(const TaggedObject * v)110     ARK_INLINE explicit JSTaggedValue(const TaggedObject *v) : value_(static_cast<JSTaggedType>(ToUintPtr(v))) {}
111 
JSTaggedValue(int64_t v)112     ARK_INLINE explicit JSTaggedValue(int64_t v)
113     {
114         if (UNLIKELY(static_cast<int32_t>(v) != v)) {
115             value_ = JSTaggedValue(static_cast<double>(v)).GetRawData();
116             return;
117         }
118         value_ = JSTaggedValue(static_cast<int32_t>(v)).GetRawData();
119     }
120 
121     ~JSTaggedValue() = default;
122     DEFAULT_COPY_SEMANTIC(JSTaggedValue);
123     DEFAULT_MOVE_SEMANTIC(JSTaggedValue);
124 
CreateWeakRef()125     inline void CreateWeakRef()
126     {
127         ASSERT_PRINT(IsHeapObject() && ((value_ & TAG_WEAK) == 0U),
128                      "The least significant two bits of JSTaggedValue are not zero.");
129         value_ = value_ | TAG_WEAK;
130     }
131 
RemoveWeakTag()132     inline void RemoveWeakTag()
133     {
134         ASSERT_PRINT(IsHeapObject() && ((value_ & TAG_WEAK) == TAG_WEAK), "The tagged value is not a weak ref.");
135         value_ = value_ & (~TAG_WEAK);
136     }
137 
CreateAndGetWeakRef()138     inline JSTaggedValue CreateAndGetWeakRef() const
139     {
140         ASSERT_PRINT(IsHeapObject() && ((value_ & TAG_WEAK) == 0U),
141                      "The least significant two bits of JSTaggedValue are not zero.");
142         return JSTaggedValue(value_ | TAG_WEAK);
143     }
144 
GetWeakRawValue()145     inline JSTaggedValue GetWeakRawValue() const
146     {
147         if (IsHeapObject()) {
148             return JSTaggedValue(value_ & (~TAG_WEAK));
149         }
150         return JSTaggedValue(value_);
151     }
152 
IsWeak()153     ARK_INLINE bool IsWeak() const
154     {
155         return ((value_ & TAG_WEAK_MASK) == TAG_WEAK);
156     }
157 
IsDouble()158     ARK_INLINE bool IsDouble() const
159     {
160         return !IsInt() && !IsObject();
161     }
162 
IsInt()163     ARK_INLINE bool IsInt() const
164     {
165         return (value_ & TAG_MARK) == TAG_INT;
166     }
167 
IsSpecial()168     ARK_INLINE bool IsSpecial() const
169     {
170         return ((value_ & TAG_SPECIAL_MASK) == TAG_SPECIAL) || IsHole();
171     }
172 
IsObject()173     ARK_INLINE bool IsObject() const
174     {
175         return ((value_ & TAG_MARK) == TAG_OBJECT);
176     }
177 
GetWeakReferentUnChecked()178     ARK_INLINE TaggedObject *GetWeakReferentUnChecked() const
179     {
180         return reinterpret_cast<TaggedObject *>(value_ & (~TAG_WEAK));
181     }
182 
IsHeapObject()183     ARK_INLINE bool IsHeapObject() const
184     {
185         return ((value_ & TAG_HEAPOBJECT_MASK) == 0U);
186     }
187 
IsInvalidValue()188     ARK_INLINE bool IsInvalidValue() const
189     {
190         return value_ <= INVALID_VALUE_LIMIT;
191     }
192 
GetDouble()193     ARK_INLINE double GetDouble() const
194     {
195         ASSERT_PRINT(IsDouble(), "can not convert JSTaggedValue to Double : " << std::hex << value_);
196         return CastTaggedToDouble(value_ - DOUBLE_ENCODE_OFFSET);
197     }
198 
GetInt()199     ARK_INLINE int GetInt() const
200     {
201         ASSERT_PRINT(IsInt(), "can not convert JSTaggedValue to Int :" << std::hex << value_);
202         return static_cast<int>(value_ & (~TAG_MARK));
203     }
204 
GetRawData()205     ARK_INLINE JSTaggedType GetRawData() const
206     {
207         return value_;
208     }
209 
210     //  This function returns the heap object pointer which may have the weak tag.
GetRawHeapObject()211     ARK_INLINE TaggedObject *GetRawHeapObject() const
212     {
213         ASSERT_PRINT(IsHeapObject(), "can not convert JSTaggedValue to HeapObject :" << std::hex << value_);
214         return reinterpret_cast<TaggedObject *>(value_);
215     }
216 
GetWeakReferent()217     ARK_INLINE TaggedObject *GetWeakReferent() const
218     {
219         ASSERT_PRINT(IsWeak(), "can not convert JSTaggedValue to WeakRef HeapObject :" << std::hex << value_);
220         return reinterpret_cast<TaggedObject *>(value_ & (~TAG_WEAK));
221     }
222 
Cast(void * ptr)223     static ARK_INLINE JSTaggedType Cast(void *ptr)
224     {
225         ASSERT_PRINT(sizeof(void *) == TaggedTypeSize(), "32bit platform is not support yet");
226         return static_cast<JSTaggedType>(ToUintPtr(ptr));
227     }
228 
IsFalse()229     ARK_INLINE bool IsFalse() const
230     {
231         return value_ == VALUE_FALSE;
232     }
233 
IsTrue()234     ARK_INLINE bool IsTrue() const
235     {
236         return value_ == VALUE_TRUE;
237     }
238 
IsUndefined()239     ARK_INLINE bool IsUndefined() const
240     {
241         return value_ == VALUE_UNDEFINED;
242     }
243 
IsNull()244     ARK_INLINE bool IsNull() const
245     {
246         return value_ == VALUE_NULL;
247     }
248 
IsUndefinedOrNull()249     ARK_INLINE bool IsUndefinedOrNull() const
250     {
251         return ((value_ & TAG_HEAPOBJECT_MASK) == TAG_SPECIAL);
252     }
253 
IsHole()254     ARK_INLINE bool IsHole() const
255     {
256         return value_ == VALUE_HOLE || value_ == 0U;
257     }
258 
IsException()259     ARK_INLINE bool IsException() const
260     {
261         return value_ == VALUE_EXCEPTION;
262     }
263 
IsImpureNaN(double value)264     static ARK_INLINE bool IsImpureNaN(double value)
265     {
266         // Tests if the double value would break tagged double encoding.
267         return base::bit_cast<JSTaggedType>(value) >= (TAG_INT - DOUBLE_ENCODE_OFFSET);
268     }
269 
270     ARK_INLINE bool operator==(const JSTaggedValue &other) const
271     {
272         return value_ == other.value_;
273     }
274 
275     ARK_INLINE bool operator!=(const JSTaggedValue &other) const
276     {
277         return value_ != other.value_;
278     }
279 
IsWeakForHeapObject()280     ARK_INLINE bool IsWeakForHeapObject() const
281     {
282         return (value_ & TAG_WEAK) == 1U;
283     }
284 
False()285     static ARK_INLINE constexpr JSTaggedValue False()
286     {
287         return JSTaggedValue(VALUE_FALSE);
288     }
289 
True()290     static ARK_INLINE constexpr JSTaggedValue True()
291     {
292         return JSTaggedValue(VALUE_TRUE);
293     }
294 
Undefined()295     static ARK_INLINE constexpr JSTaggedValue Undefined()
296     {
297         return JSTaggedValue(VALUE_UNDEFINED);
298     }
299 
Null()300     static ARK_INLINE constexpr JSTaggedValue Null()
301     {
302         return JSTaggedValue(VALUE_NULL);
303     }
304 
Hole()305     static ARK_INLINE constexpr JSTaggedValue Hole()
306     {
307         return JSTaggedValue(VALUE_HOLE);
308     }
309 
Exception()310     static ARK_INLINE constexpr JSTaggedValue Exception()
311     {
312         return JSTaggedValue(VALUE_EXCEPTION);
313     }
314 
GetNumber()315     ARK_INLINE double GetNumber() const
316     {
317         return IsInt() ? GetInt() : GetDouble();
318     }
319 
GetTaggedObject()320     ARK_INLINE TaggedObject *GetTaggedObject() const
321     {
322         ASSERT_PRINT(IsHeapObject() && ((value_ & TAG_WEAK) == 0U),
323                      "can not convert JSTaggedValue to HeapObject :" << std::hex << value_);
324         return reinterpret_cast<TaggedObject *>(value_);
325     }
326 
GetHeapObject()327     ARK_INLINE TaggedObject *GetHeapObject() const
328     {
329         if (IsWeakForHeapObject()) {
330             return GetTaggedWeakRef();
331         }
332         return GetTaggedObject();
333     }
334 
GetRawTaggedObject()335     ARK_INLINE TaggedObject *GetRawTaggedObject() const
336     {
337         return reinterpret_cast<TaggedObject *>(GetRawHeapObject());
338     }
339 
GetTaggedWeakRef()340     ARK_INLINE TaggedObject *GetTaggedWeakRef() const
341     {
342         return reinterpret_cast<TaggedObject *>(GetWeakReferent());
343     }
344 
345     static JSTaggedValue OrdinaryToPrimitive(JSThread *thread, const JSHandle<JSTaggedValue> &tagged,
346                                              PreferredPrimitiveType type = PREFER_NUMBER);
347 
348     // ecma6 7.1 Type Conversion
349     static JSTaggedValue ToPrimitive(JSThread *thread, const JSHandle<JSTaggedValue> &tagged,
350                                      PreferredPrimitiveType type = NO_PREFERENCE);
351     bool ToBoolean() const;
352     static JSTaggedNumber ToNumber(JSThread *thread, JSTaggedValue tagged);
353     static JSTaggedNumber ToNumber(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
354     static JSTaggedValue ToBigInt(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
355     static JSTaggedValue ToBigInt64(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
356     static JSTaggedValue ToBigUint64(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
357     static JSTaggedNumber ToInteger(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
358     static JSHandle<JSTaggedValue> ToNumeric(JSThread *thread, JSHandle<JSTaggedValue> tagged);
359     static int32_t ToInt32(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
360     static uint32_t ToUint32(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
361     static int16_t ToInt16(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
362     static uint16_t ToUint16(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
363     static int8_t ToInt8(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
364     static uint8_t ToUint8(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
365     static uint8_t ToUint8Clamp(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
366     static JSHandle<EcmaString> ToString(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
367     static JSHandle<EcmaString> ToString(JSThread *thread, JSTaggedValue val);
368     static JSHandle<JSObject> ToObject(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
369     static JSHandle<JSTaggedValue> ToPropertyKey(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
370     static JSTaggedNumber ToLength(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
371     static JSTaggedValue CanonicalNumericIndexString(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
372     static JSTaggedNumber ToIndex(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
373     static JSTaggedNumber StringToDouble(JSTaggedValue tagged);
374     static JSTaggedNumber StringToNumber(JSTaggedValue tagged);
375 
376     static bool ToArrayLength(JSThread *thread, const JSHandle<JSTaggedValue> &tagged, uint32_t *output);
377     static bool ToElementIndex(JSTaggedValue key, uint32_t *output);
378     static bool StringToElementIndex(JSTaggedValue key, uint32_t *output);
379     static bool IsPureString(JSTaggedValue key);
380     uint32_t GetArrayLength() const;
381 
382     // ecma6 7.2 Testing and Comparison Operations
383     bool IsCallable() const;
384     bool IsConstructor() const;
385     bool IsExtensible(JSThread *thread) const;
386     bool IsInteger() const;
387     bool WithinInt32() const;
388     bool IsZero() const;
389     bool IsExactlyZero() const;
390     static bool IsPropertyKey(const JSHandle<JSTaggedValue> &key);
391     static JSHandle<JSTaggedValue> RequireObjectCoercible(JSThread *thread, const JSHandle<JSTaggedValue> &tagged,
392                                                           const char *message = "RequireObjectCoercible throw Error");
393     static bool SameValue(const JSTaggedValue &x, const JSTaggedValue &y);
394     static bool SameValue(const JSHandle<JSTaggedValue> &xHandle, const JSHandle<JSTaggedValue> &yHandle);
395     static bool SameValueZero(const JSTaggedValue &x, const JSTaggedValue &y);
396     static bool Less(JSThread *thread, const JSHandle<JSTaggedValue> &x, const JSHandle<JSTaggedValue> &y);
397     static bool Equal(JSThread *thread, const JSHandle<JSTaggedValue> &x, const JSHandle<JSTaggedValue> &y);
398     static bool StrictEqual(const JSThread *thread, const JSHandle<JSTaggedValue> &x, const JSHandle<JSTaggedValue> &y);
399     static bool StrictEqual(const JSTaggedValue &x, const JSTaggedValue &y);
400     static bool SameValueNumberic(const JSTaggedValue &x, const JSTaggedValue &y);
401 
402     // ES6 7.4 Operations on Iterator Objects
403     static JSObject *CreateIterResultObject(JSThread *thread, const JSHandle<JSTaggedValue> &value, bool done);
404 
405     // ECMAScript 2023 allow the use of most Symbols as keys in weak collections
406     static bool CanBeHeldWeakly(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
407 
408     // ecma6 7.3
409     static OperationResult GetProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
410                                        const JSHandle<JSTaggedValue> &key);
411 
412     static OperationResult GetProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, uint32_t key);
413     static OperationResult GetProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
414                                        const JSHandle<JSTaggedValue> &key, const JSHandle<JSTaggedValue> &receiver);
415     static bool SetProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, uint32_t key,
416                             const JSHandle<JSTaggedValue> &value, bool mayThrow = false);
417 
418     static bool SetProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, const JSHandle<JSTaggedValue> &key,
419                             const JSHandle<JSTaggedValue> &value, bool mayThrow = false);
420 
421     static bool SetProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, const JSHandle<JSTaggedValue> &key,
422                             const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &receiver,
423                             bool mayThrow = false);
424     static bool DeleteProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
425                                const JSHandle<JSTaggedValue> &key);
426     static bool DeletePropertyOrThrow(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
427                                       const JSHandle<JSTaggedValue> &key);
428     static bool DefinePropertyOrThrow(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
429                                       const JSHandle<JSTaggedValue> &key, const PropertyDescriptor &desc);
430     static bool DefineOwnProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
431                                   const JSHandle<JSTaggedValue> &key, const PropertyDescriptor &desc);
432     static bool GetOwnProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, const JSHandle<JSTaggedValue> &key,
433                                PropertyDescriptor &desc);
434     static bool SetPrototype(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
435                              const JSHandle<JSTaggedValue> &proto);
436     static JSTaggedValue GetPrototype(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
437     static bool PreventExtensions(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
438     static JSHandle<TaggedArray> GetOwnPropertyKeys(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
439     static JSHandle<TaggedArray> GetAllPropertyKeys(JSThread *thread,
440         const JSHandle<JSTaggedValue> &obj, uint32_t filter);
441     static JSHandle<TaggedArray> GetOwnEnumPropertyKeys(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
442     static bool HasProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, const JSHandle<JSTaggedValue> &key);
443     static bool HasProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj, uint32_t key);
444     static bool HasOwnProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
445                                const JSHandle<JSTaggedValue> &key);
446     static bool GlobalHasOwnProperty(JSThread *thread, const JSHandle<JSTaggedValue> &key);
447 
448     // Type
449     bool IsJSMap() const;
450     bool IsJSSet() const;
451     bool IsJSWeakMap() const;
452     bool IsJSWeakSet() const;
453     bool IsJSWeakRef() const;
454     bool IsJSFinalizationRegistry() const;
455     bool IsCellRecord() const;
456     bool IsJSRegExp() const;
457     bool IsNumber() const;
458     bool IsBigInt() const;
459     bool IsString() const;
460     bool IsLineString() const;
461     bool IsConstantString() const;
462     bool IsTreeString() const;
463     bool IsSlicedString() const;
464     bool IsStringOrSymbol() const;
465     bool IsLexicalEnv() const;
466     bool IsTaggedArray() const;
467     bool IsDictionary() const;
468     bool IsByteArray() const;
469     bool IsConstantPool() const;
470     bool IsAOTLiteralInfo() const;
471     bool IsVTable() const;
472     bool IsLinkedNode() const;
473     bool IsRBTreeNode() const;
474     bool IsNativePointer() const;
475     bool IsJSNativePointer() const;
476     bool CheckIsJSNativePointer() const;
477     bool IsBoolean() const;
478     bool IsSymbol() const;
479     bool IsJSObject() const;
480     bool IsOnlyJSObject() const;
481     bool IsJSGlobalObject() const;
482     bool IsJSError() const;
483     bool IsArray(JSThread *thread) const;
484     bool IsCOWArray() const;
485     bool IsMutantTaggedArray() const;
486     bool IsJSArray() const;
487     bool IsJSCOWArray() const;
488     bool IsStableJSArray(JSThread *thread) const;
489     bool IsStableJSArguments(JSThread *thread) const;
490     bool HasStableElements(JSThread *thread) const;
491     bool IsTypedArray() const;
492     bool IsJSTypedArray() const;
493     bool IsJSInt8Array() const;
494     bool IsJSUint8Array() const;
495     bool IsJSUint8ClampedArray() const;
496     bool IsJSInt16Array() const;
497     bool IsJSUint16Array() const;
498     bool IsJSInt32Array() const;
499     bool IsJSUint32Array() const;
500     bool IsJSFloat32Array() const;
501     bool IsJSFloat64Array() const;
502     bool IsJSBigInt64Array() const;
503     bool IsJSBigUint64Array() const;
504     bool IsArguments() const;
505     bool IsDate() const;
506     bool IsBoundFunction() const;
507     bool IsJSIntlBoundFunction() const;
508     bool IsProxyRevocFunction() const;
509     bool IsJSAsyncFunction() const;
510     bool IsJSAsyncAwaitStatusFunction() const;
511     bool IsClassConstructor() const;
512     bool IsClassPrototype() const;
513     bool IsJSFunction() const;
514     bool IsJSFunctionBase() const;
515     bool CheckIsJSFunctionBase() const;
516     bool IsECMAObject() const;
517     bool IsJSPrimitiveRef() const;
518     bool IsJSPrimitive() const;
519     bool IsAccessorData() const;
520     bool IsInternalAccessor() const;
521     bool IsAccessor() const;
522     bool IsJSGlobalEnv() const;
523     bool IsJSProxy() const;
524     bool CheckIsJSProxy() const;
525     bool IsJSHClass() const;
526     bool IsForinIterator() const;
527     bool IsStringIterator() const;
528     bool IsArrayBuffer() const;
529     bool IsSharedArrayBuffer() const;
530 
531     bool IsJSSetIterator() const;
532     bool IsJSRegExpIterator() const;
533     bool IsJSMapIterator() const;
534     bool IsJSArrayIterator() const;
535     bool IsIterator() const;
536     bool IsAsyncIterator() const;
537     bool IsGeneratorFunction() const;
538     bool IsAsyncGeneratorFunction() const;
539     bool IsGeneratorObject() const;
540     bool IsGeneratorContext() const;
541     bool IsAsyncGeneratorRequest() const;
542     bool IsAsyncIteratorRecord() const;
543     bool IsAsyncFromSyncIterator() const;
544     bool IsAsyncGeneratorObject() const;
545     bool IsAsyncFuncObject() const;
546     bool IsJSPromise() const;
547     bool IsRecord() const;
548     bool IsPromiseReaction() const;
549     bool IsProgram() const;
550     bool IsJSPromiseReactionFunction() const;
551     bool IsJSPromiseExecutorFunction() const;
552     bool IsJSAsyncModuleFulfilledFunction() const;
553     bool IsJSAsyncModuleRejectedFunction() const;
554     bool IsJSAsyncFromSyncIterUnwarpFunction() const;
555     bool IsJSPromiseAllResolveElementFunction() const;
556     bool IsJSAsyncGeneratorResNextRetProRstFtn() const;
557     bool IsPromiseCapability() const;
558     bool IsPromiseIteratorRecord() const;
559     bool IsPromiseRecord() const;
560     bool IsJSPromiseAnyRejectElementFunction() const;
561     bool IsJSPromiseAllSettledElementFunction() const;
562     bool IsJSPromiseFinallyFunction() const;
563     bool IsJSPromiseValueThunkOrThrowerFunction() const;
564     bool IsResolvingFunctionsRecord() const;
565     bool IsCompletionRecord() const;
566     bool IsDataView() const;
567     bool IsTemplateMap() const;
568     bool IsMicroJobQueue() const;
569     bool IsPendingJob() const;
570     bool IsJSLocale() const;
571     bool IsJSDateTimeFormat() const;
572     bool IsJSRelativeTimeFormat() const;
573     bool IsJSIntl() const;
574     bool IsJSNumberFormat() const;
575     bool IsJSCollator() const;
576     bool IsJSPluralRules() const;
577     bool IsJSDisplayNames() const;
578     bool IsJSListFormat() const;
579     bool IsMethod() const;
580     bool IsClassLiteral() const;
581 
582     // non ECMA standard jsapis
583     bool IsJSAPIArrayList() const;
584     bool IsJSAPIArrayListIterator() const;
585     bool IsJSAPIHashMap() const;
586     bool IsJSAPIHashMapIterator() const;
587     bool IsJSAPIHashSet() const;
588     bool IsJSAPIHashSetIterator() const;
589     bool IsJSAPILightWeightMap() const;
590     bool IsJSAPILightWeightMapIterator() const;
591     bool IsJSAPILightWeightSet() const;
592     bool IsJSAPILightWeightSetIterator() const;
593     bool IsJSAPITreeMap() const;
594     bool IsJSAPITreeSet() const;
595     bool IsJSAPITreeMapIterator() const;
596     bool IsJSAPITreeSetIterator() const;
597     bool IsJSAPIVector() const;
598     bool IsJSAPIVectorIterator() const;
599     bool IsJSAPIQueue() const;
600     bool IsJSAPIQueueIterator() const;
601     bool IsJSAPIPlainArray() const;
602     bool IsJSAPIPlainArrayIterator() const;
603     bool IsJSAPIDeque() const;
604     bool IsJSAPIDequeIterator() const;
605     bool IsJSAPIStack() const;
606     bool IsJSAPIStackIterator() const;
607     bool IsJSAPIList() const;
608     bool IsJSAPILinkedList() const;
609     bool IsJSAPIListIterator() const;
610     bool IsJSAPILinkedListIterator() const;
611     bool IsSpecialContainer() const;
612     bool HasOrdinaryGet() const;
613     bool IsPrototypeHandler() const;
614     bool IsTransitionHandler() const;
615     bool IsTransWithProtoHandler() const;
616     bool IsStoreTSHandler() const;
617     bool IsPropertyBox() const;
618     bool IsProtoChangeMarker() const;
619     bool IsProtoChangeDetails() const;
620     bool IsMarkerCell() const;
621     bool IsTrackInfoObject() const;
622     bool IsSpecialKeysObject() const;
623     bool IsSlowKeysObject() const;
624     bool IsRegularObject() const;
625     bool IsMachineCodeObject() const;
626     bool IsClassInfoExtractor() const;
627     bool IsTSType() const;
628     bool IsTSObjectType() const;
629     bool IsTSClassType() const;
630     bool IsTSUnionType() const;
631     bool IsTSInterfaceType() const;
632     bool IsTSClassInstanceType() const;
633     bool IsTSFunctionType() const;
634     bool IsTSArrayType() const;
635     bool IsTSIteratorInstanceType() const;
636     bool IsTSNamespaceType() const;
637 
638     bool IsCjsExports() const;
639     bool IsCjsModule() const;
640     bool IsCjsRequire() const;
641     bool IsModuleRecord() const;
642     bool IsSourceTextModule() const;
643     bool IsImportEntry() const;
644     bool IsLocalExportEntry() const;
645     bool IsIndirectExportEntry() const;
646     bool IsStarExportEntry() const;
647     bool IsResolvedBinding() const;
648     bool IsResolvedIndexBinding() const;
649     bool IsModuleNamespace() const;
650     bool IsJSSharedObject() const;
651     bool IsJSSharedFunction() const;
652     bool IsJSShared() const;
653     static bool IsSameTypeOrHClass(JSTaggedValue x, JSTaggedValue y);
654 
655     static ComparisonResult Compare(JSThread *thread, const JSHandle<JSTaggedValue> &x,
656                                     const JSHandle<JSTaggedValue> &y);
657     static int IntLexicographicCompare(JSTaggedValue x, JSTaggedValue y);
658     static ComparisonResult StrictNumberCompare(double x, double y);
659     static bool StrictNumberEquals(double x, double y);
660     static bool StrictIntEquals(int x, int y);
661     static bool StringCompare(EcmaString *xStr, EcmaString *yStr);
662 
663     static JSHandle<JSTaggedValue> ToPrototypeOrObj(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
664     inline uint32_t GetKeyHashCode() const;
665     static JSTaggedValue GetSuperBase(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
666     static JSTaggedValue TryCastDoubleToInt32(double d);
667 
668     void DumpTaggedValue(std::ostream &os) const DUMP_API_ATTR;
669     void Dump(std::ostream &os) const DUMP_API_ATTR;
670     void D() const DUMP_API_ATTR;
671     void DumpForSnapshot(std::vector<Reference> &vec, bool isVmMode = true) const;
672     static void DV(JSTaggedType val) DUMP_API_ATTR;
673 
674 private:
675     JSTaggedType value_;
676 
677     inline double ExtractNumber() const;
678 
679     void DumpSpecialValue(std::ostream &os) const;
680     void DumpHeapObjectType(std::ostream &os) const;
681 
682     // non ECMA standard jsapis
683     static bool HasContainerProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
684                                      const JSHandle<JSTaggedValue> &key);
685     static JSHandle<TaggedArray> GetOwnContainerPropertyKeys(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
686     static JSHandle<TaggedArray> GetOwnContainerEnumPropertyKeys(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
687     static bool GetContainerProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
688                                      const JSHandle<JSTaggedValue> &key, PropertyDescriptor &desc);
689     static OperationResult GetJSAPIProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
690                                             const JSHandle<JSTaggedValue> &key);
691     static bool SetJSAPIProperty(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
692                                  const JSHandle<JSTaggedValue> &key,
693                                  const JSHandle<JSTaggedValue> &value);
694     static JSHandle<EcmaString> NativePointerToString(JSThread *thread, const JSHandle<JSTaggedValue> &tagged);
695 };
696 STATIC_ASSERT_EQ_ARCH(sizeof(JSTaggedValue), JSTaggedValue::SizeArch32, JSTaggedValue::SizeArch64);
697 }  // namespace panda::ecmascript
698 #endif  // ECMASCRIPT_JS_TAGGED_VALUE_H
699