• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "napi_accessibility_event_info.h"
17 #include "hilog_wrapper.h"
18 #include "napi_accessibility_utils.h"
19 
20 using namespace OHOS;
21 using namespace OHOS::Accessibility;
22 
DefineJSAccessibilityEventInfo(napi_env env,napi_value exports)23 void NAccessibilityEventInfo::DefineJSAccessibilityEventInfo(napi_env env, napi_value exports)
24 {
25     napi_value constructor = nullptr;
26 
27     NAPI_CALL_RETURN_VOID(env, napi_define_class(env, "EventInfo", sizeof("EventInfo"),
28         NAccessibilityEventInfo::JSConstructor, nullptr, 0, nullptr, &constructor));
29 
30     NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, exports, "EventInfo", constructor));
31 }
32 
JSConstructor(napi_env env,napi_callback_info info)33 napi_value NAccessibilityEventInfo::JSConstructor(napi_env env, napi_callback_info info)
34 {
35     size_t argc = ARGS_SIZE_ONE;
36     napi_value argv[ARGS_SIZE_ONE] = {nullptr};
37     napi_valuetype valueType;
38     NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
39     if (argc != ARGS_SIZE_ONE) {
40         HILOG_ERROR("argc %{public}zu is not 1", argc);
41         return nullptr;
42     }
43     NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valueType));
44     if (valueType != napi_object) {
45         HILOG_ERROR("valueType %{public}d is not napi_object", valueType);
46         return nullptr;
47     }
48     return argv[PARAM0];
49 }
50