1 /* 2 * Copyright (c) 2024 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_JS_ZIP_NAPI_COMMON_NAPI_FUNC_ARG_H 17 #define INTERFACES_KITS_JS_ZIP_NAPI_COMMON_NAPI_FUNC_ARG_H 18 19 #include "header.h" 20 21 namespace OHOS { 22 namespace AppExecFwk { 23 namespace LIBZIP { 24 enum ArgumentCount { 25 ZERO = 0, 26 ONE = 1, 27 TWO = 2, 28 THREE = 3, 29 FOUR = 4, 30 FIVE = 5, 31 SIX = 6, 32 SEVEN = 7, 33 }; 34 35 enum ArgumentPosition { 36 FIRST = 0, 37 SECOND = 1, 38 THIRD = 2, 39 FOURTH = 3, 40 FIFTH = 4, 41 SIXTH = 5, 42 SEVENTH = 6, 43 }; 44 45 class NapiFuncArg final { 46 public: 47 NapiFuncArg(napi_env env, napi_callback_info info); 48 virtual ~NapiFuncArg(); 49 50 bool InitArgs(size_t argc); 51 bool InitArgs(size_t minArgc, size_t maxArgc); 52 53 size_t GetArgc() const; 54 napi_value GetThisVar() const; 55 56 napi_value operator[](size_t argPos) const; 57 napi_value GetArg(size_t argPos) const; 58 59 private: 60 napi_env env_ = nullptr; 61 napi_callback_info info_ = nullptr; 62 63 size_t argc_ = 0; 64 std::unique_ptr<napi_value[]> argv_ = {nullptr}; 65 napi_value thisVar_ = nullptr; 66 67 bool InitArgs(std::function<bool()> argcChecker); 68 69 void SetArgc(size_t argc); 70 void SetThisVar(napi_value thisVar); 71 }; 72 } // namespace LIBZIP 73 } // namespace AppExecFwk 74 } // namespace OHOS 75 #endif // INTERFACES_KITS_JS_ZIP_NAPI_COMMON_NAPI_FUNC_ARG_H