• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 BASE_FAULTLOGGER_NAPI_NAPI_UTIL_H
17 #define BASE_FAULTLOGGER_NAPI_NAPI_UTIL_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "logger.h"
23 #include "napi/native_api.h"
24 #include "napi/native_node_api.h"
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 class NapiUtil {
29 public:
30     static napi_value CreateErrorMessage(napi_env env, std::string message);
31     static napi_value CreateUndefined(napi_env env);
32     static void SetPropertyInt32(napi_env env, napi_value object, std::string name, int32_t value);
33     static void SetPropertyInt64(napi_env env, napi_value object, std::string name, int64_t value);
34     static void SetPropertyStringUtf8(napi_env env, napi_value object, std::string name, std::string value);
35     static bool IsMatchType(napi_env env, napi_value value, napi_valuetype type);
36 
37     static napi_value CreateString(const napi_env env, const std::string& str);
38     static void ThrowError(napi_env env, int code, const std::string& msg, bool isThrow = true);
39     static std::string CreateServiceErrMsg();
40     static std::string CreateParamCntErrMsg();
41     static std::string CreateErrMsg(const std::string name);
42     static std::string CreateErrMsg(const std::string name, const std::string& type);
43     static std::string CreateErrMsg(const std::string name, const napi_valuetype type);
44 };
45 }  // namespace HiviewDFX
46 }  // namespace OHOS
47 #endif // NAPI_UTIL_H