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 "JSWebAPIException.h"
22 #include "JSWebAPIError.h"
28 #define CLASS_NAME "WebAPIException"
30 JSClassRef JSWebAPIException::m_classRef = NULL;
32 JSClassDefinition JSWebAPIException::m_classInfo =
35 kJSClassAttributeNone,
37 JSWebAPIError::getClassRef(),
45 NULL, // deleteProperty,
46 NULL, // getPropertyNames,
47 NULL, // callAsFunction,
48 NULL, // callAsConstructor,
50 NULL, // convertToType,
53 JSStaticFunction JSWebAPIException::m_function[] =
55 { "toString", toString, kJSPropertyAttributeNone },
59 JSStaticValue JSWebAPIException::m_properties[] = {
63 const JSClassDefinition* JSWebAPIException::getClassInfo()
68 JSClassRef JSWebAPIException::getClassRef()
72 m_classRef = JSClassCreate(&m_classInfo);
77 bool JSWebAPIException::isObjectOfClass(JSContextRef context, JSValueRef value)
79 return JSValueIsObjectOfClass(context, value, getClassRef());
82 JSObjectRef JSWebAPIException::createJSObject(JSContextRef context, WebAPIError* webapiError)
84 JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(webapiError));
85 if (NULL == jsObjectRef) {
86 LoggerE("object creation error");
92 WebAPIError* JSWebAPIException::getPriv(JSContextRef context, JSObjectRef object)
94 if(!JSValueIsObjectOfClass(context, object, getClassRef()))
97 return static_cast<WebAPIError*>(JSObjectGetPrivate(object));
100 void JSWebAPIException::initialize(JSContextRef /*context*/, JSObjectRef /*object*/)
104 void JSWebAPIException::finalize(JSObjectRef /*object*/)
108 JSValueRef JSWebAPIException::toString(JSContextRef context,
110 JSObjectRef thisObject,
111 size_t argumentCount,
112 const JSValueRef arguments[],
113 JSValueRef* exception)
115 WebAPIError* webapiErrObj = getPriv(context, thisObject);
118 LoggerE("Private object is not set.");
122 std::string name = webapiErrObj->getName();
123 std::string message = webapiErrObj->getMessage();
125 std::string result = name + ": " + message;
127 return JSUtil::toJSValueRef(context, result);
130 bool JSWebAPIException::hasInstance(JSContextRef context,
131 JSObjectRef /*constructor*/,
132 JSValueRef possibleInstance,
133 JSValueRef* /*exception*/)
135 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());