• 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 "common_func.h"
17 
18 #include "../common/napi/n_func_arg.h"
19 
20 namespace OHOS {
21 namespace DistributedFS {
22 namespace ModuleFile {
23 using namespace std;
24 
GetCallbackHandles(napi_env env,napi_value object)25 tuple<bool, napi_ref, napi_ref, napi_ref> CommonFunc::GetCallbackHandles(napi_env env, napi_value object)
26 {
27     bool succ = false;
28     NVal prop = NVal(env, object);
29     napi_value successProp, failProp, completeProp;
30     napi_ref successHandle = nullptr;
31     napi_ref failHandle = nullptr;
32     napi_ref completeHandle = nullptr;
33     string success = "success";
34     string fail = "fail";
35     string complete = "complete";
36 
37     successProp = prop.GetProp(success).val_;
38     if (successProp != nullptr) {
39         napi_create_reference(env, successProp, 1, &successHandle);
40         succ = true;
41     }
42 
43     failProp = prop.GetProp(fail).val_;
44     if (succ && failProp != nullptr) {
45         napi_create_reference(env, failProp, 1, &failHandle);
46         succ = true;
47     }
48 
49     completeProp = prop.GetProp(complete).val_;
50     if (succ && completeProp != nullptr) {
51         napi_create_reference(env, completeProp, 1, &completeHandle);
52         succ = true;
53     }
54 
55     return { succ, successHandle, failHandle, completeHandle };
56 }
57 } // namespace ModuleFile
58 } // namespace DistributedFS
59 } // namespace OHOS
60