1 /*
2 * Copyright (c) 2023 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 #ifndef OHOS_ABILITY_RUNTIME_JS_API_UTILS_H
17 #define OHOS_ABILITY_RUNTIME_JS_API_UTILS_H
18
19 #include "want.h"
20 #include "js_runtime.h"
21 #include "js_runtime_utils.h"
22
23 namespace OHOS {
24 namespace AbilityRuntime {
25 namespace JsApiUtils {
26 bool UnWrapAbilityResult(NativeEngine &engine, NativeValue* argv, int &resultCode, AAFwk::Want &want);
27 bool UnWrapWant(NativeEngine &engine, NativeValue* param, AAFwk::Want &want);
28 bool UnwrapWantParams(NativeEngine &engine, NativeValue* param, AAFwk::WantParams &wantParams);
29
30 template<typename numtype>
UnwrapNumberValue(NativeValue * param,numtype & value)31 bool UnwrapNumberValue(NativeValue* param, numtype &value)
32 {
33 if (param == nullptr) {
34 return false;
35 }
36 if (param->TypeOf() != NativeValueType::NATIVE_NUMBER) {
37 return false;
38 }
39 value = *ConvertNativeValueTo<NativeNumber>(param);
40 return true;
41 }
42
43
44 bool UnwrapStringValue(NativeValue* param, std::string &value);
45 bool UnwrapArrayStringValue(NativeValue* param, std::vector<std::string> &value);
46 bool IsNarmalObject(NativeValue* value);
47 }
48 } // namespace AbilityRuntime
49 } // namespace OHOS
50
51 #endif // OHOS_ABILITY_RUNTIME_JS_API_UTILS_H