1 /*
2 * Copyright (c) 2021-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 #include "js_form_error.h"
16
17 #include "hilog_wrapper.h"
18 #include "js_runtime_utils.h"
19 #include "napi_form_util.h"
20
21 namespace OHOS {
22 namespace AbilityRuntime {
CreateJsFormError(NativeEngine & engine)23 NativeValue* CreateJsFormError(NativeEngine &engine)
24 {
25 NativeValue* objValue = engine.CreateObject();
26 NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
27 object->SetProperty("ERR_COMMON", CreateJsValue(engine, ERR_COMMON));
28 object->SetProperty("ERR_PERMISSION_DENY", CreateJsValue(engine, ERR_PERMISSION_DENY));
29 object->SetProperty("ERR_GET_INFO_FAILED", CreateJsValue(engine, ERR_GET_INFO_FAILED));
30 object->SetProperty("ERR_GET_BUNDLE_FAILED", CreateJsValue(engine, ERR_GET_BUNDLE_FAILED));
31 object->SetProperty("ERR_GET_LAYOUT_FAILED", CreateJsValue(engine, ERR_GET_LAYOUT_FAILED));
32 object->SetProperty("ERR_ADD_INVALID_PARAM", CreateJsValue(engine, ERR_ADD_INVALID_PARAM));
33 object->SetProperty("ERR_CFG_NOT_MATCH_ID", CreateJsValue(engine, ERR_CFG_NOT_MATCH_ID));
34 object->SetProperty("ERR_NOT_EXIST_ID", CreateJsValue(engine, ERR_NOT_EXIST_ID));
35 object->SetProperty("ERR_BIND_PROVIDER_FAILED", CreateJsValue(engine, ERR_BIND_PROVIDER_FAILED));
36 object->SetProperty("ERR_MAX_SYSTEM_FORMS", CreateJsValue(engine, ERR_MAX_SYSTEM_FORMS));
37 object->SetProperty("ERR_MAX_INSTANCES_PER_FORM", CreateJsValue(engine, ERR_MAX_INSTANCES_PER_FORM));
38 object->SetProperty("ERR_OPERATION_FORM_NOT_SELF", CreateJsValue(engine, ERR_OPERATION_FORM_NOT_SELF));
39 object->SetProperty("ERR_PROVIDER_DEL_FAIL", CreateJsValue(engine, ERR_PROVIDER_DEL_FAIL));
40 object->SetProperty("ERR_MAX_FORMS_PER_CLIENT", CreateJsValue(engine, ERR_MAX_FORMS_PER_CLIENT));
41 object->SetProperty("ERR_MAX_SYSTEM_TEMP_FORMS", CreateJsValue(engine, ERR_MAX_SYSTEM_TEMP_FORMS));
42 object->SetProperty("ERR_FORM_NO_SUCH_MODULE", CreateJsValue(engine, ERR_FORM_NO_SUCH_MODULE));
43 object->SetProperty("ERR_FORM_NO_SUCH_ABILITY", CreateJsValue(engine, ERR_FORM_NO_SUCH_ABILITY));
44 object->SetProperty("ERR_FORM_NO_SUCH_DIMENSION", CreateJsValue(engine, ERR_FORM_NO_SUCH_DIMENSION));
45 object->SetProperty("ERR_FORM_FA_NOT_INSTALLED", CreateJsValue(engine, ERR_FORM_FA_NOT_INSTALLED));
46 object->SetProperty("ERR_SYSTEM_RESPONSES_FAILED", CreateJsValue(engine, ERR_SYSTEM_RESPONSES_FAILED));
47 object->SetProperty("ERR_FORM_DUPLICATE_ADDED", CreateJsValue(engine, ERR_FORM_DUPLICATE_ADDED));
48 object->SetProperty("ERR_DISTRIBUTED_SCHEDULE_FAILED", CreateJsValue(engine, ERR_DISTRIBUTED_SCHEDULE_FAILED));
49 object->SetProperty("ERR_IN_RECOVERY", CreateJsValue(engine, ERR_IN_RECOVERY));
50 return objValue;
51 }
52
FormErrorInit(NativeEngine * engine,NativeValue * exportObj)53 NativeValue* FormErrorInit(NativeEngine *engine, NativeValue *exportObj)
54 {
55 HILOG_INFO("%{public}s called.", __func__);
56 if (engine == nullptr || exportObj == nullptr) {
57 HILOG_ERROR("%{public}s engine or exportObj nullptr.", __func__);
58 return nullptr;
59 }
60
61 NativeObject* object = ConvertNativeValueTo<NativeObject>(exportObj);
62 if (object == nullptr) {
63 HILOG_ERROR("%{public}s convertNativeValueTo result is nullptr.", __func__);
64 return nullptr;
65 }
66 object->SetProperty("FormError", CreateJsFormError(*engine));
67
68 HILOG_INFO("%{public}s called end.", __func__);
69 return exportObj;
70 }
71 } // namespace AbilityRuntime
72 } // namespace OHOS
73