#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"
{
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));
}
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;
}
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;
}