• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef INTERFACES_KITS_NAPI_COMMON_NAPI_N_FUNC_ARG_H
17 #define INTERFACES_KITS_NAPI_COMMON_NAPI_N_FUNC_ARG_H
18 
19 #include <functional>
20 #include <memory>
21 
22 #include "node_api.h"
23 #include "js_native_api_types.h"
24 
25 namespace OHOS {
26 namespace DistributedFS {
27 enum NARG_CNT {
28     ZERO = 0,
29     ONE = 1,
30     TWO = 2,
31     THREE = 3,
32     FOUR = 4,
33 };
34 
35 enum NARG_POS {
36     FIRST = 0,
37     SECOND = 1,
38     THIRD = 2,
39     FOURTH = 3,
40 };
41 
42 class NFuncArg final {
43 public:
44     NFuncArg(napi_env env, napi_callback_info info);
45     virtual ~NFuncArg();
46 
47     bool InitArgs(size_t argc);
48     bool InitArgs(size_t minArgc, size_t maxArgc);
49 
50     size_t GetArgc() const;
51     napi_value GetThisVar() const;
52 
53     napi_value operator[](size_t idx) const;
54     napi_value GetArg(size_t argPos) const;
55 
56 private:
57     napi_env env_ = nullptr;
58     napi_callback_info info_ = nullptr;
59 
60     size_t argc_ = 0;
61     std::unique_ptr<napi_value[]> argv_ = { nullptr };
62     napi_value thisVar_ = nullptr;
63 
64     bool InitArgs(std::function<bool()> argcChecker);
65 
66     void SetArgc(size_t argc);
67     void SetThisVar(napi_value thisVar);
68 };
69 } // namespace DistributedFS
70 } // namespace OHOS
71 #endif