2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dpl/shared_ptr.h>
21 #include <CommonsJavaScript/Validator.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <CommonsJavaScript/JSCallbackManager.h>
24 #include <CommonsJavaScript/Utils.h>
25 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
27 #include "JSCallApi.h"
28 #include "JSCallHistory.h"
29 #include "Converter.h"
33 using namespace WrtDeviceApis;
34 using namespace WrtDeviceApis::Commons;
35 using namespace WrtDeviceApis::CommonsJavaScript;
40 JSClassRef JSCallApi::m_jsClassRef = NULL;
42 JSClassDefinition JSCallApi::m_classInfo =
45 kJSClassAttributeNone,
63 JSStaticValue JSCallApi::m_property[] = {
64 { "history", getProperty, NULL, kJSPropertyAttributeReadOnly },
68 const JSClassRef JSCallApi::getClassRef() {
70 m_jsClassRef = JSClassCreate(&m_classInfo);
75 const JSClassDefinition* JSCallApi::getClassInfo(){
79 void JSCallApi::initialize(JSContextRef context, JSObjectRef object) {
80 JSCallApiPriv *priv = static_cast<JSCallApiPriv*>(JSObjectGetPrivate(object));
83 priv = new JSCallApiPriv(context);
85 if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
86 LogError("Object can't store private data.");
92 void JSCallApi::finalize(JSObjectRef object) {
93 JSCallApiPriv* priv = static_cast<JSCallApiPriv*>(JSObjectGetPrivate(object));
96 JSObjectSetPrivate(object, NULL);
101 JSValueRef JSCallApi::getProperty(JSContextRef context,
103 JSStringRef propertyName,
104 JSValueRef* exception)
106 JSCallApiPriv *priv = static_cast<JSCallApiPriv*>(JSObjectGetPrivate(object));
108 return JSValueMakeUndefined(context);
111 JSContextRef globalContext = priv->getContext();
114 Converter convert(context);
115 if(JSStringIsEqualToUTF8CString(propertyName, "history")) {
116 return TizenApis::Tizen1_0::JSCallHistory::createJSObject(globalContext, object);
118 } catch(Commons::Exception) {
119 LogWarning("trying to get incorrect value");
121 return JSValueMakeUndefined(context);
124 bool JSCallApi::hasInstance(JSContextRef context, JSObjectRef constructor,
125 JSValueRef possibleInstance, JSValueRef* exception) {
126 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());