merge wrt-plugins-tizen_0.2.0-12
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Contact / JSContactPhoneNumber.cpp
index b17f12b..f0c6ca2 100755 (executable)
@@ -172,14 +172,17 @@ JSObjectRef JSContactPhoneNumber::constructor(JSContextRef context,
 
        BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
        Try {
-               if (argumentCount != 2)
+               if (argumentCount < 1 || argumentCount > 2)
                        ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
 
                if (!JSValueIsString(gContext, arguments[0]))
                        ThrowMsg(InvalidArgumentException, "1st argument is not string.");
 
-               if (!JSIsArrayValue(gContext, arguments[1]))
-                       ThrowMsg(InvalidArgumentException, "2nd argument is not array.");
+               if (argumentCount >= 2)
+               {
+                       if (!JSIsArrayValue(gContext, arguments[1]) && !JSValueIsNull(gContext, arguments[1]))
+                               ThrowMsg(InvalidArgumentException, "2nd argument is not array.");
+               }
 
        } Catch(Exception ) {
                LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
@@ -190,7 +193,7 @@ JSObjectRef JSContactPhoneNumber::constructor(JSContextRef context,
        ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
 
        std::string number;
-       ContactPhoneNumberTypeArrayPtr types;
+       ContactPhoneNumberTypeArrayPtr types(NULL);
 
        Try {
                number = converter->toString(arguments[0]);
@@ -201,9 +204,16 @@ JSObjectRef JSContactPhoneNumber::constructor(JSContextRef context,
        }
 
        Try {
-               types = converter->toContactPhoneNumberTypeArray(arguments[1]);
-               if(types->size() == 0)
+               if(argumentCount >= 2)
+               {
+                       if(JSIsArrayValue(gContext, arguments[1]))
+                               types = converter->toContactPhoneNumberTypeArray(arguments[1]);
+               }
+               if(types == NULL)
+               {
+                       types = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
                        types->push_back(CONTACT_PHONE_NUMBER_TYPE_VOICE);
+               }
        } Catch(Exception) {
                LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
                *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");