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 
16 #include "js_application_quick_fix_info.h"
17 
18 #include "js_runtime_utils.h"
19 
20 namespace OHOS {
21 namespace AbilityRuntime {
CreateJsApplicationQuickFixInfo(napi_env env,const AAFwk::ApplicationQuickFixInfo & appQuickFixInfo)22 napi_value CreateJsApplicationQuickFixInfo(
23     napi_env env, const AAFwk::ApplicationQuickFixInfo &appQuickFixInfo)
24 {
25     napi_value objValue = nullptr;
26     napi_create_object(env, &objValue);
27     napi_set_named_property(env, objValue, "bundleName", CreateJsValue(env, appQuickFixInfo.bundleName));
28     napi_set_named_property(env, objValue, "bundleVersionCode",
29         CreateJsValue(env, appQuickFixInfo.bundleVersionCode));
30     napi_set_named_property(env, objValue, "bundleVersionName",
31         CreateJsValue(env, appQuickFixInfo.bundleVersionName));
32     napi_set_named_property(env, objValue, "quickFixVersionCode",
33         CreateJsValue(env, appQuickFixInfo.appqfInfo.versionCode));
34     napi_set_named_property(env, objValue, "quickFixVersionName",
35         CreateJsValue(env, appQuickFixInfo.appqfInfo.versionName));
36     napi_set_named_property(env, objValue, "hapModuleQuickFixInfo",
37         CreateJsHapModuleQuickFixInfoArray(env, appQuickFixInfo.appqfInfo.hqfInfos));
38     return objValue;
39 }
40 
CreateJsHapModuleQuickFixInfoArray(napi_env env,const std::vector<AppExecFwk::HqfInfo> & hqfInfos)41 napi_value CreateJsHapModuleQuickFixInfoArray(napi_env env, const std::vector<AppExecFwk::HqfInfo> &hqfInfos)
42 {
43     napi_value arrayValue = nullptr;
44     napi_create_array_with_length(env, hqfInfos.size(), &arrayValue);
45     uint32_t index = 0;
46     for (const auto &hqfInfo : hqfInfos) {
47         napi_value objValue = nullptr;
48         napi_create_object(env, &objValue);
49         napi_set_named_property(env, objValue, "moduleName", CreateJsValue(env, hqfInfo.moduleName));
50         napi_set_named_property(env, objValue, "originHapHash", CreateJsValue(env, hqfInfo.hapSha256));
51         napi_set_named_property(env, objValue, "quickFixFilePath", CreateJsValue(env, hqfInfo.hqfFilePath));
52         napi_set_element(env, arrayValue, index++, objValue);
53     }
54     return arrayValue;
55 }
56 } // namespace AbilityRuntime
57 } // namespace OHOS
58