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 #ifndef NAPI_ARG_H 16 #define NAPI_ARG_H 17 18 #include <memory> 19 20 #include "app_log_wrapper.h" 21 #include "napi/native_api.h" 22 #include "napi/native_common.h" 23 #include "napi/native_node_api.h" 24 25 namespace OHOS { 26 namespace AppExecFwk { 27 class NapiArg { 28 public: NapiArg(napi_env env,napi_callback_info info)29 NapiArg(napi_env env, napi_callback_info info): env_(env), info_(info) {} ~NapiArg()30 ~NapiArg() {} 31 32 bool Init(size_t minArgc, size_t maxArgc); 33 34 size_t GetArgc() const; 35 36 size_t GetMaxArgc() const; 37 38 napi_value GetArgv(size_t pos) const; 39 40 napi_value operator[](size_t pos) const; 41 42 private: 43 napi_env env_ = nullptr; 44 napi_callback_info info_ = nullptr; 45 size_t argc_ = 0; 46 size_t maxArgc_ = 0; 47 std::unique_ptr<napi_value[]> argv_ = { nullptr }; 48 napi_value thisArg_ = nullptr; 49 }; 50 } 51 } 52 #endif