#include <CommonsJavaScript/Validator.h>
#include <Tizen/Common/JSTizenExceptionFactory.h>
#include <Tizen/Common/JSTizenException.h>
-//#include <Tizen/Common/JSGlobalContextFactory.h>
#include "ContactConverter.h"
#include "JSContactAnniversary.h"
{
LogDebug("entered");
-// AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD);
+ bool js2ndParamIsString = false;
+
+// AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADD);
// TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
JSContactAnniversaryPriv *priv = static_cast<JSContactAnniversaryPriv*>(JSObjectGetPrivate(constructor));
}
JSContextRef gContext = priv->getContext();
-// JSContextRef gContext = JSGlobalContextFactory::getInstance()->get();
-
BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
Try {
- if (argumentCount < 1 || argumentCount > 2)
- ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
+ if (argumentCount < 1)
+ ThrowMsg(InvalidArgumentException, "1st argument must be a 'Date object'");
if (!JSValueIsObject(gContext, arguments[0]))
- ThrowMsg(InvalidArgumentException, "1st argument is not object.");
+ ThrowMsg(InvalidArgumentException, "1st argument must be a 'Date object'");
if (argumentCount >= 2)
{
- if (!JSValueIsString(gContext, arguments[1]) && !JSValueIsNull(gContext, arguments[1]))
- ThrowMsg(InvalidArgumentException, "2nd argument is not string.");
+ if (!JSValueIsUndefined(context, arguments[1]) && !JSValueIsNull(context, arguments[1]))
+ js2ndParamIsString = true;
}
} 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 'Date object'");
return NULL;
}
std::tm date;
std::string label;
- bool labelIsSet = false;
Try {
date = converter->toDateTm(arguments[0]);
} 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 'Date object'");
return NULL;
}
Try {
- if(argumentCount >= 2)
- {
- if(!JSValueIsNull(gContext, arguments[1]))
- {
- label = converter->toString(arguments[1]);
- labelIsSet = true;
- }
- }
+ if (js2ndParamIsString)
+ label = converter->toString(arguments[1]);
+
} Catch(Exception) {
LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
*exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
contactAnniversary->setDate(date);
// NOTE: Currently not support label field
- //if(labelIsSet)
+ //if(js2ndParamIsString)
// contactAnniversary->setLabel(label);
JSObjectRef jsobject;
{
Try
{
- // NOTE: Currently not support this field
- //ContactAnniversaryPtr anniversary = getPrivData(object);
- //ContactConverterFactory::ConverterType converter =
- // ContactConverterFactory::getConverter(context);
- //anniversary->setLabel(converter->toString(value));
+ ContactAnniversaryPtr anniversary = getPrivData(object);
+ ContactConverterFactory::ConverterType converter =
+ ContactConverterFactory::getConverter(context);
+ BasicValidator validator =
+ BasicValidatorFactory::getValidator(context, exception);
+ if(validator->isNullOrUndefined(value))
+ anniversary->unsetLabel();
+ else
+ anniversary->setLabel(converter->toString(value));
return true;
}
Catch(WrtDeviceApis::Commons::Exception)