Update change log and spec for wrt-plugins-tizen_0.4.29
[framework/web/wrt-plugins-tizen.git] / src / Messaging / JSMessage.cpp
index 05d9b1d..6454250 100644 (file)
 #include "MessagingListener.h"
 #include "ReqReceiverMessage.h"
 
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
+#include <JSWebAPIErrorFactory.h>
 #include <SecurityExceptions.h>
 
 #include <CommonsJavaScript/ScopedJSStringRef.h>
 // ==== new common headers
 #include <GlobalContextManager.h>
 #include <PlatformException.h>
-#include <JSWebAPIError.h>
-#include <JSWebAPIException.h>
 #include <JSUtil.h>
+#include <Export.h>
 #include <ArgumentValidator.h>
 // ====
 
@@ -122,6 +120,26 @@ JSStaticValue JSMessage::m_property[] = {
     { 0, 0, 0, 0 }
 };
 
+JSClassRef JSMessage::jsInit(JSContextRef context)
+{
+    LoggerI("enter");
+    return JSClassCreate(&m_classInfo);
+}
+
+const JSClassDefinition* JSMessage::getClassInfo()
+{
+    LoggerI("enter");
+    return &(m_classInfo);
+}
+
+JSClassRef DLL_EXPORT JSMessage::getClassRef()
+{
+    LoggerI("enter");
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
 
 JSValueRef JSMessage::createJSObject(JSContextRef context,
                EmailAccountInfo& account,
@@ -186,11 +204,9 @@ JSValueRef JSMessage::createJSObject(JSContextRef context,
         const IMessagePtr& msg,
         EventUpdateMessageAnswerReceiver* listener)
 {
-       JSClassRef jsClassRef = JSClassCreate(getClassInfo());
        JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
        priv->setUpdateMsgReceiver(listener);
-       JSObjectRef jsValueRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
-       JSClassRelease(jsClassRef);
+       JSObjectRef jsValueRef = JSObjectMake(context, JSMessage::getClassRef(), static_cast<void*>(priv));
        if (NULL == jsValueRef) {
                LoggerE("object creation error");
                return JSValueMakeUndefined(context);
@@ -202,14 +218,11 @@ JSValueRef JSMessage::createJSObject(JSContextRef context,
         const IMessagePtr& msg)
 {
        LoggerD("createJSObject");
-       JSClassRef jsClassRef = JSClassCreate(getClassInfo());
-       LoggerD("jsClassRef success");
        JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
        LoggerD("priv success");
 
-       JSObjectRef jsValueRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
+       JSObjectRef jsValueRef = JSObjectMake(context, JSMessage::getClassRef(), static_cast<void*>(priv));
        LoggerD("JSObjectMake success");
-       JSClassRelease(jsClassRef);
        if (NULL == jsValueRef) {
                LoggerE("object creation error");
                return JSValueMakeUndefined(context);
@@ -438,7 +451,7 @@ bool JSMessage::hasInstance(JSContextRef context,
        return true;
 }
 
-JSObjectRef JSMessage::constructor(JSContextRef context,
+JSObjectRef DLL_EXPORT JSMessage::constructor(JSContextRef context,
         JSObjectRef constructor,
         size_t argumentCount,
         const JSValueRef arguments[],
@@ -571,17 +584,15 @@ JSObjectRef JSMessage::constructor(JSContextRef context,
     }
     catch(BasePlatformException &bex) {
         LoggerE("Message creation failed: " << bex.getMessage());
-        JSObjectRef error = JSWebAPIException::makeJSWebAPIException(context, bex);
-        *exception = error;
-        return error;
+        return JSWebAPIErrorFactory::postException(context, exception, bex);
     }
     catch(...) {
         DeviceAPI::Common::UnknownException err("UnknownError in Message constructor.");
-        JSObjectRef error = JSWebAPIException::makeJSWebAPIException(context, err);
-        *exception = error;
-        return error;
+        return JSWebAPIErrorFactory::postException(context, exception, err);
     }
-    return NULL;
+
+    return JSWebAPIErrorFactory::postException(context, exception,
+            DeviceAPI::Common::UnknownException("UnknownError in Message constructor."));
 }
 
 JSValueRef JSMessage::convertToType(JSContextRef context,
@@ -1389,14 +1400,14 @@ bool JSMessage::setAttachments(JSContextRef context,
             static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
 
         if (!priv) {
-            return JSTizenExceptionFactory::postException(context, exception,
-                          JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+            return JSWebAPIErrorFactory::postException(context, exception,
+                          JSWebAPIErrorFactory::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
         }
     }
     Catch(WrtDeviceApis::Commons::NullPointerException) {
         LoggerE("Error on pointer, null value");
-          return JSTizenExceptionFactory::postException(context, exception,
-                          JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+          return JSWebAPIErrorFactory::postException(context, exception,
+                          JSWebAPIErrorFactory::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
     }
 
     vector<string> attachments;
@@ -1455,18 +1466,18 @@ bool JSMessage::setAttachments(JSContextRef context,
     }
     Catch(WrtDeviceApis::Commons::ConversionException) {
         LoggerE("Error on conversion");
-         return JSTizenExceptionFactory::postException(context, exception,
-                  JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+         return JSWebAPIErrorFactory::postException(context, exception,
+                  JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
     }
     Catch(WrtDeviceApis::Commons::NullPointerException) {
         LoggerE("Error on pointer, null value");
-         return JSTizenExceptionFactory::postException(context, exception,
-                        JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+         return JSWebAPIErrorFactory::postException(context, exception,
+                        JSWebAPIErrorFactory::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
     }
     Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
         LoggerE("Invalid argument");
-          return JSTizenExceptionFactory::postException(context, exception,
-                          JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+          return JSWebAPIErrorFactory::postException(context, exception,
+                          JSWebAPIErrorFactory::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
     }
     return false;
 }