14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2024 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 CONTAINERSTREEMAPCOMMON_FUZZER_H
174514f5e3Sopenharmony_ci#define CONTAINERSTREEMAPCOMMON_FUZZER_H
184514f5e3Sopenharmony_ci
194514f5e3Sopenharmony_ci#include "ecmascript/containers/containers_hashmap.h"
204514f5e3Sopenharmony_ci#include "ecmascript/containers/containers_private.h"
214514f5e3Sopenharmony_ci#include "ecmascript/ecma_string-inl.h"
224514f5e3Sopenharmony_ci#include "ecmascript/ecma_vm.h"
234514f5e3Sopenharmony_ci#include "ecmascript/global_env.h"
244514f5e3Sopenharmony_ci#include "ecmascript/js_handle.h"
254514f5e3Sopenharmony_ci#include "ecmascript/napi/include/jsnapi.h"
264514f5e3Sopenharmony_ci
274514f5e3Sopenharmony_cinamespace panda::ecmascript {
284514f5e3Sopenharmony_ciusing namespace panda::ecmascript::containers;
294514f5e3Sopenharmony_ciclass ContainersHashMapFuzzTestHelper {
304514f5e3Sopenharmony_cipublic:
314514f5e3Sopenharmony_ci    static JSFunction *JSObjectCreate(JSThread *thread)
324514f5e3Sopenharmony_ci    {
334514f5e3Sopenharmony_ci        EcmaVM *ecmaVM = thread->GetEcmaVM();
344514f5e3Sopenharmony_ci        JSHandle<GlobalEnv> globalEnv = ecmaVM->GetGlobalEnv();
354514f5e3Sopenharmony_ci        return globalEnv->GetObjectFunction().GetObject<JSFunction>();
364514f5e3Sopenharmony_ci    }
374514f5e3Sopenharmony_ci
384514f5e3Sopenharmony_ci    static EcmaRuntimeCallInfo *CreateEcmaRuntimeCallInfo(JSThread *thread, uint32_t numArgs)
394514f5e3Sopenharmony_ci    {
404514f5e3Sopenharmony_ci        auto factory = thread->GetEcmaVM()->GetFactory();
414514f5e3Sopenharmony_ci        JSHandle<JSTaggedValue> hclass(thread, JSObjectCreate(thread));
424514f5e3Sopenharmony_ci        JSHandle<JSTaggedValue> callee(
434514f5e3Sopenharmony_ci            factory->NewJSObjectByConstructor(JSHandle<JSFunction>::Cast(hclass), hclass));
444514f5e3Sopenharmony_ci        JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
454514f5e3Sopenharmony_ci        EcmaRuntimeCallInfo *objCallInfo =
464514f5e3Sopenharmony_ci            EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, callee, undefined, numArgs);
474514f5e3Sopenharmony_ci        return objCallInfo;
484514f5e3Sopenharmony_ci    }
494514f5e3Sopenharmony_ci
504514f5e3Sopenharmony_ci    static JSTaggedValue InitializeHashMapConstructor(JSThread *thread)
514514f5e3Sopenharmony_ci    {
524514f5e3Sopenharmony_ci        ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
534514f5e3Sopenharmony_ci        JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
544514f5e3Sopenharmony_ci
554514f5e3Sopenharmony_ci        JSHandle<JSTaggedValue> globalObject = env->GetJSGlobalObject();
564514f5e3Sopenharmony_ci        JSHandle<JSTaggedValue> key(factory->NewFromASCII("ArkPrivate"));
574514f5e3Sopenharmony_ci        JSHandle<JSTaggedValue> value =
584514f5e3Sopenharmony_ci            JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(globalObject), key).GetValue();
594514f5e3Sopenharmony_ci
604514f5e3Sopenharmony_ci        auto objCallInfo = CreateEcmaRuntimeCallInfo(thread, 6);
614514f5e3Sopenharmony_ci        objCallInfo->SetFunction(JSTaggedValue::Undefined());
624514f5e3Sopenharmony_ci        objCallInfo->SetThis(value.GetTaggedValue());
634514f5e3Sopenharmony_ci        objCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int>(ContainerTag::HashMap)));
644514f5e3Sopenharmony_ci        JSTaggedValue result = ContainersPrivate::Load(objCallInfo);
654514f5e3Sopenharmony_ci        return result;
664514f5e3Sopenharmony_ci    }
674514f5e3Sopenharmony_ci
684514f5e3Sopenharmony_ci    static JSHandle<JSAPIHashMap> CreateJSAPIHashMap(JSThread *thread)
694514f5e3Sopenharmony_ci    {
704514f5e3Sopenharmony_ci        JSHandle<JSFunction> newTarget(thread, InitializeHashMapConstructor(thread));
714514f5e3Sopenharmony_ci        auto objCallInfo = CreateEcmaRuntimeCallInfo(thread, 4);
724514f5e3Sopenharmony_ci        objCallInfo->SetFunction(newTarget.GetTaggedValue());
734514f5e3Sopenharmony_ci        objCallInfo->SetNewTarget(newTarget.GetTaggedValue());
744514f5e3Sopenharmony_ci        objCallInfo->SetThis(JSTaggedValue::Undefined());
754514f5e3Sopenharmony_ci
764514f5e3Sopenharmony_ci        JSTaggedValue result = ContainersHashMap::HashMapConstructor(objCallInfo);
774514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> map(thread, result);
784514f5e3Sopenharmony_ci        return map;
794514f5e3Sopenharmony_ci    }
804514f5e3Sopenharmony_ci
814514f5e3Sopenharmony_ci    static bool InitializeFuzzTest(const uint8_t *data, size_t size, double &input, EcmaVM *&vm,
824514f5e3Sopenharmony_ci                                   JSThread *&thread)
834514f5e3Sopenharmony_ci    {
844514f5e3Sopenharmony_ci        RuntimeOption option;
854514f5e3Sopenharmony_ci        option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
864514f5e3Sopenharmony_ci        vm = JSNApi::CreateJSVM(option);
874514f5e3Sopenharmony_ci        thread = vm->GetAssociatedJSThread();
884514f5e3Sopenharmony_ci        if (vm == nullptr || thread == nullptr) {
894514f5e3Sopenharmony_ci            return false;
904514f5e3Sopenharmony_ci        }
914514f5e3Sopenharmony_ci        if (size == 0) {
924514f5e3Sopenharmony_ci            JSNApi::DestroyJSVM(vm);
934514f5e3Sopenharmony_ci            return false;
944514f5e3Sopenharmony_ci        }
954514f5e3Sopenharmony_ci
964514f5e3Sopenharmony_ci        size_t maxByteLen = sizeof(uint32_t);
974514f5e3Sopenharmony_ci        if (size > maxByteLen) {
984514f5e3Sopenharmony_ci            size = maxByteLen;
994514f5e3Sopenharmony_ci        }
1004514f5e3Sopenharmony_ci        if (memcpy_s(&input, maxByteLen, data, size) != 0) {
1014514f5e3Sopenharmony_ci            std::cout << "memcpy_s failed!";
1024514f5e3Sopenharmony_ci            UNREACHABLE();
1034514f5e3Sopenharmony_ci        }
1044514f5e3Sopenharmony_ci        return true;
1054514f5e3Sopenharmony_ci    }
1064514f5e3Sopenharmony_ci
1074514f5e3Sopenharmony_ci    static void ContainersHashMapEntriesFuzzTest(const uint8_t *data, size_t size)
1084514f5e3Sopenharmony_ci    {
1094514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
1104514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
1114514f5e3Sopenharmony_ci        double input = 0;
1124514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
1134514f5e3Sopenharmony_ci            return;
1144514f5e3Sopenharmony_ci        }
1154514f5e3Sopenharmony_ci
1164514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
1174514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
1184514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
1194514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
1204514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
1214514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input));
1224514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
1234514f5e3Sopenharmony_ci
1244514f5e3Sopenharmony_ci        auto callInfo2 = CreateEcmaRuntimeCallInfo(thread, 4);
1254514f5e3Sopenharmony_ci        callInfo2->SetFunction(JSTaggedValue::Undefined());
1264514f5e3Sopenharmony_ci        callInfo2->SetThis(tMap.GetTaggedValue());
1274514f5e3Sopenharmony_ci        ContainersHashMap::Entries(callInfo2);
1284514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
1294514f5e3Sopenharmony_ci    }
1304514f5e3Sopenharmony_ci
1314514f5e3Sopenharmony_ci    static void ContainersHashMapFuzzTest(const uint8_t *data, size_t size)
1324514f5e3Sopenharmony_ci    {
1334514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
1344514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
1354514f5e3Sopenharmony_ci        double input = 0;
1364514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
1374514f5e3Sopenharmony_ci            return;
1384514f5e3Sopenharmony_ci        }
1394514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> stack = CreateJSAPIHashMap(thread);
1404514f5e3Sopenharmony_ci        EcmaRuntimeCallInfo *callInfo = CreateEcmaRuntimeCallInfo(thread, 6);
1414514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
1424514f5e3Sopenharmony_ci        callInfo->SetThis(stack.GetTaggedValue());
1434514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
1444514f5e3Sopenharmony_ci        ContainersHashMap::HashMapConstructor(callInfo);
1454514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
1464514f5e3Sopenharmony_ci    }
1474514f5e3Sopenharmony_ci
1484514f5e3Sopenharmony_ci    static void ContainersHashMapClearFuzzTest(const uint8_t *data, size_t size)
1494514f5e3Sopenharmony_ci    {
1504514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
1514514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
1524514f5e3Sopenharmony_ci        double input = 0;
1534514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
1544514f5e3Sopenharmony_ci            return;
1554514f5e3Sopenharmony_ci        }
1564514f5e3Sopenharmony_ci
1574514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
1584514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
1594514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
1604514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
1614514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
1624514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input));
1634514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
1644514f5e3Sopenharmony_ci        auto callInfo1 = CreateEcmaRuntimeCallInfo(thread, 4);
1654514f5e3Sopenharmony_ci        callInfo1->SetFunction(JSTaggedValue::Undefined());
1664514f5e3Sopenharmony_ci        callInfo1->SetThis(tMap.GetTaggedValue());
1674514f5e3Sopenharmony_ci        ContainersHashMap::Clear(callInfo1);
1684514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
1694514f5e3Sopenharmony_ci    }
1704514f5e3Sopenharmony_ci
1714514f5e3Sopenharmony_ci    static void ContainersHashMapForEachFuzzTest(const uint8_t *data, size_t size)
1724514f5e3Sopenharmony_ci    {
1734514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
1744514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
1754514f5e3Sopenharmony_ci        double input = 0;
1764514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
1774514f5e3Sopenharmony_ci            return;
1784514f5e3Sopenharmony_ci        }
1794514f5e3Sopenharmony_ci
1804514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
1814514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
1824514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
1834514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
1844514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
1854514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input));
1864514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
1874514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> dMap = CreateJSAPIHashMap(thread);
1884514f5e3Sopenharmony_ci        auto callInfo1 = CreateEcmaRuntimeCallInfo(thread, 8);
1894514f5e3Sopenharmony_ci        callInfo1->SetFunction(JSTaggedValue::Undefined());
1904514f5e3Sopenharmony_ci        callInfo1->SetThis(tMap.GetTaggedValue());
1914514f5e3Sopenharmony_ci        callInfo1->SetCallArg(0, JSTaggedValue::Undefined());
1924514f5e3Sopenharmony_ci        callInfo1->SetCallArg(1, dMap.GetTaggedValue());
1934514f5e3Sopenharmony_ci        ContainersHashMap::ForEach(callInfo1);
1944514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
1954514f5e3Sopenharmony_ci    }
1964514f5e3Sopenharmony_ci
1974514f5e3Sopenharmony_ci    static void ContainersHashMapGetFuzzTest(const uint8_t *data, size_t size)
1984514f5e3Sopenharmony_ci    {
1994514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
2004514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
2014514f5e3Sopenharmony_ci        double input = 0;
2024514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
2034514f5e3Sopenharmony_ci            return;
2044514f5e3Sopenharmony_ci        }
2054514f5e3Sopenharmony_ci
2064514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
2074514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
2084514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
2094514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
2104514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
2114514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input + 1));
2124514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
2134514f5e3Sopenharmony_ci
2144514f5e3Sopenharmony_ci        auto callInfo1 = CreateEcmaRuntimeCallInfo(thread, 6);
2154514f5e3Sopenharmony_ci        callInfo1->SetFunction(JSTaggedValue::Undefined());
2164514f5e3Sopenharmony_ci        callInfo1->SetThis(tMap.GetTaggedValue());
2174514f5e3Sopenharmony_ci        callInfo1->SetCallArg(0, JSTaggedValue(input));
2184514f5e3Sopenharmony_ci        ContainersHashMap::Get(callInfo1);
2194514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
2204514f5e3Sopenharmony_ci    }
2214514f5e3Sopenharmony_ci
2224514f5e3Sopenharmony_ci    static void ContainersHashMapGetLengthFuzzTest(const uint8_t *data, size_t size)
2234514f5e3Sopenharmony_ci    {
2244514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
2254514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
2264514f5e3Sopenharmony_ci        double input = 0;
2274514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
2284514f5e3Sopenharmony_ci            return;
2294514f5e3Sopenharmony_ci        }
2304514f5e3Sopenharmony_ci
2314514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
2324514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
2334514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
2344514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
2354514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
2364514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input));
2374514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
2384514f5e3Sopenharmony_ci
2394514f5e3Sopenharmony_ci        auto callInfo1 = CreateEcmaRuntimeCallInfo(thread, 4);
2404514f5e3Sopenharmony_ci        callInfo1->SetFunction(JSTaggedValue::Undefined());
2414514f5e3Sopenharmony_ci        callInfo1->SetThis(tMap.GetTaggedValue());
2424514f5e3Sopenharmony_ci        ContainersHashMap::GetLength(callInfo1);
2434514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
2444514f5e3Sopenharmony_ci    }
2454514f5e3Sopenharmony_ci
2464514f5e3Sopenharmony_ci    static void ContainersHashMapHasKeyFuzzTest(const uint8_t *data, size_t size)
2474514f5e3Sopenharmony_ci    {
2484514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
2494514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
2504514f5e3Sopenharmony_ci        double input = 0;
2514514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
2524514f5e3Sopenharmony_ci            return;
2534514f5e3Sopenharmony_ci        }
2544514f5e3Sopenharmony_ci
2554514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
2564514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
2574514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
2584514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
2594514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
2604514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input));
2614514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
2624514f5e3Sopenharmony_ci
2634514f5e3Sopenharmony_ci        EcmaRuntimeCallInfo *callInfo1 = CreateEcmaRuntimeCallInfo(thread, 6);
2644514f5e3Sopenharmony_ci        callInfo1->SetFunction(JSTaggedValue::Undefined());
2654514f5e3Sopenharmony_ci        callInfo1->SetThis(tMap.GetTaggedValue());
2664514f5e3Sopenharmony_ci        callInfo1->SetCallArg(0, JSTaggedValue(input));
2674514f5e3Sopenharmony_ci        ContainersHashMap::HasKey(callInfo1);
2684514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
2694514f5e3Sopenharmony_ci    }
2704514f5e3Sopenharmony_ci
2714514f5e3Sopenharmony_ci    static void ContainersHashMapHasValueFuzzTest(const uint8_t *data, size_t size)
2724514f5e3Sopenharmony_ci    {
2734514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
2744514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
2754514f5e3Sopenharmony_ci        double input = 0;
2764514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
2774514f5e3Sopenharmony_ci            return;
2784514f5e3Sopenharmony_ci        }
2794514f5e3Sopenharmony_ci
2804514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
2814514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
2824514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
2834514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
2844514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
2854514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input));
2864514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
2874514f5e3Sopenharmony_ci
2884514f5e3Sopenharmony_ci        EcmaRuntimeCallInfo *callInfo1 = CreateEcmaRuntimeCallInfo(thread, 6);
2894514f5e3Sopenharmony_ci        callInfo1->SetFunction(JSTaggedValue::Undefined());
2904514f5e3Sopenharmony_ci        callInfo1->SetThis(tMap.GetTaggedValue());
2914514f5e3Sopenharmony_ci        callInfo1->SetCallArg(0, JSTaggedValue(input));
2924514f5e3Sopenharmony_ci        ContainersHashMap::HasValue(callInfo1);
2934514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
2944514f5e3Sopenharmony_ci    }
2954514f5e3Sopenharmony_ci
2964514f5e3Sopenharmony_ci    static void ContainersHashMapIsEmptyFuzzTest(const uint8_t *data, size_t size)
2974514f5e3Sopenharmony_ci    {
2984514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
2994514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
3004514f5e3Sopenharmony_ci        double input = 0;
3014514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
3024514f5e3Sopenharmony_ci            return;
3034514f5e3Sopenharmony_ci        }
3044514f5e3Sopenharmony_ci
3054514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
3064514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
3074514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
3084514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
3094514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
3104514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input));
3114514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
3124514f5e3Sopenharmony_ci        EcmaRuntimeCallInfo *callInfo2 = CreateEcmaRuntimeCallInfo(thread, 4);
3134514f5e3Sopenharmony_ci        callInfo2->SetFunction(JSTaggedValue::Undefined());
3144514f5e3Sopenharmony_ci        callInfo2->SetThis(tMap.GetTaggedValue());
3154514f5e3Sopenharmony_ci        ContainersHashMap::IsEmpty(callInfo2);
3164514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
3174514f5e3Sopenharmony_ci    }
3184514f5e3Sopenharmony_ci
3194514f5e3Sopenharmony_ci    static void ContainersHashMapKeysFuzzTest(const uint8_t *data, size_t size)
3204514f5e3Sopenharmony_ci    {
3214514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
3224514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
3234514f5e3Sopenharmony_ci        double input = 0;
3244514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
3254514f5e3Sopenharmony_ci            return;
3264514f5e3Sopenharmony_ci        }
3274514f5e3Sopenharmony_ci
3284514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
3294514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
3304514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
3314514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
3324514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
3334514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input));
3344514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
3354514f5e3Sopenharmony_ci
3364514f5e3Sopenharmony_ci        auto callInfo1 = CreateEcmaRuntimeCallInfo(thread, 4);
3374514f5e3Sopenharmony_ci        callInfo1->SetFunction(JSTaggedValue::Undefined());
3384514f5e3Sopenharmony_ci        callInfo1->SetThis(tMap.GetTaggedValue());
3394514f5e3Sopenharmony_ci        ContainersHashMap::Keys(callInfo1);
3404514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
3414514f5e3Sopenharmony_ci    }
3424514f5e3Sopenharmony_ci
3434514f5e3Sopenharmony_ci    static void ContainersHashMapRemoveFuzzTest(const uint8_t *data, size_t size)
3444514f5e3Sopenharmony_ci    {
3454514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
3464514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
3474514f5e3Sopenharmony_ci        double input = 0;
3484514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
3494514f5e3Sopenharmony_ci            return;
3504514f5e3Sopenharmony_ci        }
3514514f5e3Sopenharmony_ci
3524514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
3534514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
3544514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
3554514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
3564514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
3574514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input));
3584514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
3594514f5e3Sopenharmony_ci
3604514f5e3Sopenharmony_ci        auto callInfo1 = CreateEcmaRuntimeCallInfo(thread, 6);
3614514f5e3Sopenharmony_ci        callInfo1->SetFunction(JSTaggedValue::Undefined());
3624514f5e3Sopenharmony_ci        callInfo1->SetThis(tMap.GetTaggedValue());
3634514f5e3Sopenharmony_ci        callInfo1->SetCallArg(0, JSTaggedValue(input + 1));
3644514f5e3Sopenharmony_ci        ContainersHashMap::Remove(callInfo1);
3654514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
3664514f5e3Sopenharmony_ci    }
3674514f5e3Sopenharmony_ci
3684514f5e3Sopenharmony_ci    static void ContainersHashMapReplaceFuzzTest(const uint8_t *data, size_t size)
3694514f5e3Sopenharmony_ci    {
3704514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
3714514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
3724514f5e3Sopenharmony_ci        double input = 0;
3734514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
3744514f5e3Sopenharmony_ci            return;
3754514f5e3Sopenharmony_ci        }
3764514f5e3Sopenharmony_ci
3774514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
3784514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
3794514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
3804514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
3814514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
3824514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input));
3834514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
3844514f5e3Sopenharmony_ci
3854514f5e3Sopenharmony_ci        EcmaRuntimeCallInfo *callInfo1 = CreateEcmaRuntimeCallInfo(thread, 8);
3864514f5e3Sopenharmony_ci        callInfo1->SetFunction(JSTaggedValue::Undefined());
3874514f5e3Sopenharmony_ci        callInfo1->SetThis(tMap.GetTaggedValue());
3884514f5e3Sopenharmony_ci        callInfo1->SetCallArg(0, JSTaggedValue(input + 1));
3894514f5e3Sopenharmony_ci        callInfo1->SetCallArg(1, JSTaggedValue(input));
3904514f5e3Sopenharmony_ci        ContainersHashMap::Replace(callInfo1);
3914514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
3924514f5e3Sopenharmony_ci    }
3934514f5e3Sopenharmony_ci
3944514f5e3Sopenharmony_ci    static void ContainersHashMapSetFuzzTest(const uint8_t *data, size_t size)
3954514f5e3Sopenharmony_ci    {
3964514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
3974514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
3984514f5e3Sopenharmony_ci        double input = 0;
3994514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
4004514f5e3Sopenharmony_ci            return;
4014514f5e3Sopenharmony_ci        }
4024514f5e3Sopenharmony_ci
4034514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
4044514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
4054514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
4064514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
4074514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
4084514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input + 1));
4094514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
4104514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
4114514f5e3Sopenharmony_ci    }
4124514f5e3Sopenharmony_ci
4134514f5e3Sopenharmony_ci    static void ContainersHashMapSetAllFuzzTest(const uint8_t *data, size_t size)
4144514f5e3Sopenharmony_ci    {
4154514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
4164514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
4174514f5e3Sopenharmony_ci        double input = 0;
4184514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
4194514f5e3Sopenharmony_ci            return;
4204514f5e3Sopenharmony_ci        }
4214514f5e3Sopenharmony_ci
4224514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
4234514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
4244514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
4254514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
4264514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
4274514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input));
4284514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
4294514f5e3Sopenharmony_ci
4304514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> dMap = CreateJSAPIHashMap(thread);
4314514f5e3Sopenharmony_ci        auto callInfo1 = CreateEcmaRuntimeCallInfo(thread, 6);
4324514f5e3Sopenharmony_ci        callInfo1->SetFunction(JSTaggedValue::Undefined());
4334514f5e3Sopenharmony_ci        callInfo1->SetThis(dMap.GetTaggedValue());
4344514f5e3Sopenharmony_ci        callInfo1->SetCallArg(0, tMap.GetTaggedValue());
4354514f5e3Sopenharmony_ci        ContainersHashMap::SetAll(callInfo1);
4364514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
4374514f5e3Sopenharmony_ci    }
4384514f5e3Sopenharmony_ci
4394514f5e3Sopenharmony_ci    static void ContainersHashMapValuesFuzzTest(const uint8_t *data, size_t size)
4404514f5e3Sopenharmony_ci    {
4414514f5e3Sopenharmony_ci        EcmaVM *vm = nullptr;
4424514f5e3Sopenharmony_ci        JSThread *thread = nullptr;
4434514f5e3Sopenharmony_ci        double input = 0;
4444514f5e3Sopenharmony_ci        if (!InitializeFuzzTest(data, size, input, vm, thread)) {
4454514f5e3Sopenharmony_ci            return;
4464514f5e3Sopenharmony_ci        }
4474514f5e3Sopenharmony_ci
4484514f5e3Sopenharmony_ci        JSHandle<JSAPIHashMap> tMap = CreateJSAPIHashMap(thread);
4494514f5e3Sopenharmony_ci        auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8);
4504514f5e3Sopenharmony_ci        callInfo->SetFunction(JSTaggedValue::Undefined());
4514514f5e3Sopenharmony_ci        callInfo->SetThis(tMap.GetTaggedValue());
4524514f5e3Sopenharmony_ci        callInfo->SetCallArg(0, JSTaggedValue(input));
4534514f5e3Sopenharmony_ci        callInfo->SetCallArg(1, JSTaggedValue(input));
4544514f5e3Sopenharmony_ci        ContainersHashMap::Set(callInfo);
4554514f5e3Sopenharmony_ci
4564514f5e3Sopenharmony_ci        auto callInfo1 = CreateEcmaRuntimeCallInfo(thread, 4);
4574514f5e3Sopenharmony_ci        callInfo1->SetFunction(JSTaggedValue::Undefined());
4584514f5e3Sopenharmony_ci        callInfo1->SetThis(tMap.GetTaggedValue());
4594514f5e3Sopenharmony_ci        ContainersHashMap::Values(callInfo1);
4604514f5e3Sopenharmony_ci        JSNApi::DestroyJSVM(vm);
4614514f5e3Sopenharmony_ci    }
4624514f5e3Sopenharmony_ci};
4634514f5e3Sopenharmony_ci}  // namespace panda::ecmascript
4644514f5e3Sopenharmony_ci#endif