upload tizen1.0 source
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Contact / JSContactAddress.cpp
index 7108335..24870c1 100755 (executable)
@@ -25,7 +25,6 @@
 #include <CommonsJavaScript/Validator.h>
 #include <Tizen/Common/JSTizenExceptionFactory.h>
 #include <Tizen/Common/JSTizenException.h>
-//#include <Tizen/Common/JSGlobalContextFactory.h>
 #include "ContactConverter.h"
 #include "JSContactAddress.h"
 #include "JSContactAddressTypeArray.h"
@@ -168,7 +167,9 @@ JSObjectRef JSContactAddress::constructor(JSContextRef context,
 {
        LogDebug("entered");
 
-//     AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD);
+       bool js1stParamIsObject = false;
+
+//     AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADD);
 //     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
        JSContactAddressPriv *priv = static_cast<JSContactAddressPriv*>(JSObjectGetPrivate(constructor));
@@ -177,35 +178,38 @@ JSObjectRef JSContactAddress::constructor(JSContextRef context,
        }
        JSContextRef gContext = priv->getContext();
 
-//     JSContextRef gContext = JSGlobalContextFactory::getInstance()->get();
-
        BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
        Try {
-               if (argumentCount > 1)
-                       ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
-
-               if (argumentCount == 1)
+               if (argumentCount >= 1)
                {
-                       if (!JSValueIsObject(gContext, arguments[0]) && !JSValueIsNull(gContext, arguments[0]))
-                               ThrowMsg(InvalidArgumentException, "1st argument is not object.");
+                       if (JSValueIsObject(gContext, arguments[0]))
+                               js1stParamIsObject = true;
+
+                       if (!js1stParamIsObject &&
+                                       !JSValueIsNull(gContext, arguments[0]) &&
+                                       !JSValueIsUndefined(gContext, arguments[0]))
+                               ThrowMsg(InvalidArgumentException, "1st argument must be a 'ContactAddressInit object'");
                }
 
        } Catch(Exception ) {
                LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'ContactAddressInit object'");
                return NULL;
        }
 
        ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
 
-       ContactAddressPtr contactEmailAddress(new ContactAddress());
+       ContactAddressPtr contactEmailAddress(NULL);
 
        Try {
-               if(argumentCount == 1 && !JSValueIsNull(gContext, arguments[0]))
+               if(js1stParamIsObject)
                        contactEmailAddress = converter->toContactAddressFromInit(arguments[0]);
+               else
+                       contactEmailAddress = ContactAddressPtr(new ContactAddress());
+
        } Catch(Exception) {
                LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'ContactAddressInit object'");
                return NULL;
        }
 
@@ -215,7 +219,7 @@ JSObjectRef JSContactAddress::constructor(JSContextRef context,
                jsobject = createJSObject(gContext, contactEmailAddress);
        } Catch(Exception) {
                LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
-               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
                return NULL;
        }