• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 IsFunction(napi_value object);
30     static bool IsArrayBuffer(napi_value value);
31     static bool IsNumber(napi_value value);
32     static bool IsCallable(napi_env env, napi_value value);
33     static bool IsCallable(napi_env env, napi_ref value);
34     static size_t GetCallbackInfoArgc(napi_env env, napi_callback_info cbInfo);
35     static napi_value GetNamePropertyInParentPort(napi_env env, napi_ref parentPort, const char* name);
36     static void SetNamePropertyInGlobal(napi_env env, const char* name, napi_value value);
37     static napi_value GetUndefinedValue(napi_env env);
38     static bool IsObject(napi_value value);
39     static char* GetString(napi_env env, napi_value value);
40     static napi_value CreateBooleanValue(napi_env env, bool value);
41     static napi_value GetGlobalObject(napi_env env);
42     static napi_ref CreateReference(napi_env env, napi_value value, uint32_t refcount);
43     static napi_value CreateUint32(napi_env env, uint32_t value);
44     static uv_loop_t* GetLibUV(napi_env env);
45     static napi_value GetReferenceValue(napi_env env, napi_ref ref);
46     static void DeleteReference(napi_env env, napi_ref ref);
47     static napi_value GetNameProperty(napi_env env, napi_value obj, const char* name);
48     static bool HasNameProperty(napi_env env, napi_value obj, const char* name);
49     static bool GetBooleanValue(napi_env env, napi_value value);
50     static bool StrictEqual(napi_env env, napi_value value, napi_value cmpValue);
51     static napi_value GetConstructorName(napi_env env, napi_value object);
52     static napi_value CreateObject(napi_env env);
53     static napi_value CreatePromise(napi_env env, napi_deferred* deferred);
54     static uint32_t GetArrayLength(napi_env env, napi_value array);
55     static uint32_t GetUint32Value(napi_env env, napi_value value);
56     static bool IsExceptionPending(napi_env env);
57 };
58 } // namespace Commonlibrary::Concurrent::Common::Helper
59 #endif // JS_CONCURRENT_MODULE_COMMON_HELPER_NAPI_HELPER_H
60