1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef JS_CONCURRENT_MODULE_COMMON_HELPER_NAPI_HELPER_H_ 17 #define JS_CONCURRENT_MODULE_COMMON_HELPER_NAPI_HELPER_H_ 18 19 #include <uv.h> 20 #include "napi/native_api.h" 21 #include "napi/native_node_api.h" 22 23 namespace Commonlibrary::Concurrent::Common::Helper { 24 class NapiHelper { 25 public: 26 static bool IsString(napi_value value); 27 static bool IsNotUndefined(napi_value value); 28 static bool IsArray(napi_value value); 29 static bool IsConstructor(napi_env env, napi_callback_info cbInfo); 30 static bool IsCallable(napi_env env, napi_value value); 31 static bool IsCallable(napi_env env, napi_ref value); 32 static size_t GetCallbackInfoArgc(napi_env env, napi_callback_info cbInfo); 33 static napi_value GetNamePropertyInParentPort(napi_env env, napi_ref parentPort, const char* name); 34 static void SetNamePropertyInGlobal(napi_env env, const char* name, napi_value value); 35 static napi_value GetUndefinedValue(napi_env env); 36 static bool IsObject(napi_value value); 37 static char* GetString(napi_env env, napi_value value); 38 static napi_value CreateBooleanValue(napi_env env, bool value); 39 static napi_value GetGlobalObject(napi_env env); 40 static napi_ref CreateReference(napi_env env, napi_value value, uint32_t refcount); 41 static napi_value CreateUint32(napi_env env, uint32_t value); 42 static uv_loop_t* GetLibUV(napi_env env); 43 static napi_value GetReferenceValue(napi_env env, napi_ref ref); 44 static void DeleteReference(napi_env env, napi_ref ref); 45 static napi_value GetNameProperty(napi_env env, napi_value obj, const char* name); 46 static bool GetBooleanValue(napi_env env, napi_value value); 47 static bool StrictEqual(napi_env env, napi_value value, napi_value cmpValue); 48 }; 49 } // namespace Commonlibrary::Concurrent::Common::Helper 50 #endif // JS_CONCURRENT_MODULE_COMMON_HELPER_NAPI_HELPER_H_ 51