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"
19 #include <CommonsJavaScript/Converter.h>
25 const std::string JSTizenException::UNKNOWN_ERROR = "UnknownError";
26 const std::string JSTizenException::TYPE_MISMATCH_ERROR = "TypeMismatchError";
27 const std::string JSTizenException::INVALID_VALUES_ERROR = "InvalidValuesError";
28 const std::string JSTizenException::TIMEOUT_ERROR = "TimeoutError";
29 const std::string JSTizenException::IO_ERROR = "IOError";
30 const std::string JSTizenException::NOT_SUPPORTED_ERROR = "NotSupportedError";
31 const std::string JSTizenException::PERMISSION_DENIED_ERROR = "SecurityError";
32 const std::string JSTizenException::NOT_FOUND_ERROR = "NotFoundError";
33 const std::string JSTizenException::SERVICE_NOT_AVAILABLE = "ServiceNotAvailableError";
34 const std::string JSTizenException::NETWORK_ERROR = "NetworkError";
35 const std::string JSTizenException::INVALID_ACCESS_ERROR = "InvalidAccessError";
38 #define PLUGIN_NAME "TizenException"
39 #define PROPERTY_NAME "name"
40 #define PROPERTY_MESSAGE "message"
42 const std::string PROPERTY_ERROR[] = {
43 DeviceAPI::Common::JSTizenException::UNKNOWN_ERROR,
44 DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR,
45 DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR,
46 DeviceAPI::Common::JSTizenException::TIMEOUT_ERROR,
47 DeviceAPI::Common::JSTizenException::IO_ERROR,
48 DeviceAPI::Common::JSTizenException::NOT_SUPPORTED_ERROR,
49 DeviceAPI::Common::JSTizenException::PERMISSION_DENIED_ERROR,
50 DeviceAPI::Common::JSTizenException::NOT_FOUND_ERROR,
51 DeviceAPI::Common::JSTizenException::NETWORK_ERROR,
52 DeviceAPI::Common::JSTizenException::INVALID_ACCESS_ERROR,
56 JSClassRef JSTizenException::m_classRef = NULL;
58 JSClassDefinition JSTizenException::m_classInfo = {
60 kJSClassAttributeNone,
70 NULL, //DeleteProperty,
72 NULL, //CallAsFunction,
73 NULL, //CallAsConstructor,
75 NULL, //ConvertToType,
78 JSStaticValue JSTizenException::m_properties[] = {
79 { PROPERTY_NAME, getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
80 { PROPERTY_MESSAGE, getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
84 const JSClassDefinition* JSTizenException::getClassInfo() {
88 JSClassRef JSTizenException::getClassRef() {
90 m_classRef = JSClassCreate(&m_classInfo);
95 void JSTizenException::initialize(JSContextRef /*context*/, JSObjectRef /*object*/) {
98 void JSTizenException::finalize(JSObjectRef object) {
99 PrivateObject* privateObject = static_cast<PrivateObject*> (JSObjectGetPrivate(object));
101 JSObjectSetPrivate(object, NULL);
102 delete privateObject;
106 bool JSTizenException::hasProperty(JSContextRef /*context*/, JSObjectRef /*object*/, JSStringRef propertyName) {
107 const size_t size = sizeof(PROPERTY_ERROR) / sizeof(PROPERTY_ERROR[0]);
108 for (size_t i = 0; i < size; ++i) {
109 if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_ERROR[i].c_str())) {
116 JSValueRef JSTizenException::getStaticProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* /*exception*/) {
117 PrivateObject* privateObject = static_cast<PrivateObject*> (JSObjectGetPrivate(object));
118 if (!privateObject) {
119 LoggerE("Private object is not set.");
120 return JSValueMakeUndefined(context);
123 // WrtDeviceApis::CommonsJavaScript::Converter converter(context);
125 // if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NAME)) {
126 // return converter.toJSValueRef(privateObject->getObject()->getName());
127 // } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_MESSAGE)) {
128 // return converter.toJSValueRef(privateObject->getObject()->getMessage());
130 // } catch (const WrtDeviceApis::Commons::ConversionException& ex) {
131 // LoggerE("Exception: " << ex.GetMessage());
134 return JSValueMakeUndefined(context);
137 bool JSTizenException::hasInstance(JSContextRef context, JSObjectRef /*constructor*/, JSValueRef possibleInstance, JSValueRef* /*exception*/) {
138 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());