X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fstandards%2FTizen%2FContact%2FJSContactAddress.cpp;h=24870c1134803cc7483e500ac78a2008710d619e;hb=37fad6a43e6da3aa466886818d0c8a8c952f28f2;hp=710833562cc60f01a1ef4b7ab2428454dadd7936;hpb=65d2bd12c33044282c41ce78c6e1bdbb441d1cff;p=profile%2Fivi%2Fwrt-plugins-tizen.git diff --git a/src/standards/Tizen/Contact/JSContactAddress.cpp b/src/standards/Tizen/Contact/JSContactAddress.cpp index 7108335..24870c1 100755 --- a/src/standards/Tizen/Contact/JSContactAddress.cpp +++ b/src/standards/Tizen/Contact/JSContactAddress.cpp @@ -25,7 +25,6 @@ #include #include #include -//#include #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(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; }