14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_NAPI_INCLUDE_JSNAPI_EXPO_H
174514f5e3Sopenharmony_ci#define ECMASCRIPT_NAPI_INCLUDE_JSNAPI_EXPO_H
184514f5e3Sopenharmony_ci
194514f5e3Sopenharmony_ci#include <cassert>
204514f5e3Sopenharmony_ci#include <cstdint>
214514f5e3Sopenharmony_ci#include <functional>
224514f5e3Sopenharmony_ci#include <memory>
234514f5e3Sopenharmony_ci#include <map>
244514f5e3Sopenharmony_ci#include <shared_mutex>
254514f5e3Sopenharmony_ci#include <string>
264514f5e3Sopenharmony_ci#include <unordered_map>
274514f5e3Sopenharmony_ci#include <vector>
284514f5e3Sopenharmony_ci
294514f5e3Sopenharmony_ci#include "ecmascript/base/aligned_struct.h"
304514f5e3Sopenharmony_ci#include "ecmascript/base/config.h"
314514f5e3Sopenharmony_ci#include "ecmascript/mem/mem_common.h"
324514f5e3Sopenharmony_ci#include "ecmascript/common_enum.h"
334514f5e3Sopenharmony_ci
344514f5e3Sopenharmony_ci#ifndef NDEBUG
354514f5e3Sopenharmony_ci#include "libpandabase/utils/debug.h"
364514f5e3Sopenharmony_ci#endif
374514f5e3Sopenharmony_ci
384514f5e3Sopenharmony_ci#ifdef ERROR
394514f5e3Sopenharmony_ci#undef ERROR
404514f5e3Sopenharmony_ci#endif
414514f5e3Sopenharmony_ci
424514f5e3Sopenharmony_cinamespace panda {
434514f5e3Sopenharmony_ciclass JSNApiHelper;
444514f5e3Sopenharmony_ciclass EscapeLocalScope;
454514f5e3Sopenharmony_ciclass PromiseRejectInfo;
464514f5e3Sopenharmony_citemplate<typename T>
474514f5e3Sopenharmony_ciclass CopyableGlobal;
484514f5e3Sopenharmony_citemplate<typename T>
494514f5e3Sopenharmony_ciclass Global;
504514f5e3Sopenharmony_ciclass JSNApi;
514514f5e3Sopenharmony_ciclass SymbolRef;
524514f5e3Sopenharmony_citemplate<typename T>
534514f5e3Sopenharmony_ciclass Local;
544514f5e3Sopenharmony_ciclass JSValueRef;
554514f5e3Sopenharmony_ciclass PrimitiveRef;
564514f5e3Sopenharmony_ciclass ArrayRef;
574514f5e3Sopenharmony_ciclass BigIntRef;
584514f5e3Sopenharmony_ciclass StringRef;
594514f5e3Sopenharmony_ciclass ObjectRef;
604514f5e3Sopenharmony_ciclass FunctionRef;
614514f5e3Sopenharmony_ciclass NumberRef;
624514f5e3Sopenharmony_ciclass MapIteratorRef;
634514f5e3Sopenharmony_ciclass SendableMapIteratorRef;
644514f5e3Sopenharmony_ciclass BooleanRef;
654514f5e3Sopenharmony_ciclass NativePointerRef;
664514f5e3Sopenharmony_ciclass TypedArrayRef;
674514f5e3Sopenharmony_ciclass JsiRuntimeCallInfo;
684514f5e3Sopenharmony_ciclass RuntimeOption;
694514f5e3Sopenharmony_cinamespace test {
704514f5e3Sopenharmony_ciclass JSNApiTests;
714514f5e3Sopenharmony_ci}  // namespace test
724514f5e3Sopenharmony_ciclass BufferRef;
734514f5e3Sopenharmony_cinamespace ecmascript {
744514f5e3Sopenharmony_ciclass EcmaVM;
754514f5e3Sopenharmony_ciclass JSTaggedValue;
764514f5e3Sopenharmony_ciclass EcmaContext;
774514f5e3Sopenharmony_ciclass JSRuntimeOptions;
784514f5e3Sopenharmony_ciclass JSThread;
794514f5e3Sopenharmony_cistruct EcmaRuntimeCallInfo;
804514f5e3Sopenharmony_cinamespace base {
814514f5e3Sopenharmony_citemplate<size_t ElementAlign, typename... Ts>
824514f5e3Sopenharmony_cistruct AlignedStruct;
834514f5e3Sopenharmony_cistruct AlignedPointer;
844514f5e3Sopenharmony_ci}
854514f5e3Sopenharmony_cinamespace job {
864514f5e3Sopenharmony_cienum class QueueType : uint8_t {
874514f5e3Sopenharmony_ci    QUEUE_PROMISE,
884514f5e3Sopenharmony_ci    QUEUE_SCRIPT,
894514f5e3Sopenharmony_ci};
904514f5e3Sopenharmony_ci}
914514f5e3Sopenharmony_ci}  // namespace ecmascript
924514f5e3Sopenharmony_ci
934514f5e3Sopenharmony_cistruct HmsMap {
944514f5e3Sopenharmony_ci    std::string originalPath;
954514f5e3Sopenharmony_ci    std::string targetPath;
964514f5e3Sopenharmony_ci    uint32_t sinceVersion;
974514f5e3Sopenharmony_ci};
984514f5e3Sopenharmony_ci
994514f5e3Sopenharmony_ciusing WeakRefClearCallBack = void (*)(void *);
1004514f5e3Sopenharmony_ciusing WeakFinalizeTaskCallback = std::function<void()>;
1014514f5e3Sopenharmony_ciusing NativePointerCallback = void (*)(void *env, void* data, void* hint);
1024514f5e3Sopenharmony_ciusing NativePointerCallbackFinishNotify = std::function<void(size_t totalBindSize_)>;
1034514f5e3Sopenharmony_ciusing NativePointerCallbackData = std::pair<NativePointerCallback, std::tuple<void*, void*, void*>>;
1044514f5e3Sopenharmony_ciusing TriggerGCData = std::pair<void*, uint8_t>;
1054514f5e3Sopenharmony_ciusing TriggerGCTaskCallback = std::function<void(TriggerGCData& data)>;
1064514f5e3Sopenharmony_ciusing StartIdleMonitorCallback = std::function<void()>;
1074514f5e3Sopenharmony_ciusing EcmaVM = ecmascript::EcmaVM;
1084514f5e3Sopenharmony_ciusing EcmaContext = ecmascript::EcmaContext;
1094514f5e3Sopenharmony_ciusing JSThread = ecmascript::JSThread;
1104514f5e3Sopenharmony_ciusing JSTaggedType = uint64_t;
1114514f5e3Sopenharmony_ciusing ConcurrentCallback = void (*)(Local<JSValueRef> result, bool success, void *taskInfo, void *data);
1124514f5e3Sopenharmony_ciusing SourceMapCallback = std::function<std::string(const std::string& rawStack)>;
1134514f5e3Sopenharmony_ciusing SourceMapTranslateCallback = std::function<bool(std::string& url, int& line, int& column)>;
1144514f5e3Sopenharmony_ciusing DeviceDisconnectCallback = std::function<bool()>;
1154514f5e3Sopenharmony_ciusing QueueType = ecmascript::job::QueueType;
1164514f5e3Sopenharmony_ci
1174514f5e3Sopenharmony_ci#define ECMA_DISALLOW_COPY(className)      \
1184514f5e3Sopenharmony_ci    className(const className &) = delete; \
1194514f5e3Sopenharmony_ci    className &operator=(const className &) = delete
1204514f5e3Sopenharmony_ci
1214514f5e3Sopenharmony_ci#define ECMA_DISALLOW_MOVE(className) \
1224514f5e3Sopenharmony_ci    className(className &&) = delete; \
1234514f5e3Sopenharmony_ci    className &operator=(className &&) = delete
1244514f5e3Sopenharmony_ci
1254514f5e3Sopenharmony_ci#ifdef PANDA_TARGET_WINDOWS
1264514f5e3Sopenharmony_ci#define ECMA_PUBLIC_API __declspec(dllexport)
1274514f5e3Sopenharmony_ci#else
1284514f5e3Sopenharmony_ci#define ECMA_PUBLIC_API __attribute__((visibility ("default")))
1294514f5e3Sopenharmony_ci#endif
1304514f5e3Sopenharmony_ci
1314514f5e3Sopenharmony_ci#ifndef NDEBUG
1324514f5e3Sopenharmony_ci#define ECMA_ASSERT(cond) \
1334514f5e3Sopenharmony_ci    if (!(cond)) { \
1344514f5e3Sopenharmony_ci        panda::debug::AssertionFail(#cond, __FILE__, __LINE__, __FUNCTION__); \
1354514f5e3Sopenharmony_ci    }
1364514f5e3Sopenharmony_ci#else
1374514f5e3Sopenharmony_ci#define ECMA_ASSERT(cond) static_cast<void>(0)
1384514f5e3Sopenharmony_ci#endif
1394514f5e3Sopenharmony_ci
1404514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API AsyncNativeCallbacksPack {
1414514f5e3Sopenharmony_cipublic:
1424514f5e3Sopenharmony_ci    AsyncNativeCallbacksPack() = default;
1434514f5e3Sopenharmony_ci    ~AsyncNativeCallbacksPack() = default;
1444514f5e3Sopenharmony_ci    AsyncNativeCallbacksPack(AsyncNativeCallbacksPack&&) = default;
1454514f5e3Sopenharmony_ci    AsyncNativeCallbacksPack& operator=(AsyncNativeCallbacksPack&&) = default;
1464514f5e3Sopenharmony_ci    AsyncNativeCallbacksPack(const AsyncNativeCallbacksPack &) = default;
1474514f5e3Sopenharmony_ci    AsyncNativeCallbacksPack &operator=(const AsyncNativeCallbacksPack &) = default;
1484514f5e3Sopenharmony_ci
1494514f5e3Sopenharmony_ci    void Clear()
1504514f5e3Sopenharmony_ci    {
1514514f5e3Sopenharmony_ci        callBacks_.clear();
1524514f5e3Sopenharmony_ci        totalBindingSize_ = 0;
1534514f5e3Sopenharmony_ci        notify_ = nullptr;
1544514f5e3Sopenharmony_ci    }
1554514f5e3Sopenharmony_ci
1564514f5e3Sopenharmony_ci    bool TotallyEmpty() const
1574514f5e3Sopenharmony_ci    {
1584514f5e3Sopenharmony_ci        return callBacks_.empty() && totalBindingSize_ == 0 && notify_ == nullptr;
1594514f5e3Sopenharmony_ci    }
1604514f5e3Sopenharmony_ci
1614514f5e3Sopenharmony_ci    bool Empty() const
1624514f5e3Sopenharmony_ci    {
1634514f5e3Sopenharmony_ci        return callBacks_.empty();
1644514f5e3Sopenharmony_ci    }
1654514f5e3Sopenharmony_ci
1664514f5e3Sopenharmony_ci    void RegisterFinishNotify(NativePointerCallbackFinishNotify notify)
1674514f5e3Sopenharmony_ci    {
1684514f5e3Sopenharmony_ci        notify_ = notify;
1694514f5e3Sopenharmony_ci    }
1704514f5e3Sopenharmony_ci
1714514f5e3Sopenharmony_ci    size_t GetNumCallBacks() const
1724514f5e3Sopenharmony_ci    {
1734514f5e3Sopenharmony_ci        return callBacks_.size();
1744514f5e3Sopenharmony_ci    }
1754514f5e3Sopenharmony_ci
1764514f5e3Sopenharmony_ci    void ProcessAll()
1774514f5e3Sopenharmony_ci    {
1784514f5e3Sopenharmony_ci        for (auto &iter : callBacks_) {
1794514f5e3Sopenharmony_ci            NativePointerCallback callback = iter.first;
1804514f5e3Sopenharmony_ci            std::tuple<void*, void*, void*> &param = iter.second;
1814514f5e3Sopenharmony_ci            if (callback != nullptr) {
1824514f5e3Sopenharmony_ci                callback(std::get<0>(param), std::get<1>(param), std::get<2>(param)); // 2 is the param.
1834514f5e3Sopenharmony_ci            }
1844514f5e3Sopenharmony_ci        }
1854514f5e3Sopenharmony_ci        NotifyFinish();
1864514f5e3Sopenharmony_ci    }
1874514f5e3Sopenharmony_ci
1884514f5e3Sopenharmony_ci    size_t GetTotalBindingSize() const
1894514f5e3Sopenharmony_ci    {
1904514f5e3Sopenharmony_ci        return totalBindingSize_;
1914514f5e3Sopenharmony_ci    }
1924514f5e3Sopenharmony_ci
1934514f5e3Sopenharmony_ci    void AddCallback(NativePointerCallbackData callback, size_t bindingSize)
1944514f5e3Sopenharmony_ci    {
1954514f5e3Sopenharmony_ci        callBacks_.emplace_back(callback);
1964514f5e3Sopenharmony_ci        totalBindingSize_ += bindingSize;
1974514f5e3Sopenharmony_ci    }
1984514f5e3Sopenharmony_ciprivate:
1994514f5e3Sopenharmony_ci    void NotifyFinish() const
2004514f5e3Sopenharmony_ci    {
2014514f5e3Sopenharmony_ci        if (notify_ != nullptr) {
2024514f5e3Sopenharmony_ci            notify_(totalBindingSize_);
2034514f5e3Sopenharmony_ci        }
2044514f5e3Sopenharmony_ci    }
2054514f5e3Sopenharmony_ci
2064514f5e3Sopenharmony_ci    std::vector<NativePointerCallbackData> callBacks_ {};
2074514f5e3Sopenharmony_ci    size_t totalBindingSize_ {0};
2084514f5e3Sopenharmony_ci    NativePointerCallbackFinishNotify notify_ {nullptr};
2094514f5e3Sopenharmony_ci};
2104514f5e3Sopenharmony_ciusing NativePointerTaskCallback = std::function<void(AsyncNativeCallbacksPack *callbacksPack)>;
2114514f5e3Sopenharmony_ci
2124514f5e3Sopenharmony_citemplate<typename T>
2134514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API Local {  // NOLINT(cppcoreguidelines-special-member-functions, hicpp-special-member-functions)
2144514f5e3Sopenharmony_cipublic:
2154514f5e3Sopenharmony_ci    inline Local() = default;
2164514f5e3Sopenharmony_ci
2174514f5e3Sopenharmony_ci    template<typename S>
2184514f5e3Sopenharmony_ci    inline Local(const Local<S> &current) : address_(reinterpret_cast<uintptr_t>(*current))
2194514f5e3Sopenharmony_ci    {
2204514f5e3Sopenharmony_ci        // Check
2214514f5e3Sopenharmony_ci    }
2224514f5e3Sopenharmony_ci
2234514f5e3Sopenharmony_ci    Local(const EcmaVM *vm, const Global<T> &current);
2244514f5e3Sopenharmony_ci
2254514f5e3Sopenharmony_ci    Local(const EcmaVM *vm, const CopyableGlobal<T> &current);
2264514f5e3Sopenharmony_ci
2274514f5e3Sopenharmony_ci    ~Local() = default;
2284514f5e3Sopenharmony_ci
2294514f5e3Sopenharmony_ci    inline T *operator*() const
2304514f5e3Sopenharmony_ci    {
2314514f5e3Sopenharmony_ci        return GetAddress();
2324514f5e3Sopenharmony_ci    }
2334514f5e3Sopenharmony_ci
2344514f5e3Sopenharmony_ci    inline T *operator->() const
2354514f5e3Sopenharmony_ci    {
2364514f5e3Sopenharmony_ci        return GetAddress();
2374514f5e3Sopenharmony_ci    }
2384514f5e3Sopenharmony_ci
2394514f5e3Sopenharmony_ci    inline bool IsEmpty() const
2404514f5e3Sopenharmony_ci    {
2414514f5e3Sopenharmony_ci        return GetAddress() == nullptr;
2424514f5e3Sopenharmony_ci    }
2434514f5e3Sopenharmony_ci
2444514f5e3Sopenharmony_ci    inline void Empty()
2454514f5e3Sopenharmony_ci    {
2464514f5e3Sopenharmony_ci        address_ = 0;
2474514f5e3Sopenharmony_ci    }
2484514f5e3Sopenharmony_ci
2494514f5e3Sopenharmony_ci    inline bool IsNull() const
2504514f5e3Sopenharmony_ci    {
2514514f5e3Sopenharmony_ci        return IsEmpty() || GetAddress()->IsHole();
2524514f5e3Sopenharmony_ci    }
2534514f5e3Sopenharmony_ci
2544514f5e3Sopenharmony_ci    explicit inline Local(uintptr_t addr) : address_(addr) {}
2554514f5e3Sopenharmony_ci
2564514f5e3Sopenharmony_ciprivate:
2574514f5e3Sopenharmony_ci    inline T *GetAddress() const
2584514f5e3Sopenharmony_ci    {
2594514f5e3Sopenharmony_ci        return reinterpret_cast<T *>(address_);
2604514f5e3Sopenharmony_ci    };
2614514f5e3Sopenharmony_ci    uintptr_t address_ = 0U;
2624514f5e3Sopenharmony_ci    friend JSNApiHelper;
2634514f5e3Sopenharmony_ci    friend EscapeLocalScope;
2644514f5e3Sopenharmony_ci    friend JsiRuntimeCallInfo;
2654514f5e3Sopenharmony_ci};
2664514f5e3Sopenharmony_ci
2674514f5e3Sopenharmony_ci/**
2684514f5e3Sopenharmony_ci * A Copyable global handle, keeps a separate global handle for each CopyableGlobal.
2694514f5e3Sopenharmony_ci *
2704514f5e3Sopenharmony_ci * Support Copy Constructor and Assign, Move Constructor And Assign.
2714514f5e3Sopenharmony_ci *
2724514f5e3Sopenharmony_ci * If destructed, the global handle held will be automatically released.
2734514f5e3Sopenharmony_ci *
2744514f5e3Sopenharmony_ci * Usage: It Can be used as heap object assign to another variable, a value passing parameter, or
2754514f5e3Sopenharmony_ci *        a value passing return value and so on.
2764514f5e3Sopenharmony_ci */
2774514f5e3Sopenharmony_citemplate<typename T>
2784514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API CopyableGlobal {
2794514f5e3Sopenharmony_cipublic:
2804514f5e3Sopenharmony_ci    inline CopyableGlobal() = default;
2814514f5e3Sopenharmony_ci    ~CopyableGlobal()
2824514f5e3Sopenharmony_ci    {
2834514f5e3Sopenharmony_ci        Free();
2844514f5e3Sopenharmony_ci    }
2854514f5e3Sopenharmony_ci
2864514f5e3Sopenharmony_ci    inline CopyableGlobal(const CopyableGlobal &that)
2874514f5e3Sopenharmony_ci    {
2884514f5e3Sopenharmony_ci        Copy(that);
2894514f5e3Sopenharmony_ci    }
2904514f5e3Sopenharmony_ci
2914514f5e3Sopenharmony_ci    inline CopyableGlobal &operator=(const CopyableGlobal &that)
2924514f5e3Sopenharmony_ci    {
2934514f5e3Sopenharmony_ci        Copy(that);
2944514f5e3Sopenharmony_ci        return *this;
2954514f5e3Sopenharmony_ci    }
2964514f5e3Sopenharmony_ci
2974514f5e3Sopenharmony_ci    inline CopyableGlobal(CopyableGlobal &&that)
2984514f5e3Sopenharmony_ci    {
2994514f5e3Sopenharmony_ci        Move(that);
3004514f5e3Sopenharmony_ci    }
3014514f5e3Sopenharmony_ci
3024514f5e3Sopenharmony_ci    inline CopyableGlobal &operator=(CopyableGlobal &&that)
3034514f5e3Sopenharmony_ci    {
3044514f5e3Sopenharmony_ci        Move(that);
3054514f5e3Sopenharmony_ci        return *this;
3064514f5e3Sopenharmony_ci    }
3074514f5e3Sopenharmony_ci
3084514f5e3Sopenharmony_ci    template<typename S>
3094514f5e3Sopenharmony_ci    CopyableGlobal(const EcmaVM *vm, const Local<S> &current);
3104514f5e3Sopenharmony_ci
3114514f5e3Sopenharmony_ci    CopyableGlobal(const EcmaVM *vm, const Local<T> &current);
3124514f5e3Sopenharmony_ci
3134514f5e3Sopenharmony_ci    template<typename S>
3144514f5e3Sopenharmony_ci    CopyableGlobal(const CopyableGlobal<S> &that)
3154514f5e3Sopenharmony_ci    {
3164514f5e3Sopenharmony_ci        Copy(that);
3174514f5e3Sopenharmony_ci    }
3184514f5e3Sopenharmony_ci
3194514f5e3Sopenharmony_ci    void Reset()
3204514f5e3Sopenharmony_ci    {
3214514f5e3Sopenharmony_ci        Free();
3224514f5e3Sopenharmony_ci    }
3234514f5e3Sopenharmony_ci
3244514f5e3Sopenharmony_ci    Local<T> ToLocal() const
3254514f5e3Sopenharmony_ci    {
3264514f5e3Sopenharmony_ci        if (IsEmpty()) {
3274514f5e3Sopenharmony_ci            return Local<T>();
3284514f5e3Sopenharmony_ci        }
3294514f5e3Sopenharmony_ci        return Local<T>(vm_, *this);
3304514f5e3Sopenharmony_ci    }
3314514f5e3Sopenharmony_ci
3324514f5e3Sopenharmony_ci    void Empty()
3334514f5e3Sopenharmony_ci    {
3344514f5e3Sopenharmony_ci        address_ = 0;
3354514f5e3Sopenharmony_ci    }
3364514f5e3Sopenharmony_ci
3374514f5e3Sopenharmony_ci    inline T *operator*() const
3384514f5e3Sopenharmony_ci    {
3394514f5e3Sopenharmony_ci        return GetAddress();
3404514f5e3Sopenharmony_ci    }
3414514f5e3Sopenharmony_ci
3424514f5e3Sopenharmony_ci    inline T *operator->() const
3434514f5e3Sopenharmony_ci    {
3444514f5e3Sopenharmony_ci        return GetAddress();
3454514f5e3Sopenharmony_ci    }
3464514f5e3Sopenharmony_ci
3474514f5e3Sopenharmony_ci    inline bool IsEmpty() const
3484514f5e3Sopenharmony_ci    {
3494514f5e3Sopenharmony_ci        return GetAddress() == nullptr;
3504514f5e3Sopenharmony_ci    }
3514514f5e3Sopenharmony_ci
3524514f5e3Sopenharmony_ci    void SetWeakCallback(void *ref, WeakRefClearCallBack freeGlobalCallBack,
3534514f5e3Sopenharmony_ci                         WeakRefClearCallBack nativeFinalizeCallback);
3544514f5e3Sopenharmony_ci    void SetWeak();
3554514f5e3Sopenharmony_ci
3564514f5e3Sopenharmony_ci    void ClearWeak();
3574514f5e3Sopenharmony_ci
3584514f5e3Sopenharmony_ci    bool IsWeak() const;
3594514f5e3Sopenharmony_ci
3604514f5e3Sopenharmony_ci    const EcmaVM *GetEcmaVM() const
3614514f5e3Sopenharmony_ci    {
3624514f5e3Sopenharmony_ci        return vm_;
3634514f5e3Sopenharmony_ci    }
3644514f5e3Sopenharmony_ci
3654514f5e3Sopenharmony_ciprivate:
3664514f5e3Sopenharmony_ci    inline T *GetAddress() const
3674514f5e3Sopenharmony_ci    {
3684514f5e3Sopenharmony_ci        return reinterpret_cast<T *>(address_);
3694514f5e3Sopenharmony_ci    };
3704514f5e3Sopenharmony_ci    inline void Copy(const CopyableGlobal &that);
3714514f5e3Sopenharmony_ci    template<typename S>
3724514f5e3Sopenharmony_ci    inline void Copy(const CopyableGlobal<S> &that);
3734514f5e3Sopenharmony_ci    inline void Move(CopyableGlobal &that);
3744514f5e3Sopenharmony_ci    inline void Free();
3754514f5e3Sopenharmony_ci    uintptr_t address_ = 0U;
3764514f5e3Sopenharmony_ci    const EcmaVM *vm_ {nullptr};
3774514f5e3Sopenharmony_ci};
3784514f5e3Sopenharmony_ci
3794514f5e3Sopenharmony_citemplate<typename T>
3804514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API Global {  // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions
3814514f5e3Sopenharmony_cipublic:
3824514f5e3Sopenharmony_ci    inline Global() = default;
3834514f5e3Sopenharmony_ci
3844514f5e3Sopenharmony_ci    inline Global(const Global &that)
3854514f5e3Sopenharmony_ci    {
3864514f5e3Sopenharmony_ci        Update(that);
3874514f5e3Sopenharmony_ci    }
3884514f5e3Sopenharmony_ci
3894514f5e3Sopenharmony_ci    inline Global &operator=(const Global &that)
3904514f5e3Sopenharmony_ci    {
3914514f5e3Sopenharmony_ci        Update(that);
3924514f5e3Sopenharmony_ci        return *this;
3934514f5e3Sopenharmony_ci    }
3944514f5e3Sopenharmony_ci
3954514f5e3Sopenharmony_ci    inline Global(Global &&that)
3964514f5e3Sopenharmony_ci    {
3974514f5e3Sopenharmony_ci        Update(that);
3984514f5e3Sopenharmony_ci    }
3994514f5e3Sopenharmony_ci
4004514f5e3Sopenharmony_ci    inline Global &operator=(Global &&that)
4014514f5e3Sopenharmony_ci    {
4024514f5e3Sopenharmony_ci        Update(that);
4034514f5e3Sopenharmony_ci        return *this;
4044514f5e3Sopenharmony_ci    }
4054514f5e3Sopenharmony_ci
4064514f5e3Sopenharmony_ci    template<typename S>
4074514f5e3Sopenharmony_ci    Global(const EcmaVM *vm, const Local<S> &current);
4084514f5e3Sopenharmony_ci    template<typename S>
4094514f5e3Sopenharmony_ci    Global(const EcmaVM *vm, const Global<S> &current);
4104514f5e3Sopenharmony_ci
4114514f5e3Sopenharmony_ci    ~Global() = default;
4124514f5e3Sopenharmony_ci
4134514f5e3Sopenharmony_ci    Local<T> ToLocal() const
4144514f5e3Sopenharmony_ci    {
4154514f5e3Sopenharmony_ci        if (IsEmpty()) {
4164514f5e3Sopenharmony_ci            return Local<T>();
4174514f5e3Sopenharmony_ci        }
4184514f5e3Sopenharmony_ci        return Local<T>(vm_, *this);
4194514f5e3Sopenharmony_ci    }
4204514f5e3Sopenharmony_ci
4214514f5e3Sopenharmony_ci    Local<T> ToLocal(const EcmaVM *vm) const
4224514f5e3Sopenharmony_ci    {
4234514f5e3Sopenharmony_ci        return Local<T>(vm, *this);
4244514f5e3Sopenharmony_ci    }
4254514f5e3Sopenharmony_ci
4264514f5e3Sopenharmony_ci    void Empty()
4274514f5e3Sopenharmony_ci    {
4284514f5e3Sopenharmony_ci        address_ = 0;
4294514f5e3Sopenharmony_ci    }
4304514f5e3Sopenharmony_ci
4314514f5e3Sopenharmony_ci    // This method must be called before Global is released.
4324514f5e3Sopenharmony_ci    void FreeGlobalHandleAddr();
4334514f5e3Sopenharmony_ci
4344514f5e3Sopenharmony_ci    inline T *operator*() const
4354514f5e3Sopenharmony_ci    {
4364514f5e3Sopenharmony_ci        return GetAddress();
4374514f5e3Sopenharmony_ci    }
4384514f5e3Sopenharmony_ci
4394514f5e3Sopenharmony_ci    inline T *operator->() const
4404514f5e3Sopenharmony_ci    {
4414514f5e3Sopenharmony_ci        return GetAddress();
4424514f5e3Sopenharmony_ci    }
4434514f5e3Sopenharmony_ci
4444514f5e3Sopenharmony_ci    inline bool IsEmpty() const
4454514f5e3Sopenharmony_ci    {
4464514f5e3Sopenharmony_ci        return GetAddress() == nullptr;
4474514f5e3Sopenharmony_ci    }
4484514f5e3Sopenharmony_ci
4494514f5e3Sopenharmony_ci    void SetWeak();
4504514f5e3Sopenharmony_ci
4514514f5e3Sopenharmony_ci    void SetWeakCallback(void *ref, WeakRefClearCallBack freeGlobalCallBack,
4524514f5e3Sopenharmony_ci                         WeakRefClearCallBack nativeFinalizeCallback);
4534514f5e3Sopenharmony_ci
4544514f5e3Sopenharmony_ci    void ClearWeak();
4554514f5e3Sopenharmony_ci
4564514f5e3Sopenharmony_ci    bool IsWeak() const;
4574514f5e3Sopenharmony_ci
4584514f5e3Sopenharmony_ci    const EcmaVM *GetEcmaVM() const
4594514f5e3Sopenharmony_ci    {
4604514f5e3Sopenharmony_ci        return vm_;
4614514f5e3Sopenharmony_ci    }
4624514f5e3Sopenharmony_ci
4634514f5e3Sopenharmony_ciprivate:
4644514f5e3Sopenharmony_ci    inline T *GetAddress() const
4654514f5e3Sopenharmony_ci    {
4664514f5e3Sopenharmony_ci        return reinterpret_cast<T *>(address_);
4674514f5e3Sopenharmony_ci    };
4684514f5e3Sopenharmony_ci    inline void Update(const Global &that);
4694514f5e3Sopenharmony_ci    uintptr_t address_ = 0U;
4704514f5e3Sopenharmony_ci    const EcmaVM *vm_ {nullptr};
4714514f5e3Sopenharmony_ci};
4724514f5e3Sopenharmony_ci
4734514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API JSValueRef {
4744514f5e3Sopenharmony_cipublic:
4754514f5e3Sopenharmony_ci    static Local<PrimitiveRef> Undefined(const EcmaVM *vm);
4764514f5e3Sopenharmony_ci    static Local<PrimitiveRef> Null(const EcmaVM *vm);
4774514f5e3Sopenharmony_ci    static Local<PrimitiveRef> Hole(const EcmaVM *vm);
4784514f5e3Sopenharmony_ci    static Local<PrimitiveRef> True(const EcmaVM *vm);
4794514f5e3Sopenharmony_ci    static Local<PrimitiveRef> False(const EcmaVM *vm);
4804514f5e3Sopenharmony_ci
4814514f5e3Sopenharmony_ci    bool BooleaValue(const EcmaVM *vm);
4824514f5e3Sopenharmony_ci    int64_t IntegerValue(const EcmaVM *vm);
4834514f5e3Sopenharmony_ci    uint32_t Uint32Value(const EcmaVM *vm);
4844514f5e3Sopenharmony_ci    int32_t Int32Value(const EcmaVM *vm);
4854514f5e3Sopenharmony_ci    double GetValueDouble(bool &isNumber);
4864514f5e3Sopenharmony_ci    int32_t GetValueInt32(bool &isNumber);
4874514f5e3Sopenharmony_ci    uint32_t GetValueUint32(bool &isNumber);
4884514f5e3Sopenharmony_ci    int64_t GetValueInt64(bool &isNumber);
4894514f5e3Sopenharmony_ci    bool GetValueBool(bool &isBool);
4904514f5e3Sopenharmony_ci
4914514f5e3Sopenharmony_ci    Local<NumberRef> ToNumber(const EcmaVM *vm);
4924514f5e3Sopenharmony_ci    Local<BooleanRef> ToBoolean(const EcmaVM *vm);
4934514f5e3Sopenharmony_ci    Local<BigIntRef> ToBigInt(const EcmaVM *vm);
4944514f5e3Sopenharmony_ci    Local<StringRef> ToString(const EcmaVM *vm);
4954514f5e3Sopenharmony_ci    Local<ObjectRef> ToObject(const EcmaVM *vm);
4964514f5e3Sopenharmony_ci    Local<ObjectRef> ToEcmaObject(const EcmaVM *vm);
4974514f5e3Sopenharmony_ci    Local<NativePointerRef> ToNativePointer(const EcmaVM *vm);
4984514f5e3Sopenharmony_ci
4994514f5e3Sopenharmony_ci    bool IsUndefined();
5004514f5e3Sopenharmony_ci    bool IsNull();
5014514f5e3Sopenharmony_ci    bool IsHole();
5024514f5e3Sopenharmony_ci    bool IsTrue();
5034514f5e3Sopenharmony_ci    bool IsFalse();
5044514f5e3Sopenharmony_ci    bool IsNumber();
5054514f5e3Sopenharmony_ci    bool IsBigInt(const EcmaVM *vm);
5064514f5e3Sopenharmony_ci    bool IsInt();
5074514f5e3Sopenharmony_ci    bool WithinInt32();
5084514f5e3Sopenharmony_ci    bool IsBoolean();
5094514f5e3Sopenharmony_ci    bool IsString(const EcmaVM *vm);
5104514f5e3Sopenharmony_ci    bool IsSymbol(const EcmaVM *vm);
5114514f5e3Sopenharmony_ci    bool IsObject(const EcmaVM *vm);
5124514f5e3Sopenharmony_ci    bool IsArray(const EcmaVM *vm);
5134514f5e3Sopenharmony_ci    bool IsJSArray(const EcmaVM *vm);
5144514f5e3Sopenharmony_ci    bool IsConstructor(const EcmaVM *vm);
5154514f5e3Sopenharmony_ci    bool IsFunction(const EcmaVM *vm);
5164514f5e3Sopenharmony_ci
5174514f5e3Sopenharmony_ci    bool IsJSFunction(const EcmaVM *vm);
5184514f5e3Sopenharmony_ci    bool IsProxy(const EcmaVM *vm);
5194514f5e3Sopenharmony_ci    bool IsPromise(const EcmaVM *vm);
5204514f5e3Sopenharmony_ci    bool IsDataView(const EcmaVM *vm);
5214514f5e3Sopenharmony_ci    bool IsTypedArray(const EcmaVM *vm);
5224514f5e3Sopenharmony_ci    bool IsNativePointer(const EcmaVM *vm);
5234514f5e3Sopenharmony_ci    bool IsDate(const EcmaVM *vm);
5244514f5e3Sopenharmony_ci    bool IsError(const EcmaVM *vm);
5254514f5e3Sopenharmony_ci    bool IsMap(const EcmaVM *vm);
5264514f5e3Sopenharmony_ci    bool IsSet(const EcmaVM *vm);
5274514f5e3Sopenharmony_ci    bool IsWeakRef(const EcmaVM *vm);
5284514f5e3Sopenharmony_ci    bool IsWeakMap(const EcmaVM *vm);
5294514f5e3Sopenharmony_ci    bool IsWeakSet(const EcmaVM *vm);
5304514f5e3Sopenharmony_ci    bool IsRegExp(const EcmaVM *vm);
5314514f5e3Sopenharmony_ci    bool IsArrayIterator(const EcmaVM *vm);
5324514f5e3Sopenharmony_ci    bool IsStringIterator(const EcmaVM *vm);
5334514f5e3Sopenharmony_ci    bool IsSetIterator(const EcmaVM *vm);
5344514f5e3Sopenharmony_ci    bool IsMapIterator(const EcmaVM *vm);
5354514f5e3Sopenharmony_ci    bool IsArrayBuffer(const EcmaVM *vm);
5364514f5e3Sopenharmony_ci    bool IsBuffer(const EcmaVM *vm);
5374514f5e3Sopenharmony_ci    bool IsUint8Array(const EcmaVM *vm);
5384514f5e3Sopenharmony_ci    bool IsInt8Array(const EcmaVM *vm);
5394514f5e3Sopenharmony_ci    bool IsUint8ClampedArray(const EcmaVM *vm);
5404514f5e3Sopenharmony_ci    bool IsInt16Array(const EcmaVM *vm);
5414514f5e3Sopenharmony_ci    bool IsUint16Array(const EcmaVM *vm);
5424514f5e3Sopenharmony_ci    bool IsInt32Array(const EcmaVM *vm);
5434514f5e3Sopenharmony_ci    bool IsUint32Array(const EcmaVM *vm);
5444514f5e3Sopenharmony_ci    bool IsFloat32Array(const EcmaVM *vm);
5454514f5e3Sopenharmony_ci    bool IsFloat64Array(const EcmaVM *vm);
5464514f5e3Sopenharmony_ci    bool IsBigInt64Array(const EcmaVM *vm);
5474514f5e3Sopenharmony_ci    bool IsBigUint64Array(const EcmaVM *vm);
5484514f5e3Sopenharmony_ci    bool IsJSPrimitiveRef(const EcmaVM *vm);
5494514f5e3Sopenharmony_ci    bool IsJSPrimitiveNumber(const EcmaVM *vm);
5504514f5e3Sopenharmony_ci    bool IsJSPrimitiveInt(const EcmaVM *vm);
5514514f5e3Sopenharmony_ci    bool IsJSPrimitiveBoolean(const EcmaVM *vm);
5524514f5e3Sopenharmony_ci    bool IsJSPrimitiveString(const EcmaVM *vm);
5534514f5e3Sopenharmony_ci
5544514f5e3Sopenharmony_ci    bool IsJSSharedInt8Array(const EcmaVM *vm);
5554514f5e3Sopenharmony_ci    bool IsJSSharedUint8Array(const EcmaVM *vm);
5564514f5e3Sopenharmony_ci    bool IsJSSharedUint8ClampedArray(const EcmaVM *vm);
5574514f5e3Sopenharmony_ci    bool IsJSSharedInt16Array(const EcmaVM *vm);
5584514f5e3Sopenharmony_ci    bool IsJSSharedUint16Array(const EcmaVM *vm);
5594514f5e3Sopenharmony_ci    bool IsJSSharedInt32Array(const EcmaVM *vm);
5604514f5e3Sopenharmony_ci    bool IsJSSharedUint32Array(const EcmaVM *vm);
5614514f5e3Sopenharmony_ci    bool IsJSSharedFloat32Array(const EcmaVM *vm);
5624514f5e3Sopenharmony_ci
5634514f5e3Sopenharmony_ci    bool IsGeneratorObject(const EcmaVM *vm);
5644514f5e3Sopenharmony_ci    bool IsJSPrimitiveSymbol(const EcmaVM *vm);
5654514f5e3Sopenharmony_ci
5664514f5e3Sopenharmony_ci    bool IsArgumentsObject(const EcmaVM *vm);
5674514f5e3Sopenharmony_ci    bool IsGeneratorFunction(const EcmaVM *vm);
5684514f5e3Sopenharmony_ci    bool IsAsyncFunction(const EcmaVM *vm);
5694514f5e3Sopenharmony_ci    bool IsConcurrentFunction(const EcmaVM *vm);
5704514f5e3Sopenharmony_ci    bool IsJSLocale(const EcmaVM *vm);
5714514f5e3Sopenharmony_ci    bool IsJSDateTimeFormat(const EcmaVM *vm);
5724514f5e3Sopenharmony_ci    bool IsJSRelativeTimeFormat(const EcmaVM *vm);
5734514f5e3Sopenharmony_ci    bool IsJSIntl(const EcmaVM *vm);
5744514f5e3Sopenharmony_ci    bool IsJSNumberFormat(const EcmaVM *vm);
5754514f5e3Sopenharmony_ci    bool IsJSCollator(const EcmaVM *vm);
5764514f5e3Sopenharmony_ci    bool IsJSPluralRules(const EcmaVM *vm);
5774514f5e3Sopenharmony_ci    bool IsJSListFormat(const EcmaVM *vm);
5784514f5e3Sopenharmony_ci    bool IsAsyncGeneratorFunction(const EcmaVM *vm);
5794514f5e3Sopenharmony_ci    bool IsAsyncGeneratorObject(const EcmaVM *vm);
5804514f5e3Sopenharmony_ci
5814514f5e3Sopenharmony_ci    bool IsModuleNamespaceObject(const EcmaVM *vm);
5824514f5e3Sopenharmony_ci    bool IsNativeModuleFailureInfoObject(const EcmaVM *vm);
5834514f5e3Sopenharmony_ci    bool IsSharedArrayBuffer(const EcmaVM *vm);
5844514f5e3Sopenharmony_ci    bool IsSendableArrayBuffer(const EcmaVM *vm);
5854514f5e3Sopenharmony_ci
5864514f5e3Sopenharmony_ci    bool IsStrictEquals(const EcmaVM *vm, Local<JSValueRef> value);
5874514f5e3Sopenharmony_ci    Local<StringRef> Typeof(const EcmaVM *vm);
5884514f5e3Sopenharmony_ci    bool InstanceOf(const EcmaVM *vm, Local<JSValueRef> value);
5894514f5e3Sopenharmony_ci
5904514f5e3Sopenharmony_ci    bool IsArrayList(const EcmaVM *vm);
5914514f5e3Sopenharmony_ci    bool IsDeque(const EcmaVM *vm);
5924514f5e3Sopenharmony_ci    bool IsHashMap(const EcmaVM *vm);
5934514f5e3Sopenharmony_ci    bool IsHashSet(const EcmaVM *vm);
5944514f5e3Sopenharmony_ci    bool IsLightWeightMap(const EcmaVM *vm);
5954514f5e3Sopenharmony_ci    bool IsLightWeightSet(const EcmaVM *vm);
5964514f5e3Sopenharmony_ci    bool IsLinkedList(const EcmaVM *vm);
5974514f5e3Sopenharmony_ci    bool IsLinkedListIterator(const EcmaVM *vm);
5984514f5e3Sopenharmony_ci    bool IsList(const EcmaVM *vm);
5994514f5e3Sopenharmony_ci    bool IsPlainArray(const EcmaVM *vm);
6004514f5e3Sopenharmony_ci    bool IsQueue(const EcmaVM *vm);
6014514f5e3Sopenharmony_ci    bool IsStack(const EcmaVM *vm);
6024514f5e3Sopenharmony_ci    bool IsTreeMap(const EcmaVM *vm);
6034514f5e3Sopenharmony_ci    bool IsTreeSet(const EcmaVM *vm);
6044514f5e3Sopenharmony_ci    bool IsVector(const EcmaVM *vm);
6054514f5e3Sopenharmony_ci    bool IsSendableObject(const EcmaVM *vm);
6064514f5e3Sopenharmony_ci    bool IsJSShared(const EcmaVM *vm);
6074514f5e3Sopenharmony_ci    bool IsSharedArray(const EcmaVM *vm);
6084514f5e3Sopenharmony_ci    bool IsSharedTypedArray(const EcmaVM *vm);
6094514f5e3Sopenharmony_ci    bool IsSharedSet(const EcmaVM *vm);
6104514f5e3Sopenharmony_ci    bool IsSharedMap(const EcmaVM *vm);
6114514f5e3Sopenharmony_ci    bool IsSharedMapIterator(const EcmaVM *vm);
6124514f5e3Sopenharmony_ci    bool IsHeapObject();
6134514f5e3Sopenharmony_ci    void *GetNativePointerValue(const EcmaVM *vm, bool &isNativePointer);
6144514f5e3Sopenharmony_ci    bool IsDetachedArraybuffer(const EcmaVM *vm, bool &isArrayBuffer);
6154514f5e3Sopenharmony_ci    void DetachedArraybuffer(const EcmaVM *vm, bool &isArrayBuffer);
6164514f5e3Sopenharmony_ci    void GetDataViewInfo(const EcmaVM *vm,
6174514f5e3Sopenharmony_ci                         bool &isDataView,
6184514f5e3Sopenharmony_ci                         size_t *byteLength,
6194514f5e3Sopenharmony_ci                         void **data,
6204514f5e3Sopenharmony_ci                         JSValueRef **arrayBuffer,
6214514f5e3Sopenharmony_ci                         size_t *byteOffset);
6224514f5e3Sopenharmony_ci    void TryGetArrayLength(const EcmaVM *vm, bool *isArrayOrSharedArray, uint32_t *arrayLength);
6234514f5e3Sopenharmony_ci
6244514f5e3Sopenharmony_ciprivate:
6254514f5e3Sopenharmony_ci    JSTaggedType value_;
6264514f5e3Sopenharmony_ci    friend JSNApi;
6274514f5e3Sopenharmony_ci    template<typename T>
6284514f5e3Sopenharmony_ci    friend class Global;
6294514f5e3Sopenharmony_ci    template<typename T>
6304514f5e3Sopenharmony_ci    friend class Local;
6314514f5e3Sopenharmony_ci    void *GetNativePointerValueImpl(const EcmaVM *vm, bool &isNativePointer);
6324514f5e3Sopenharmony_ci};
6334514f5e3Sopenharmony_ci
6344514f5e3Sopenharmony_ci// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions, hicpp-special-member-functions)
6354514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API PropertyAttribute {
6364514f5e3Sopenharmony_cipublic:
6374514f5e3Sopenharmony_ci    static PropertyAttribute Default()
6384514f5e3Sopenharmony_ci    {
6394514f5e3Sopenharmony_ci        return PropertyAttribute();
6404514f5e3Sopenharmony_ci    }
6414514f5e3Sopenharmony_ci    PropertyAttribute() = default;
6424514f5e3Sopenharmony_ci    PropertyAttribute(Local<JSValueRef> value, bool w, bool e, bool c)
6434514f5e3Sopenharmony_ci        : value_(value),
6444514f5e3Sopenharmony_ci          writable_(w),
6454514f5e3Sopenharmony_ci          enumerable_(e),
6464514f5e3Sopenharmony_ci          configurable_(c),
6474514f5e3Sopenharmony_ci          hasWritable_(true),
6484514f5e3Sopenharmony_ci          hasEnumerable_(true),
6494514f5e3Sopenharmony_ci          hasConfigurable_(true)
6504514f5e3Sopenharmony_ci    {}
6514514f5e3Sopenharmony_ci    ~PropertyAttribute() = default;
6524514f5e3Sopenharmony_ci
6534514f5e3Sopenharmony_ci    bool IsWritable() const
6544514f5e3Sopenharmony_ci    {
6554514f5e3Sopenharmony_ci        return writable_;
6564514f5e3Sopenharmony_ci    }
6574514f5e3Sopenharmony_ci    void SetWritable(bool flag)
6584514f5e3Sopenharmony_ci    {
6594514f5e3Sopenharmony_ci        writable_ = flag;
6604514f5e3Sopenharmony_ci        hasWritable_ = true;
6614514f5e3Sopenharmony_ci    }
6624514f5e3Sopenharmony_ci    bool IsEnumerable() const
6634514f5e3Sopenharmony_ci    {
6644514f5e3Sopenharmony_ci        return enumerable_;
6654514f5e3Sopenharmony_ci    }
6664514f5e3Sopenharmony_ci    void SetEnumerable(bool flag)
6674514f5e3Sopenharmony_ci    {
6684514f5e3Sopenharmony_ci        enumerable_ = flag;
6694514f5e3Sopenharmony_ci        hasEnumerable_ = true;
6704514f5e3Sopenharmony_ci    }
6714514f5e3Sopenharmony_ci    bool IsConfigurable() const
6724514f5e3Sopenharmony_ci    {
6734514f5e3Sopenharmony_ci        return configurable_;
6744514f5e3Sopenharmony_ci    }
6754514f5e3Sopenharmony_ci    void SetConfigurable(bool flag)
6764514f5e3Sopenharmony_ci    {
6774514f5e3Sopenharmony_ci        configurable_ = flag;
6784514f5e3Sopenharmony_ci        hasConfigurable_ = true;
6794514f5e3Sopenharmony_ci    }
6804514f5e3Sopenharmony_ci    bool HasWritable() const
6814514f5e3Sopenharmony_ci    {
6824514f5e3Sopenharmony_ci        return hasWritable_;
6834514f5e3Sopenharmony_ci    }
6844514f5e3Sopenharmony_ci    bool HasConfigurable() const
6854514f5e3Sopenharmony_ci    {
6864514f5e3Sopenharmony_ci        return hasConfigurable_;
6874514f5e3Sopenharmony_ci    }
6884514f5e3Sopenharmony_ci    bool HasEnumerable() const
6894514f5e3Sopenharmony_ci    {
6904514f5e3Sopenharmony_ci        return hasEnumerable_;
6914514f5e3Sopenharmony_ci    }
6924514f5e3Sopenharmony_ci    Local<JSValueRef> GetValue(const EcmaVM *vm) const
6934514f5e3Sopenharmony_ci    {
6944514f5e3Sopenharmony_ci        if (value_.IsEmpty()) {
6954514f5e3Sopenharmony_ci            return JSValueRef::Undefined(vm);
6964514f5e3Sopenharmony_ci        }
6974514f5e3Sopenharmony_ci        return value_;
6984514f5e3Sopenharmony_ci    }
6994514f5e3Sopenharmony_ci    void SetValue(Local<JSValueRef> value)
7004514f5e3Sopenharmony_ci    {
7014514f5e3Sopenharmony_ci        value_ = value;
7024514f5e3Sopenharmony_ci    }
7034514f5e3Sopenharmony_ci    inline bool HasValue() const
7044514f5e3Sopenharmony_ci    {
7054514f5e3Sopenharmony_ci        return !value_.IsEmpty();
7064514f5e3Sopenharmony_ci    }
7074514f5e3Sopenharmony_ci    Local<JSValueRef> GetGetter(const EcmaVM *vm) const
7084514f5e3Sopenharmony_ci    {
7094514f5e3Sopenharmony_ci        if (getter_.IsEmpty()) {
7104514f5e3Sopenharmony_ci            return JSValueRef::Undefined(vm);
7114514f5e3Sopenharmony_ci        }
7124514f5e3Sopenharmony_ci        return getter_;
7134514f5e3Sopenharmony_ci    }
7144514f5e3Sopenharmony_ci    void SetGetter(Local<JSValueRef> value)
7154514f5e3Sopenharmony_ci    {
7164514f5e3Sopenharmony_ci        getter_ = value;
7174514f5e3Sopenharmony_ci    }
7184514f5e3Sopenharmony_ci    bool HasGetter() const
7194514f5e3Sopenharmony_ci    {
7204514f5e3Sopenharmony_ci        return !getter_.IsEmpty();
7214514f5e3Sopenharmony_ci    }
7224514f5e3Sopenharmony_ci    Local<JSValueRef> GetSetter(const EcmaVM *vm) const
7234514f5e3Sopenharmony_ci    {
7244514f5e3Sopenharmony_ci        if (setter_.IsEmpty()) {
7254514f5e3Sopenharmony_ci            return JSValueRef::Undefined(vm);
7264514f5e3Sopenharmony_ci        }
7274514f5e3Sopenharmony_ci        return setter_;
7284514f5e3Sopenharmony_ci    }
7294514f5e3Sopenharmony_ci    void SetSetter(Local<JSValueRef> value)
7304514f5e3Sopenharmony_ci    {
7314514f5e3Sopenharmony_ci        setter_ = value;
7324514f5e3Sopenharmony_ci    }
7334514f5e3Sopenharmony_ci    bool HasSetter() const
7344514f5e3Sopenharmony_ci    {
7354514f5e3Sopenharmony_ci        return !setter_.IsEmpty();
7364514f5e3Sopenharmony_ci    }
7374514f5e3Sopenharmony_ci
7384514f5e3Sopenharmony_ciprivate:
7394514f5e3Sopenharmony_ci    Local<JSValueRef> value_;
7404514f5e3Sopenharmony_ci    Local<JSValueRef> getter_;
7414514f5e3Sopenharmony_ci    Local<JSValueRef> setter_;
7424514f5e3Sopenharmony_ci    bool writable_ = false;
7434514f5e3Sopenharmony_ci    bool enumerable_ = false;
7444514f5e3Sopenharmony_ci    bool configurable_ = false;
7454514f5e3Sopenharmony_ci    bool hasWritable_ = false;
7464514f5e3Sopenharmony_ci    bool hasEnumerable_ = false;
7474514f5e3Sopenharmony_ci    bool hasConfigurable_ = false;
7484514f5e3Sopenharmony_ci};
7494514f5e3Sopenharmony_ci
7504514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API NativePointerRef : public JSValueRef {
7514514f5e3Sopenharmony_cipublic:
7524514f5e3Sopenharmony_ci    static Local<NativePointerRef> New(const EcmaVM *vm, void *nativePointer, size_t nativeBindingsize = 0);
7534514f5e3Sopenharmony_ci    static Local<NativePointerRef> New(const EcmaVM *vm, void *nativePointer, NativePointerCallback callBack,
7544514f5e3Sopenharmony_ci                                       void *data, size_t nativeBindingsize = 0);
7554514f5e3Sopenharmony_ci    static Local<NativePointerRef> NewConcurrent(const EcmaVM *vm, void *nativePointer,
7564514f5e3Sopenharmony_ci                                                 NativePointerCallback callBack,
7574514f5e3Sopenharmony_ci                                                 void *data, size_t nativeBindingsize = 0);
7584514f5e3Sopenharmony_ci    static Local<NativePointerRef> NewSendable(const EcmaVM *vm,
7594514f5e3Sopenharmony_ci                                               void *nativePointer,
7604514f5e3Sopenharmony_ci                                               NativePointerCallback callBack = nullptr,
7614514f5e3Sopenharmony_ci                                               void *data = nullptr,
7624514f5e3Sopenharmony_ci                                               size_t nativeBindingsize = 0);
7634514f5e3Sopenharmony_ci    void *Value();
7644514f5e3Sopenharmony_ci};
7654514f5e3Sopenharmony_ci
7664514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API ObjectRef : public JSValueRef {
7674514f5e3Sopenharmony_cipublic:
7684514f5e3Sopenharmony_ci    enum class SendableType {
7694514f5e3Sopenharmony_ci        NONE,
7704514f5e3Sopenharmony_ci        OBJECT,
7714514f5e3Sopenharmony_ci        GENERIC,
7724514f5e3Sopenharmony_ci    };
7734514f5e3Sopenharmony_ci    struct SendablePropertiesInfo {
7744514f5e3Sopenharmony_ci        std::vector<Local<JSValueRef>> keys;
7754514f5e3Sopenharmony_ci        std::vector<SendableType> types;
7764514f5e3Sopenharmony_ci        std::vector<PropertyAttribute> attributes;
7774514f5e3Sopenharmony_ci    };
7784514f5e3Sopenharmony_ci    static constexpr int MAX_PROPERTIES_ON_STACK = 32;
7794514f5e3Sopenharmony_ci    static inline ObjectRef *Cast(JSValueRef *value)
7804514f5e3Sopenharmony_ci    {
7814514f5e3Sopenharmony_ci        return static_cast<ObjectRef *>(value);
7824514f5e3Sopenharmony_ci    }
7834514f5e3Sopenharmony_ci    static Local<ObjectRef> New(const EcmaVM *vm);
7844514f5e3Sopenharmony_ci    static uintptr_t NewObject(const EcmaVM *vm);
7854514f5e3Sopenharmony_ci    static Local<ObjectRef> NewS(const EcmaVM *vm);
7864514f5e3Sopenharmony_ci    static Local<ObjectRef> NewWithProperties(const EcmaVM *vm, size_t propertyCount, const Local<JSValueRef> *keys,
7874514f5e3Sopenharmony_ci                                              const PropertyAttribute *attributes);
7884514f5e3Sopenharmony_ci    static Local<ObjectRef> NewSWithProperties(const EcmaVM *vm, SendablePropertiesInfo &info);
7894514f5e3Sopenharmony_ci    static Local<ObjectRef> NewWithNamedProperties(const EcmaVM *vm, size_t propertyCount, const char **keys,
7904514f5e3Sopenharmony_ci                                                   const Local<JSValueRef> *values);
7914514f5e3Sopenharmony_ci    static Local<ObjectRef> CreateNativeModuleFailureInfo(const EcmaVM *vm, const std::string &failureInfo);
7924514f5e3Sopenharmony_ci    static Local<ObjectRef> CreateAccessorData(const EcmaVM *vm, Local<FunctionRef> getter, Local<FunctionRef> setter);
7934514f5e3Sopenharmony_ci    static Local<ObjectRef> CreateSendableAccessorData(const EcmaVM *vm,
7944514f5e3Sopenharmony_ci                                                       Local<FunctionRef> getter,
7954514f5e3Sopenharmony_ci                                                       Local<FunctionRef> setter);
7964514f5e3Sopenharmony_ci    bool ConvertToNativeBindingObject(const EcmaVM *vm, Local<NativePointerRef> value);
7974514f5e3Sopenharmony_ci    bool Set(const EcmaVM *vm, Local<JSValueRef> key, Local<JSValueRef> value);
7984514f5e3Sopenharmony_ci    bool Set(const EcmaVM *vm, const char *utf8, Local<JSValueRef> value);
7994514f5e3Sopenharmony_ci    bool Set(const EcmaVM *vm, uint32_t key, Local<JSValueRef> value);
8004514f5e3Sopenharmony_ci    bool SetAccessorProperty(const EcmaVM *vm, Local<JSValueRef> key, Local<FunctionRef> getter,
8014514f5e3Sopenharmony_ci                             Local<FunctionRef> setter, PropertyAttribute attribute = PropertyAttribute::Default());
8024514f5e3Sopenharmony_ci    Local<JSValueRef> Get(const EcmaVM *vm, Local<JSValueRef> key);
8034514f5e3Sopenharmony_ci    Local<JSValueRef> Get(const EcmaVM *vm, const char *utf8);
8044514f5e3Sopenharmony_ci    Local<JSValueRef> Get(const EcmaVM *vm, int32_t key);
8054514f5e3Sopenharmony_ci
8064514f5e3Sopenharmony_ci    bool GetOwnProperty(const EcmaVM *vm, Local<JSValueRef> key, PropertyAttribute &property);
8074514f5e3Sopenharmony_ci    Local<ArrayRef> GetOwnPropertyNames(const EcmaVM *vm);
8084514f5e3Sopenharmony_ci    Local<ArrayRef> GetAllPropertyNames(const EcmaVM *vm, uint32_t filter);
8094514f5e3Sopenharmony_ci    Local<ArrayRef> GetOwnEnumerablePropertyNames(const EcmaVM *vm);
8104514f5e3Sopenharmony_ci    Local<JSValueRef> GetPrototype(const EcmaVM *vm);
8114514f5e3Sopenharmony_ci    bool SetPrototype(const EcmaVM *vm, Local<ObjectRef> prototype);
8124514f5e3Sopenharmony_ci
8134514f5e3Sopenharmony_ci    bool DefineProperty(const EcmaVM *vm, Local<JSValueRef> key, PropertyAttribute attribute);
8144514f5e3Sopenharmony_ci
8154514f5e3Sopenharmony_ci    bool Has(const EcmaVM *vm, Local<JSValueRef> key);
8164514f5e3Sopenharmony_ci    bool Has(const EcmaVM *vm, uint32_t key);
8174514f5e3Sopenharmony_ci
8184514f5e3Sopenharmony_ci    bool HasOwnProperty(const EcmaVM *vm, Local<JSValueRef> key);
8194514f5e3Sopenharmony_ci
8204514f5e3Sopenharmony_ci    bool Delete(const EcmaVM *vm, Local<JSValueRef> key);
8214514f5e3Sopenharmony_ci    bool Delete(const EcmaVM *vm, uint32_t key);
8224514f5e3Sopenharmony_ci
8234514f5e3Sopenharmony_ci    Local<JSValueRef> Freeze(const EcmaVM *vm);
8244514f5e3Sopenharmony_ci    Local<JSValueRef> Seal(const EcmaVM *vm);
8254514f5e3Sopenharmony_ci
8264514f5e3Sopenharmony_ci    void SetNativePointerFieldCount(const EcmaVM *vm, int32_t count);
8274514f5e3Sopenharmony_ci    int32_t GetNativePointerFieldCount(const EcmaVM *vm);
8284514f5e3Sopenharmony_ci    void *GetNativePointerField(const EcmaVM *vm, int32_t index);
8294514f5e3Sopenharmony_ci    void SetNativePointerField(const EcmaVM *vm,
8304514f5e3Sopenharmony_ci                               int32_t index,
8314514f5e3Sopenharmony_ci                               void *nativePointer = nullptr,
8324514f5e3Sopenharmony_ci                               NativePointerCallback callBack = nullptr,
8334514f5e3Sopenharmony_ci                               void *data = nullptr, size_t nativeBindingsize = 0);
8344514f5e3Sopenharmony_ci    void SetConcurrentNativePointerField(const EcmaVM *vm,
8354514f5e3Sopenharmony_ci                                         int32_t index,
8364514f5e3Sopenharmony_ci                                         void *nativePointer = nullptr,
8374514f5e3Sopenharmony_ci                                         NativePointerCallback callBack = nullptr,
8384514f5e3Sopenharmony_ci                                         void *data = nullptr, size_t nativeBindingsize = 0);
8394514f5e3Sopenharmony_ci};
8404514f5e3Sopenharmony_ci
8414514f5e3Sopenharmony_ciusing FunctionCallback = Local<JSValueRef>(*)(JsiRuntimeCallInfo*);
8424514f5e3Sopenharmony_ciusing InternalFunctionCallback = JSValueRef(*)(JsiRuntimeCallInfo*);
8434514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API FunctionRef : public ObjectRef {
8444514f5e3Sopenharmony_cipublic:
8454514f5e3Sopenharmony_ci    struct SendablePropertiesInfos {
8464514f5e3Sopenharmony_ci        SendablePropertiesInfo instancePropertiesInfo;
8474514f5e3Sopenharmony_ci        SendablePropertiesInfo staticPropertiesInfo;
8484514f5e3Sopenharmony_ci        SendablePropertiesInfo nonStaticPropertiesInfo;
8494514f5e3Sopenharmony_ci    };
8504514f5e3Sopenharmony_ci    static Local<FunctionRef> New(EcmaVM *vm, FunctionCallback nativeFunc, NativePointerCallback deleter = nullptr,
8514514f5e3Sopenharmony_ci        void *data = nullptr, bool callNapi = false, size_t nativeBindingsize = 0);
8524514f5e3Sopenharmony_ci    static Local<FunctionRef> NewConcurrent(EcmaVM *vm,
8534514f5e3Sopenharmony_ci                                            FunctionCallback nativeFunc,
8544514f5e3Sopenharmony_ci                                            NativePointerCallback deleter = nullptr,
8554514f5e3Sopenharmony_ci                                            void *data = nullptr,
8564514f5e3Sopenharmony_ci                                            bool callNapi = false,
8574514f5e3Sopenharmony_ci                                            size_t nativeBindingsize = 0);
8584514f5e3Sopenharmony_ci    static Local<FunctionRef> New(EcmaVM *vm, InternalFunctionCallback nativeFunc, NativePointerCallback deleter,
8594514f5e3Sopenharmony_ci        void *data = nullptr, bool callNapi = false, size_t nativeBindingsize = 0);
8604514f5e3Sopenharmony_ci    static Local<FunctionRef> NewConcurrent(EcmaVM *vm,
8614514f5e3Sopenharmony_ci                                            InternalFunctionCallback nativeFunc,
8624514f5e3Sopenharmony_ci                                            NativePointerCallback deleter,
8634514f5e3Sopenharmony_ci                                            void *data = nullptr,
8644514f5e3Sopenharmony_ci                                            bool callNapi = false,
8654514f5e3Sopenharmony_ci                                            size_t nativeBindingsize = 0);
8664514f5e3Sopenharmony_ci    static Local<FunctionRef> NewSendable(EcmaVM *vm,
8674514f5e3Sopenharmony_ci                                          InternalFunctionCallback nativeFunc,
8684514f5e3Sopenharmony_ci                                          NativePointerCallback deleter,
8694514f5e3Sopenharmony_ci                                          void *data = nullptr,
8704514f5e3Sopenharmony_ci                                          bool callNapi = false,
8714514f5e3Sopenharmony_ci                                          size_t nativeBindingsize = 0);
8724514f5e3Sopenharmony_ci    static Local<FunctionRef> NewClassFunction(EcmaVM *vm, FunctionCallback nativeFunc, NativePointerCallback deleter,
8734514f5e3Sopenharmony_ci        void *data, bool callNapi = false, size_t nativeBindingsize = 0);
8744514f5e3Sopenharmony_ci    static Local<FunctionRef> NewConcurrentClassFunction(EcmaVM *vm,
8754514f5e3Sopenharmony_ci                                                         InternalFunctionCallback nativeFunc,
8764514f5e3Sopenharmony_ci                                                         NativePointerCallback deleter,
8774514f5e3Sopenharmony_ci                                                         void *data,
8784514f5e3Sopenharmony_ci                                                         bool callNapi = false,
8794514f5e3Sopenharmony_ci                                                         size_t nativeBindingsize = 0);
8804514f5e3Sopenharmony_ci    static Local<FunctionRef> NewClassFunction(EcmaVM *vm,
8814514f5e3Sopenharmony_ci                                               InternalFunctionCallback nativeFunc,
8824514f5e3Sopenharmony_ci                                               NativePointerCallback deleter,
8834514f5e3Sopenharmony_ci                                               void *data,
8844514f5e3Sopenharmony_ci                                               bool callNapi = false,
8854514f5e3Sopenharmony_ci                                               size_t nativeBindingsize = 0);
8864514f5e3Sopenharmony_ci    static Local<FunctionRef> NewSendableClassFunction(const EcmaVM *vm,
8874514f5e3Sopenharmony_ci                                                       InternalFunctionCallback nativeFunc,
8884514f5e3Sopenharmony_ci                                                       NativePointerCallback deleter,
8894514f5e3Sopenharmony_ci                                                       void *data,
8904514f5e3Sopenharmony_ci                                                       Local<StringRef> name,
8914514f5e3Sopenharmony_ci                                                       SendablePropertiesInfos &infos,
8924514f5e3Sopenharmony_ci                                                       Local<FunctionRef> parent,
8934514f5e3Sopenharmony_ci                                                       bool callNapi = false,
8944514f5e3Sopenharmony_ci                                                       size_t nativeBindingsize = 0);
8954514f5e3Sopenharmony_ci    JSValueRef* CallForNapi(const EcmaVM *vm, JSValueRef *thisObj, JSValueRef *const argv[],
8964514f5e3Sopenharmony_ci        int32_t length);
8974514f5e3Sopenharmony_ci    Local<JSValueRef> Call(const EcmaVM *vm, Local<JSValueRef> thisObj, const Local<JSValueRef> argv[],
8984514f5e3Sopenharmony_ci        int32_t length);
8994514f5e3Sopenharmony_ci    Local<JSValueRef> Constructor(const EcmaVM *vm, const Local<JSValueRef> argv[], int32_t length);
9004514f5e3Sopenharmony_ci    JSValueRef* ConstructorOptimize(const EcmaVM *vm, JSValueRef* argv[], int32_t length);
9014514f5e3Sopenharmony_ci
9024514f5e3Sopenharmony_ci    Local<JSValueRef> GetFunctionPrototype(const EcmaVM *vm);
9034514f5e3Sopenharmony_ci    bool Inherit(const EcmaVM *vm, Local<FunctionRef> parent);
9044514f5e3Sopenharmony_ci    void SetName(const EcmaVM *vm, Local<StringRef> name);
9054514f5e3Sopenharmony_ci    Local<StringRef> GetName(const EcmaVM *vm);
9064514f5e3Sopenharmony_ci    Local<StringRef> GetSourceCode(const EcmaVM *vm, int lineNumber);
9074514f5e3Sopenharmony_ci    bool IsNative(const EcmaVM *vm);
9084514f5e3Sopenharmony_ci    void SetData(const EcmaVM *vm, void *data, NativePointerCallback deleter = nullptr, bool callNapi = false);
9094514f5e3Sopenharmony_ci    void* GetData(const EcmaVM *vm);
9104514f5e3Sopenharmony_ci};
9114514f5e3Sopenharmony_ci
9124514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API PrimitiveRef : public JSValueRef {
9134514f5e3Sopenharmony_cipublic:
9144514f5e3Sopenharmony_ci    Local<JSValueRef> GetValue(const EcmaVM *vm);
9154514f5e3Sopenharmony_ci};
9164514f5e3Sopenharmony_ci
9174514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SymbolRef : public PrimitiveRef {
9184514f5e3Sopenharmony_cipublic:
9194514f5e3Sopenharmony_ci    static Local<SymbolRef> New(const EcmaVM *vm, Local<StringRef> description = Local<StringRef>());
9204514f5e3Sopenharmony_ci    Local<StringRef> GetDescription(const EcmaVM *vm);
9214514f5e3Sopenharmony_ci};
9224514f5e3Sopenharmony_ci
9234514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API BooleanRef : public PrimitiveRef {
9244514f5e3Sopenharmony_cipublic:
9254514f5e3Sopenharmony_ci    static Local<BooleanRef> New(const EcmaVM *vm, bool input);
9264514f5e3Sopenharmony_ci    bool Value();
9274514f5e3Sopenharmony_ci};
9284514f5e3Sopenharmony_ci
9294514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API StringRef : public PrimitiveRef {
9304514f5e3Sopenharmony_cipublic:
9314514f5e3Sopenharmony_ci    static inline StringRef *Cast(JSValueRef *value)
9324514f5e3Sopenharmony_ci    {
9334514f5e3Sopenharmony_ci        // check
9344514f5e3Sopenharmony_ci        return static_cast<StringRef *>(value);
9354514f5e3Sopenharmony_ci    }
9364514f5e3Sopenharmony_ci    static Local<StringRef> NewFromUtf8WithoutStringTable(const EcmaVM *vm, const char *utf8, int length = -1);
9374514f5e3Sopenharmony_ci    static Local<StringRef> NewFromUtf8(const EcmaVM *vm, const char *utf8, int length = -1);
9384514f5e3Sopenharmony_ci    static Local<StringRef> NewFromUtf16WithoutStringTable(const EcmaVM *vm, const char16_t *utf16, int length = -1);
9394514f5e3Sopenharmony_ci    static Local<StringRef> NewFromUtf16(const EcmaVM *vm, const char16_t *utf16, int length = -1);
9404514f5e3Sopenharmony_ci    std::string ToString(const EcmaVM *vm);
9414514f5e3Sopenharmony_ci    std::string DebuggerToString(const EcmaVM *vm);
9424514f5e3Sopenharmony_ci    uint32_t Length(const EcmaVM *vm);
9434514f5e3Sopenharmony_ci    size_t Utf8Length(const EcmaVM *vm, bool isGetBufferSize = false);
9444514f5e3Sopenharmony_ci    uint32_t WriteUtf8(const EcmaVM *vm, char *buffer, uint32_t length, bool isWriteBuffer = false);
9454514f5e3Sopenharmony_ci    uint32_t WriteUtf16(const EcmaVM *vm, char16_t *buffer, uint32_t length);
9464514f5e3Sopenharmony_ci    uint32_t WriteLatin1(const EcmaVM *vm, char *buffer, uint32_t length);
9474514f5e3Sopenharmony_ci    static Local<StringRef> GetNapiWrapperString(const EcmaVM *vm);
9484514f5e3Sopenharmony_ci    Local<TypedArrayRef> EncodeIntoUint8Array(const EcmaVM *vm);
9494514f5e3Sopenharmony_ci};
9504514f5e3Sopenharmony_ci
9514514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API PromiseRejectInfo {
9524514f5e3Sopenharmony_cipublic:
9534514f5e3Sopenharmony_ci    enum class ECMA_PUBLIC_API PROMISE_REJECTION_EVENT : uint32_t { REJECT = 0, HANDLE };
9544514f5e3Sopenharmony_ci    PromiseRejectInfo(Local<JSValueRef> promise, Local<JSValueRef> reason,
9554514f5e3Sopenharmony_ci                      PromiseRejectInfo::PROMISE_REJECTION_EVENT operation, void* data);
9564514f5e3Sopenharmony_ci    ~PromiseRejectInfo() {}
9574514f5e3Sopenharmony_ci    Local<JSValueRef> GetPromise() const;
9584514f5e3Sopenharmony_ci    Local<JSValueRef> GetReason() const;
9594514f5e3Sopenharmony_ci    PromiseRejectInfo::PROMISE_REJECTION_EVENT GetOperation() const;
9604514f5e3Sopenharmony_ci    void* GetData() const;
9614514f5e3Sopenharmony_ci
9624514f5e3Sopenharmony_ciprivate:
9634514f5e3Sopenharmony_ci    Local<JSValueRef> promise_ {};
9644514f5e3Sopenharmony_ci    Local<JSValueRef> reason_ {};
9654514f5e3Sopenharmony_ci    PROMISE_REJECTION_EVENT operation_ = PROMISE_REJECTION_EVENT::REJECT;
9664514f5e3Sopenharmony_ci    void* data_ {nullptr};
9674514f5e3Sopenharmony_ci};
9684514f5e3Sopenharmony_ci
9694514f5e3Sopenharmony_ci/**
9704514f5e3Sopenharmony_ci * An external exception handler.
9714514f5e3Sopenharmony_ci */
9724514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API TryCatch {
9734514f5e3Sopenharmony_cipublic:
9744514f5e3Sopenharmony_ci    explicit TryCatch(const EcmaVM *ecmaVm) : ecmaVm_(ecmaVm) {};
9754514f5e3Sopenharmony_ci
9764514f5e3Sopenharmony_ci    /**
9774514f5e3Sopenharmony_ci     * Consumes the exception by default if not rethrow explicitly.
9784514f5e3Sopenharmony_ci     */
9794514f5e3Sopenharmony_ci    ~TryCatch();
9804514f5e3Sopenharmony_ci
9814514f5e3Sopenharmony_ci    bool HasCaught() const;
9824514f5e3Sopenharmony_ci    void Rethrow();
9834514f5e3Sopenharmony_ci    Local<ObjectRef> GetAndClearException();
9844514f5e3Sopenharmony_ci    Local<ObjectRef> GetException();
9854514f5e3Sopenharmony_ci    void ClearException();
9864514f5e3Sopenharmony_ci
9874514f5e3Sopenharmony_ci    ECMA_DISALLOW_COPY(TryCatch);
9884514f5e3Sopenharmony_ci    ECMA_DISALLOW_MOVE(TryCatch);
9894514f5e3Sopenharmony_ci
9904514f5e3Sopenharmony_ci    bool getrethrow_()
9914514f5e3Sopenharmony_ci    {
9924514f5e3Sopenharmony_ci        return rethrow_;
9934514f5e3Sopenharmony_ci    }
9944514f5e3Sopenharmony_ci
9954514f5e3Sopenharmony_ciprivate:
9964514f5e3Sopenharmony_ci    // Disable dynamic allocation
9974514f5e3Sopenharmony_ci    void* operator new(size_t size) = delete;
9984514f5e3Sopenharmony_ci    void operator delete(void*, size_t) = delete;
9994514f5e3Sopenharmony_ci    void* operator new[](size_t size) = delete;
10004514f5e3Sopenharmony_ci    void operator delete[](void*, size_t) = delete;
10014514f5e3Sopenharmony_ci
10024514f5e3Sopenharmony_ci    const EcmaVM *ecmaVm_ {nullptr};
10034514f5e3Sopenharmony_ci    bool rethrow_ {false};
10044514f5e3Sopenharmony_ci};
10054514f5e3Sopenharmony_ci
10064514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API BigIntRef : public PrimitiveRef {
10074514f5e3Sopenharmony_cipublic:
10084514f5e3Sopenharmony_ci    static Local<BigIntRef> New(const EcmaVM *vm, uint64_t input);
10094514f5e3Sopenharmony_ci    static Local<BigIntRef> New(const EcmaVM *vm, int64_t input);
10104514f5e3Sopenharmony_ci    static Local<JSValueRef> CreateBigWords(const EcmaVM *vm, bool sign, uint32_t size, const uint64_t* words);
10114514f5e3Sopenharmony_ci    void BigIntToInt64(const EcmaVM *vm, int64_t *value, bool *lossless);
10124514f5e3Sopenharmony_ci    void BigIntToUint64(const EcmaVM *vm, uint64_t *value, bool *lossless);
10134514f5e3Sopenharmony_ci    void GetWordsArray(const EcmaVM *vm, bool* signBit, size_t wordCount, uint64_t* words);
10144514f5e3Sopenharmony_ci    uint32_t GetWordsArraySize(const EcmaVM *vm);
10154514f5e3Sopenharmony_ci};
10164514f5e3Sopenharmony_ci
10174514f5e3Sopenharmony_ci// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions, hicpp-special-member-functions)
10184514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API LocalScope {
10194514f5e3Sopenharmony_cipublic:
10204514f5e3Sopenharmony_ci    explicit LocalScope(const EcmaVM *vm);
10214514f5e3Sopenharmony_ci    virtual ~LocalScope();
10224514f5e3Sopenharmony_ci
10234514f5e3Sopenharmony_ciprotected:
10244514f5e3Sopenharmony_ci    inline LocalScope(const EcmaVM *vm, JSTaggedType value);
10254514f5e3Sopenharmony_ci
10264514f5e3Sopenharmony_ciprivate:
10274514f5e3Sopenharmony_ci    void *prevNext_ = nullptr;
10284514f5e3Sopenharmony_ci    void *prevEnd_ = nullptr;
10294514f5e3Sopenharmony_ci    int prevHandleStorageIndex_ {-1};
10304514f5e3Sopenharmony_ci    void *prevPrimitiveNext_ = nullptr;
10314514f5e3Sopenharmony_ci    void *prevPrimitiveEnd_ = nullptr;
10324514f5e3Sopenharmony_ci    int prevPrimitiveStorageIndex_ {-1};
10334514f5e3Sopenharmony_ci    void *thread_ = nullptr;
10344514f5e3Sopenharmony_ci};
10354514f5e3Sopenharmony_ci
10364514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API EscapeLocalScope final : public LocalScope {
10374514f5e3Sopenharmony_cipublic:
10384514f5e3Sopenharmony_ci    explicit EscapeLocalScope(const EcmaVM *vm);
10394514f5e3Sopenharmony_ci    ~EscapeLocalScope() override = default;
10404514f5e3Sopenharmony_ci
10414514f5e3Sopenharmony_ci    ECMA_DISALLOW_COPY(EscapeLocalScope);
10424514f5e3Sopenharmony_ci    ECMA_DISALLOW_MOVE(EscapeLocalScope);
10434514f5e3Sopenharmony_ci
10444514f5e3Sopenharmony_ci    template<typename T>
10454514f5e3Sopenharmony_ci    inline Local<T> Escape(Local<T> current)
10464514f5e3Sopenharmony_ci    {
10474514f5e3Sopenharmony_ci        ECMA_ASSERT(!alreadyEscape_);
10484514f5e3Sopenharmony_ci        alreadyEscape_ = true;
10494514f5e3Sopenharmony_ci        *(reinterpret_cast<T *>(escapeHandle_)) = **current;
10504514f5e3Sopenharmony_ci        return Local<T>(escapeHandle_);
10514514f5e3Sopenharmony_ci    }
10524514f5e3Sopenharmony_ci
10534514f5e3Sopenharmony_ciprivate:
10544514f5e3Sopenharmony_ci    bool alreadyEscape_ = false;
10554514f5e3Sopenharmony_ci    uintptr_t escapeHandle_ = 0U;
10564514f5e3Sopenharmony_ci};
10574514f5e3Sopenharmony_ci
10584514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API IntegerRef : public PrimitiveRef {
10594514f5e3Sopenharmony_cipublic:
10604514f5e3Sopenharmony_ci    static Local<IntegerRef> New(const EcmaVM *vm, int input);
10614514f5e3Sopenharmony_ci    static Local<IntegerRef> NewFromUnsigned(const EcmaVM *vm, unsigned int input);
10624514f5e3Sopenharmony_ci    int Value();
10634514f5e3Sopenharmony_ci};
10644514f5e3Sopenharmony_ci
10654514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API ArrayBufferRef : public ObjectRef {
10664514f5e3Sopenharmony_cipublic:
10674514f5e3Sopenharmony_ci    static Local<ArrayBufferRef> New(const EcmaVM *vm, int32_t length);
10684514f5e3Sopenharmony_ci    static Local<ArrayBufferRef> New(const EcmaVM *vm, void *buffer, int32_t length,
10694514f5e3Sopenharmony_ci                                     const NativePointerCallback &deleter, void *data);
10704514f5e3Sopenharmony_ci
10714514f5e3Sopenharmony_ci    int32_t ByteLength(const EcmaVM *vm);
10724514f5e3Sopenharmony_ci    void *GetBuffer(const EcmaVM *vm);
10734514f5e3Sopenharmony_ci
10744514f5e3Sopenharmony_ci    void Detach(const EcmaVM *vm);
10754514f5e3Sopenharmony_ci    bool IsDetach(const EcmaVM *vm);
10764514f5e3Sopenharmony_ci};
10774514f5e3Sopenharmony_ci
10784514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SendableArrayBufferRef : public ObjectRef {
10794514f5e3Sopenharmony_cipublic:
10804514f5e3Sopenharmony_ci    static Local<SendableArrayBufferRef> New(const EcmaVM *vm, int32_t length);
10814514f5e3Sopenharmony_ci    static Local<SendableArrayBufferRef> New(const EcmaVM *vm, void *buffer, int32_t length,
10824514f5e3Sopenharmony_ci                                             const NativePointerCallback &deleter, void *data);
10834514f5e3Sopenharmony_ci
10844514f5e3Sopenharmony_ci    int32_t ByteLength(const EcmaVM *vm);
10854514f5e3Sopenharmony_ci    void *GetBuffer(const EcmaVM *vm);
10864514f5e3Sopenharmony_ci
10874514f5e3Sopenharmony_ci    void Detach(const EcmaVM *vm);
10884514f5e3Sopenharmony_ci    bool IsDetach(const EcmaVM *vm);
10894514f5e3Sopenharmony_ci};
10904514f5e3Sopenharmony_ci
10914514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API DateRef : public ObjectRef {
10924514f5e3Sopenharmony_cipublic:
10934514f5e3Sopenharmony_ci    static Local<DateRef> New(const EcmaVM *vm, double time);
10944514f5e3Sopenharmony_ci    Local<StringRef> ToString(const EcmaVM *vm);
10954514f5e3Sopenharmony_ci    double GetTime(const EcmaVM *vm);
10964514f5e3Sopenharmony_ci};
10974514f5e3Sopenharmony_ci
10984514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API TypedArrayRef : public ObjectRef {
10994514f5e3Sopenharmony_cipublic:
11004514f5e3Sopenharmony_ci    uint32_t ByteLength(const EcmaVM *vm);
11014514f5e3Sopenharmony_ci    uint32_t ByteOffset(const EcmaVM *vm);
11024514f5e3Sopenharmony_ci    uint32_t ArrayLength(const EcmaVM *vm);
11034514f5e3Sopenharmony_ci    Local<ArrayBufferRef> GetArrayBuffer(const EcmaVM *vm);
11044514f5e3Sopenharmony_ci};
11054514f5e3Sopenharmony_ci
11064514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SendableTypedArrayRef : public ObjectRef {
11074514f5e3Sopenharmony_cipublic:
11084514f5e3Sopenharmony_ci    uint32_t ByteLength(const EcmaVM *vm);
11094514f5e3Sopenharmony_ci    uint32_t ByteOffset(const EcmaVM *vm);
11104514f5e3Sopenharmony_ci    uint32_t ArrayLength(const EcmaVM *vm);
11114514f5e3Sopenharmony_ci    Local<SendableArrayBufferRef> GetArrayBuffer(const EcmaVM *vm);
11124514f5e3Sopenharmony_ci};
11134514f5e3Sopenharmony_ci
11144514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API ArrayRef : public ObjectRef {
11154514f5e3Sopenharmony_cipublic:
11164514f5e3Sopenharmony_ci    static Local<ArrayRef> New(const EcmaVM *vm, uint32_t length = 0);
11174514f5e3Sopenharmony_ci    uint32_t Length(const EcmaVM *vm);
11184514f5e3Sopenharmony_ci    static bool SetValueAt(const EcmaVM *vm, Local<JSValueRef> obj, uint32_t index, Local<JSValueRef> value);
11194514f5e3Sopenharmony_ci    static Local<JSValueRef> GetValueAt(const EcmaVM *vm, Local<JSValueRef> obj, uint32_t index);
11204514f5e3Sopenharmony_ci};
11214514f5e3Sopenharmony_ci
11224514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SendableArrayRef : public ObjectRef {
11234514f5e3Sopenharmony_cipublic:
11244514f5e3Sopenharmony_ci    static Local<SendableArrayRef> New(const EcmaVM *vm, uint32_t length = 0);
11254514f5e3Sopenharmony_ci    uint32_t Length(const EcmaVM *vm);
11264514f5e3Sopenharmony_ci    static Local<JSValueRef> GetValueAt(const EcmaVM *vm, Local<JSValueRef> obj, uint32_t index);
11274514f5e3Sopenharmony_ci    static bool SetProperty(const EcmaVM *vm, Local<JSValueRef> obj, uint32_t index, Local<JSValueRef> value);
11284514f5e3Sopenharmony_ci};
11294514f5e3Sopenharmony_ci
11304514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API Int8ArrayRef : public TypedArrayRef {
11314514f5e3Sopenharmony_cipublic:
11324514f5e3Sopenharmony_ci    static Local<Int8ArrayRef> New(const EcmaVM *vm, Local<ArrayBufferRef> buffer, int32_t byteOffset, int32_t length);
11334514f5e3Sopenharmony_ci};
11344514f5e3Sopenharmony_ci
11354514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SharedInt8ArrayRef : public SendableTypedArrayRef {
11364514f5e3Sopenharmony_cipublic:
11374514f5e3Sopenharmony_ci    static Local<SharedInt8ArrayRef> New(const EcmaVM *vm, Local<SendableArrayBufferRef> buffer,
11384514f5e3Sopenharmony_ci                                         int32_t byteOffset, int32_t length);
11394514f5e3Sopenharmony_ci};
11404514f5e3Sopenharmony_ci
11414514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API Uint8ArrayRef : public TypedArrayRef {
11424514f5e3Sopenharmony_cipublic:
11434514f5e3Sopenharmony_ci    static Local<Uint8ArrayRef> New(const EcmaVM *vm, Local<ArrayBufferRef> buffer, int32_t byteOffset, int32_t length);
11444514f5e3Sopenharmony_ci};
11454514f5e3Sopenharmony_ci
11464514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SharedUint8ArrayRef : public SendableTypedArrayRef {
11474514f5e3Sopenharmony_cipublic:
11484514f5e3Sopenharmony_ci    static Local<SharedUint8ArrayRef> New(const EcmaVM *vm, Local<SendableArrayBufferRef> buffer,
11494514f5e3Sopenharmony_ci                                          int32_t byteOffset, int32_t length);
11504514f5e3Sopenharmony_ci};
11514514f5e3Sopenharmony_ci
11524514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API Uint8ClampedArrayRef : public TypedArrayRef {
11534514f5e3Sopenharmony_cipublic:
11544514f5e3Sopenharmony_ci    static Local<Uint8ClampedArrayRef> New(const EcmaVM *vm, Local<ArrayBufferRef> buffer, int32_t byteOffset,
11554514f5e3Sopenharmony_ci                                           int32_t length);
11564514f5e3Sopenharmony_ci};
11574514f5e3Sopenharmony_ci
11584514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API Int16ArrayRef : public TypedArrayRef {
11594514f5e3Sopenharmony_cipublic:
11604514f5e3Sopenharmony_ci    static Local<Int16ArrayRef> New(const EcmaVM *vm, Local<ArrayBufferRef> buffer, int32_t byteOffset, int32_t length);
11614514f5e3Sopenharmony_ci};
11624514f5e3Sopenharmony_ci
11634514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SharedInt16ArrayRef : public SendableTypedArrayRef {
11644514f5e3Sopenharmony_cipublic:
11654514f5e3Sopenharmony_ci    static Local<SharedInt16ArrayRef> New(const EcmaVM *vm, Local<SendableArrayBufferRef> buffer,
11664514f5e3Sopenharmony_ci                                          int32_t byteOffset, int32_t length);
11674514f5e3Sopenharmony_ci};
11684514f5e3Sopenharmony_ci
11694514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API Uint16ArrayRef : public TypedArrayRef {
11704514f5e3Sopenharmony_cipublic:
11714514f5e3Sopenharmony_ci    static Local<Uint16ArrayRef> New(const EcmaVM *vm, Local<ArrayBufferRef> buffer, int32_t byteOffset,
11724514f5e3Sopenharmony_ci                                     int32_t length);
11734514f5e3Sopenharmony_ci};
11744514f5e3Sopenharmony_ci
11754514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SharedUint16ArrayRef : public SendableTypedArrayRef {
11764514f5e3Sopenharmony_cipublic:
11774514f5e3Sopenharmony_ci    static Local<SharedUint16ArrayRef> New(const EcmaVM *vm, Local<SendableArrayBufferRef> buffer,
11784514f5e3Sopenharmony_ci                                           int32_t byteOffset, int32_t length);
11794514f5e3Sopenharmony_ci};
11804514f5e3Sopenharmony_ci
11814514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API Int32ArrayRef : public TypedArrayRef {
11824514f5e3Sopenharmony_cipublic:
11834514f5e3Sopenharmony_ci    static Local<Int32ArrayRef> New(const EcmaVM *vm, Local<ArrayBufferRef> buffer, int32_t byteOffset, int32_t length);
11844514f5e3Sopenharmony_ci};
11854514f5e3Sopenharmony_ci
11864514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SharedInt32ArrayRef : public SendableTypedArrayRef {
11874514f5e3Sopenharmony_cipublic:
11884514f5e3Sopenharmony_ci    static Local<SharedInt32ArrayRef> New(const EcmaVM *vm, Local<SendableArrayBufferRef> buffer,
11894514f5e3Sopenharmony_ci                                          int32_t byteOffset, int32_t length);
11904514f5e3Sopenharmony_ci};
11914514f5e3Sopenharmony_ci
11924514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SharedFloat32ArrayRef : public SendableTypedArrayRef {
11934514f5e3Sopenharmony_cipublic:
11944514f5e3Sopenharmony_ci    static Local<SharedFloat32ArrayRef> New(const EcmaVM *vm, Local<SendableArrayBufferRef> buffer,
11954514f5e3Sopenharmony_ci                                            int32_t byteOffset, int32_t length);
11964514f5e3Sopenharmony_ci};
11974514f5e3Sopenharmony_ci
11984514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SharedUint8ClampedArrayRef : public SendableTypedArrayRef {
11994514f5e3Sopenharmony_cipublic:
12004514f5e3Sopenharmony_ci    static Local<SharedUint8ClampedArrayRef> New(const EcmaVM *vm, Local<SendableArrayBufferRef> buffer,
12014514f5e3Sopenharmony_ci                                                 int32_t byteOffset, int32_t length);
12024514f5e3Sopenharmony_ci};
12034514f5e3Sopenharmony_ci
12044514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API Uint32ArrayRef : public TypedArrayRef {
12054514f5e3Sopenharmony_cipublic:
12064514f5e3Sopenharmony_ci    static Local<Uint32ArrayRef> New(const EcmaVM *vm, Local<ArrayBufferRef> buffer, int32_t byteOffset,
12074514f5e3Sopenharmony_ci                                     int32_t length);
12084514f5e3Sopenharmony_ci};
12094514f5e3Sopenharmony_ci
12104514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SharedUint32ArrayRef : public SendableTypedArrayRef {
12114514f5e3Sopenharmony_cipublic:
12124514f5e3Sopenharmony_ci    static Local<SharedUint32ArrayRef> New(const EcmaVM *vm, Local<SendableArrayBufferRef> buffer,
12134514f5e3Sopenharmony_ci                                           int32_t byteOffset, int32_t length);
12144514f5e3Sopenharmony_ci};
12154514f5e3Sopenharmony_ci
12164514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API Float32ArrayRef : public TypedArrayRef {
12174514f5e3Sopenharmony_cipublic:
12184514f5e3Sopenharmony_ci    static Local<Float32ArrayRef> New(const EcmaVM *vm, Local<ArrayBufferRef> buffer, int32_t byteOffset,
12194514f5e3Sopenharmony_ci                                      int32_t length);
12204514f5e3Sopenharmony_ci};
12214514f5e3Sopenharmony_ci
12224514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API Float64ArrayRef : public TypedArrayRef {
12234514f5e3Sopenharmony_cipublic:
12244514f5e3Sopenharmony_ci    static Local<Float64ArrayRef> New(const EcmaVM *vm, Local<ArrayBufferRef> buffer, int32_t byteOffset,
12254514f5e3Sopenharmony_ci                                      int32_t length);
12264514f5e3Sopenharmony_ci};
12274514f5e3Sopenharmony_ci
12284514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API BigInt64ArrayRef : public TypedArrayRef {
12294514f5e3Sopenharmony_cipublic:
12304514f5e3Sopenharmony_ci    static Local<BigInt64ArrayRef> New(const EcmaVM *vm, Local<ArrayBufferRef> buffer, int32_t byteOffset,
12314514f5e3Sopenharmony_ci                                      int32_t length);
12324514f5e3Sopenharmony_ci};
12334514f5e3Sopenharmony_ci
12344514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API BigUint64ArrayRef : public TypedArrayRef {
12354514f5e3Sopenharmony_cipublic:
12364514f5e3Sopenharmony_ci    static Local<BigUint64ArrayRef> New(const EcmaVM *vm, Local<ArrayBufferRef> buffer, int32_t byteOffset,
12374514f5e3Sopenharmony_ci                                      int32_t length);
12384514f5e3Sopenharmony_ci};
12394514f5e3Sopenharmony_ci
12404514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API Exception {
12414514f5e3Sopenharmony_cipublic:
12424514f5e3Sopenharmony_ci    static Local<JSValueRef> Error(const EcmaVM *vm, Local<StringRef> message);
12434514f5e3Sopenharmony_ci    static Local<JSValueRef> RangeError(const EcmaVM *vm, Local<StringRef> message);
12444514f5e3Sopenharmony_ci    static Local<JSValueRef> ReferenceError(const EcmaVM *vm, Local<StringRef> message);
12454514f5e3Sopenharmony_ci    static Local<JSValueRef> SyntaxError(const EcmaVM *vm, Local<StringRef> message);
12464514f5e3Sopenharmony_ci    static Local<JSValueRef> TypeError(const EcmaVM *vm, Local<StringRef> message);
12474514f5e3Sopenharmony_ci    static Local<JSValueRef> AggregateError(const EcmaVM *vm, Local<StringRef> message);
12484514f5e3Sopenharmony_ci    static Local<JSValueRef> EvalError(const EcmaVM *vm, Local<StringRef> message);
12494514f5e3Sopenharmony_ci    static Local<JSValueRef> OOMError(const EcmaVM *vm, Local<StringRef> message);
12504514f5e3Sopenharmony_ci    static Local<JSValueRef> TerminationError(const EcmaVM *vm, Local<StringRef> message);
12514514f5e3Sopenharmony_ci};
12524514f5e3Sopenharmony_ci
12534514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API FunctionCallScope {
12544514f5e3Sopenharmony_cipublic:
12554514f5e3Sopenharmony_ci    FunctionCallScope(EcmaVM *vm);
12564514f5e3Sopenharmony_ci    ~FunctionCallScope();
12574514f5e3Sopenharmony_ci
12584514f5e3Sopenharmony_ciprivate:
12594514f5e3Sopenharmony_ci    EcmaVM *vm_;
12604514f5e3Sopenharmony_ci};
12614514f5e3Sopenharmony_ci
12624514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API JSExecutionScope {
12634514f5e3Sopenharmony_cipublic:
12644514f5e3Sopenharmony_ci    explicit JSExecutionScope(const EcmaVM *vm);
12654514f5e3Sopenharmony_ci    ~JSExecutionScope();
12664514f5e3Sopenharmony_ci    ECMA_DISALLOW_COPY(JSExecutionScope);
12674514f5e3Sopenharmony_ci    ECMA_DISALLOW_MOVE(JSExecutionScope);
12684514f5e3Sopenharmony_ci
12694514f5e3Sopenharmony_ciprivate:
12704514f5e3Sopenharmony_ci    void *lastCurrentThread_ = nullptr;
12714514f5e3Sopenharmony_ci    bool isRevert_ = false;
12724514f5e3Sopenharmony_ci};
12734514f5e3Sopenharmony_ci
12744514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API JsiNativeScope {
12754514f5e3Sopenharmony_cipublic:
12764514f5e3Sopenharmony_ci    explicit JsiNativeScope(const EcmaVM *vm);
12774514f5e3Sopenharmony_ci    ~JsiNativeScope();
12784514f5e3Sopenharmony_ci    ECMA_DISALLOW_COPY(JsiNativeScope);
12794514f5e3Sopenharmony_ci    ECMA_DISALLOW_MOVE(JsiNativeScope);
12804514f5e3Sopenharmony_ci
12814514f5e3Sopenharmony_ciprivate:
12824514f5e3Sopenharmony_ci    JSThread *thread_;
12834514f5e3Sopenharmony_ci    uint16_t oldThreadState_;
12844514f5e3Sopenharmony_ci};
12854514f5e3Sopenharmony_ci
12864514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API JsiFastNativeScope {
12874514f5e3Sopenharmony_cipublic:
12884514f5e3Sopenharmony_ci    explicit JsiFastNativeScope(const EcmaVM *vm);
12894514f5e3Sopenharmony_ci    ~JsiFastNativeScope();
12904514f5e3Sopenharmony_ci    ECMA_DISALLOW_COPY(JsiFastNativeScope);
12914514f5e3Sopenharmony_ci    ECMA_DISALLOW_MOVE(JsiFastNativeScope);
12924514f5e3Sopenharmony_ci
12934514f5e3Sopenharmony_ciprivate:
12944514f5e3Sopenharmony_ci    JSThread *thread_ {nullptr};
12954514f5e3Sopenharmony_ci    uint16_t oldThreadState_ {0};
12964514f5e3Sopenharmony_ci    bool hasSwitchState_ {false};
12974514f5e3Sopenharmony_ci};
12984514f5e3Sopenharmony_ci
12994514f5e3Sopenharmony_ci/**
13004514f5e3Sopenharmony_ci * JsiRuntimeCallInfo is used for ace_engine and napi, is same to ark EcamRuntimeCallInfo except data.
13014514f5e3Sopenharmony_ci */
13024514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API JsiRuntimeCallInfo
13034514f5e3Sopenharmony_ci    : public ecmascript::base::AlignedStruct<ecmascript::base::AlignedPointer::Size(),
13044514f5e3Sopenharmony_ci                                             ecmascript::base::AlignedPointer,
13054514f5e3Sopenharmony_ci                                             ecmascript::base::AlignedPointer,
13064514f5e3Sopenharmony_ci                                             ecmascript::base::AlignedPointer> {
13074514f5e3Sopenharmony_ci    enum class Index : size_t {
13084514f5e3Sopenharmony_ci        ThreadIndex = 0,
13094514f5e3Sopenharmony_ci        NumArgsIndex,
13104514f5e3Sopenharmony_ci        StackArgsIndex,
13114514f5e3Sopenharmony_ci        NumOfMembers
13124514f5e3Sopenharmony_ci    };
13134514f5e3Sopenharmony_cipublic:
13144514f5e3Sopenharmony_ci    JsiRuntimeCallInfo() = default;
13154514f5e3Sopenharmony_ci    ~JsiRuntimeCallInfo() = default;
13164514f5e3Sopenharmony_ci
13174514f5e3Sopenharmony_ci    inline JSThread *GetThread() const
13184514f5e3Sopenharmony_ci    {
13194514f5e3Sopenharmony_ci        return thread_;
13204514f5e3Sopenharmony_ci    }
13214514f5e3Sopenharmony_ci
13224514f5e3Sopenharmony_ci    EcmaVM *GetVM() const;
13234514f5e3Sopenharmony_ci
13244514f5e3Sopenharmony_ci    inline uint32_t GetArgsNumber() const
13254514f5e3Sopenharmony_ci    {
13264514f5e3Sopenharmony_ci        ECMA_ASSERT(numArgs_ >= FIRST_ARGS_INDEX);
13274514f5e3Sopenharmony_ci        return numArgs_ - FIRST_ARGS_INDEX;
13284514f5e3Sopenharmony_ci    }
13294514f5e3Sopenharmony_ci
13304514f5e3Sopenharmony_ci    void* GetData();
13314514f5e3Sopenharmony_ci
13324514f5e3Sopenharmony_ci    inline Local<JSValueRef> GetFunctionRef() const
13334514f5e3Sopenharmony_ci    {
13344514f5e3Sopenharmony_ci        return GetArgRef(FUNC_INDEX);
13354514f5e3Sopenharmony_ci    }
13364514f5e3Sopenharmony_ci
13374514f5e3Sopenharmony_ci    inline Local<JSValueRef> GetNewTargetRef() const
13384514f5e3Sopenharmony_ci    {
13394514f5e3Sopenharmony_ci        return GetArgRef(NEW_TARGET_INDEX);
13404514f5e3Sopenharmony_ci    }
13414514f5e3Sopenharmony_ci
13424514f5e3Sopenharmony_ci    inline Local<JSValueRef> GetThisRef() const
13434514f5e3Sopenharmony_ci    {
13444514f5e3Sopenharmony_ci        return GetArgRef(THIS_INDEX);
13454514f5e3Sopenharmony_ci    }
13464514f5e3Sopenharmony_ci
13474514f5e3Sopenharmony_ci    inline Local<JSValueRef> GetCallArgRef(uint32_t idx) const
13484514f5e3Sopenharmony_ci    {
13494514f5e3Sopenharmony_ci        return GetArgRef(FIRST_ARGS_INDEX + idx);
13504514f5e3Sopenharmony_ci    }
13514514f5e3Sopenharmony_ci
13524514f5e3Sopenharmony_ciprivate:
13534514f5e3Sopenharmony_ci    enum ArgsIndex : uint8_t { FUNC_INDEX = 0, NEW_TARGET_INDEX, THIS_INDEX, FIRST_ARGS_INDEX };
13544514f5e3Sopenharmony_ci
13554514f5e3Sopenharmony_ci    Local<JSValueRef> GetArgRef(uint32_t idx) const
13564514f5e3Sopenharmony_ci    {
13574514f5e3Sopenharmony_ci        return Local<JSValueRef>(GetArgAddress(idx));
13584514f5e3Sopenharmony_ci    }
13594514f5e3Sopenharmony_ci
13604514f5e3Sopenharmony_ci    uintptr_t GetArgAddress(uint32_t idx) const
13614514f5e3Sopenharmony_ci    {
13624514f5e3Sopenharmony_ci        if (idx < GetArgsNumber() + FIRST_ARGS_INDEX) {
13634514f5e3Sopenharmony_ci            return reinterpret_cast<uintptr_t>(&stackArgs_[idx]);
13644514f5e3Sopenharmony_ci        }
13654514f5e3Sopenharmony_ci        return 0U;
13664514f5e3Sopenharmony_ci    }
13674514f5e3Sopenharmony_ci
13684514f5e3Sopenharmony_ciprivate:
13694514f5e3Sopenharmony_ci    alignas(sizeof(JSTaggedType)) JSThread *thread_ {nullptr};
13704514f5e3Sopenharmony_ci    alignas(sizeof(JSTaggedType))  uint32_t numArgs_ = 0;
13714514f5e3Sopenharmony_ci    __extension__ alignas(sizeof(JSTaggedType)) JSTaggedType stackArgs_[0];
13724514f5e3Sopenharmony_ci    friend class FunctionRef;
13734514f5e3Sopenharmony_ci};
13744514f5e3Sopenharmony_ci
13754514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API MapRef : public ObjectRef {
13764514f5e3Sopenharmony_cipublic:
13774514f5e3Sopenharmony_ci    int32_t GetSize(const EcmaVM *vm);
13784514f5e3Sopenharmony_ci    int32_t GetTotalElements(const EcmaVM *vm);
13794514f5e3Sopenharmony_ci    Local<JSValueRef> Get(const EcmaVM *vm, Local<JSValueRef> key);
13804514f5e3Sopenharmony_ci    Local<JSValueRef> Get(const EcmaVM *vm, const char *utf8);
13814514f5e3Sopenharmony_ci    Local<JSValueRef> GetKey(const EcmaVM *vm, int entry);
13824514f5e3Sopenharmony_ci    Local<JSValueRef> GetValue(const EcmaVM *vm, int entry);
13834514f5e3Sopenharmony_ci    static Local<MapRef> New(const EcmaVM *vm);
13844514f5e3Sopenharmony_ci    void Set(const EcmaVM *vm, Local<JSValueRef> key, Local<JSValueRef> value);
13854514f5e3Sopenharmony_ci    void Set(const EcmaVM *vm, const char *utf8, Local<JSValueRef> value);
13864514f5e3Sopenharmony_ci    bool Has(const EcmaVM *vm, Local<JSValueRef> key);
13874514f5e3Sopenharmony_ci    bool Has(const EcmaVM *vm, const char *utf8);
13884514f5e3Sopenharmony_ci    void Delete(const EcmaVM *vm, Local<JSValueRef> key);
13894514f5e3Sopenharmony_ci    void Clear(const EcmaVM *vm);
13904514f5e3Sopenharmony_ci    Local<MapIteratorRef> GetEntries(const EcmaVM *vm);
13914514f5e3Sopenharmony_ci    Local<MapIteratorRef> GetKeys(const EcmaVM *vm);
13924514f5e3Sopenharmony_ci    Local<MapIteratorRef> GetValues(const EcmaVM *vm);
13934514f5e3Sopenharmony_ci};
13944514f5e3Sopenharmony_ci
13954514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SendableMapRef : public ObjectRef {
13964514f5e3Sopenharmony_cipublic:
13974514f5e3Sopenharmony_ci    static Local<SendableMapRef> New(const EcmaVM *vm);
13984514f5e3Sopenharmony_ci    uint32_t GetSize(const EcmaVM *vm);
13994514f5e3Sopenharmony_ci    uint32_t GetTotalElements(const EcmaVM *vm);
14004514f5e3Sopenharmony_ci    Local<JSValueRef> Get(const EcmaVM *vm, Local<JSValueRef> key);
14014514f5e3Sopenharmony_ci    Local<JSValueRef> Get(const EcmaVM *vm, const char *utf8);
14024514f5e3Sopenharmony_ci    Local<JSValueRef> GetKey(const EcmaVM *vm, int entry);
14034514f5e3Sopenharmony_ci    Local<JSValueRef> GetValue(const EcmaVM *vm, int entry);
14044514f5e3Sopenharmony_ci    void Set(const EcmaVM *vm, Local<JSValueRef> key, Local<JSValueRef> value);
14054514f5e3Sopenharmony_ci    void Set(const EcmaVM *vm, const char *utf8, Local<JSValueRef> value);
14064514f5e3Sopenharmony_ci    bool Has(const EcmaVM *vm, Local<JSValueRef> key);
14074514f5e3Sopenharmony_ci    bool Has(const EcmaVM *vm, const char *utf8);
14084514f5e3Sopenharmony_ci    void Delete(const EcmaVM *vm, Local<JSValueRef> key);
14094514f5e3Sopenharmony_ci    void Clear(const EcmaVM *vm);
14104514f5e3Sopenharmony_ci    Local<SendableMapIteratorRef> GetEntries(const EcmaVM *vm);
14114514f5e3Sopenharmony_ci    Local<SendableMapIteratorRef> GetKeys(const EcmaVM *vm);
14124514f5e3Sopenharmony_ci    Local<SendableMapIteratorRef> GetValues(const EcmaVM *vm);
14134514f5e3Sopenharmony_ci};
14144514f5e3Sopenharmony_ci
14154514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SendableSetRef : public ObjectRef {
14164514f5e3Sopenharmony_cipublic:
14174514f5e3Sopenharmony_ci    static Local<SendableSetRef> New(const EcmaVM *vm);
14184514f5e3Sopenharmony_ci    uint32_t GetSize(const EcmaVM *vm);
14194514f5e3Sopenharmony_ci    uint32_t GetTotalElements(const EcmaVM *vm);
14204514f5e3Sopenharmony_ci    Local<JSValueRef> GetValue(const EcmaVM *vm, int entry);
14214514f5e3Sopenharmony_ci    void Add(const EcmaVM *vm, Local<JSValueRef> value);
14224514f5e3Sopenharmony_ci};
14234514f5e3Sopenharmony_ci
14244514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API BufferRef : public ObjectRef {
14254514f5e3Sopenharmony_cipublic:
14264514f5e3Sopenharmony_ci    static Local<BufferRef> New(const EcmaVM *vm, int32_t length);
14274514f5e3Sopenharmony_ci    static Local<BufferRef> New(const EcmaVM *vm, void *buffer, int32_t length, const NativePointerCallback &deleter,
14284514f5e3Sopenharmony_ci                                void *data);
14294514f5e3Sopenharmony_ci
14304514f5e3Sopenharmony_ci    int32_t ByteLength(const EcmaVM *vm);
14314514f5e3Sopenharmony_ci    void *GetBuffer(const EcmaVM *vm);
14324514f5e3Sopenharmony_ci    static ecmascript::JSTaggedValue BufferToStringCallback(ecmascript::EcmaRuntimeCallInfo *ecmaRuntimeCallInfo);
14334514f5e3Sopenharmony_ci};
14344514f5e3Sopenharmony_ci
14354514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API PromiseRef : public ObjectRef {
14364514f5e3Sopenharmony_cipublic:
14374514f5e3Sopenharmony_ci    Local<PromiseRef> Catch(const EcmaVM *vm, Local<FunctionRef> handler);
14384514f5e3Sopenharmony_ci    Local<PromiseRef> Then(const EcmaVM *vm, Local<FunctionRef> handler);
14394514f5e3Sopenharmony_ci    Local<PromiseRef> Finally(const EcmaVM *vm, Local<FunctionRef> handler);
14404514f5e3Sopenharmony_ci    Local<PromiseRef> Then(const EcmaVM *vm, Local<FunctionRef> onFulfilled, Local<FunctionRef> onRejected);
14414514f5e3Sopenharmony_ci
14424514f5e3Sopenharmony_ci    Local<JSValueRef> GetPromiseState(const EcmaVM *vm);
14434514f5e3Sopenharmony_ci    Local<JSValueRef> GetPromiseResult(const EcmaVM *vm);
14444514f5e3Sopenharmony_ci};
14454514f5e3Sopenharmony_ci
14464514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API PromiseCapabilityRef : public ObjectRef {
14474514f5e3Sopenharmony_cipublic:
14484514f5e3Sopenharmony_ci    static Local<PromiseCapabilityRef> New(const EcmaVM *vm);
14494514f5e3Sopenharmony_ci    bool Resolve(const EcmaVM *vm, uintptr_t value);
14504514f5e3Sopenharmony_ci    bool Resolve(const EcmaVM *vm, Local<JSValueRef> value);
14514514f5e3Sopenharmony_ci    bool Reject(const EcmaVM *vm, uintptr_t reason);
14524514f5e3Sopenharmony_ci    bool Reject(const EcmaVM *vm, Local<JSValueRef> reason);
14534514f5e3Sopenharmony_ci    Local<PromiseRef> GetPromise(const EcmaVM *vm);
14544514f5e3Sopenharmony_ci};
14554514f5e3Sopenharmony_ci
14564514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API NumberRef : public PrimitiveRef {
14574514f5e3Sopenharmony_cipublic:
14584514f5e3Sopenharmony_ci    static Local<NumberRef> New(const EcmaVM *vm, double input);
14594514f5e3Sopenharmony_ci    static Local<NumberRef> New(const EcmaVM *vm, int32_t input);
14604514f5e3Sopenharmony_ci    static Local<NumberRef> New(const EcmaVM *vm, uint32_t input);
14614514f5e3Sopenharmony_ci    static Local<NumberRef> New(const EcmaVM *vm, int64_t input);
14624514f5e3Sopenharmony_ci
14634514f5e3Sopenharmony_ci    double Value();
14644514f5e3Sopenharmony_ci};
14654514f5e3Sopenharmony_ci
14664514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API DataViewRef : public ObjectRef {
14674514f5e3Sopenharmony_cipublic:
14684514f5e3Sopenharmony_ci    static Local<DataViewRef> New(const EcmaVM *vm, Local<ArrayBufferRef> arrayBuffer, uint32_t byteOffset,
14694514f5e3Sopenharmony_ci                                  uint32_t byteLength);
14704514f5e3Sopenharmony_ci    uint32_t ByteLength();
14714514f5e3Sopenharmony_ci    uint32_t ByteOffset();
14724514f5e3Sopenharmony_ci    Local<ArrayBufferRef> GetArrayBuffer(const EcmaVM *vm);
14734514f5e3Sopenharmony_ci};
14744514f5e3Sopenharmony_ci
14754514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API MapIteratorRef : public ObjectRef {
14764514f5e3Sopenharmony_cipublic:
14774514f5e3Sopenharmony_ci    int32_t GetIndex();
14784514f5e3Sopenharmony_ci    Local<JSValueRef> GetKind(const EcmaVM *vm);
14794514f5e3Sopenharmony_ci    static Local<MapIteratorRef> New(const EcmaVM *vm, Local<MapRef> map);
14804514f5e3Sopenharmony_ci    ecmascript::EcmaRuntimeCallInfo* GetEcmaRuntimeCallInfo(const EcmaVM *vm);
14814514f5e3Sopenharmony_ci    static Local<ArrayRef> Next(const EcmaVM *vm, ecmascript::EcmaRuntimeCallInfo* ecmaRuntimeCallInfo);
14824514f5e3Sopenharmony_ci    Local<JSValueRef> Next(const EcmaVM *vm);
14834514f5e3Sopenharmony_ci};
14844514f5e3Sopenharmony_ci
14854514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SendableMapIteratorRef : public ObjectRef {
14864514f5e3Sopenharmony_cipublic:
14874514f5e3Sopenharmony_ci    Local<JSValueRef> Next(const EcmaVM *vm);
14884514f5e3Sopenharmony_ci};
14894514f5e3Sopenharmony_ci
14904514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API JSNApi {
14914514f5e3Sopenharmony_cipublic:
14924514f5e3Sopenharmony_ci    struct DebugOption {
14934514f5e3Sopenharmony_ci        const char *libraryPath;
14944514f5e3Sopenharmony_ci        bool isDebugMode = false;
14954514f5e3Sopenharmony_ci        int port = -1;
14964514f5e3Sopenharmony_ci    };
14974514f5e3Sopenharmony_ci    using DebuggerPostTask = std::function<void(std::function<void()>&&)>;
14984514f5e3Sopenharmony_ci
14994514f5e3Sopenharmony_ci    using UncatchableErrorHandler = std::function<void(panda::TryCatch&)>;
15004514f5e3Sopenharmony_ci
15014514f5e3Sopenharmony_ci    struct NativeBindingInfo {
15024514f5e3Sopenharmony_ci        static NativeBindingInfo* CreateNewInstance() { return new(std::nothrow) NativeBindingInfo(); }
15034514f5e3Sopenharmony_ci        void *env = nullptr;
15044514f5e3Sopenharmony_ci        void *nativeValue = nullptr;
15054514f5e3Sopenharmony_ci        void *attachFunc = nullptr;
15064514f5e3Sopenharmony_ci        void *attachData = nullptr;
15074514f5e3Sopenharmony_ci        void *detachFunc = nullptr;
15084514f5e3Sopenharmony_ci        void *detachData = nullptr;
15094514f5e3Sopenharmony_ci        void *hint = nullptr;
15104514f5e3Sopenharmony_ci    };
15114514f5e3Sopenharmony_ci
15124514f5e3Sopenharmony_ci    // JSVM
15134514f5e3Sopenharmony_ci    // fixme: Rename SEMI_GC to YOUNG_GC
15144514f5e3Sopenharmony_ci    enum class ECMA_PUBLIC_API TRIGGER_GC_TYPE : uint8_t {
15154514f5e3Sopenharmony_ci        SEMI_GC,
15164514f5e3Sopenharmony_ci        OLD_GC,
15174514f5e3Sopenharmony_ci        FULL_GC,
15184514f5e3Sopenharmony_ci        SHARED_GC,
15194514f5e3Sopenharmony_ci        SHARED_FULL_GC
15204514f5e3Sopenharmony_ci    };
15214514f5e3Sopenharmony_ci
15224514f5e3Sopenharmony_ci    enum class ECMA_PUBLIC_API TRIGGER_IDLE_GC_TYPE : uint8_t {
15234514f5e3Sopenharmony_ci        LOCAL_CONCURRENT_MARK = 1,
15244514f5e3Sopenharmony_ci        LOCAL_REMARK = 1 << 1,
15254514f5e3Sopenharmony_ci        FULL_GC = 1 << 2,
15264514f5e3Sopenharmony_ci        SHARED_CONCURRENT_MARK = 1 << 3,
15274514f5e3Sopenharmony_ci        SHARED_FULL_GC = 1 << 4,
15284514f5e3Sopenharmony_ci    };
15294514f5e3Sopenharmony_ci
15304514f5e3Sopenharmony_ci    enum class ECMA_PUBLIC_API MemoryReduceDegree : uint8_t {
15314514f5e3Sopenharmony_ci        LOW = 0,
15324514f5e3Sopenharmony_ci        MIDDLE,
15334514f5e3Sopenharmony_ci        HIGH,
15344514f5e3Sopenharmony_ci    };
15354514f5e3Sopenharmony_ci
15364514f5e3Sopenharmony_ci    enum class PatchErrorCode : uint8_t {
15374514f5e3Sopenharmony_ci        SUCCESS = 0,
15384514f5e3Sopenharmony_ci        PATCH_HAS_LOADED,
15394514f5e3Sopenharmony_ci        PATCH_NOT_LOADED,
15404514f5e3Sopenharmony_ci        FILE_NOT_EXECUTED,
15414514f5e3Sopenharmony_ci        FILE_NOT_FOUND,
15424514f5e3Sopenharmony_ci        PACKAGE_NOT_ESMODULE,
15434514f5e3Sopenharmony_ci        MODIFY_IMPORT_EXPORT_NOT_SUPPORT,
15444514f5e3Sopenharmony_ci        INTERNAL_ERROR
15454514f5e3Sopenharmony_ci    };
15464514f5e3Sopenharmony_ci
15474514f5e3Sopenharmony_ci    static EcmaVM *CreateJSVM(const RuntimeOption &option);
15484514f5e3Sopenharmony_ci    static void DestroyJSVM(EcmaVM *ecmaVm);
15494514f5e3Sopenharmony_ci    static void RegisterUncatchableErrorHandler(EcmaVM *ecmaVm, const UncatchableErrorHandler &handler);
15504514f5e3Sopenharmony_ci
15514514f5e3Sopenharmony_ci    // aot load
15524514f5e3Sopenharmony_ci    static void LoadAotFileInternal(EcmaVM *vm, const std::string &moduleName, std::string &aotFileName);
15534514f5e3Sopenharmony_ci    static void LoadAotFile(EcmaVM *vm, const std::string &moduleName);
15544514f5e3Sopenharmony_ci#if defined(CROSS_PLATFORM) && defined(ANDROID_PLATFORM)
15554514f5e3Sopenharmony_ci    static void LoadAotFile(EcmaVM *vm, [[maybe_unused]] const std::string &bundleName,
15564514f5e3Sopenharmony_ci                            const std::string &moduleName,
15574514f5e3Sopenharmony_ci                            std::function<bool(std::string fileName, uint8_t **buff, size_t *buffSize)> cb);
15584514f5e3Sopenharmony_ci#endif
15594514f5e3Sopenharmony_ci    // context
15604514f5e3Sopenharmony_ci    static EcmaContext *CreateJSContext(EcmaVM *vm);
15614514f5e3Sopenharmony_ci    static void SwitchCurrentContext(EcmaVM *vm, EcmaContext *context);
15624514f5e3Sopenharmony_ci    static void DestroyJSContext(EcmaVM *vm, EcmaContext *context);
15634514f5e3Sopenharmony_ci
15644514f5e3Sopenharmony_ci    // context execute
15654514f5e3Sopenharmony_ci    static bool ExecuteInContext(EcmaVM *vm, const std::string &fileName, const std::string &entry,
15664514f5e3Sopenharmony_ci                                 bool needUpdate = false);
15674514f5e3Sopenharmony_ci    // JS code
15684514f5e3Sopenharmony_ci    static bool ExecuteForAbsolutePath(const EcmaVM *vm, const std::string &fileName, const std::string &entry,
15694514f5e3Sopenharmony_ci                                       bool needUpdate = false, bool executeFromJob = false);
15704514f5e3Sopenharmony_ci    static bool Execute(const EcmaVM *vm, const std::string &fileName, const std::string &entry,
15714514f5e3Sopenharmony_ci                        bool needUpdate = false, bool executeFromJob = false);
15724514f5e3Sopenharmony_ci    static bool Execute(EcmaVM *vm, const uint8_t *data, int32_t size, const std::string &entry,
15734514f5e3Sopenharmony_ci                        const std::string &filename = "", bool needUpdate = false);
15744514f5e3Sopenharmony_ci    static int ExecuteWithSingletonPatternFlag(EcmaVM *vm, const std::string &bundleName,
15754514f5e3Sopenharmony_ci        const std::string &moduleName, const std::string &ohmurl, bool isSingletonPattern);
15764514f5e3Sopenharmony_ci    static bool IsExecuteModuleInAbcFile(EcmaVM *vm, const std::string &bundleName,
15774514f5e3Sopenharmony_ci        const std::string &moduleName, const std::string &ohmurl);
15784514f5e3Sopenharmony_ci    // merge abc, execute module buffer
15794514f5e3Sopenharmony_ci    static bool ExecuteModuleBuffer(EcmaVM *vm, const uint8_t *data, int32_t size, const std::string &filename = "",
15804514f5e3Sopenharmony_ci                                    bool needUpdate = false);
15814514f5e3Sopenharmony_ci    static bool ExecuteModuleFromBuffer(EcmaVM *vm, const void *data, int32_t size, const std::string &file);
15824514f5e3Sopenharmony_ci    static Local<ObjectRef> GetExportObject(EcmaVM *vm, const std::string &file, const std::string &key);
15834514f5e3Sopenharmony_ci    static Local<ObjectRef> GetExportObjectFromBuffer(EcmaVM *vm, const std::string &file, const std::string &key);
15844514f5e3Sopenharmony_ci    static Local<ObjectRef> GetExportObjectFromOhmUrl(EcmaVM *vm, const std::string &ohmUrl, const std::string &key);
15854514f5e3Sopenharmony_ci    static Local<ObjectRef> ExecuteNativeModule(EcmaVM *vm, const std::string &key);
15864514f5e3Sopenharmony_ci    static Local<ObjectRef> GetModuleNameSpaceFromFile(EcmaVM *vm, const std::string &file,
15874514f5e3Sopenharmony_ci                                                       const std::string &module_path);
15884514f5e3Sopenharmony_ci    static Local<ObjectRef> GetModuleNameSpaceWithModuleInfo(EcmaVM *vm, const std::string &file,
15894514f5e3Sopenharmony_ci                                                             const std::string &module_path);
15904514f5e3Sopenharmony_ci
15914514f5e3Sopenharmony_ci    /*
15924514f5e3Sopenharmony_ci     * Execute panda file from secure mem. secure memory lifecycle managed externally.
15934514f5e3Sopenharmony_ci     * The data parameter needs to be created externally by an external caller and managed externally
15944514f5e3Sopenharmony_ci     * by the external caller. The size parameter is the size of the data memory. The entry parameter
15954514f5e3Sopenharmony_ci     * is the name of the entry function. The filename parameter is used to uniquely identify this
15964514f5e3Sopenharmony_ci     * memory internally.
15974514f5e3Sopenharmony_ci     */
15984514f5e3Sopenharmony_ci    static bool ExecuteSecure(EcmaVM *vm, uint8_t *data, int32_t size, const std::string &entry,
15994514f5e3Sopenharmony_ci                                const std::string &filename = "", bool needUpdate = false);
16004514f5e3Sopenharmony_ci    /*
16014514f5e3Sopenharmony_ci     * Execute panda file(merge abc) from secure mem. secure memory lifecycle managed externally.
16024514f5e3Sopenharmony_ci     * The data parameter needs to be created externally by an external caller and managed externally
16034514f5e3Sopenharmony_ci     * by the external caller. The size parameter is the size of the data memory. The filename parameter
16044514f5e3Sopenharmony_ci     * is used to uniquely identify this memory internally.
16054514f5e3Sopenharmony_ci     */
16064514f5e3Sopenharmony_ci    static bool ExecuteModuleBufferSecure(EcmaVM *vm, uint8_t *data, int32_t size, const std::string &filename = "",
16074514f5e3Sopenharmony_ci                                          bool needUpdate = false);
16084514f5e3Sopenharmony_ci
16094514f5e3Sopenharmony_ci    static bool ExecuteSecureWithOhmUrl(EcmaVM *vm, uint8_t *data, int32_t size, const std::string &srcFilename,
16104514f5e3Sopenharmony_ci                                        const std::string &ohmUrl);
16114514f5e3Sopenharmony_ci
16124514f5e3Sopenharmony_ci    // ObjectRef Operation
16134514f5e3Sopenharmony_ci    static Local<ObjectRef> GetGlobalObject(const EcmaVM *vm);
16144514f5e3Sopenharmony_ci    static void ExecutePendingJob(const EcmaVM *vm);
16154514f5e3Sopenharmony_ci
16164514f5e3Sopenharmony_ci    // Memory
16174514f5e3Sopenharmony_ci    // fixme: Rename SEMI_GC to YOUNG_GC
16184514f5e3Sopenharmony_ci    static void TriggerGC(const EcmaVM *vm, TRIGGER_GC_TYPE gcType = TRIGGER_GC_TYPE::SEMI_GC);
16194514f5e3Sopenharmony_ci    static void TriggerGC(const EcmaVM *vm, ecmascript::GCReason reason,
16204514f5e3Sopenharmony_ci        TRIGGER_GC_TYPE gcType = TRIGGER_GC_TYPE::SEMI_GC);
16214514f5e3Sopenharmony_ci    static void HintGC(const EcmaVM *vm, MemoryReduceDegree degree, ecmascript::GCReason reason);
16224514f5e3Sopenharmony_ci    static void TriggerIdleGC(const EcmaVM *vm, TRIGGER_IDLE_GC_TYPE gcType);
16234514f5e3Sopenharmony_ci    static void SetStartIdleMonitorCallback(const StartIdleMonitorCallback& callback);
16244514f5e3Sopenharmony_ci    static StartIdleMonitorCallback GetStartIdleMonitorCallback();
16254514f5e3Sopenharmony_ci    // Exception
16264514f5e3Sopenharmony_ci    static void ThrowException(const EcmaVM *vm, Local<JSValueRef> error);
16274514f5e3Sopenharmony_ci    static void PrintExceptionInfo(const EcmaVM *vm);
16284514f5e3Sopenharmony_ci    static Local<ObjectRef> GetAndClearUncaughtException(const EcmaVM *vm);
16294514f5e3Sopenharmony_ci    static Local<ObjectRef> GetUncaughtException(const EcmaVM *vm);
16304514f5e3Sopenharmony_ci    static bool IsExecutingPendingJob(const EcmaVM *vm);
16314514f5e3Sopenharmony_ci    static bool HasPendingException(const EcmaVM *vm);
16324514f5e3Sopenharmony_ci    static bool HasPendingJob(const EcmaVM *vm);
16334514f5e3Sopenharmony_ci    static void EnableUserUncaughtErrorHandler(EcmaVM *vm);
16344514f5e3Sopenharmony_ci    // prevewer debugger.
16354514f5e3Sopenharmony_ci    static bool StartDebuggerCheckParameters(EcmaVM *vm, const DebugOption &option, int32_t instanceId,
16364514f5e3Sopenharmony_ci                                             const DebuggerPostTask &debuggerPostTask);
16374514f5e3Sopenharmony_ci    static bool StartDebugger(EcmaVM *vm, const DebugOption &option, int32_t instanceId = 0,
16384514f5e3Sopenharmony_ci        const DebuggerPostTask &debuggerPostTask = {});
16394514f5e3Sopenharmony_ci    // To be compatible with the old process.
16404514f5e3Sopenharmony_ci    static bool StartDebuggerForOldProcess(EcmaVM *vm, const DebugOption &option, int32_t instanceId = 0,
16414514f5e3Sopenharmony_ci        const DebuggerPostTask &debuggerPostTask = {});
16424514f5e3Sopenharmony_ci    // socketpair process in ohos platform.
16434514f5e3Sopenharmony_ci    static bool StartDebuggerForSocketPair(int tid, int socketfd = -1);
16444514f5e3Sopenharmony_ci    static bool StopDebugger(int tid);
16454514f5e3Sopenharmony_ci    static bool NotifyDebugMode(int tid, EcmaVM *vm, const DebugOption &option, int32_t instanceId = 0,
16464514f5e3Sopenharmony_ci                                const DebuggerPostTask &debuggerPostTask = {}, bool debugApp = false);
16474514f5e3Sopenharmony_ci    static bool StoreDebugInfo(
16484514f5e3Sopenharmony_ci        int tid, EcmaVM *vm, const DebugOption &option, const DebuggerPostTask &debuggerPostTask, bool debugApp);
16494514f5e3Sopenharmony_ci    static bool StopDebugger(EcmaVM *vm);
16504514f5e3Sopenharmony_ci    static bool IsMixedDebugEnabled(const EcmaVM *vm);
16514514f5e3Sopenharmony_ci    static bool IsDebugModeEnabled(const EcmaVM *vm);
16524514f5e3Sopenharmony_ci    static void NotifyNativeCalling(const EcmaVM *vm, const void *nativeAddress);
16534514f5e3Sopenharmony_ci    static void NotifyNativeReturn(const EcmaVM *vm, const void *nativeAddress);
16544514f5e3Sopenharmony_ci    static void NotifyLoadModule(const EcmaVM *vm);
16554514f5e3Sopenharmony_ci    static void NotifyUIIdle(const EcmaVM *vm, int idleTime);
16564514f5e3Sopenharmony_ci    static void NotifyLooperIdleStart(const EcmaVM *vm, int64_t timestamp, int idleTime);
16574514f5e3Sopenharmony_ci    static void NotifyLooperIdleEnd(const EcmaVM *vm, int64_t timestamp);
16584514f5e3Sopenharmony_ci    static bool IsJSMainThreadOfEcmaVM(const EcmaVM *vm);
16594514f5e3Sopenharmony_ci    static void SetDeviceDisconnectCallback(EcmaVM *vm, DeviceDisconnectCallback cb);
16604514f5e3Sopenharmony_ci    // Serialize & Deserialize.
16614514f5e3Sopenharmony_ci    static void* SerializeValue(const EcmaVM *vm, Local<JSValueRef> data, Local<JSValueRef> transfer,
16624514f5e3Sopenharmony_ci                                Local<JSValueRef> cloneList,
16634514f5e3Sopenharmony_ci                                bool defaultTransfer = false,
16644514f5e3Sopenharmony_ci                                bool defaultCloneShared = true);
16654514f5e3Sopenharmony_ci    static Local<JSValueRef> DeserializeValue(const EcmaVM *vm, void *recoder, void *hint);
16664514f5e3Sopenharmony_ci    static void DeleteSerializationData(void *data);
16674514f5e3Sopenharmony_ci    static void SetHostPromiseRejectionTracker(EcmaVM *vm, void *cb, void* data);
16684514f5e3Sopenharmony_ci    static void SetHostResolveBufferTracker(EcmaVM *vm,
16694514f5e3Sopenharmony_ci        std::function<bool(std::string dirPath, uint8_t **buff, size_t *buffSize, std::string &errorMsg)> cb);
16704514f5e3Sopenharmony_ci    static void SetUnloadNativeModuleCallback(EcmaVM *vm, const std::function<bool(const std::string &moduleKey)> &cb);
16714514f5e3Sopenharmony_ci    static void SetNativePtrGetter(EcmaVM *vm, void* cb);
16724514f5e3Sopenharmony_ci    static void SetSourceMapCallback(EcmaVM *vm, SourceMapCallback cb);
16734514f5e3Sopenharmony_ci    static void SetSourceMapTranslateCallback(EcmaVM *vm, SourceMapTranslateCallback cb);
16744514f5e3Sopenharmony_ci    static void SetHostEnqueueJob(const EcmaVM* vm, Local<JSValueRef> cb,
16754514f5e3Sopenharmony_ci                                QueueType queueType = QueueType::QUEUE_PROMISE);
16764514f5e3Sopenharmony_ci    static EcmaVM* CreateEcmaVM(const ecmascript::JSRuntimeOptions &options);
16774514f5e3Sopenharmony_ci    static void PreFork(EcmaVM *vm);
16784514f5e3Sopenharmony_ci    static void PostFork(EcmaVM *vm, const RuntimeOption &option);
16794514f5e3Sopenharmony_ci    static void AddWorker(EcmaVM *hostVm, EcmaVM *workerVm);
16804514f5e3Sopenharmony_ci    static bool DeleteWorker(EcmaVM *hostVm, EcmaVM *workerVm);
16814514f5e3Sopenharmony_ci    static void GetStackBeforeCallNapiSuccess(EcmaVM *vm, bool &getStackBeforeCallNapiSuccess);
16824514f5e3Sopenharmony_ci    static void GetStackAfterCallNapi(EcmaVM *vm);
16834514f5e3Sopenharmony_ci    static PatchErrorCode LoadPatch(EcmaVM *vm, const std::string &patchFileName, const std::string &baseFileName);
16844514f5e3Sopenharmony_ci    static PatchErrorCode LoadPatch(EcmaVM *vm,
16854514f5e3Sopenharmony_ci                                    const std::string &patchFileName, uint8_t *patchBuffer, size_t patchSize,
16864514f5e3Sopenharmony_ci                                    const std::string &baseFileName, uint8_t *baseBuffer, size_t baseSize);
16874514f5e3Sopenharmony_ci    static PatchErrorCode UnloadPatch(EcmaVM *vm, const std::string &patchFileName);
16884514f5e3Sopenharmony_ci    // check whether the exception is caused by quickfix methods.
16894514f5e3Sopenharmony_ci    static bool IsQuickFixCausedException(EcmaVM *vm, Local<ObjectRef> exception, const std::string &patchFileName);
16904514f5e3Sopenharmony_ci    // register quickfix query function.
16914514f5e3Sopenharmony_ci    static void RegisterQuickFixQueryFunc(EcmaVM *vm, std::function<bool(std::string baseFileName,
16924514f5e3Sopenharmony_ci                        std::string &patchFileName,
16934514f5e3Sopenharmony_ci                        uint8_t **patchBuffer,
16944514f5e3Sopenharmony_ci                        size_t &patchSize)> callBack);
16954514f5e3Sopenharmony_ci    static bool IsBundle(EcmaVM *vm);
16964514f5e3Sopenharmony_ci    static void SetBundle(EcmaVM *vm, bool value);
16974514f5e3Sopenharmony_ci    static bool IsNormalizedOhmUrlPack(EcmaVM *vm);
16984514f5e3Sopenharmony_ci    static bool IsOhmUrl(const std::string &srcName);
16994514f5e3Sopenharmony_ci    static void SetAssetPath(EcmaVM *vm, const std::string &assetPath);
17004514f5e3Sopenharmony_ci    static void SetMockModuleList(EcmaVM *vm, const std::map<std::string, std::string> &list);
17014514f5e3Sopenharmony_ci    static void SetPkgNameList(EcmaVM *vm, const std::map<std::string, std::string> &list);
17024514f5e3Sopenharmony_ci    static std::string GetPkgName(EcmaVM *vm, const std::string &moduleName);
17034514f5e3Sopenharmony_ci    static void SetPkgAliasList(EcmaVM *vm, const std::map<std::string, std::string> &list);
17044514f5e3Sopenharmony_ci    static void SetHmsModuleList(EcmaVM *vm, const std::vector<panda::HmsMap> &list);
17054514f5e3Sopenharmony_ci    static void SetModuleInfo(EcmaVM *vm, const std::string &assetPath, const std::string &entryPoint);
17064514f5e3Sopenharmony_ci    static void SetpkgContextInfoList(EcmaVM *vm, const std::map<std::string,
17074514f5e3Sopenharmony_ci        std::vector<std::vector<std::string>>> &list);
17084514f5e3Sopenharmony_ci    static void SetExecuteBufferMode(const EcmaVM *vm);
17094514f5e3Sopenharmony_ci    static void SetLoop(EcmaVM *vm, void *loop);
17104514f5e3Sopenharmony_ci    static void SetWeakFinalizeTaskCallback(EcmaVM *vm, const WeakFinalizeTaskCallback &callback);
17114514f5e3Sopenharmony_ci    static void SetAsyncCleanTaskCallback(EcmaVM *vm, const NativePointerTaskCallback &callback);
17124514f5e3Sopenharmony_ci    static void SetTriggerGCTaskCallback(EcmaVM *vm, const TriggerGCTaskCallback& callback);
17134514f5e3Sopenharmony_ci    static void SetStartIdleMonitorCallback(EcmaVM *vm, const StartIdleMonitorCallback& callback);
17144514f5e3Sopenharmony_ci    static std::string GetAssetPath(EcmaVM *vm);
17154514f5e3Sopenharmony_ci    static bool InitForConcurrentThread(EcmaVM *vm, ConcurrentCallback cb, void *data);
17164514f5e3Sopenharmony_ci    static bool InitForConcurrentFunction(EcmaVM *vm, Local<JSValueRef> func, void *taskInfo);
17174514f5e3Sopenharmony_ci    static void* GetCurrentTaskInfo(const EcmaVM *vm);
17184514f5e3Sopenharmony_ci    static void ClearCurrentTaskInfo(const EcmaVM *vm);
17194514f5e3Sopenharmony_ci    static void SetBundleName(EcmaVM *vm, const std::string &bundleName);
17204514f5e3Sopenharmony_ci    static std::string GetBundleName(EcmaVM *vm);
17214514f5e3Sopenharmony_ci    static void SetModuleName(EcmaVM *vm, const std::string &moduleName);
17224514f5e3Sopenharmony_ci    static std::string GetModuleName(EcmaVM *vm);
17234514f5e3Sopenharmony_ci    static std::pair<std::string, std::string> GetCurrentModuleInfo(EcmaVM *vm, bool needRecordName = false);
17244514f5e3Sopenharmony_ci    static std::string NormalizePath(const std::string &string);
17254514f5e3Sopenharmony_ci    static void AllowCrossThreadExecution(EcmaVM *vm);
17264514f5e3Sopenharmony_ci    static void SynchronizVMInfo(EcmaVM *vm, const EcmaVM *hostVM);
17274514f5e3Sopenharmony_ci    static bool IsProfiling(EcmaVM *vm);
17284514f5e3Sopenharmony_ci    static void SetProfilerState(const EcmaVM *vm, bool value);
17294514f5e3Sopenharmony_ci    static void SetRequestAotCallback(EcmaVM *vm, const std::function<int32_t(const std::string &bundleName,
17304514f5e3Sopenharmony_ci                    const std::string &moduleName,
17314514f5e3Sopenharmony_ci                    int32_t triggerMode)> &cb);
17324514f5e3Sopenharmony_ci    static void SetSearchHapPathTracker(EcmaVM *vm, std::function<bool(const std::string moduleName,
17334514f5e3Sopenharmony_ci                    std::string &hapPath)> cb);
17344514f5e3Sopenharmony_ci    static void *GetEnv(EcmaVM *vm);
17354514f5e3Sopenharmony_ci    static void SetEnv(EcmaVM *vm, void *env);
17364514f5e3Sopenharmony_ci    static void SetMultiThreadCheck(bool multiThreadCheck = true);
17374514f5e3Sopenharmony_ci    static void SetErrorInfoEnhance(bool errorInfoEnhance = true);
17384514f5e3Sopenharmony_ci
17394514f5e3Sopenharmony_ci    // Napi Heavy Logics fast path
17404514f5e3Sopenharmony_ci    static Local<JSValueRef> NapiHasProperty(const EcmaVM *vm, uintptr_t nativeObj, uintptr_t key);
17414514f5e3Sopenharmony_ci    static Local<JSValueRef> NapiHasOwnProperty(const EcmaVM *vm, uintptr_t nativeObj, uintptr_t key);
17424514f5e3Sopenharmony_ci    static Local<JSValueRef> NapiGetProperty(const EcmaVM *vm, uintptr_t nativeObj, uintptr_t key);
17434514f5e3Sopenharmony_ci    static Local<JSValueRef> NapiDeleteProperty(const EcmaVM *vm, uintptr_t nativeObj, uintptr_t key);
17444514f5e3Sopenharmony_ci    static Local<JSValueRef> NapiGetNamedProperty(const EcmaVM *vm, uintptr_t nativeObj, const char* utf8Key);
17454514f5e3Sopenharmony_ci
17464514f5e3Sopenharmony_ci    static Local<JSValueRef> CreateLocal(const EcmaVM *vm, JSValueRef src);
17474514f5e3Sopenharmony_ci
17484514f5e3Sopenharmony_ci    // Napi helper function
17494514f5e3Sopenharmony_ci    static bool KeyIsNumber(const char* utf8);
17504514f5e3Sopenharmony_ci    static int GetStartRealTime(const EcmaVM *vm);
17514514f5e3Sopenharmony_ci    static void NotifyTaskBegin(const EcmaVM *vm);
17524514f5e3Sopenharmony_ci    static void NotifyTaskFinished(const EcmaVM *vm);
17534514f5e3Sopenharmony_ci    static bool IsMultiThreadCheckEnabled(const EcmaVM *vm);
17544514f5e3Sopenharmony_ci    static uint32_t GetCurrentThreadId();
17554514f5e3Sopenharmony_ciprivate:
17564514f5e3Sopenharmony_ci    static int vmCount_;
17574514f5e3Sopenharmony_ci    static bool initialize_;
17584514f5e3Sopenharmony_ci    static bool isForked_;
17594514f5e3Sopenharmony_ci    static bool CreateRuntime(const RuntimeOption &option);
17604514f5e3Sopenharmony_ci    static bool DestroyRuntime();
17614514f5e3Sopenharmony_ci    static StartIdleMonitorCallback startIdleMonitorCallback_;
17624514f5e3Sopenharmony_ci
17634514f5e3Sopenharmony_ci    static uintptr_t GetHandleAddr(const EcmaVM *vm, uintptr_t localAddress);
17644514f5e3Sopenharmony_ci    static uintptr_t GetGlobalHandleAddr(const EcmaVM *vm, uintptr_t localAddress);
17654514f5e3Sopenharmony_ci    static uintptr_t SetWeak(const EcmaVM *vm, uintptr_t localAddress);
17664514f5e3Sopenharmony_ci    static uintptr_t SetWeakCallback(const EcmaVM *vm, uintptr_t localAddress, void *ref,
17674514f5e3Sopenharmony_ci                                     WeakRefClearCallBack freeGlobalCallBack,
17684514f5e3Sopenharmony_ci                                     WeakRefClearCallBack nativeFinalizeCallback);
17694514f5e3Sopenharmony_ci    static uintptr_t ClearWeak(const EcmaVM *vm, uintptr_t localAddress);
17704514f5e3Sopenharmony_ci    static bool IsWeak(const EcmaVM *vm, uintptr_t localAddress);
17714514f5e3Sopenharmony_ci    static void DisposeGlobalHandleAddr(const EcmaVM *vm, uintptr_t addr);
17724514f5e3Sopenharmony_ci    static bool IsSerializationTimeoutCheckEnabled(const EcmaVM *vm);
17734514f5e3Sopenharmony_ci    static void GenerateTimeoutTraceIfNeeded(const EcmaVM *vm, std::chrono::system_clock::time_point &start,
17744514f5e3Sopenharmony_ci                                     std::chrono::system_clock::time_point &end, bool isSerialization);
17754514f5e3Sopenharmony_ci    static void UpdateAOTCompileStatus(ecmascript::JSRuntimeOptions &jsOption, const RuntimeOption &option);
17764514f5e3Sopenharmony_ci    template<typename T>
17774514f5e3Sopenharmony_ci    friend class Global;
17784514f5e3Sopenharmony_ci    template<typename T>
17794514f5e3Sopenharmony_ci    friend class CopyableGlobal;
17804514f5e3Sopenharmony_ci    template<typename T>
17814514f5e3Sopenharmony_ci    friend class Local;
17824514f5e3Sopenharmony_ci    friend class test::JSNApiTests;
17834514f5e3Sopenharmony_ci};
17844514f5e3Sopenharmony_ci
17854514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API ProxyRef : public ObjectRef {
17864514f5e3Sopenharmony_cipublic:
17874514f5e3Sopenharmony_ci    Local<JSValueRef> GetHandler(const EcmaVM *vm);
17884514f5e3Sopenharmony_ci    Local<JSValueRef> GetTarget(const EcmaVM *vm);
17894514f5e3Sopenharmony_ci    bool IsRevoked();
17904514f5e3Sopenharmony_ci};
17914514f5e3Sopenharmony_ci
17924514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API WeakMapRef : public ObjectRef {
17934514f5e3Sopenharmony_cipublic:
17944514f5e3Sopenharmony_ci    int32_t GetSize(const EcmaVM *vm);
17954514f5e3Sopenharmony_ci    int32_t GetTotalElements(const EcmaVM *vm);
17964514f5e3Sopenharmony_ci    Local<JSValueRef> GetKey(const EcmaVM *vm, int entry);
17974514f5e3Sopenharmony_ci    Local<JSValueRef> GetValue(const EcmaVM *vm, int entry);
17984514f5e3Sopenharmony_ci    static Local<WeakMapRef> New(const EcmaVM *vm);
17994514f5e3Sopenharmony_ci    void Set(const EcmaVM *vm, const Local<JSValueRef> &key, const Local<JSValueRef> &value);
18004514f5e3Sopenharmony_ci    bool Has(const EcmaVM *vm, Local<JSValueRef> key);
18014514f5e3Sopenharmony_ci};
18024514f5e3Sopenharmony_ci
18034514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SetRef : public ObjectRef {
18044514f5e3Sopenharmony_cipublic:
18054514f5e3Sopenharmony_ci    int32_t GetSize(const EcmaVM *vm);
18064514f5e3Sopenharmony_ci    int32_t GetTotalElements(const EcmaVM *vm);
18074514f5e3Sopenharmony_ci    Local<JSValueRef> GetValue(const EcmaVM *vm, int entry);
18084514f5e3Sopenharmony_ci    static Local<SetRef> New(const EcmaVM *vm);
18094514f5e3Sopenharmony_ci    void Add(const EcmaVM *vm, Local<JSValueRef> value);
18104514f5e3Sopenharmony_ci};
18114514f5e3Sopenharmony_ci
18124514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API WeakSetRef : public ObjectRef {
18134514f5e3Sopenharmony_cipublic:
18144514f5e3Sopenharmony_ci    int32_t GetSize(const EcmaVM *vm);
18154514f5e3Sopenharmony_ci    int32_t GetTotalElements(const EcmaVM *vm);
18164514f5e3Sopenharmony_ci    Local<JSValueRef> GetValue(const EcmaVM *vm, int entry);
18174514f5e3Sopenharmony_ci    static Local<WeakSetRef> New(const EcmaVM *vm);
18184514f5e3Sopenharmony_ci    void Add(const EcmaVM *vm, Local<JSValueRef> value);
18194514f5e3Sopenharmony_ci};
18204514f5e3Sopenharmony_ci
18214514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API SetIteratorRef : public ObjectRef {
18224514f5e3Sopenharmony_cipublic:
18234514f5e3Sopenharmony_ci    int32_t GetIndex();
18244514f5e3Sopenharmony_ci    Local<JSValueRef> GetKind(const EcmaVM *vm);
18254514f5e3Sopenharmony_ci    static Local<SetIteratorRef> New(const EcmaVM *vm, Local<SetRef> set);
18264514f5e3Sopenharmony_ci    ecmascript::EcmaRuntimeCallInfo *GetEcmaRuntimeCallInfo(const EcmaVM *vm);
18274514f5e3Sopenharmony_ci    static Local<ArrayRef> Next(const EcmaVM *vm, ecmascript::EcmaRuntimeCallInfo *ecmaRuntimeCallInfo);
18284514f5e3Sopenharmony_ci};
18294514f5e3Sopenharmony_ci
18304514f5e3Sopenharmony_ci/* Attention pls, ExternalStringCache only can be utilized in main thread. Threads of Worker or Taskpool call
18314514f5e3Sopenharmony_ci * functions of this class will cause data race.
18324514f5e3Sopenharmony_ci */
18334514f5e3Sopenharmony_ciclass ECMA_PUBLIC_API ExternalStringCache final {
18344514f5e3Sopenharmony_cipublic:
18354514f5e3Sopenharmony_ci    static bool RegisterStringCacheTable(const EcmaVM *vm, uint32_t size);
18364514f5e3Sopenharmony_ci    static bool SetCachedString(const EcmaVM *vm, const char *name, uint32_t propertyIndex);
18374514f5e3Sopenharmony_ci    static bool HasCachedString(const EcmaVM *vm, uint32_t propertyIndex);
18384514f5e3Sopenharmony_ci    static Local<StringRef> GetCachedString(const EcmaVM *vm, uint32_t propertyIndex);
18394514f5e3Sopenharmony_ci};
18404514f5e3Sopenharmony_ci}
18414514f5e3Sopenharmony_ci#endif
1842