2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include "ApplicationUtil.h"
19 #include <dpl/assert.h>
22 namespace Application {
24 using namespace WrtDeviceApis::CommonsJavaScript;
26 ApplicationUtil::ApplicationUtil(JSContextRef context,
27 JSValueRef* exception) :
29 m_exception(exception)
31 Assert(NULL != m_context && "Context cannot be NULL.");
34 ApplicationUtil::~ApplicationUtil()
38 bool ApplicationUtil::isObject(const JSValueRef& arg)
40 return !JSValueIsNull(m_context, arg) &&
41 !JSValueIsUndefined(m_context, arg) &&
42 JSValueIsObject(m_context, arg);
45 bool ApplicationUtil::isString(const JSValueRef& arg)
47 return !JSValueIsNull(m_context, arg) &&
48 !JSValueIsUndefined(m_context, arg) &&
49 JSValueIsString(m_context, arg);
52 bool ApplicationUtil::isFunction(const JSValueRef& arg)
54 Converter converter(m_context);
55 return !JSValueIsNull(m_context, arg) &&
56 !JSValueIsUndefined(m_context, arg) &&
57 JSObjectIsFunction(m_context, converter.toJSObjectRef(arg));
60 bool ApplicationUtil::isArray(const JSValueRef& arg)
62 Converter converter(m_context);
63 return !JSValueIsNull(m_context, arg) &&
64 !JSValueIsUndefined(m_context, arg) &&
65 JSIsArrayValue(m_context, arg);
68 bool ApplicationUtil::isNullOrString(const JSValueRef& arg)
70 return !JSValueIsUndefined(m_context, arg) &&
71 (JSValueIsNull(m_context, arg) ||
72 JSValueIsString(m_context, arg));
75 bool ApplicationUtil::isNullOrObject(const JSValueRef& arg)
77 return !JSValueIsUndefined(m_context, arg) &&
78 (JSValueIsNull(m_context, arg) ||
79 JSValueIsObject(m_context, arg));
82 bool ApplicationUtil::isNullOrFunction(const JSValueRef& arg)
84 Converter converter(m_context);
85 return !JSValueIsUndefined(m_context, arg) &&
86 (JSValueIsNull(m_context, arg) ||
87 JSObjectIsFunction(m_context, converter.toJSObjectRef(arg)));
90 bool ApplicationUtil::isNullOrArray(const JSValueRef& arg)
92 Converter converter(m_context);
93 return !JSValueIsUndefined(m_context, arg) &&
94 (JSValueIsNull(m_context, arg) ||
95 JSIsArrayValue(m_context, arg));
98 bool ApplicationUtil::isNullOrUndefined(const JSValueRef& arg)
100 return (JSValueIsNull(m_context, arg) ||
101 JSValueIsUndefined(m_context, arg));
104 bool ApplicationUtil::isNullOrUndefinedOrString(const JSValueRef& arg)
106 return (JSValueIsNull(m_context, arg) ||
107 JSValueIsUndefined(m_context, arg) ||
108 JSValueIsString(m_context, arg));
111 bool ApplicationUtil::isNullOrUndefinedOrObject(const JSValueRef& arg)
113 return (JSValueIsNull(m_context, arg) ||
114 JSValueIsUndefined(m_context, arg) ||
115 JSValueIsObject(m_context, arg));
118 bool ApplicationUtil::isNullOrUndefinedOrFunction(const JSValueRef& arg)
120 Converter converter(m_context);
121 return (JSValueIsNull(m_context, arg) ||
122 JSValueIsUndefined(m_context, arg) ||
123 JSObjectIsFunction(m_context, converter.toJSObjectRef(arg)));
126 bool ApplicationUtil::isNullOrUndefinedOrArray(const JSValueRef& arg)
128 Converter converter(m_context);
129 return (JSValueIsNull(m_context, arg) ||
130 JSValueIsUndefined(m_context, arg) ||
131 JSIsArrayValue(m_context, arg));