1 /* 2 * Copyright (c) 2023 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 NAPI_HELPER_H 17 #define NAPI_HELPER_H 18 #include "napi/native_api.h" 19 20 class NapiHelper { 21 public: 22 static bool IsString(napi_value value); 23 static bool IsNotUndefined(napi_value value); 24 static bool IsArray(napi_value value); 25 static bool IsFunction(napi_value object); 26 static bool IsArrayBuffer(napi_value value); 27 static bool IsNumber(napi_value value); 28 static bool IsCallable(napi_env env, napi_value value); 29 static bool IsCallable(napi_env env, napi_ref value); 30 static size_t GetCallbackInfoArgc(napi_env env, napi_callback_info cbInfo); 31 static napi_value GetNamePropertyInParentPort(napi_env env, napi_ref parentPort, const char *name); 32 static void SetNamePropertyInGlobal(napi_env env, const char *name, napi_value value); 33 static napi_value GetUndefinedValue(napi_env env); 34 static bool IsObject(napi_value value); 35 static char *GetString(napi_env env, napi_value value); 36 static napi_value CreateBooleanValue(napi_env env, bool value); 37 static napi_value GetGlobalObject(napi_env env); 38 static napi_ref CreateReference(napi_env env, napi_value value, uint32_t refcount); 39 static napi_value CreateUint32(napi_env env, uint32_t value); 40 static napi_value GetReferenceValue(napi_env env, napi_ref ref); 41 static void DeleteReference(napi_env env, napi_ref ref); 42 static napi_value GetNameProperty(napi_env env, napi_value obj, const char *name); 43 static bool GetBooleanValue(napi_env env, napi_value value); 44 static bool StrictEqual(napi_env env, napi_value value, napi_value cmpValue); 45 static napi_value GetConstructorName(napi_env env, napi_value object); 46 static napi_value CreateObject(napi_env env); 47 static napi_value CreatePromise(napi_env env, napi_deferred *deferred); 48 static uint32_t GetArrayLength(napi_env env, napi_value array); 49 static uint32_t GetUint32Value(napi_env env, napi_value value); 50 static bool IsExceptionPending(napi_env env); 51 }; 52 #endif //NAPI_HELPER_H