Update change log and spec for wrt-plugins-tizen_0.4.11
[framework/web/wrt-plugins-tizen.git] / src / Contact / JSContact.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        JSContact.cpp
20  * @author      Kisub Song (kisubs.song@samsung.com)
21  * @version     0.1
22  * @brief       Implementation of the JSContact class
23  */
24
25 #include <dpl/log/log.h>
26 #include <dpl/shared_ptr.h>
27 #include <CommonsJavaScript/Validator.h>
28 #include <JSTizenExceptionFactory.h>
29 #include <JSTizenException.h>
30 #include <SecurityExceptions.h>
31 #include "ContactFactory.h"
32 #include "plugin_config.h"
33 #include "ContactConverter.h"
34 #include "JSContact.h"
35 #include "Contact.h"
36
37 #define FILTER_CLASS_NAME "Contact"
38
39 #define CONTACT_ATTR_ID             "id"
40 #define CONTACT_ATTR_ADDRESSBOOK_ID "addressBookId"
41 #define CONTACT_ATTR_PERSON_ID      "personId"
42 #define CONTACT_ATTR_LAST_UPDATED   "lastUpdated"
43 #define CONTACT_ATTR_IS_FAVORITE    "isFavorite"
44 #define CONTACT_ATTR_NAME           "name"
45 #define CONTACT_ATTR_ADDRESSES      "addresses"
46 #define CONTACT_ATTR_PHOTO_URI      "photoURI"
47 #define CONTACT_ATTR_PHONE_NUMBERS  "phoneNumbers"
48 #define CONTACT_ATTR_EMAILS         "emails"
49 #define CONTACT_ATTR_BIRTHDAY       "birthday"
50 #define CONTACT_ATTR_ANNIVERSARIES  "anniversaries"
51 #define CONTACT_ATTR_ORGANIZATIONS  "organizations"
52 #define CONTACT_ATTR_NOTES          "notes"
53 #define CONTACT_ATTR_URLS           "urls"
54 #define CONTACT_ATTR_LAST_UPDATED   "lastUpdated"
55 #define CONTACT_ATTR_RINGTONE_URI   "ringtoneURI"
56 #define CONTACT_ATTR_GROUP_IDS      "groupIds"
57 #define CONTACT_FUNC_CONVERT_TO_STRING          "convertToString"
58 #define CONTACT_FUNC_CLONE                                      "clone"
59
60 namespace DeviceAPI {
61 namespace Contact {
62
63 using namespace DeviceAPI::Common;
64 using namespace WrtDeviceApis::Commons;
65 using namespace WrtDeviceApis::CommonsJavaScript;
66
67 JSClassDefinition JSContact::m_classInfo =
68 {
69         0,
70         kJSClassAttributeNone,
71         FILTER_CLASS_NAME,
72         NULL,
73         m_property,
74         m_functions,
75         Initialize,
76         Finalize,
77         NULL, //hasProperty,
78         NULL, //GetProperty,
79         NULL, //SetProperty,
80         NULL, //DeleteProperty,
81         NULL, //getPropertyNames,
82         NULL, //CallAsFunction,
83         constructor, //CallAsConstructor,
84         hasInstance, //HasInstance,
85         NULL, //ConvertToType,
86 };
87
88 JSStaticValue JSContact::m_property[] = {
89         { CONTACT_ATTR_ID, getId, NULL, kJSPropertyAttributeReadOnly },
90         { CONTACT_ATTR_ADDRESSBOOK_ID, getAddressBookId, NULL, kJSPropertyAttributeReadOnly },
91         { CONTACT_ATTR_PERSON_ID, getPersonId, NULL, kJSPropertyAttributeReadOnly },
92         { CONTACT_ATTR_LAST_UPDATED, getLastUpdated, NULL, kJSPropertyAttributeReadOnly },
93         { CONTACT_ATTR_IS_FAVORITE, getIsFavorite, NULL, kJSPropertyAttributeReadOnly },
94         { CONTACT_ATTR_NAME, getName, setName, kJSPropertyAttributeNone },
95         { CONTACT_ATTR_ADDRESSES, getAddresses, setAddresses, kJSPropertyAttributeNone },
96         { CONTACT_ATTR_PHOTO_URI, getPhotoURI, setPhotoURI, kJSPropertyAttributeNone },
97         { CONTACT_ATTR_PHONE_NUMBERS, getPhoneNumbers, setPhoneNumbers, kJSPropertyAttributeNone },
98         { CONTACT_ATTR_EMAILS, getEmails, setEmails, kJSPropertyAttributeNone },
99         { CONTACT_ATTR_BIRTHDAY, getBirthday, setBirthday, kJSPropertyAttributeNone },
100         { CONTACT_ATTR_ANNIVERSARIES, getAnniversaries, setAnniversaries, kJSPropertyAttributeNone },
101         { CONTACT_ATTR_ORGANIZATIONS, getOrganizations, setOrganizations, kJSPropertyAttributeNone },
102         { CONTACT_ATTR_NOTES, getNotes, setNotes, kJSPropertyAttributeNone },
103         { CONTACT_ATTR_URLS, getUrls, setUrls, kJSPropertyAttributeNone },
104         { CONTACT_ATTR_RINGTONE_URI, getRingtoneURI, setRingtoneURI, kJSPropertyAttributeNone },
105         { CONTACT_ATTR_GROUP_IDS, getGroupIds, setGroupIds, kJSPropertyAttributeNone },
106         { 0, 0, 0, 0 }
107 };
108
109 JSStaticFunction JSContact::m_functions[] =
110 {
111         { CONTACT_FUNC_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
112         { CONTACT_FUNC_CLONE, clone, kJSPropertyAttributeNone },
113         { 0, 0, 0 }
114 };
115
116 JSClassRef JSContact::m_classRef = JSClassCreate(&m_classInfo);
117
118 JSClassRef JSContact::getClassRef() {
119         if (!m_classRef) {
120                 m_classRef = JSClassCreate(&m_classInfo);
121         }
122         return m_classRef;
123 }
124
125 bool JSContact::isObjectOfClass(JSContextRef context, JSValueRef value)
126 {
127         return JSValueIsObjectOfClass(context, value, getClassRef());
128 }
129
130 ContactPtr JSContact::getContact(JSContextRef context, JSValueRef value)
131 {
132         if (!isObjectOfClass(context, value)) {
133                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
134         }
135         JSObjectRef object = JSValueToObject(context, value, NULL);
136         if (!object) {
137                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
138         }
139         JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
140         if (!priv) {
141                 Throw(WrtDeviceApis::Commons::NullPointerException);
142         }
143         return priv->getObject();
144 }
145
146 void JSContact::Initialize(JSContextRef context, JSObjectRef object)
147 {
148         if (!JSObjectGetPrivate(object))
149         {
150                 ContactPtr contact = ContactFactory::getInstance().createContact();
151                 JSContactPriv *priv = new JSContactPriv(context, ContactPtr(contact));
152                 if (!JSObjectSetPrivate(object, priv)) {
153                         delete priv;
154                 }
155         }
156 }
157
158 void JSContact::Finalize(JSObjectRef object)
159 {
160         JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
161
162         if (priv != NULL)
163                 delete (priv);
164 }
165
166 JSObjectRef JSContact::createJSObject(JSContextRef context, ContactPtr contact)
167 {
168         JSContactPriv *priv = new JSContactPriv(context, contact);
169         JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
170         if (NULL == jsObjectRef) {
171                 LogError("object creation error");
172                 return NULL;
173         }
174         return jsObjectRef;
175 }
176
177 ContactPtr JSContact::getPrivData(JSObjectRef object)
178 {
179         JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
180         if (!priv) {
181                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
182         }
183         ContactPtr result = priv->getObject();
184         if (!result) {
185                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null.");
186         }
187         return result;
188 }
189
190 JSObjectRef JSContact::constructor(JSContextRef context,
191                 JSObjectRef constructor,
192                 size_t argumentCount,
193                 const JSValueRef arguments[],
194                 JSValueRef* exception)
195 {
196         LogDebug("entered");
197
198         bool jsNoParam = false;
199         bool js1stParamIsObject = false;
200         bool js1stParamIsString = false;
201
202         JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(constructor));
203         if (!priv) {
204                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
205         }
206         JSContextRef gContext = priv->getContext();
207
208         BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
209         if (argumentCount == 0)
210         {
211                 jsNoParam = true;
212         }
213         else
214         {
215                 if (JSValueIsNull(gContext, arguments[0]) || JSValueIsUndefined(gContext, arguments[0]))
216                         jsNoParam = true;
217                 else if (JSValueIsObject(gContext, arguments[0]))
218                         js1stParamIsObject = true;
219                 else if (JSValueIsString(gContext, arguments[0]))
220                         js1stParamIsString = true;
221                 else
222                 {
223                         LogError("Argument type mismatch : 1nd argument must be ContactInit object or string");
224                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "2nd argument must be 'ContactTextFormat'");
225                         return NULL;
226                 }
227         }
228
229         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
230
231         ContactPtr contact(NULL);
232         if(js1stParamIsObject)
233         {
234                 Try {
235                         contact = converter->toContactFromInit(arguments[0]);
236
237                 } Catch(ConversionException) {
238                         LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
239                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactInit object'");
240                         return NULL;
241                 } Catch(Exception) {
242                         LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
243                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
244                         return NULL;
245                 }
246         }
247         else if(js1stParamIsString)
248         {
249                 Try {
250                         std::string stringRepresentation;       // vCard string
251
252                         stringRepresentation = converter->toString(arguments[0]);
253
254                         contact = ContactFactory::getInstance().createContact();
255                         contact->setContactFromString(stringRepresentation);
256
257                 } Catch(ConversionException) {
258                         LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
259                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "2nd argument must be 'ContactTextFormat'");
260                         return NULL;
261                 } Catch(InvalidArgumentException) {
262                         LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
263                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "1st argument must be vCard string");
264                         return NULL;
265                 } Catch(UnsupportedException) {
266                         LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
267                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, "Only support vCard 3.0");
268                         return NULL;
269                 } Catch(Exception) {
270                         LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
271                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
272                         return NULL;
273                 }
274         }
275         else
276         {
277                 Try {
278                         contact = ContactFactory::getInstance().createContact();
279                 } Catch(Exception) {
280                         LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
281                         *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
282                         return NULL;
283                 }
284         }
285
286         JSObjectRef jsobject;
287
288         Try {
289                 jsobject = createJSObject(gContext, contact);
290         } Catch(Exception) {
291                 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
292                 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
293                 return NULL;
294         }
295
296         return jsobject;
297 }
298
299 bool JSContact::hasInstance(JSContextRef context,
300                 JSObjectRef constructor,
301                 JSValueRef possibleInstance,
302                 JSValueRef* exception)
303 {
304         return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
305 }
306
307 JSValueRef JSContact::getId(JSContextRef context,
308                 JSObjectRef object,
309                 JSStringRef propertyName,
310                 JSValueRef* exception)
311 {
312         Try
313         {
314                 ContactConverterFactory::ConverterType converter =
315                                 ContactConverterFactory::getConverter(context);
316                 ContactPtr contact = getPrivData(object);
317                 if(!contact->getIdIsSet())
318                         return JSValueMakeNull(context);
319                 else
320                         return converter->toJSValueRef(contact->getId());
321         }
322         Catch(WrtDeviceApis::Commons::Exception)
323         {
324                 LogWarning("trying to get incorrect value");
325         }
326         return JSValueMakeUndefined(context);
327 }
328
329 JSValueRef JSContact::getAddressBookId(JSContextRef context,
330                 JSObjectRef object,
331                 JSStringRef propertyName,
332                 JSValueRef* exception)
333 {
334         Try
335         {
336                 ContactConverterFactory::ConverterType converter =
337                                 ContactConverterFactory::getConverter(context);
338                 ContactPtr contact = getPrivData(object);
339                 if(!contact->getAddressBookIdIsSet())
340                         return JSValueMakeNull(context);
341                 else
342                         return converter->toJSValueRef(contact->getAddressBookId());
343         }
344         Catch(WrtDeviceApis::Commons::Exception)
345         {
346                 LogWarning("trying to get incorrect value");
347         }
348         return JSValueMakeUndefined(context);
349 }
350
351 JSValueRef JSContact::getPersonId(JSContextRef context,
352                 JSObjectRef object,
353                 JSStringRef propertyName,
354                 JSValueRef* exception)
355 {
356         Try
357         {
358                 ContactConverterFactory::ConverterType converter =
359                                 ContactConverterFactory::getConverter(context);
360                 ContactPtr contact = getPrivData(object);
361                 if(!contact->getPersonIdIsSet())
362                         return JSValueMakeNull(context);
363                 else
364                         return converter->toJSValueRef(contact->getPersonId());
365         }
366         Catch(WrtDeviceApis::Commons::Exception)
367         {
368                 LogWarning("trying to get incorrect value");
369         }
370         return JSValueMakeUndefined(context);
371 }
372
373 JSValueRef JSContact::getLastUpdated(JSContextRef context,
374                 JSObjectRef object,
375                 JSStringRef propertyName,
376                 JSValueRef* exception)
377 {
378         Try
379         {
380                 ContactConverterFactory::ConverterType converter =
381                                 ContactConverterFactory::getConverter(context);
382                 ContactPtr contact = getPrivData(object);
383                 if(!contact->getLastUpdatedIsSet())
384                         return JSValueMakeNull(context);
385                 else
386                         return converter->toJSValueRef(contact->getLastUpdated());
387         }
388         Catch(WrtDeviceApis::Commons::Exception)
389         {
390                 LogWarning("trying to get incorrect value");
391         }
392
393         return JSValueMakeUndefined(context);
394 }
395
396 JSValueRef JSContact::getIsFavorite(JSContextRef context,
397                 JSObjectRef object,
398                 JSStringRef propertyName,
399                 JSValueRef* exception)
400 {
401         Try
402         {
403                 ContactConverterFactory::ConverterType converter =
404                                 ContactConverterFactory::getConverter(context);
405                 ContactPtr contact = getPrivData(object);
406                 return converter->toJSValueRef(contact->getIsFavorite());
407         }
408         Catch(WrtDeviceApis::Commons::Exception)
409         {
410                 LogWarning("trying to get incorrect value");
411         }
412
413         return JSValueMakeUndefined(context);
414 }
415
416 JSValueRef JSContact::getName(JSContextRef context,
417                 JSObjectRef object,
418                 JSStringRef propertyName,
419                 JSValueRef* exception)
420 {
421         Try
422         {
423                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
424                 if (!priv) {
425                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
426                 }
427                 JSContextRef gContext = priv->getContext();
428
429                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
430                 ContactPtr contact = getPrivData(object);
431                 ContactNamePtr contactName = contact->getName();
432                 if(contactName == NULL)
433                         return JSValueMakeNull(context);
434                 else
435                         return converter->toJSValueRef(contactName);
436         }
437         Catch(WrtDeviceApis::Commons::Exception)
438         {
439                 LogWarning("trying to get incorrect value");
440         }
441
442         return JSValueMakeUndefined(context);
443 }
444
445 bool JSContact::setName(JSContextRef context,
446                 JSObjectRef object,
447                 JSStringRef propertyName,
448                 JSValueRef value,
449                 JSValueRef* exception)
450 {
451         Try
452         {
453                 ContactPtr contact = getPrivData(object);
454                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
455                 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
456                 if(validator->isNullOrUndefined(value))
457                         contact->unsetName();
458                 else
459                         contact->setName(converter->toContactName(value));
460                 return true;
461         }
462         Catch(WrtDeviceApis::Commons::Exception)
463         {
464                 LogWarning("trying to set incorrect value");
465         }
466
467         JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
468         return false;
469 }
470
471 JSValueRef JSContact::getAddresses(JSContextRef context,
472                 JSObjectRef object,
473                 JSStringRef propertyName,
474                 JSValueRef* exception)
475 {
476         Try
477         {
478                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
479                 if (!priv) {
480                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
481                 }
482                 JSContextRef gContext = priv->getContext();
483                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
484                 ContactPtr contact = getPrivData(object);
485
486                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
487                 if(newContactT->addressesJSObjIsSet()){
488                         return newContactT->getAddressesJSObj();
489                 }else{
490                         JSValueRef tempJSValue = newContactT->getAddressesJSValue();
491                         tempJSValue = converter->toJSValueRef(newContactT->getAddresses());
492
493                         JSObjectRef convertedJSObject = newContactT->getAddressesJSObj();
494                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
495                         newContactT->setAddressesJSObj(true, convertedJSObject);
496
497                         JSValueProtect(gContext, convertedJSObject);
498                         newContactT->setContext(gContext);
499                         return tempJSValue;
500                 }
501         }
502         Catch(WrtDeviceApis::Commons::Exception)
503         {
504                 LogWarning("trying to get incorrect value");
505         }
506
507         return JSValueMakeUndefined(context);
508 }
509
510 bool JSContact::setAddresses(JSContextRef context,
511                 JSObjectRef object,
512                 JSStringRef propertyName,
513                 JSValueRef value,
514                 JSValueRef* exception)
515 {
516         Try
517         {
518                 ContactPtr contact = getPrivData(object);
519                 ContactConverterFactory::ConverterType converter =
520                                 ContactConverterFactory::getConverter(context);
521                 contact->setAddresses(converter->toContactAddressArray(value));
522                 return true;
523         }
524         Catch(WrtDeviceApis::Commons::Exception)
525         {
526                 LogWarning("trying to set incorrect value");
527         }
528
529         JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
530         return false;
531 }
532
533 JSValueRef JSContact::getPhotoURI(JSContextRef context,
534                 JSObjectRef object,
535                 JSStringRef propertyName,
536                 JSValueRef* exception)
537 {
538         Try
539         {
540                 ContactConverterFactory::ConverterType converter =
541                                 ContactConverterFactory::getConverter(context);
542                 ContactPtr contact = getPrivData(object);
543                 if(!contact->getPhotoURIIsSet())
544                         return JSValueMakeNull(context);
545                 else
546                         return converter->toJSValueRef(contact->getPhotoURI());
547         }
548         Catch(WrtDeviceApis::Commons::Exception)
549         {
550                 LogWarning("trying to get incorrect value");
551         }
552
553         return JSValueMakeUndefined(context);
554 }
555
556 bool JSContact::setPhotoURI(JSContextRef context,
557                 JSObjectRef object,
558                 JSStringRef propertyName,
559                 JSValueRef value,
560                 JSValueRef* exception)
561 {
562         Try
563         {
564                 ContactPtr contact = getPrivData(object);
565                 ContactConverterFactory::ConverterType converter =
566                                 ContactConverterFactory::getConverter(context);
567                 BasicValidator validator =
568                                 BasicValidatorFactory::getValidator(context, exception);
569                 if(validator->isNullOrUndefined(value))
570                         contact->unsetPhotoURI();
571                 else
572                         contact->setPhotoURI(converter->toString(value));
573                 return true;
574         }
575         Catch(WrtDeviceApis::Commons::Exception)
576         {
577                 LogWarning("trying to set incorrect value");
578         }
579
580         JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
581         return false;
582 }
583
584 JSValueRef JSContact::getPhoneNumbers(JSContextRef context,
585                 JSObjectRef object,
586                 JSStringRef propertyName,
587                 JSValueRef* exception)
588 {
589         Try
590         {
591                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
592                 if (!priv) {
593                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
594                 }
595                 JSContextRef gContext = priv->getContext();
596                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
597                 ContactPtr contact = getPrivData(object);
598
599                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
600                 if(newContactT->numbersJSObjIsSet()){
601                         return newContactT->getNumbersJSObj();
602                 }else{
603                         JSValueRef tempJSValue = newContactT->getNumbersJSValue();
604                         tempJSValue = converter->toJSValueRef(newContactT->getPhoneNumbers());
605
606                         JSObjectRef convertedJSObject = newContactT->getNumbersJSObj();
607                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
608                         newContactT->setNumbersJSObj(true, convertedJSObject);
609
610                         JSValueProtect(gContext, convertedJSObject);
611                         newContactT->setContext(gContext);
612                         return tempJSValue;
613                 }
614         }
615         Catch(WrtDeviceApis::Commons::Exception)
616         {
617                 LogWarning("trying to get incorrect value");
618         }
619
620         return JSValueMakeUndefined(context);
621 }
622
623 bool JSContact::setPhoneNumbers(JSContextRef context,
624                 JSObjectRef object,
625                 JSStringRef propertyName,
626                 JSValueRef value,
627                 JSValueRef* exception)
628 {
629         Try
630         {
631                 ContactPtr contact = getPrivData(object);
632                 ContactConverterFactory::ConverterType converter =
633                                 ContactConverterFactory::getConverter(context);
634                 contact->setPhoneNumbers(
635                                 converter->toContactPhoneNumberArray(value));
636                 return true;
637         }
638         Catch(WrtDeviceApis::Commons::Exception)
639         {
640                 LogWarning("trying to set incorrect value");
641         }
642
643         JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
644         return false;
645 }
646
647 JSValueRef JSContact::getEmails(JSContextRef context,
648                 JSObjectRef object,
649                 JSStringRef propertyName,
650                 JSValueRef* exception)
651 {
652         Try
653         {
654                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
655                 if (!priv) {
656                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
657                 }
658                 JSContextRef gContext = priv->getContext();
659
660                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
661                 ContactPtr contact = getPrivData(object);
662
663                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
664                 if(newContactT->EmailsJSObjIsSet()){
665                         LogDebug("return init value");
666                         return newContactT->getEmailsJSObj();
667                 }else{
668                         LogDebug("new array");
669                         JSValueRef tempJSValue = newContactT->getEmailsJSValue();
670                         tempJSValue = converter->toJSValueRef(newContactT->getEmails());
671
672                         JSObjectRef convertedJSObject = newContactT->getEmailsJSObj();
673                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
674                         newContactT->setEmailsJSObj(true, convertedJSObject);
675
676                         JSValueProtect(gContext, convertedJSObject);
677                         newContactT->setContext(gContext);
678                         return tempJSValue;
679                 }
680         }
681         Catch(WrtDeviceApis::Commons::Exception)
682         {
683                 LogWarning("trying to get incorrect value");
684         }
685
686         return JSValueMakeUndefined(context);
687 }
688
689 bool JSContact::setEmails(JSContextRef context,
690                 JSObjectRef object,
691                 JSStringRef propertyName,
692                 JSValueRef value,
693                 JSValueRef* exception)
694 {
695         Try
696         {
697                 ContactPtr contact = getPrivData(object);
698                 ContactConverterFactory::ConverterType converter =
699                                 ContactConverterFactory::getConverter(context);
700                 contact->setEmails(converter->toContactEmailAddressArray(value));
701                 return true;
702         }
703         Catch(WrtDeviceApis::Commons::Exception)
704         {
705                 LogWarning("trying to set incorrect value");
706         }
707
708         JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
709         return false;
710 }
711
712 JSValueRef JSContact::getBirthday(JSContextRef context,
713                 JSObjectRef object,
714                 JSStringRef propertyName,
715                 JSValueRef* exception)
716 {
717         Try
718         {
719                 ContactConverterFactory::ConverterType converter =
720                                 ContactConverterFactory::getConverter(context);
721                 ContactPtr contact = getPrivData(object);
722                 if(!contact->getBirthdayIsSet())
723                         return JSValueMakeNull(context);
724                 else
725                         return converter->toJSValueRef(contact->getBirthday());
726         }
727         Catch(WrtDeviceApis::Commons::Exception)
728         {
729                 LogWarning("trying to get incorrect value");
730         }
731
732         return JSValueMakeUndefined(context);
733 }
734
735 bool JSContact::setBirthday(JSContextRef context,
736                 JSObjectRef object,
737                 JSStringRef propertyName,
738                 JSValueRef value,
739                 JSValueRef* exception)
740 {
741         Try
742         {
743                 ContactPtr contact = getPrivData(object);
744                 ContactConverterFactory::ConverterType converter =
745                                 ContactConverterFactory::getConverter(context);
746                 BasicValidator validator =
747                                 BasicValidatorFactory::getValidator(context, exception);
748                 if(validator->isNullOrUndefined(value))
749                         contact->unsetBirthday();
750                 else
751                         contact->setBirthday(converter->toDateTm(value));
752                 return true;
753         }
754         Catch(WrtDeviceApis::Commons::Exception)
755         {
756                 LogWarning("trying to set incorrect value");
757         }
758
759         JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
760         return false;
761 }
762
763 JSValueRef JSContact::getAnniversaries(JSContextRef context,
764                 JSObjectRef object,
765                 JSStringRef propertyName,
766                 JSValueRef* exception)
767 {
768         Try
769         {
770                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
771                 if (!priv) {
772                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
773                 }
774                 JSContextRef gContext = priv->getContext();
775
776                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
777                 ContactPtr contact = getPrivData(object);
778
779                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
780                 if(newContactT->anniversariesJSObjIsSet()){
781                         return newContactT->getAnniversariesJSObj();
782                 }else{
783                         JSValueRef tempJSValue = newContactT->getAnniversariesJSValue();
784                         tempJSValue = converter->toJSValueRef(newContactT->getAnniversaries());
785
786                         JSObjectRef convertedJSObject = newContactT->getAnniversariesJSObj();
787                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
788                         newContactT->setAnniversariesJSObj(true, convertedJSObject);
789
790                         JSValueProtect(gContext, convertedJSObject);
791                         newContactT->setContext(gContext);
792                         return tempJSValue;
793                 }
794         }
795         Catch(WrtDeviceApis::Commons::Exception)
796         {
797                 LogWarning("trying to get incorrect value");
798         }
799
800         return JSValueMakeUndefined(context);
801 }
802
803 bool JSContact::setAnniversaries(JSContextRef context,
804                 JSObjectRef object,
805                 JSStringRef propertyName,
806                 JSValueRef value,
807                 JSValueRef* exception)
808 {
809         Try
810         {
811                 ContactPtr contact = getPrivData(object);
812                 ContactConverterFactory::ConverterType converter =
813                                 ContactConverterFactory::getConverter(context);
814                 contact->setAnniversaries(
815                                 converter->toContactAnniversaryArray(value));
816                 return true;
817         }
818         Catch(WrtDeviceApis::Commons::Exception)
819         {
820                 LogWarning("trying to set incorrect value");
821         }
822
823         JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
824         return false;
825 }
826
827 JSValueRef JSContact::getOrganizations(JSContextRef context,
828                 JSObjectRef object,
829                 JSStringRef propertyName,
830                 JSValueRef* exception)
831 {
832         Try
833         {
834                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
835                 if (!priv) {
836                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
837                 }
838                 JSContextRef gContext = priv->getContext();
839
840                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
841                 ContactPtr contact = getPrivData(object);
842
843                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
844                 if(newContactT->organizationsJSObjIsSet()){
845                         return newContactT->getOrganizationsJSObj();
846                 }else{
847                         JSValueRef tempJSValue = newContactT->getOrganizationsJSValue();
848                         tempJSValue = converter->toJSValueRef(newContactT->getOrganizations());
849
850                         JSObjectRef convertedJSObject = newContactT->getOrganizationsJSObj();
851                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
852                         newContactT->setOrganizationsJSObj(true, convertedJSObject);
853
854                         JSValueProtect(gContext, convertedJSObject);
855                         newContactT->setContext(gContext);
856                         return tempJSValue;
857                 }
858         }
859         Catch(WrtDeviceApis::Commons::Exception)
860         {
861                 LogWarning("trying to get incorrect value");
862         }
863
864         return JSValueMakeUndefined(context);
865 }
866
867 bool JSContact::setOrganizations(JSContextRef context,
868                 JSObjectRef object,
869                 JSStringRef propertyName,
870                 JSValueRef value,
871                 JSValueRef* exception)
872 {
873         Try
874         {
875                 ContactPtr contact = getPrivData(object);
876                 ContactConverterFactory::ConverterType converter =
877                                 ContactConverterFactory::getConverter(context);
878                 contact->setOrganizations(
879                                 converter->toContactOrganizationArray(value));
880                 return true;
881         }
882         Catch(WrtDeviceApis::Commons::Exception)
883         {
884                 LogWarning("trying to set incorrect value");
885         }
886
887         JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
888         return false;
889 }
890
891 JSValueRef JSContact::getNotes(JSContextRef context,
892                 JSObjectRef object,
893                 JSStringRef propertyName,
894                 JSValueRef* exception)
895 {
896         Try
897         {
898                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
899                 if (!priv) {
900                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
901                 }
902                 JSContextRef gContext = priv->getContext();
903
904                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
905                 ContactPtr contact = getPrivData(object);
906
907                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
908                 if(newContactT->notesJSObjIsSet()){
909                         return newContactT->getNotesJSObj();
910                 }else{
911                         JSValueRef tempJSValue = newContactT->getNotesJSValue();
912                         tempJSValue = converter->toJSValueRef(newContactT->getNotes());
913
914                         JSObjectRef convertedJSObject = newContactT->getNotesJSObj();
915                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
916                         newContactT->setNotesJSObj(true, convertedJSObject);
917
918                         JSValueProtect(gContext, convertedJSObject);
919                         newContactT->setContext(gContext);
920                         return tempJSValue;
921                 }
922         }
923         Catch(WrtDeviceApis::Commons::Exception)
924         {
925                 LogWarning("trying to get incorrect value");
926         }
927
928         return JSValueMakeUndefined(context);
929 }
930
931 bool JSContact::setNotes(JSContextRef context,
932                 JSObjectRef object,
933                 JSStringRef propertyName,
934                 JSValueRef value,
935                 JSValueRef* exception)
936 {
937         Try
938         {
939                 ContactPtr contact = getPrivData(object);
940                 ContactConverterFactory::ConverterType converter =
941                                 ContactConverterFactory::getConverter(context);
942                 contact->setNotes(converter->toStringArray(value));
943                 return true;
944         }
945         Catch(WrtDeviceApis::Commons::Exception)
946         {
947                 LogWarning("trying to set incorrect value");
948         }
949
950         JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
951         return false;
952 }
953
954 JSValueRef JSContact::getUrls(JSContextRef context,
955                 JSObjectRef object,
956                 JSStringRef propertyName,
957                 JSValueRef* exception)
958 {
959         Try
960         {
961                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
962                 if (!priv) {
963                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
964                 }
965                 JSContextRef gContext = priv->getContext();
966
967                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
968                 ContactPtr contact = getPrivData(object);
969
970                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
971                 if(newContactT->urlsJSObjIsSet()){
972                         return newContactT->getUrlsJSObj();
973                 }else{
974                         JSValueRef tempJSValue = newContactT->getUrlsJSValue();
975                         tempJSValue = converter->toJSValueRef(newContactT->getUrls());
976
977                         JSObjectRef convertedJSObject = newContactT->getUrlsJSObj();
978                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
979                         newContactT->setUrlsJSObj(true, convertedJSObject);
980
981                         JSValueProtect(gContext, convertedJSObject);
982                         newContactT->setContext(gContext);
983                         return tempJSValue;
984                 }
985         }
986         Catch(WrtDeviceApis::Commons::Exception)
987         {
988                 LogWarning("trying to get incorrect value");
989         }
990
991         return JSValueMakeUndefined(context);
992 }
993
994 bool JSContact::setUrls(JSContextRef context,
995                 JSObjectRef object,
996                 JSStringRef propertyName,
997                 JSValueRef value,
998                 JSValueRef* exception)
999 {
1000         Try
1001         {
1002                 ContactPtr contact = getPrivData(object);
1003                 ContactConverterFactory::ConverterType converter =
1004                                 ContactConverterFactory::getConverter(context);
1005                 contact->setUrls(converter->toContactWebSiteArray(value));
1006                 return true;
1007         }
1008         Catch(WrtDeviceApis::Commons::Exception)
1009         {
1010                 LogWarning("trying to set incorrect value");
1011         }
1012
1013         JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
1014         return false;
1015 }
1016
1017 JSValueRef JSContact::getRingtoneURI(JSContextRef context,
1018                 JSObjectRef object,
1019                 JSStringRef propertyName,
1020                 JSValueRef* exception)
1021 {
1022         Try
1023         {
1024                 ContactConverterFactory::ConverterType converter =
1025                                 ContactConverterFactory::getConverter(context);
1026                 ContactPtr contact = getPrivData(object);
1027                 if(!contact->getRingtoneURIIsSet())
1028                         return JSValueMakeNull(context);
1029                 else
1030                         return converter->toJSValueRef(contact->getRingtoneURI());
1031         }
1032         Catch(WrtDeviceApis::Commons::Exception)
1033         {
1034                 LogWarning("trying to get incorrect value");
1035         }
1036
1037         return JSValueMakeUndefined(context);
1038 }
1039
1040 bool JSContact::setRingtoneURI(JSContextRef context,
1041                 JSObjectRef object,
1042                 JSStringRef propertyName,
1043                 JSValueRef value,
1044                 JSValueRef* exception)
1045 {
1046         Try
1047         {
1048                 ContactPtr contact = getPrivData(object);
1049                 ContactConverterFactory::ConverterType converter =
1050                                 ContactConverterFactory::getConverter(context);
1051                 BasicValidator validator =
1052                                 BasicValidatorFactory::getValidator(context, exception);
1053                 if(validator->isNullOrUndefined(value))
1054                         contact->unsetRingtoneURI();
1055                 else
1056                         contact->setRingtoneURI(converter->toString(value));
1057                 return true;
1058         }
1059         Catch(WrtDeviceApis::Commons::Exception)
1060         {
1061                 LogWarning("trying to set incorrect value");
1062         }
1063
1064         JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
1065         return false;
1066 }
1067
1068 JSValueRef JSContact::getGroupIds(JSContextRef context,
1069                 JSObjectRef object,
1070                 JSStringRef propertyName,
1071                 JSValueRef* exception)
1072 {
1073         Try
1074         {
1075                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
1076                 if (!priv) {
1077                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
1078                 }
1079                 JSContextRef gContext = priv->getContext();
1080
1081                 ContactConverterFactory::ConverterType converter =
1082                                 ContactConverterFactory::getConverter(gContext);
1083                 ContactPtr contact = getPrivData(object);
1084                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
1085
1086                 if(newContactT->groupIdsJSObjIsSet()){
1087                         return newContactT->getGroupIdsJSObj();
1088                 }else{
1089                         JSValueRef tempJSValue = newContactT->getGroupIdsJSValue();
1090                         tempJSValue = converter->toJSValueRef(newContactT->getGroupIds());
1091
1092                         JSObjectRef convertedJSObject = newContactT->getGroupIdsJSObj();
1093                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
1094                         newContactT->setGroupIdsJSObj(true, convertedJSObject);
1095
1096                         JSValueProtect(gContext, convertedJSObject);
1097                         newContactT->setContext(gContext);
1098                         return tempJSValue;
1099                 }
1100         }
1101         Catch(WrtDeviceApis::Commons::Exception)
1102         {
1103                 LogWarning("trying to get incorrect value");
1104         }
1105
1106         return JSValueMakeUndefined(context);
1107 }
1108
1109 bool JSContact::setGroupIds(JSContextRef context,
1110                 JSObjectRef object,
1111                 JSStringRef propertyName,
1112                 JSValueRef value,
1113                 JSValueRef* exception)
1114 {
1115         Try
1116         {
1117                 ContactPtr contact = getPrivData(object);
1118                 ContactConverterFactory::ConverterType converter =
1119                                 ContactConverterFactory::getConverter(context);
1120                 contact->setGroupIds(converter->toStringArray(value));
1121                 return true;
1122         }
1123         Catch(WrtDeviceApis::Commons::Exception)
1124         {
1125                 LogWarning("trying to set incorrect value");
1126         }
1127
1128         JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
1129         return false;
1130 }
1131
1132 JSValueRef JSContact::convertToString(JSContextRef context,
1133                 JSObjectRef object,
1134                 JSObjectRef thisObject,
1135                 size_t argumentCount,
1136                 const JSValueRef arguments[],
1137                 JSValueRef* exception)
1138 {
1139         LogDebug("entered");
1140         ContactPtr contact(NULL);
1141
1142         Try     {
1143                 contact = getPrivData(thisObject);
1144                 if (contact == NULL) {
1145                         ThrowMsg(InvalidArgumentException, "No private object.");
1146                 }
1147         } Catch(Exception) {
1148                 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
1149                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1150         }
1151
1152 //      AceSecurityStatus status = CONTACT_CHECK_ACCESS(
1153 //      CONTACT_FUNCTION_API_CONVERT_TO_STRING);
1154 //      TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1155
1156         BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
1157         Try {
1158                 if (argumentCount >= 1 &&
1159                                 ( !JSValueIsUndefined(context, arguments[0] ) &&
1160                                 ( !JSValueIsNull(context, arguments[0]) ) &&
1161                                 ( !JSValueIsString(context, arguments[0] )) ))
1162                         ThrowMsg(ConversionException, "1st argument must be 'ContactTextFormat string'");
1163         } Catch (Exception) {
1164                 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
1165                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
1166         }
1167
1168         std::string format;
1169
1170         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1171         Try     {
1172                 if(argumentCount >= 1)
1173                         format = converter->toString(arguments[0]);
1174         } Catch(Exception) {
1175                 LogError("Error on conversion : " << _rethrown_exception.GetMessage());
1176                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
1177         }
1178
1179         std::string vCard;
1180         Try {
1181                 vCard = contact->convertToString(format);
1182         } Catch(ConversionException) {
1183                 LogError("Error on platform : " << _rethrown_exception.GetMessage());
1184                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
1185         } Catch(UnsupportedException) {
1186                 LogError("Error on platform : " << _rethrown_exception.GetMessage());
1187                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Only support vCard 3.0");
1188         } Catch(Exception) {
1189                 LogError("Error on platform : " << _rethrown_exception.GetMessage());
1190                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1191         }
1192
1193         JSValueRef result;
1194         Try {
1195                 result = converter->toJSValueRef(vCard);
1196         } Catch(Exception) {
1197                 LogError("Error on conversion : " << _rethrown_exception.GetMessage());
1198                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1199         }
1200
1201         return result;
1202 }
1203
1204 JSValueRef JSContact::clone(JSContextRef context,
1205                 JSObjectRef object,
1206                 JSObjectRef thisObject,
1207                 size_t argumentCount,
1208                 const JSValueRef arguments[],
1209                 JSValueRef* exception)
1210 {
1211         LogDebug("entered");
1212         ContactPtr contact(NULL);
1213
1214         Try     {
1215                 contact = getPrivData(thisObject);
1216                 if (contact == NULL) {
1217                         ThrowMsg(InvalidArgumentException, "No private object.");
1218                 }
1219         } Catch(Exception) {
1220                 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
1221                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1222         }
1223
1224 //      AceSecurityStatus status = CONTACT_CHECK_ACCESS(
1225 //      CONTACT_FUNCTION_API_CONVERT_TO_STRING);
1226 //      TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1227
1228         ContactPtr clonedContact(NULL);
1229         Try {
1230                 clonedContact = contact->clone();
1231         } Catch(Exception) {
1232                 LogError("Error on conversion : " << _rethrown_exception.GetMessage());
1233                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1234         }
1235
1236         JSValueRef result;
1237         Try {
1238                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(thisObject));
1239                 if (!priv) {
1240                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
1241                 }
1242                 JSContextRef gContext = priv->getContext();
1243                 result = createJSObject(gContext, clonedContact);
1244         } Catch(Exception) {
1245                 LogError("Error on conversion : " << _rethrown_exception.GetMessage());
1246                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1247         }
1248
1249         return result;
1250 }
1251
1252 } // Contact
1253 } // DeviceAPI