Update change log and spec for wrt-plugins-tizen_0.4.25-1
[platform/framework/web/wrt-plugins-tizen.git] / src / Messaging / JSMessage.cpp
index e12ae06..7ffde2f 100644 (file)
@@ -37,6 +37,7 @@
 #include <GlobalContextManager.h>
 #include <PlatformException.h>
 #include <JSWebAPIError.h>
+#include <JSWebAPIException.h>
 #include <JSUtil.h>
 #include <ArgumentValidator.h>
 // ====
@@ -323,18 +324,69 @@ bool JSMessage::setProperty(JSContextRef context,
     LoggerI("Main setProperty()");
     int index = 0;
     // for non-NULL property names
-    while(m_property[index].name != NULL) {
-        // if property name matches
-        if(JSStringIsEqualToUTF8CString(propertyName,m_property[index].name)) {
-            if(m_property[index].setProperty != NULL) {
-                // if setProperty() function exists - call it
-                return m_property[index].setProperty(context, object, propertyName, value, exception);
-            } else {
-                // otherwise return true (lack of function - readonly attribute)
-                return true;
+    try{
+        while(m_property[index].name != NULL) {
+            // if property name matches
+            if(JSStringIsEqualToUTF8CString(propertyName,m_property[index].name)) {
+                if(m_property[index].setProperty != NULL) {
+                    if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_TO)){
+                        if (JSValueIsNull(context, value))
+                        {
+                            throw TypeMismatchException("Value is null");
+                        }
+                        JSUtil::JSArrayToStringVector(context, value);
+                    }
+                    if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_CC)){
+                        if (JSValueIsNull(context, value))
+                        {
+                            throw TypeMismatchException("Value is null");
+                        }
+                        JSUtil::JSArrayToStringVector(context, value);
+                    }
+                    if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_BCC)){
+                        if (JSValueIsNull(context, value))
+                        {
+                            throw TypeMismatchException("Value is null");
+                        }
+                        JSUtil::JSArrayToStringVector(context, value);
+                    }
+                    if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_BODY)){
+                        if (!JSValueIsNull(context, value)) {
+                            if (!JSValueIsObject(context, value)) {
+                                throw TypeMismatchException("Value is not Object");
+                            }
+                            JSUtil::JSValueToObject(context, value);
+                        }
+                    }
+                    if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_IS_READ)){
+                        JSUtil::JSValueToBoolean(context, value);
+                    }
+                    if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY)){
+                        JSUtil::JSValueToBoolean(context, value);
+                    }
+                    if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_SUBJECT)){
+                        JSUtil::JSValueToString(context, value);
+                    }
+                    if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_ATTACHMENTS)){
+                        if (!JSValueIsNull(context, value)) {
+                            if (!JSValueIsObject(context, value)) {
+                                throw TypeMismatchException("Value is not Object");
+                            }
+                            JSUtil::JSValueToObject(context, value);
+                        }
+                    }
+                    // if setProperty() function exists - call it
+                    return m_property[index].setProperty(context, object, propertyName, value, exception);
+                } else {
+                    // otherwise return true (lack of function - readonly attribute)
+                    return true;
+                }
             }
+            index++;
         }
-        index++;
+    } catch (const BasePlatformException &err) {
+       LoggerW(err.getName() << ": " << err.getMessage());
+       return true;
     }
     return false;
 }
@@ -522,15 +574,15 @@ JSObjectRef JSMessage::constructor(JSContextRef context,
     }
     catch(BasePlatformException &bex) {
         LoggerE("Message creation failed: " << bex.getMessage());
-        JSObjectRef error = JSWebAPIError::makeJSWebAPIError(context, bex);
+        JSObjectRef error = JSWebAPIException::makeJSWebAPIException(context, bex);
         *exception = error;
-        return NULL;
+        return error;
     }
     catch(...) {
         DeviceAPI::Common::UnknownException err("UnknownError in Message constructor.");
-        JSObjectRef error = JSWebAPIError::makeJSWebAPIError(context, err);
+        JSObjectRef error = JSWebAPIException::makeJSWebAPIException(context, err);
         *exception = error;
-        return NULL;
+        return error;
     }
     return NULL;
 }
@@ -1732,7 +1784,7 @@ JSValueRef JSMessage::getInResponseTo(JSContextRef context,
                if (msg->getMessageType() != EMAIL)
                {
                        LoggerD("not EMAIL type return empty string");
-                       return converter->toJSValueRef("");
+                       return JSValueMakeNull(context);
                }
 
                IEmailPtr email = MessageFactory::convertToEmail(msg);
@@ -1744,7 +1796,7 @@ JSValueRef JSMessage::getInResponseTo(JSContextRef context,
                if (convId == msgId)
                {
                        LoggerD("Not forwared and replied, return empty string");
-                       return converter->toJSValueRef("");
+                       return JSValueMakeNull(context);
                }
 
                return converter->toJSValueRef(converter->convertIntToString(convId));