#include <GlobalContextManager.h>
#include <PlatformException.h>
#include <JSWebAPIError.h>
+#include <JSWebAPIException.h>
#include <JSUtil.h>
#include <ArgumentValidator.h>
// ====
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;
}
}
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;
}
if (msg->getMessageType() != EMAIL)
{
LoggerD("not EMAIL type return empty string");
- return converter->toJSValueRef("");
+ return JSValueMakeNull(context);
}
IEmailPtr email = MessageFactory::convertToEmail(msg);
if (convId == msgId)
{
LoggerD("Not forwared and replied, return empty string");
- return converter->toJSValueRef("");
+ return JSValueMakeNull(context);
}
return converter->toJSValueRef(converter->convertIntToString(convId));