upload tizen1.0 source
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Application / ApplicationUtil.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "ApplicationUtil.h"
18 #include <dpl/assert.h>
19
20 namespace TizenApis {
21 namespace Tizen1_0 {
22 namespace Application {
23
24 using namespace WrtDeviceApis::CommonsJavaScript;
25
26 ApplicationUtil::ApplicationUtil(JSContextRef context,
27         JSValueRef* exception) :
28     m_context(context),
29     m_exception(exception)
30 {
31     Assert(NULL != m_context && "Context cannot be NULL.");
32 }
33
34 ApplicationUtil::~ApplicationUtil()
35 {
36 }
37
38 bool ApplicationUtil::isObject(const JSValueRef& arg)
39 {
40     return !JSValueIsNull(m_context, arg) &&
41                    !JSValueIsUndefined(m_context, arg) &&
42            JSValueIsObject(m_context, arg);
43 }
44
45 bool ApplicationUtil::isString(const JSValueRef& arg)
46 {
47     return !JSValueIsNull(m_context, arg) &&
48                    !JSValueIsUndefined(m_context, arg) &&
49            JSValueIsString(m_context, arg);
50 }
51
52 bool ApplicationUtil::isFunction(const JSValueRef& arg)
53 {
54         Converter converter(m_context);
55     return !JSValueIsNull(m_context, arg) &&
56                    !JSValueIsUndefined(m_context, arg) &&
57            JSObjectIsFunction(m_context, converter.toJSObjectRef(arg));
58 }
59
60 bool ApplicationUtil::isArray(const JSValueRef& arg)
61 {
62         Converter converter(m_context);
63     return !JSValueIsNull(m_context, arg) &&
64                    !JSValueIsUndefined(m_context, arg) &&
65            JSIsArrayValue(m_context, arg);
66 }
67
68 bool ApplicationUtil::isNullOrString(const JSValueRef& arg)
69 {
70     return !JSValueIsUndefined(m_context, arg) &&
71                    (JSValueIsNull(m_context, arg) ||
72            JSValueIsString(m_context, arg));
73 }
74
75 bool ApplicationUtil::isNullOrObject(const JSValueRef& arg)
76 {
77     return !JSValueIsUndefined(m_context, arg) &&
78                    (JSValueIsNull(m_context, arg) ||
79            JSValueIsObject(m_context, arg));
80 }
81
82 bool ApplicationUtil::isNullOrFunction(const JSValueRef& arg)
83 {
84     Converter converter(m_context);
85     return !JSValueIsUndefined(m_context, arg) && 
86                    (JSValueIsNull(m_context, arg) ||
87            JSObjectIsFunction(m_context, converter.toJSObjectRef(arg)));
88 }
89
90 bool ApplicationUtil::isNullOrArray(const JSValueRef& arg)
91 {
92     Converter converter(m_context);
93     return !JSValueIsUndefined(m_context, arg) && 
94                    (JSValueIsNull(m_context, arg) ||
95            JSIsArrayValue(m_context, arg));
96 }
97
98 bool ApplicationUtil::isNullOrUndefined(const JSValueRef& arg)
99 {
100     return (JSValueIsNull(m_context, arg) ||
101             JSValueIsUndefined(m_context, arg));
102 }
103
104 bool ApplicationUtil::isNullOrUndefinedOrString(const JSValueRef& arg)
105 {
106     return (JSValueIsNull(m_context, arg) ||
107                    JSValueIsUndefined(m_context, arg) ||
108            JSValueIsString(m_context, arg));
109 }
110
111 bool ApplicationUtil::isNullOrUndefinedOrObject(const JSValueRef& arg)
112 {
113     return (JSValueIsNull(m_context, arg) ||
114                    JSValueIsUndefined(m_context, arg) ||
115            JSValueIsObject(m_context, arg));
116 }
117
118 bool ApplicationUtil::isNullOrUndefinedOrFunction(const JSValueRef& arg)
119 {
120     Converter converter(m_context);
121     return (JSValueIsNull(m_context, arg) ||
122                    JSValueIsUndefined(m_context, arg) ||
123            JSObjectIsFunction(m_context, converter.toJSObjectRef(arg)));
124 }
125
126 bool ApplicationUtil::isNullOrUndefinedOrArray(const JSValueRef& arg)
127 {
128     Converter converter(m_context);
129     return (JSValueIsNull(m_context, arg) ||
130                    JSValueIsUndefined(m_context, arg) ||
131            JSIsArrayValue(m_context, arg));
132 }
133
134
135 }
136 } // 
137 } //