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_private.h" 204514f5e3Sopenharmony_ci#include "ecmascript/containers/containers_treemap.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 ContainersTreeMapFuzzTestHelper { 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 InitializeTreeMapConstructor(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::TreeMap))); 644514f5e3Sopenharmony_ci JSTaggedValue result = ContainersPrivate::Load(objCallInfo); 654514f5e3Sopenharmony_ci return result; 664514f5e3Sopenharmony_ci } 674514f5e3Sopenharmony_ci 684514f5e3Sopenharmony_ci static JSHandle<JSAPITreeMap> CreateJSAPITreeMap(JSThread *thread) 694514f5e3Sopenharmony_ci { 704514f5e3Sopenharmony_ci JSHandle<JSFunction> newTarget(thread, InitializeTreeMapConstructor(thread)); 714514f5e3Sopenharmony_ci auto objCallInfo = CreateEcmaRuntimeCallInfo(thread, 6); 724514f5e3Sopenharmony_ci objCallInfo->SetFunction(newTarget.GetTaggedValue()); 734514f5e3Sopenharmony_ci objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); 744514f5e3Sopenharmony_ci objCallInfo->SetThis(JSTaggedValue::Undefined()); 754514f5e3Sopenharmony_ci 764514f5e3Sopenharmony_ci JSTaggedValue result = ContainersTreeMap::TreeMapConstructor(objCallInfo); 774514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> map(thread, result); 784514f5e3Sopenharmony_ci return map; 794514f5e3Sopenharmony_ci } 804514f5e3Sopenharmony_ci 814514f5e3Sopenharmony_ci static bool InitFuzzTest(const uint8_t *data, size_t &size, int32_t &key, EcmaVM *&vm, JSThread *&thread) 824514f5e3Sopenharmony_ci { 834514f5e3Sopenharmony_ci RuntimeOption option; 844514f5e3Sopenharmony_ci option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); 854514f5e3Sopenharmony_ci vm = JSNApi::CreateJSVM(option); 864514f5e3Sopenharmony_ci thread = vm->GetJSThread(); 874514f5e3Sopenharmony_ci if (size <= 0) { 884514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 894514f5e3Sopenharmony_ci return false; 904514f5e3Sopenharmony_ci } 914514f5e3Sopenharmony_ci size_t maxByteLen = 4; 924514f5e3Sopenharmony_ci if (size > maxByteLen) { 934514f5e3Sopenharmony_ci size = maxByteLen; 944514f5e3Sopenharmony_ci } 954514f5e3Sopenharmony_ci if (memcpy_s(&key, maxByteLen, data, size) != EOK) { 964514f5e3Sopenharmony_ci std::cout << "memcpy_s failed!"; 974514f5e3Sopenharmony_ci UNREACHABLE(); 984514f5e3Sopenharmony_ci } 994514f5e3Sopenharmony_ci return true; 1004514f5e3Sopenharmony_ci } 1014514f5e3Sopenharmony_ci 1024514f5e3Sopenharmony_ci static void ContainersTreeMapClearFuzzTest(const uint8_t *data, size_t size) 1034514f5e3Sopenharmony_ci { 1044514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 1054514f5e3Sopenharmony_ci JSThread *thread = nullptr; 1064514f5e3Sopenharmony_ci int32_t key = 0; 1074514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 1084514f5e3Sopenharmony_ci return; 1094514f5e3Sopenharmony_ci } 1104514f5e3Sopenharmony_ci 1114514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 1124514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 1134514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 1144514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 1154514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 1164514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 1174514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 1184514f5e3Sopenharmony_ci 1194514f5e3Sopenharmony_ci auto objcallInfo = CreateEcmaRuntimeCallInfo(thread, 4); 1204514f5e3Sopenharmony_ci objcallInfo->SetFunction(JSTaggedValue::Undefined()); 1214514f5e3Sopenharmony_ci objcallInfo->SetThis(tmap.GetTaggedValue()); 1224514f5e3Sopenharmony_ci ContainersTreeMap::Clear(objcallInfo); 1234514f5e3Sopenharmony_ci 1244514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 1254514f5e3Sopenharmony_ci } 1264514f5e3Sopenharmony_ci 1274514f5e3Sopenharmony_ci static void ContainersTreeMapConstructorFuzzTest(const uint8_t *data, size_t size) 1284514f5e3Sopenharmony_ci { 1294514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 1304514f5e3Sopenharmony_ci JSThread *thread = nullptr; 1314514f5e3Sopenharmony_ci int32_t key = 0; 1324514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 1334514f5e3Sopenharmony_ci return; 1344514f5e3Sopenharmony_ci } 1354514f5e3Sopenharmony_ci 1364514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 1374514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 1384514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 1394514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 1404514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(key)); 1414514f5e3Sopenharmony_ci ContainersTreeMap::TreeMapConstructor(callInfo); 1424514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 1434514f5e3Sopenharmony_ci } 1444514f5e3Sopenharmony_ci 1454514f5e3Sopenharmony_ci static void ContainersTreeMapEntriesFuzzTest(const uint8_t *data, size_t size) 1464514f5e3Sopenharmony_ci { 1474514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 1484514f5e3Sopenharmony_ci JSThread *thread = nullptr; 1494514f5e3Sopenharmony_ci int32_t key = 0; 1504514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 1514514f5e3Sopenharmony_ci return; 1524514f5e3Sopenharmony_ci } 1534514f5e3Sopenharmony_ci 1544514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 1554514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 1564514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 1574514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 1584514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 1594514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 1604514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 1614514f5e3Sopenharmony_ci 1624514f5e3Sopenharmony_ci auto objCallInfo = CreateEcmaRuntimeCallInfo(thread, 4); 1634514f5e3Sopenharmony_ci objCallInfo->SetFunction(JSTaggedValue::Undefined()); 1644514f5e3Sopenharmony_ci objCallInfo->SetThis(tmap.GetTaggedValue()); 1654514f5e3Sopenharmony_ci ContainersTreeMap::Entries(objCallInfo); 1664514f5e3Sopenharmony_ci 1674514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 1684514f5e3Sopenharmony_ci } 1694514f5e3Sopenharmony_ci 1704514f5e3Sopenharmony_ci static JSTaggedValue TestForEachFunc([[maybe_unused]] EcmaRuntimeCallInfo *argv) 1714514f5e3Sopenharmony_ci { 1724514f5e3Sopenharmony_ci return JSTaggedValue::True(); 1734514f5e3Sopenharmony_ci } 1744514f5e3Sopenharmony_ci 1754514f5e3Sopenharmony_ci static void ContainersTreeMapForEachFuzzTest(const uint8_t *data, size_t size) 1764514f5e3Sopenharmony_ci { 1774514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 1784514f5e3Sopenharmony_ci JSThread *thread = nullptr; 1794514f5e3Sopenharmony_ci int32_t key = 0; 1804514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 1814514f5e3Sopenharmony_ci return; 1824514f5e3Sopenharmony_ci } 1834514f5e3Sopenharmony_ci 1844514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 1854514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 1864514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 1874514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 1884514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 1894514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 1904514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 1914514f5e3Sopenharmony_ci 1924514f5e3Sopenharmony_ci ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); 1934514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> dmap = CreateJSAPITreeMap(thread); 1944514f5e3Sopenharmony_ci JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv(); 1954514f5e3Sopenharmony_ci JSHandle<JSFunction> func = factory->NewJSFunction(env, reinterpret_cast<void *>(TestForEachFunc)); 1964514f5e3Sopenharmony_ci auto objCallInfo = CreateEcmaRuntimeCallInfo(thread, 8); 1974514f5e3Sopenharmony_ci objCallInfo->SetFunction(JSTaggedValue::Undefined()); 1984514f5e3Sopenharmony_ci objCallInfo->SetThis(tmap.GetTaggedValue()); 1994514f5e3Sopenharmony_ci objCallInfo->SetCallArg(0, func.GetTaggedValue()); 2004514f5e3Sopenharmony_ci objCallInfo->SetCallArg(1, dmap.GetTaggedValue()); 2014514f5e3Sopenharmony_ci ContainersTreeMap::ForEach(objCallInfo); 2024514f5e3Sopenharmony_ci 2034514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 2044514f5e3Sopenharmony_ci } 2054514f5e3Sopenharmony_ci 2064514f5e3Sopenharmony_ci static void ContainersTreeMapGetFuzzTest(const uint8_t *data, size_t size) 2074514f5e3Sopenharmony_ci { 2084514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 2094514f5e3Sopenharmony_ci JSThread *thread = nullptr; 2104514f5e3Sopenharmony_ci int32_t key = 0; 2114514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 2124514f5e3Sopenharmony_ci return; 2134514f5e3Sopenharmony_ci } 2144514f5e3Sopenharmony_ci 2154514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 2164514f5e3Sopenharmony_ci auto objcallInfo = CreateEcmaRuntimeCallInfo(thread, 8); 2174514f5e3Sopenharmony_ci objcallInfo->SetFunction(JSTaggedValue::Undefined()); 2184514f5e3Sopenharmony_ci objcallInfo->SetThis(tmap.GetTaggedValue()); 2194514f5e3Sopenharmony_ci objcallInfo->SetCallArg(0, JSTaggedValue(0)); 2204514f5e3Sopenharmony_ci objcallInfo->SetCallArg(1, JSTaggedValue(key)); 2214514f5e3Sopenharmony_ci ContainersTreeMap::Get(objcallInfo); 2224514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 2234514f5e3Sopenharmony_ci } 2244514f5e3Sopenharmony_ci 2254514f5e3Sopenharmony_ci static void ContainersTreeMapGetFirstKeyFuzzTest(const uint8_t *data, size_t size) 2264514f5e3Sopenharmony_ci { 2274514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 2284514f5e3Sopenharmony_ci JSThread *thread = nullptr; 2294514f5e3Sopenharmony_ci int32_t key = 0; 2304514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 2314514f5e3Sopenharmony_ci return; 2324514f5e3Sopenharmony_ci } 2334514f5e3Sopenharmony_ci 2344514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 2354514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 2364514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 2374514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 2384514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 2394514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 2404514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 2414514f5e3Sopenharmony_ci 2424514f5e3Sopenharmony_ci auto objCallInfo = CreateEcmaRuntimeCallInfo(thread, 4); 2434514f5e3Sopenharmony_ci objCallInfo->SetFunction(JSTaggedValue::Undefined()); 2444514f5e3Sopenharmony_ci objCallInfo->SetThis(tmap.GetTaggedValue()); 2454514f5e3Sopenharmony_ci ContainersTreeMap::GetFirstKey(objCallInfo); 2464514f5e3Sopenharmony_ci 2474514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 2484514f5e3Sopenharmony_ci } 2494514f5e3Sopenharmony_ci 2504514f5e3Sopenharmony_ci static void ContainersTreeMapGetHigherKeyFuzzTest(const uint8_t *data, size_t size) 2514514f5e3Sopenharmony_ci { 2524514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 2534514f5e3Sopenharmony_ci JSThread *thread = nullptr; 2544514f5e3Sopenharmony_ci int32_t key = 0; 2554514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 2564514f5e3Sopenharmony_ci return; 2574514f5e3Sopenharmony_ci } 2584514f5e3Sopenharmony_ci 2594514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 2604514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 2614514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 2624514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 2634514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 2644514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 2654514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 2664514f5e3Sopenharmony_ci 2674514f5e3Sopenharmony_ci auto objcallInfo = CreateEcmaRuntimeCallInfo(thread, 6); 2684514f5e3Sopenharmony_ci objcallInfo->SetFunction(JSTaggedValue::Undefined()); 2694514f5e3Sopenharmony_ci objcallInfo->SetThis(tmap.GetTaggedValue()); 2704514f5e3Sopenharmony_ci objcallInfo->SetCallArg(0, JSTaggedValue(key)); 2714514f5e3Sopenharmony_ci ContainersTreeMap::GetHigherKey(objcallInfo); 2724514f5e3Sopenharmony_ci 2734514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 2744514f5e3Sopenharmony_ci } 2754514f5e3Sopenharmony_ci 2764514f5e3Sopenharmony_ci static void ContainersTreeMapGetLastKeyFuzzTest(const uint8_t *data, size_t size) 2774514f5e3Sopenharmony_ci { 2784514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 2794514f5e3Sopenharmony_ci JSThread *thread = nullptr; 2804514f5e3Sopenharmony_ci int32_t key = 0; 2814514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 2824514f5e3Sopenharmony_ci return; 2834514f5e3Sopenharmony_ci } 2844514f5e3Sopenharmony_ci 2854514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 2864514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 2874514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 2884514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 2894514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 2904514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 2914514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 2924514f5e3Sopenharmony_ci 2934514f5e3Sopenharmony_ci auto objCallInfo = CreateEcmaRuntimeCallInfo(thread, 4); 2944514f5e3Sopenharmony_ci objCallInfo->SetFunction(JSTaggedValue::Undefined()); 2954514f5e3Sopenharmony_ci objCallInfo->SetThis(tmap.GetTaggedValue()); 2964514f5e3Sopenharmony_ci ContainersTreeMap::GetLastKey(objCallInfo); 2974514f5e3Sopenharmony_ci 2984514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 2994514f5e3Sopenharmony_ci } 3004514f5e3Sopenharmony_ci 3014514f5e3Sopenharmony_ci static void ContainersTreeMapGetLengthFuzzTest(const uint8_t *data, size_t size) 3024514f5e3Sopenharmony_ci { 3034514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 3044514f5e3Sopenharmony_ci JSThread *thread = nullptr; 3054514f5e3Sopenharmony_ci int32_t key = 0; 3064514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 3074514f5e3Sopenharmony_ci return; 3084514f5e3Sopenharmony_ci } 3094514f5e3Sopenharmony_ci 3104514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 3114514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 3124514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 3134514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 3144514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 3154514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 3164514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 3174514f5e3Sopenharmony_ci 3184514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> map = CreateJSAPITreeMap(thread); 3194514f5e3Sopenharmony_ci auto objCallInfo = CreateEcmaRuntimeCallInfo(thread, 6); 3204514f5e3Sopenharmony_ci objCallInfo->SetFunction(JSTaggedValue::Undefined()); 3214514f5e3Sopenharmony_ci objCallInfo->SetThis(map.GetTaggedValue()); 3224514f5e3Sopenharmony_ci ContainersTreeMap::GetLength(objCallInfo); 3234514f5e3Sopenharmony_ci 3244514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 3254514f5e3Sopenharmony_ci } 3264514f5e3Sopenharmony_ci 3274514f5e3Sopenharmony_ci static void ContainersTreeMapGetLowerKeyFuzzTest(const uint8_t *data, size_t size) 3284514f5e3Sopenharmony_ci { 3294514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 3304514f5e3Sopenharmony_ci JSThread *thread = nullptr; 3314514f5e3Sopenharmony_ci int32_t key = 0; 3324514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 3334514f5e3Sopenharmony_ci return; 3344514f5e3Sopenharmony_ci } 3354514f5e3Sopenharmony_ci 3364514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 3374514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 3384514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 3394514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 3404514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 3414514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 3424514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 3434514f5e3Sopenharmony_ci 3444514f5e3Sopenharmony_ci auto objcallInfo = CreateEcmaRuntimeCallInfo(thread, 6); 3454514f5e3Sopenharmony_ci objcallInfo->SetFunction(JSTaggedValue::Undefined()); 3464514f5e3Sopenharmony_ci objcallInfo->SetThis(tmap.GetTaggedValue()); 3474514f5e3Sopenharmony_ci objcallInfo->SetCallArg(0, JSTaggedValue(key)); 3484514f5e3Sopenharmony_ci ContainersTreeMap::GetLowerKey(objcallInfo); 3494514f5e3Sopenharmony_ci 3504514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 3514514f5e3Sopenharmony_ci } 3524514f5e3Sopenharmony_ci 3534514f5e3Sopenharmony_ci static void ContainersTreeMapCheckKeyFuzzTest(const uint8_t *data, size_t size) 3544514f5e3Sopenharmony_ci { 3554514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 3564514f5e3Sopenharmony_ci JSThread *thread = nullptr; 3574514f5e3Sopenharmony_ci int32_t key = 0; 3584514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 3594514f5e3Sopenharmony_ci return; 3604514f5e3Sopenharmony_ci } 3614514f5e3Sopenharmony_ci 3624514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 3634514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 3644514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 3654514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 3664514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(key)); 3674514f5e3Sopenharmony_ci 3684514f5e3Sopenharmony_ci ContainersTreeMap::HasKey(callInfo); 3694514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 3704514f5e3Sopenharmony_ci } 3714514f5e3Sopenharmony_ci 3724514f5e3Sopenharmony_ci static void ContainersTreeMapCheckValueFuzzTest(const uint8_t *data, size_t size) 3734514f5e3Sopenharmony_ci { 3744514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 3754514f5e3Sopenharmony_ci JSThread *thread = nullptr; 3764514f5e3Sopenharmony_ci int32_t key = 0; 3774514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 3784514f5e3Sopenharmony_ci return; 3794514f5e3Sopenharmony_ci } 3804514f5e3Sopenharmony_ci 3814514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 3824514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 3834514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 3844514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 3854514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(key)); 3864514f5e3Sopenharmony_ci 3874514f5e3Sopenharmony_ci ContainersTreeMap::HasValue(callInfo); 3884514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 3894514f5e3Sopenharmony_ci } 3904514f5e3Sopenharmony_ci 3914514f5e3Sopenharmony_ci static void ContainersTreeMapIsEmptyFuzzTest(const uint8_t *data, size_t size) 3924514f5e3Sopenharmony_ci { 3934514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 3944514f5e3Sopenharmony_ci JSThread *thread = nullptr; 3954514f5e3Sopenharmony_ci int32_t key = 0; 3964514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 3974514f5e3Sopenharmony_ci return; 3984514f5e3Sopenharmony_ci } 3994514f5e3Sopenharmony_ci 4004514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 4014514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 4024514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 4034514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 4044514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 4054514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 4064514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 4074514f5e3Sopenharmony_ci ContainersTreeMap::IsEmpty(callInfo); 4084514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 4094514f5e3Sopenharmony_ci } 4104514f5e3Sopenharmony_ci 4114514f5e3Sopenharmony_ci static void ContainersTreeMapKeysFuzzTest(const uint8_t *data, size_t size) 4124514f5e3Sopenharmony_ci { 4134514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 4144514f5e3Sopenharmony_ci JSThread *thread = nullptr; 4154514f5e3Sopenharmony_ci int32_t key = 0; 4164514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 4174514f5e3Sopenharmony_ci return; 4184514f5e3Sopenharmony_ci } 4194514f5e3Sopenharmony_ci 4204514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 4214514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 4224514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 4234514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 4244514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 4254514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 4264514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 4274514f5e3Sopenharmony_ci 4284514f5e3Sopenharmony_ci auto objcallInfo = CreateEcmaRuntimeCallInfo(thread, 4); 4294514f5e3Sopenharmony_ci objcallInfo->SetFunction(JSTaggedValue::Undefined()); 4304514f5e3Sopenharmony_ci objcallInfo->SetThis(tmap.GetTaggedValue()); 4314514f5e3Sopenharmony_ci ContainersTreeMap::Keys(objcallInfo); 4324514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 4334514f5e3Sopenharmony_ci } 4344514f5e3Sopenharmony_ci 4354514f5e3Sopenharmony_ci static void ContainersTreeMapRemoveFuzzTest(const uint8_t *data, size_t size) 4364514f5e3Sopenharmony_ci { 4374514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 4384514f5e3Sopenharmony_ci JSThread *thread = nullptr; 4394514f5e3Sopenharmony_ci int32_t key = 0; 4404514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 4414514f5e3Sopenharmony_ci return; 4424514f5e3Sopenharmony_ci } 4434514f5e3Sopenharmony_ci 4444514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 4454514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 4464514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 4474514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 4484514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 4494514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 4504514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 4514514f5e3Sopenharmony_ci 4524514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> map = CreateJSAPITreeMap(thread); 4534514f5e3Sopenharmony_ci auto objcallInfo = CreateEcmaRuntimeCallInfo(thread, 6); 4544514f5e3Sopenharmony_ci objcallInfo->SetFunction(JSTaggedValue::Undefined()); 4554514f5e3Sopenharmony_ci objcallInfo->SetThis(map.GetTaggedValue()); 4564514f5e3Sopenharmony_ci objcallInfo->SetCallArg(0, JSTaggedValue(key)); 4574514f5e3Sopenharmony_ci ContainersTreeMap::Remove(objcallInfo); 4584514f5e3Sopenharmony_ci 4594514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 4604514f5e3Sopenharmony_ci } 4614514f5e3Sopenharmony_ci 4624514f5e3Sopenharmony_ci static void ContainersTreeMapReplaceFuzzTest(const uint8_t *data, size_t size) 4634514f5e3Sopenharmony_ci { 4644514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 4654514f5e3Sopenharmony_ci JSThread *thread = nullptr; 4664514f5e3Sopenharmony_ci int32_t key = 0; 4674514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 4684514f5e3Sopenharmony_ci return; 4694514f5e3Sopenharmony_ci } 4704514f5e3Sopenharmony_ci 4714514f5e3Sopenharmony_ci constexpr int nodeNumbers = 8; 4724514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 4734514f5e3Sopenharmony_ci for (int i = 0; i < nodeNumbers; i++) { 4744514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 4754514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 4764514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 4774514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(key)); 4784514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 4794514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 4804514f5e3Sopenharmony_ci 4814514f5e3Sopenharmony_ci auto objCallInfo = CreateEcmaRuntimeCallInfo(thread, 8); 4824514f5e3Sopenharmony_ci objCallInfo->SetFunction(JSTaggedValue::Undefined()); 4834514f5e3Sopenharmony_ci objCallInfo->SetThis(tmap.GetTaggedValue()); 4844514f5e3Sopenharmony_ci objCallInfo->SetCallArg(0, JSTaggedValue(nodeNumbers / 2)); // 2 : half of nodeNumbers 4854514f5e3Sopenharmony_ci objCallInfo->SetCallArg(1, JSTaggedValue(nodeNumbers)); 4864514f5e3Sopenharmony_ci ContainersTreeMap::Replace(callInfo); 4874514f5e3Sopenharmony_ci } 4884514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 4894514f5e3Sopenharmony_ci } 4904514f5e3Sopenharmony_ci 4914514f5e3Sopenharmony_ci static void ContainersTreeMapSetFuzzTest(const uint8_t *data, size_t size) 4924514f5e3Sopenharmony_ci { 4934514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 4944514f5e3Sopenharmony_ci JSThread *thread = nullptr; 4954514f5e3Sopenharmony_ci int32_t key = 0; 4964514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 4974514f5e3Sopenharmony_ci return; 4984514f5e3Sopenharmony_ci } 4994514f5e3Sopenharmony_ci 5004514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 5014514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 5024514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 5034514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 5044514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 5054514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 5064514f5e3Sopenharmony_ci 5074514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 5084514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 5094514f5e3Sopenharmony_ci } 5104514f5e3Sopenharmony_ci 5114514f5e3Sopenharmony_ci static void ContainersTreeMapSetAllFuzzTest(const uint8_t *data, size_t size) 5124514f5e3Sopenharmony_ci { 5134514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 5144514f5e3Sopenharmony_ci JSThread *thread = nullptr; 5154514f5e3Sopenharmony_ci int32_t key = 0; 5164514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 5174514f5e3Sopenharmony_ci return; 5184514f5e3Sopenharmony_ci } 5194514f5e3Sopenharmony_ci 5204514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 5214514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 5224514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 5234514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 5244514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 5254514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 5264514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 5274514f5e3Sopenharmony_ci 5284514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> map = CreateJSAPITreeMap(thread); 5294514f5e3Sopenharmony_ci auto objcallInfo = CreateEcmaRuntimeCallInfo(thread, 6); 5304514f5e3Sopenharmony_ci objcallInfo->SetFunction(JSTaggedValue::Undefined()); 5314514f5e3Sopenharmony_ci objcallInfo->SetThis(map.GetTaggedValue()); 5324514f5e3Sopenharmony_ci objcallInfo->SetCallArg(0, tmap.GetTaggedValue()); 5334514f5e3Sopenharmony_ci ContainersTreeMap::SetAll(objcallInfo); 5344514f5e3Sopenharmony_ci 5354514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 5364514f5e3Sopenharmony_ci } 5374514f5e3Sopenharmony_ci 5384514f5e3Sopenharmony_ci static void ContainersTreeMapValuesFuzzTest(const uint8_t *data, size_t size) 5394514f5e3Sopenharmony_ci { 5404514f5e3Sopenharmony_ci EcmaVM *vm = nullptr; 5414514f5e3Sopenharmony_ci JSThread *thread = nullptr; 5424514f5e3Sopenharmony_ci int32_t key = 0; 5434514f5e3Sopenharmony_ci if (!InitFuzzTest(data, size, key, vm, thread)) { 5444514f5e3Sopenharmony_ci return; 5454514f5e3Sopenharmony_ci } 5464514f5e3Sopenharmony_ci 5474514f5e3Sopenharmony_ci JSHandle<JSAPITreeMap> tmap = CreateJSAPITreeMap(thread); 5484514f5e3Sopenharmony_ci auto callInfo = CreateEcmaRuntimeCallInfo(thread, 8); 5494514f5e3Sopenharmony_ci callInfo->SetFunction(JSTaggedValue::Undefined()); 5504514f5e3Sopenharmony_ci callInfo->SetThis(tmap.GetTaggedValue()); 5514514f5e3Sopenharmony_ci callInfo->SetCallArg(0, JSTaggedValue(0)); 5524514f5e3Sopenharmony_ci callInfo->SetCallArg(1, JSTaggedValue(key)); 5534514f5e3Sopenharmony_ci ContainersTreeMap::Set(callInfo); 5544514f5e3Sopenharmony_ci 5554514f5e3Sopenharmony_ci auto objcallInfo = CreateEcmaRuntimeCallInfo(thread, 4); 5564514f5e3Sopenharmony_ci objcallInfo->SetFunction(JSTaggedValue::Undefined()); 5574514f5e3Sopenharmony_ci objcallInfo->SetThis(tmap.GetTaggedValue()); 5584514f5e3Sopenharmony_ci ContainersTreeMap::Values(objcallInfo); 5594514f5e3Sopenharmony_ci 5604514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 5614514f5e3Sopenharmony_ci } 5624514f5e3Sopenharmony_ci}; 5634514f5e3Sopenharmony_ci} // namespace panda::ecmascript 5644514f5e3Sopenharmony_ci#endif