• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_ability.h"
17 
18 namespace OHOS {
19 namespace JsKit {
GetJSAbility(napi_env env)20 AppExecFwk::Ability *JSAbility::GetJSAbility(napi_env env)
21 {
22     napi_value global = nullptr;
23     napi_value abilityContext = nullptr;
24 
25     napi_status status = napi_get_global(env, &global);
26     if (status != napi_ok || global == nullptr) {
27         return nullptr;
28     }
29 
30     status = napi_get_named_property(env, global, "ability", &abilityContext);
31     if (status != napi_ok || abilityContext == nullptr) {
32         return nullptr;
33     }
34 
35     AppExecFwk::Ability *ability = nullptr;
36     status = napi_get_value_external(env, abilityContext, (void **)&ability);
37     if (status != napi_ok || ability == nullptr) {
38     }
39 
40     return ability;
41 }
42 } // namespace JsKit
43 } // namespace OHOS