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