• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 ROSENRENDER_ROSEN_FUNC_ARG
17 #define ROSENRENDER_ROSEN_FUNC_ARG
18 
19 #include <functional>
20 #include <map>
21 #include "napi/n_val.h"
22 #include "napi/uni_header.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 enum NARG_CNT {
27     ZERO = 0,
28     ONE = 1,
29     TWO = 2,
30     THREE = 3,
31     FOUR = 4,
32     FIVE = 5,
33     SIX = 6,
34     SEVEN = 7,
35     EIGHT = 8,
36     NINE = 9,
37     TEN = 10,
38     ELEVEN = 11,
39     TWELVE = 12,
40 };
41 
42 enum NARG_POS {
43     FIRST = 0,
44     SECOND = 1,
45     THIRD = 2,
46     FOURTH = 3,
47     FIFTH = 4,
48     SIXTH = 5,
49     SEVENTH = 6,
50     EIGHTH = 7,
51     NINTH = 8,
52     TENTH = 9,
53     ELEVENTH = 10,
54     TWELVETH = 11,
55 };
56 
57 class NFuncArg final {
58 public:
59     NFuncArg(napi_env env, napi_callback_info info);
60     virtual ~NFuncArg();
61 
62     bool InitArgs(size_t argc);
63     bool InitArgs(size_t minArgc, size_t maxArgc);
64     size_t GetArgc() const;
65     size_t GetMaxArgc(void) const;
66     napi_value GetThisVar() const;
67     napi_value operator[](size_t argPos) const;
68     napi_value GetArg(size_t argPos) const;
69 
70 private:
71     bool InitArgs(std::function<bool()> argcChecker);
72     void SetArgc(size_t argc);
73     void SetThisVar(napi_value thisVar);
74     void SetMaxArgc(size_t maxArgc);
75     napi_env env_ = nullptr;
76     napi_callback_info info_ = nullptr;
77     size_t argc_ = 0;
78     size_t maxArgc_ = 0;
79     std::unique_ptr<napi_value[]> argv_ = {nullptr};
80     napi_value thisVar_ = nullptr;
81 };
82 } // namespace Rosen
83 } // namespace OHOS
84 #endif // ROSENRENDER_ROSEN_FUNC_ARG
85