• 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_COMMON_H
17 #define JS_COMMON_H
18 namespace OHOS::ObjectStore {
19 class Constants {
20 public:
21     static constexpr const char *CHANGE = "change";
22     static constexpr const char *STATUS = "status";
23 };
24 #define OBJECT_REVT_NOTHING
25 
26 #define NOT_MATCH_RETURN(condition, res)                \
27     do {                                                \
28         if (!(condition)) {                             \
29             LOG_ERROR("error! %{public}s", #condition); \
30             return res;                                 \
31         }                                               \
32     } while (0)
33 
34 #define NOT_MATCH_RETURN_VOID(condition)        \
35     NOT_MATCH_RETURN(condition, OBJECT_REVT_NOTHING)
36 
37 #define NOT_MATCH_RETURN_NULL(condition)        \
38     NOT_MATCH_RETURN(condition, nullptr)
39 
40 #define NOT_MATCH_RETURN_FALSE(condition)       \
41     NOT_MATCH_RETURN(condition, false)
42 
43 #define NOT_MATCH_GOTO_ERROR(condition)         \
44     {                                                   \
45         if (!(condition)) {                             \
46             LOG_ERROR("error! %{public}s", #condition); \
47             goto ERROR;                                 \
48         }                                               \
49     }
50 
51 #define INVALID_API_THROW_ERROR(assertion)                                                                   \
52     do {                                                                                                     \
53         if (!(assertion)) {                                                                                  \
54             std::shared_ptr<DeviceNotSupportedError> apiError = std::make_shared<DeviceNotSupportedError>(); \
55             ctxt->SetError(apiError);                                                                        \
56             ctxt->status = napi_generic_failure;                                                             \
57             return;                                                                                          \
58         }                                                                                                    \
59     } while (0)
60 
61 #define INVALID_STATUS_THROW_ERROR(assertion, msg)                                   \
62     do {                                                                             \
63         if (!(assertion)) {                                                          \
64             std::shared_ptr<InnerError> innerError = std::make_shared<InnerError>(); \
65             ctxt->SetError(innerError);                                              \
66             ctxt->status = napi_generic_failure;                                     \
67             ctxt->message = msg;                                                     \
68             return;                                                                  \
69         }                                                                            \
70     } while (0)
71 } // namespace OHOS::ObjectStore
72 #endif // JS_COMMON_H