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 "JSTizenException.h"
20 #include <dpl/log/log.h>
22 #include <CommonsJavaScript/Converter.h>
27 const std::string JSTizenException::UNKNOWN_ERROR = "UnknownError";
28 const std::string JSTizenException::TYPE_MISMATCH_ERROR = "TypeMismatchError";
29 const std::string JSTizenException::INVALID_VALUES_ERROR = "InvalidValuesError";
30 const std::string JSTizenException::TIMEOUT_ERROR = "TimeoutError";
31 const std::string JSTizenException::IO_ERROR = "IOError";
32 const std::string JSTizenException::NOT_SUPPORTED_ERROR = "NotSupportedError";
33 const std::string JSTizenException::PERMISSION_DENIED_ERROR = "SecurityError";
34 const std::string JSTizenException::NOT_FOUND_ERROR = "NotFoundError";
35 const std::string JSTizenException::SERVICE_NOT_AVAILABLE = "ServiceNotAvailableError";
36 const std::string JSTizenException::NETWORK_ERROR = "NetworkError";
37 const std::string JSTizenException::INVALID_ACCESS_ERROR = "InvalidAccessError";
40 #define PLUGIN_NAME "TizenException"
41 #define PROPERTY_NAME "name"
42 #define PROPERTY_MESSAGE "message"
44 const std::string PROPERTY_ERROR[] = {
45 DeviceAPI::Common::JSTizenException::UNKNOWN_ERROR,
46 DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR,
47 DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR,
48 DeviceAPI::Common::JSTizenException::TIMEOUT_ERROR,
49 DeviceAPI::Common::JSTizenException::IO_ERROR,
50 DeviceAPI::Common::JSTizenException::NOT_SUPPORTED_ERROR,
51 DeviceAPI::Common::JSTizenException::PERMISSION_DENIED_ERROR,
52 DeviceAPI::Common::JSTizenException::NOT_FOUND_ERROR,
53 DeviceAPI::Common::JSTizenException::NETWORK_ERROR,
54 DeviceAPI::Common::JSTizenException::INVALID_ACCESS_ERROR,
58 JSClassRef JSTizenException::m_classRef = NULL;
60 JSClassDefinition JSTizenException::m_classInfo = {
62 kJSClassAttributeNone,
72 NULL, //DeleteProperty,
74 NULL, //CallAsFunction,
75 NULL, //CallAsConstructor,
77 NULL, //ConvertToType,
80 JSStaticValue JSTizenException::m_properties[] = {
81 { PROPERTY_NAME, getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
82 { PROPERTY_MESSAGE, getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
86 const JSClassDefinition* JSTizenException::getClassInfo() {
90 JSClassRef JSTizenException::getClassRef() {
92 m_classRef = JSClassCreate(&m_classInfo);
97 void JSTizenException::initialize(JSContextRef /*context*/, JSObjectRef /*object*/) {
100 void JSTizenException::finalize(JSObjectRef object) {
101 PrivateObject* privateObject = static_cast<PrivateObject*> (JSObjectGetPrivate(object));
103 JSObjectSetPrivate(object, NULL);
104 delete privateObject;
108 bool JSTizenException::hasProperty(JSContextRef /*context*/, JSObjectRef /*object*/, JSStringRef propertyName) {
109 const size_t size = sizeof(PROPERTY_ERROR) / sizeof(PROPERTY_ERROR[0]);
110 for (size_t i = 0; i < size; ++i) {
111 if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_ERROR[i].c_str())) {
118 JSValueRef JSTizenException::getStaticProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* /*exception*/) {
119 PrivateObject* privateObject = static_cast<PrivateObject*> (JSObjectGetPrivate(object));
120 if (!privateObject) {
121 LogError("Private object is not set.");
122 return JSValueMakeUndefined(context);
125 // WrtDeviceApis::CommonsJavaScript::Converter converter(context);
127 // if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NAME)) {
128 // return converter.toJSValueRef(privateObject->getObject()->getName());
129 // } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_MESSAGE)) {
130 // return converter.toJSValueRef(privateObject->getObject()->getMessage());
132 // } catch (const WrtDeviceApis::Commons::ConversionException& ex) {
133 // LogError("Exception: " << ex.GetMessage());
136 return JSValueMakeUndefined(context);
139 bool JSTizenException::hasInstance(JSContextRef context, JSObjectRef /*constructor*/, JSValueRef possibleInstance, JSValueRef* /*exception*/) {
140 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());