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