14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 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#include "jsvaluerefismodulenamespace_fuzzer.h" 174514f5e3Sopenharmony_ci#include "ecmascript/containers/containers_private.h" 184514f5e3Sopenharmony_ci#include "ecmascript/ecma_string-inl.h" 194514f5e3Sopenharmony_ci#include "ecmascript/global_env.h" 204514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_list.h" 214514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_queue.h" 224514f5e3Sopenharmony_ci#include "ecmascript/js_collator.h" 234514f5e3Sopenharmony_ci#include "ecmascript/js_handle.h" 244514f5e3Sopenharmony_ci#include "ecmascript/js_plural_rules.h" 254514f5e3Sopenharmony_ci#include "ecmascript/module/js_module_manager.h" 264514f5e3Sopenharmony_ci#include "ecmascript/module/js_module_source_text.h" 274514f5e3Sopenharmony_ci#include "ecmascript/napi/include/jsnapi.h" 284514f5e3Sopenharmony_ci#include "ecmascript/tagged_list.h" 294514f5e3Sopenharmony_ci 304514f5e3Sopenharmony_ciusing namespace panda; 314514f5e3Sopenharmony_ciusing namespace panda::ecmascript; 324514f5e3Sopenharmony_ci 334514f5e3Sopenharmony_cinamespace OHOS { 344514f5e3Sopenharmony_ciconstexpr uint32_t ERROR_TYPE_LEN = 2; 354514f5e3Sopenharmony_ci 364514f5e3Sopenharmony_civoid IsModuleNamespaceObjectFuzztest([[maybe_unused]]const uint8_t *data, size_t size) 374514f5e3Sopenharmony_ci{ 384514f5e3Sopenharmony_ci RuntimeOption option; 394514f5e3Sopenharmony_ci option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); 404514f5e3Sopenharmony_ci EcmaVM *vm = JSNApi::CreateJSVM(option); 414514f5e3Sopenharmony_ci { 424514f5e3Sopenharmony_ci JsiFastNativeScope scope(vm); 434514f5e3Sopenharmony_ci if (size <= 0) { 444514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "illegal input!"; 454514f5e3Sopenharmony_ci return; 464514f5e3Sopenharmony_ci } 474514f5e3Sopenharmony_ci ObjectFactory *objectFactory = vm->GetFactory(); 484514f5e3Sopenharmony_ci JSHandle<SourceTextModule> module = objectFactory->NewSourceTextModule(); 494514f5e3Sopenharmony_ci JSHandle<LocalExportEntry> localExportEntry1 = objectFactory->NewLocalExportEntry(); 504514f5e3Sopenharmony_ci SourceTextModule::AddLocalExportEntry(vm->GetJSThread(), module, localExportEntry1, 0, ERROR_TYPE_LEN); 514514f5e3Sopenharmony_ci JSHandle<LocalExportEntry> localExportEntry2 = objectFactory->NewLocalExportEntry(); 524514f5e3Sopenharmony_ci SourceTextModule::AddLocalExportEntry(vm->GetJSThread(), module, localExportEntry2, 1, ERROR_TYPE_LEN); 534514f5e3Sopenharmony_ci JSHandle<TaggedArray> localExportEntries(vm->GetJSThread(), module->GetLocalExportEntries()); 544514f5e3Sopenharmony_ci CString baseFileName = "a.abc"; 554514f5e3Sopenharmony_ci module->SetEcmaModuleFilenameString(baseFileName); 564514f5e3Sopenharmony_ci ModuleManager *moduleManager = vm->GetJSThread()->GetCurrentEcmaContext()->GetModuleManager(); 574514f5e3Sopenharmony_ci moduleManager->AddResolveImportedModule(baseFileName, module.GetTaggedValue()); 584514f5e3Sopenharmony_ci JSHandle<ModuleNamespace> np = ModuleNamespace::ModuleNamespaceCreate(vm->GetJSThread(), 594514f5e3Sopenharmony_ci JSHandle<JSTaggedValue>::Cast(module), localExportEntries); 604514f5e3Sopenharmony_ci ModuleNamespace::PreventExtensions(); 614514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> moduleNamespaceTag = JSHandle<JSTaggedValue>::Cast(np); 624514f5e3Sopenharmony_ci Local<JSValueRef> moduleNamespace = JSNApiHelper::ToLocal<ModuleNamespace>(moduleNamespaceTag); 634514f5e3Sopenharmony_ci moduleNamespace->IsModuleNamespaceObject(vm); 644514f5e3Sopenharmony_ci } 654514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 664514f5e3Sopenharmony_ci} 674514f5e3Sopenharmony_ci 684514f5e3Sopenharmony_civoid IsProxyFuzztest([[maybe_unused]]const uint8_t *data, size_t size) 694514f5e3Sopenharmony_ci{ 704514f5e3Sopenharmony_ci RuntimeOption option; 714514f5e3Sopenharmony_ci option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); 724514f5e3Sopenharmony_ci EcmaVM *vm = JSNApi::CreateJSVM(option); 734514f5e3Sopenharmony_ci { 744514f5e3Sopenharmony_ci JsiFastNativeScope scope(vm); 754514f5e3Sopenharmony_ci if (size <= 0) { 764514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "illegal input!"; 774514f5e3Sopenharmony_ci return; 784514f5e3Sopenharmony_ci } 794514f5e3Sopenharmony_ci auto thread = vm->GetJSThread(); 804514f5e3Sopenharmony_ci JSHandle<GlobalEnv> globalEnv = vm->GetGlobalEnv(); 814514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> hclass(thread, globalEnv->GetObjectFunction().GetObject<JSFunction>()); 824514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> targetHandle( 834514f5e3Sopenharmony_ci thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle<JSFunction>::Cast(hclass), hclass)); 844514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> handlerHandle( 854514f5e3Sopenharmony_ci thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle<JSFunction>::Cast(hclass), hclass)); 864514f5e3Sopenharmony_ci JSHandle<JSProxy> proxyHandle = JSProxy::ProxyCreate(thread, targetHandle, handlerHandle); 874514f5e3Sopenharmony_ci Local<JSValueRef> proxy = JSNApiHelper::ToLocal<JSProxy>(JSHandle<JSTaggedValue>(proxyHandle)); 884514f5e3Sopenharmony_ci proxy->IsProxy(vm); 894514f5e3Sopenharmony_ci } 904514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 914514f5e3Sopenharmony_ci} 924514f5e3Sopenharmony_ci 934514f5e3Sopenharmony_civoid IsJSCollatorFuzztest([[maybe_unused]]const uint8_t *data, size_t size) 944514f5e3Sopenharmony_ci{ 954514f5e3Sopenharmony_ci RuntimeOption option; 964514f5e3Sopenharmony_ci option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); 974514f5e3Sopenharmony_ci EcmaVM *vm = JSNApi::CreateJSVM(option); 984514f5e3Sopenharmony_ci { 994514f5e3Sopenharmony_ci JsiFastNativeScope scope(vm); 1004514f5e3Sopenharmony_ci if (size <= 0) { 1014514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "illegal input!"; 1024514f5e3Sopenharmony_ci return; 1034514f5e3Sopenharmony_ci } 1044514f5e3Sopenharmony_ci auto thread = vm->GetJSThread(); 1054514f5e3Sopenharmony_ci ObjectFactory *factory = vm->GetFactory(); 1064514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> ctor = vm->GetGlobalEnv()->GetCollatorFunction(); 1074514f5e3Sopenharmony_ci JSHandle<JSCollator> collator = 1084514f5e3Sopenharmony_ci JSHandle<JSCollator>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(ctor), ctor)); 1094514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> localeStr = thread->GlobalConstants()->GetHandledEnUsString(); 1104514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> undefinedHandle(thread, JSTaggedValue::Undefined()); 1114514f5e3Sopenharmony_ci JSHandle<JSCollator> initCollator = 1124514f5e3Sopenharmony_ci JSCollator::InitializeCollator(thread, collator, localeStr, undefinedHandle); 1134514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> collatorTagHandleVal = JSHandle<JSTaggedValue>::Cast(initCollator); 1144514f5e3Sopenharmony_ci Local<JSValueRef> object = JSNApiHelper::ToLocal<JSValueRef>(collatorTagHandleVal); 1154514f5e3Sopenharmony_ci object->IsJSCollator(vm); 1164514f5e3Sopenharmony_ci } 1174514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 1184514f5e3Sopenharmony_ci} 1194514f5e3Sopenharmony_ci 1204514f5e3Sopenharmony_civoid IsJSPluralRulesFuzztest([[maybe_unused]]const uint8_t *data, size_t size) 1214514f5e3Sopenharmony_ci{ 1224514f5e3Sopenharmony_ci RuntimeOption option; 1234514f5e3Sopenharmony_ci option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); 1244514f5e3Sopenharmony_ci EcmaVM *vm = JSNApi::CreateJSVM(option); 1254514f5e3Sopenharmony_ci { 1264514f5e3Sopenharmony_ci JsiFastNativeScope scope(vm); 1274514f5e3Sopenharmony_ci if (size <= 0) { 1284514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "illegal input!"; 1294514f5e3Sopenharmony_ci return; 1304514f5e3Sopenharmony_ci } 1314514f5e3Sopenharmony_ci auto thread = vm->GetJSThread(); 1324514f5e3Sopenharmony_ci ObjectFactory *factory = vm->GetFactory(); 1334514f5e3Sopenharmony_ci JSHandle<GlobalEnv> env = vm->GetGlobalEnv(); 1344514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> optionHandle(thread, JSTaggedValue::Undefined()); 1354514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> ctor = env->GetPluralRulesFunction(); 1364514f5e3Sopenharmony_ci JSHandle<JSPluralRules> pluralRules = 1374514f5e3Sopenharmony_ci JSHandle<JSPluralRules>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(ctor), ctor)); 1384514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> localeStr(factory->NewFromASCII("en-GB")); 1394514f5e3Sopenharmony_ci JSHandle<JSPluralRules> initPluralRules = 1404514f5e3Sopenharmony_ci JSPluralRules::InitializePluralRules(thread, pluralRules, localeStr, optionHandle); 1414514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> tagPlureRules = JSHandle<JSTaggedValue>::Cast(initPluralRules); 1424514f5e3Sopenharmony_ci Local<JSValueRef> object = JSNApiHelper::ToLocal<JSValueRef>(tagPlureRules); 1434514f5e3Sopenharmony_ci object->IsJSPluralRules(vm); 1444514f5e3Sopenharmony_ci } 1454514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 1464514f5e3Sopenharmony_ci} 1474514f5e3Sopenharmony_ci 1484514f5e3Sopenharmony_civoid IsStrictEqualsFuzztest([[maybe_unused]]const uint8_t *data, size_t size) 1494514f5e3Sopenharmony_ci{ 1504514f5e3Sopenharmony_ci RuntimeOption option; 1514514f5e3Sopenharmony_ci option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); 1524514f5e3Sopenharmony_ci EcmaVM *vm = JSNApi::CreateJSVM(option); 1534514f5e3Sopenharmony_ci if (size <= 0) { 1544514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "illegal input!"; 1554514f5e3Sopenharmony_ci return; 1564514f5e3Sopenharmony_ci } 1574514f5e3Sopenharmony_ci Local<ObjectRef> object = ObjectRef::New(vm); 1584514f5e3Sopenharmony_ci Local<ObjectRef> object1 = ObjectRef::New(vm); 1594514f5e3Sopenharmony_ci object->IsStrictEquals(vm, object1); 1604514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 1614514f5e3Sopenharmony_ci} 1624514f5e3Sopenharmony_ci 1634514f5e3Sopenharmony_civoid IsJSListFormatFuzztest([[maybe_unused]]const uint8_t *data, size_t size) 1644514f5e3Sopenharmony_ci{ 1654514f5e3Sopenharmony_ci RuntimeOption option; 1664514f5e3Sopenharmony_ci option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); 1674514f5e3Sopenharmony_ci EcmaVM *vm = JSNApi::CreateJSVM(option); 1684514f5e3Sopenharmony_ci if (size <= 0) { 1694514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "illegal input!"; 1704514f5e3Sopenharmony_ci return; 1714514f5e3Sopenharmony_ci } 1724514f5e3Sopenharmony_ci Local<JSValueRef> object = ObjectRef::New(vm); 1734514f5e3Sopenharmony_ci object->IsJSListFormat(vm); 1744514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 1754514f5e3Sopenharmony_ci} 1764514f5e3Sopenharmony_ci 1774514f5e3Sopenharmony_civoid IsJSPrimitiveRefFuzztest([[maybe_unused]]const uint8_t *data, size_t size) 1784514f5e3Sopenharmony_ci{ 1794514f5e3Sopenharmony_ci RuntimeOption option; 1804514f5e3Sopenharmony_ci option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); 1814514f5e3Sopenharmony_ci EcmaVM *vm = JSNApi::CreateJSVM(option); 1824514f5e3Sopenharmony_ci { 1834514f5e3Sopenharmony_ci JsiFastNativeScope scope(vm); 1844514f5e3Sopenharmony_ci if (size <= 0) { 1854514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "illegal input!"; 1864514f5e3Sopenharmony_ci return; 1874514f5e3Sopenharmony_ci } 1884514f5e3Sopenharmony_ci auto thread = vm->GetJSThread(); 1894514f5e3Sopenharmony_ci auto factory = vm->GetFactory(); 1904514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> nullHandle(thread, JSTaggedValue::Null()); 1914514f5e3Sopenharmony_ci JSHandle<JSHClass> jsClassHandle = factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_PRIMITIVE_REF, nullHandle); 1924514f5e3Sopenharmony_ci TaggedObject *taggedObject = factory->NewObject(jsClassHandle); 1934514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> jsTaggedValue(thread, JSTaggedValue(taggedObject)); 1944514f5e3Sopenharmony_ci Local<JSValueRef> jsValueRef = JSNApiHelper::ToLocal<JSPrimitiveRef>(jsTaggedValue); 1954514f5e3Sopenharmony_ci jsValueRef->IsJSPrimitiveRef(vm); 1964514f5e3Sopenharmony_ci } 1974514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 1984514f5e3Sopenharmony_ci} 1994514f5e3Sopenharmony_ci 2004514f5e3Sopenharmony_civoid IsDequeFuzztest([[maybe_unused]]const uint8_t *data, size_t size) 2014514f5e3Sopenharmony_ci{ 2024514f5e3Sopenharmony_ci RuntimeOption option; 2034514f5e3Sopenharmony_ci option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); 2044514f5e3Sopenharmony_ci EcmaVM *vm = JSNApi::CreateJSVM(option); 2054514f5e3Sopenharmony_ci { 2064514f5e3Sopenharmony_ci JsiFastNativeScope scope(vm); 2074514f5e3Sopenharmony_ci if (size <= 0) { 2084514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "illegal input!"; 2094514f5e3Sopenharmony_ci return; 2104514f5e3Sopenharmony_ci } 2114514f5e3Sopenharmony_ci auto thread = vm->GetJSThread(); 2124514f5e3Sopenharmony_ci auto factory = vm->GetFactory(); 2134514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> proto = thread->GetEcmaVM()->GetGlobalEnv()->GetFunctionPrototype(); 2144514f5e3Sopenharmony_ci JSHandle<JSHClass> queueClass = factory->NewEcmaHClass(JSAPIQueue::SIZE, JSType::JS_API_QUEUE, proto); 2154514f5e3Sopenharmony_ci JSHandle<JSAPIQueue> jsQueue = JSHandle<JSAPIQueue>::Cast(factory->NewJSObjectWithInit(queueClass)); 2164514f5e3Sopenharmony_ci JSHandle<TaggedArray> newElements = factory->NewTaggedArray(JSAPIQueue::DEFAULT_CAPACITY_LENGTH); 2174514f5e3Sopenharmony_ci jsQueue->SetLength(thread, JSTaggedValue(0)); 2184514f5e3Sopenharmony_ci jsQueue->SetFront(0); 2194514f5e3Sopenharmony_ci jsQueue->SetTail(0); 2204514f5e3Sopenharmony_ci jsQueue->SetElements(thread, newElements); 2214514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> Que = JSHandle<JSTaggedValue>::Cast(jsQueue); 2224514f5e3Sopenharmony_ci Local<JSValueRef> jsValueRef = JSNApiHelper::ToLocal<ArrayRef>(Que); 2234514f5e3Sopenharmony_ci jsValueRef->IsDeque(vm); 2244514f5e3Sopenharmony_ci } 2254514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 2264514f5e3Sopenharmony_ci} 2274514f5e3Sopenharmony_ci 2284514f5e3Sopenharmony_ciLocal<JSValueRef> CreateJSValueRef(EcmaVM *vm, panda::ecmascript::JSType type) 2294514f5e3Sopenharmony_ci{ 2304514f5e3Sopenharmony_ci auto thread = vm->GetJSThread(); 2314514f5e3Sopenharmony_ci auto factory = vm->GetFactory(); 2324514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> nullHandle(thread, JSTaggedValue::Null()); 2334514f5e3Sopenharmony_ci JSHandle<JSHClass> jsClassHandle = factory->NewEcmaHClass(JSObject::SIZE, type, nullHandle); 2344514f5e3Sopenharmony_ci TaggedObject *taggedObject = factory->NewObject(jsClassHandle); 2354514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> jsTaggedValue(thread, JSTaggedValue(taggedObject)); 2364514f5e3Sopenharmony_ci return JSNApiHelper::ToLocal<JSValueRef>(jsTaggedValue); 2374514f5e3Sopenharmony_ci} 2384514f5e3Sopenharmony_ci 2394514f5e3Sopenharmony_civoid IsJSIntlFuzztest([[maybe_unused]]const uint8_t *data, size_t size) 2404514f5e3Sopenharmony_ci{ 2414514f5e3Sopenharmony_ci RuntimeOption option; 2424514f5e3Sopenharmony_ci option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); 2434514f5e3Sopenharmony_ci EcmaVM *vm = JSNApi::CreateJSVM(option); 2444514f5e3Sopenharmony_ci { 2454514f5e3Sopenharmony_ci JsiFastNativeScope scope(vm); 2464514f5e3Sopenharmony_ci if (size <= 0) { 2474514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "illegal input!"; 2484514f5e3Sopenharmony_ci return; 2494514f5e3Sopenharmony_ci } 2504514f5e3Sopenharmony_ci Local<JSValueRef> jsInt1 = CreateJSValueRef(vm, JSType::JS_INTL); 2514514f5e3Sopenharmony_ci jsInt1->IsJSIntl(vm); 2524514f5e3Sopenharmony_ci } 2534514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 2544514f5e3Sopenharmony_ci} 2554514f5e3Sopenharmony_ci 2564514f5e3Sopenharmony_civoid IsJSDateTimeFormatFuzztest([[maybe_unused]]const uint8_t *data, size_t size) 2574514f5e3Sopenharmony_ci{ 2584514f5e3Sopenharmony_ci RuntimeOption option; 2594514f5e3Sopenharmony_ci option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); 2604514f5e3Sopenharmony_ci EcmaVM *vm = JSNApi::CreateJSVM(option); 2614514f5e3Sopenharmony_ci { 2624514f5e3Sopenharmony_ci JsiFastNativeScope scope(vm); 2634514f5e3Sopenharmony_ci if (size <= 0) { 2644514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "illegal input!"; 2654514f5e3Sopenharmony_ci return; 2664514f5e3Sopenharmony_ci } 2674514f5e3Sopenharmony_ci Local<JSValueRef> dateTime = CreateJSValueRef(vm, JSType::JS_DATE_TIME_FORMAT); 2684514f5e3Sopenharmony_ci dateTime->IsJSDateTimeFormat(vm); 2694514f5e3Sopenharmony_ci } 2704514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 2714514f5e3Sopenharmony_ci} 2724514f5e3Sopenharmony_ci 2734514f5e3Sopenharmony_civoid IsJSNumberFormatFuzztest([[maybe_unused]]const uint8_t *data, size_t size) 2744514f5e3Sopenharmony_ci{ 2754514f5e3Sopenharmony_ci RuntimeOption option; 2764514f5e3Sopenharmony_ci option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); 2774514f5e3Sopenharmony_ci EcmaVM *vm = JSNApi::CreateJSVM(option); 2784514f5e3Sopenharmony_ci { 2794514f5e3Sopenharmony_ci JsiFastNativeScope scope(vm); 2804514f5e3Sopenharmony_ci if (size <= 0) { 2814514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "illegal input!"; 2824514f5e3Sopenharmony_ci return; 2834514f5e3Sopenharmony_ci } 2844514f5e3Sopenharmony_ci Local<JSValueRef> number = CreateJSValueRef(vm, JSType::JS_NUMBER_FORMAT); 2854514f5e3Sopenharmony_ci number->IsJSNumberFormat(vm); 2864514f5e3Sopenharmony_ci } 2874514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 2884514f5e3Sopenharmony_ci} 2894514f5e3Sopenharmony_ci 2904514f5e3Sopenharmony_civoid IsJSRelativeTimeFormatFuzztest([[maybe_unused]]const uint8_t *data, size_t size) 2914514f5e3Sopenharmony_ci{ 2924514f5e3Sopenharmony_ci RuntimeOption option; 2934514f5e3Sopenharmony_ci option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); 2944514f5e3Sopenharmony_ci EcmaVM *vm = JSNApi::CreateJSVM(option); 2954514f5e3Sopenharmony_ci { 2964514f5e3Sopenharmony_ci JsiFastNativeScope scope(vm); 2974514f5e3Sopenharmony_ci if (size <= 0) { 2984514f5e3Sopenharmony_ci LOG_ECMA(ERROR) << "illegal input!"; 2994514f5e3Sopenharmony_ci return; 3004514f5e3Sopenharmony_ci } 3014514f5e3Sopenharmony_ci Local<JSValueRef> relative = CreateJSValueRef(vm, JSType::JS_RELATIVE_TIME_FORMAT); 3024514f5e3Sopenharmony_ci relative->IsJSRelativeTimeFormat(vm); 3034514f5e3Sopenharmony_ci } 3044514f5e3Sopenharmony_ci JSNApi::DestroyJSVM(vm); 3054514f5e3Sopenharmony_ci} 3064514f5e3Sopenharmony_ci} 3074514f5e3Sopenharmony_ci 3084514f5e3Sopenharmony_ci// Fuzzer entry point. 3094514f5e3Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 3104514f5e3Sopenharmony_ci{ 3114514f5e3Sopenharmony_ci // Run your code on data. 3124514f5e3Sopenharmony_ci OHOS::IsModuleNamespaceObjectFuzztest(data, size); 3134514f5e3Sopenharmony_ci OHOS::IsProxyFuzztest(data, size); 3144514f5e3Sopenharmony_ci OHOS::IsJSCollatorFuzztest(data, size); 3154514f5e3Sopenharmony_ci OHOS::IsJSPluralRulesFuzztest(data, size); 3164514f5e3Sopenharmony_ci OHOS::IsStrictEqualsFuzztest(data, size); 3174514f5e3Sopenharmony_ci OHOS::IsJSListFormatFuzztest(data, size); 3184514f5e3Sopenharmony_ci OHOS::IsJSPrimitiveRefFuzztest(data, size); 3194514f5e3Sopenharmony_ci OHOS::IsDequeFuzztest(data, size); 3204514f5e3Sopenharmony_ci OHOS::IsJSIntlFuzztest(data, size); 3214514f5e3Sopenharmony_ci OHOS::IsJSDateTimeFormatFuzztest(data, size); 3224514f5e3Sopenharmony_ci OHOS::IsJSNumberFormatFuzztest(data, size); 3234514f5e3Sopenharmony_ci OHOS::IsJSRelativeTimeFormatFuzztest(data, size); 3244514f5e3Sopenharmony_ci return 0; 3254514f5e3Sopenharmony_ci}