1 /*
2  * Copyright (c) 2021 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 #ifndef OHOS_ACE_TEST_NAPI_COMMON_H
16 #define OHOS_ACE_TEST_NAPI_COMMON_H
17 #include <memory>
18 #include <string>
19 
20 #include "napi/native_api.h"
21 #include "napi/native_common.h"
22 #include "napi/native_node_api.h"
23 #include "utils/log.h"
24 namespace ACE {
25 namespace NAPI {
26 namespace SYSTEM_TEST_NAPI {
27 
28 #define NAPI_CALL_BASE_BOOL(theCall, retVal) \
29     do {                                     \
30         if ((theCall) == false) {            \
31             return retVal;                   \
32         }                                    \
33     } while (0)
34 
35     bool IsTypeForNapiValue(napi_env env, napi_value param, napi_valuetype expectType);
36     bool UnwrapIntValue(napi_env env, napi_value jsValue, int& result);
37     napi_value UnwrapStringParam(std::string& str, napi_env env, napi_value argv);
38     napi_value BigIntInit(napi_env env, napi_value exports);
39     napi_value BufferInit(napi_env env, napi_value exports);
40     napi_value ThreadSafeInit(napi_env env, napi_value exports);
41     napi_value JsDateInit(napi_env env, napi_value exports);
42     napi_value CallBackScopeInit(napi_env env, napi_value exports);
43     napi_value JsStringInit(napi_env env, napi_value exports);
44     napi_value ObjectInit(napi_env env, napi_value exports);
45     napi_value ArrayDetachInit(napi_env env, napi_value exports);
46 } // namespace SYSTEM_TEST_NAPI
47 } // namespace NAPI
48 } // namespace ACE
49 #endif // OHOS_ACE_NAPI_COMMON_H