c20c1dd7a7eb4fe08938f4224ebe5702dca0954a
[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/shared_ptr.h>
26 #include <CommonsJavaScript/Validator.h>
27 #include <SecurityExceptions.h>
28 #include "ContactFactory.h"
29 #include "plugin_config.h"
30 #include "ContactConverter.h"
31 #include "JSContact.h"
32 #include "Contact.h"
33 #include <ArgumentValidator.h>
34 #include <JSWebAPIErrorFactory.h>
35 #include <TimeTracer.h>
36 #include <Logger.h>
37 #include <Export.h>
38
39 #define FILTER_CLASS_NAME "Contact"
40
41 #define CONTACT_ATTR_ID             "id"
42 #define CONTACT_ATTR_ADDRESSBOOK_ID "addressBookId"
43 #define CONTACT_ATTR_PERSON_ID      "personId"
44 #define CONTACT_ATTR_LAST_UPDATED   "lastUpdated"
45 #define CONTACT_ATTR_IS_FAVORITE    "isFavorite"
46 #define CONTACT_ATTR_NAME           "name"
47 #define CONTACT_ATTR_ADDRESSES      "addresses"
48 #define CONTACT_ATTR_PHOTO_URI      "photoURI"
49 #define CONTACT_ATTR_PHONE_NUMBERS  "phoneNumbers"
50 #define CONTACT_ATTR_EMAILS         "emails"
51 #define CONTACT_ATTR_BIRTHDAY       "birthday"
52 #define CONTACT_ATTR_ANNIVERSARIES  "anniversaries"
53 #define CONTACT_ATTR_ORGANIZATIONS  "organizations"
54 #define CONTACT_ATTR_NOTES          "notes"
55 #define CONTACT_ATTR_URLS           "urls"
56 #define CONTACT_ATTR_LAST_UPDATED   "lastUpdated"
57 #define CONTACT_ATTR_RINGTONE_URI   "ringtoneURI"
58 #define CONTACT_ATTR_GROUP_IDS      "groupIds"
59 #define CONTACT_FUNC_CONVERT_TO_STRING          "convertToString"
60 #define CONTACT_FUNC_CLONE                                      "clone"
61
62 namespace DeviceAPI {
63 namespace Contact {
64
65 using namespace DeviceAPI::Common;
66 using namespace WrtDeviceApis::Commons;
67 using namespace WrtDeviceApis::CommonsJavaScript;
68
69 JSClassDefinition JSContact::m_classInfo =
70 {
71         0,
72         kJSClassAttributeNone,
73         FILTER_CLASS_NAME,
74         NULL,
75         m_property,
76         m_functions,
77         Initialize,
78         Finalize,
79         NULL, //hasProperty,
80         NULL, //GetProperty,
81         NULL, //SetProperty,
82         NULL, //DeleteProperty,
83         NULL, //getPropertyNames,
84         NULL, //CallAsFunction,
85         constructor, //CallAsConstructor,
86         hasInstance, //HasInstance,
87         NULL, //ConvertToType,
88 };
89
90 JSStaticValue JSContact::m_property[] = {
91         { CONTACT_ATTR_ID, getId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete},
92         { CONTACT_ATTR_ADDRESSBOOK_ID, getAddressBookId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete},
93         { CONTACT_ATTR_PERSON_ID, getPersonId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete},
94         { CONTACT_ATTR_LAST_UPDATED, getLastUpdated, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
95         { CONTACT_ATTR_IS_FAVORITE, getIsFavorite, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
96         { CONTACT_ATTR_NAME, getName, setName, kJSPropertyAttributeNone },
97         { CONTACT_ATTR_ADDRESSES, getAddresses, setAddresses, kJSPropertyAttributeNone },
98         { CONTACT_ATTR_PHOTO_URI, getPhotoURI, setPhotoURI, kJSPropertyAttributeNone },
99         { CONTACT_ATTR_PHONE_NUMBERS, getPhoneNumbers, setPhoneNumbers, kJSPropertyAttributeNone },
100         { CONTACT_ATTR_EMAILS, getEmails, setEmails, kJSPropertyAttributeNone },
101         { CONTACT_ATTR_BIRTHDAY, getBirthday, setBirthday, kJSPropertyAttributeNone },
102         { CONTACT_ATTR_ANNIVERSARIES, getAnniversaries, setAnniversaries, kJSPropertyAttributeNone },
103         { CONTACT_ATTR_ORGANIZATIONS, getOrganizations, setOrganizations, kJSPropertyAttributeNone },
104         { CONTACT_ATTR_NOTES, getNotes, setNotes, kJSPropertyAttributeNone },
105         { CONTACT_ATTR_URLS, getUrls, setUrls, kJSPropertyAttributeNone },
106         { CONTACT_ATTR_RINGTONE_URI, getRingtoneURI, setRingtoneURI, kJSPropertyAttributeNone },
107         { CONTACT_ATTR_GROUP_IDS, getGroupIds, setGroupIds, kJSPropertyAttributeNone },
108         { 0, 0, 0, 0 }
109 };
110
111 JSStaticFunction JSContact::m_functions[] =
112 {
113         { CONTACT_FUNC_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
114         { CONTACT_FUNC_CLONE, clone, kJSPropertyAttributeNone },
115         { 0, 0, 0 }
116 };
117
118 JSClassRef JSContact::m_classRef = JSClassCreate(&m_classInfo);
119
120 JSClassRef DLL_EXPORT JSContact::getClassRef() {
121         if (!m_classRef) {
122                 m_classRef = JSClassCreate(&m_classInfo);
123         }
124         return m_classRef;
125 }
126
127 bool JSContact::isObjectOfClass(JSContextRef context, JSValueRef value)
128 {
129         return JSValueIsObjectOfClass(context, value, getClassRef());
130 }
131
132 ContactPtr JSContact::getContact(JSContextRef context, JSValueRef value)
133 {
134         if (!isObjectOfClass(context, value)) {
135                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
136         }
137         JSObjectRef object = JSValueToObject(context, value, NULL);
138         if (!object) {
139                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
140         }
141         JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
142         if (!priv) {
143                 Throw(WrtDeviceApis::Commons::NullPointerException);
144         }
145         return priv->getObject();
146 }
147
148 void JSContact::Initialize(JSContextRef context, JSObjectRef object)
149 {
150         if (!JSObjectGetPrivate(object))
151         {
152                 ContactPtr contact = ContactFactory::getInstance().createContact();
153                 JSContactPriv *priv = new JSContactPriv(context, ContactPtr(contact));
154                 if (!JSObjectSetPrivate(object, priv)) {
155                         delete priv;
156                 }
157         }
158 }
159
160 void JSContact::Finalize(JSObjectRef object)
161 {
162         JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
163
164         if (priv != NULL)
165                 delete (priv);
166 }
167
168 JSObjectRef JSContact::createJSObject(JSContextRef context, ContactPtr contact)
169 {
170         JSContactPriv *priv = new JSContactPriv(context, contact);
171         JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
172         if (NULL == jsObjectRef) {
173                 LoggerE("object creation error");
174                 return NULL;
175         }
176         return jsObjectRef;
177 }
178
179 ContactPtr JSContact::getPrivData(JSObjectRef object)
180 {
181         JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
182         if (!priv) {
183                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
184         }
185         ContactPtr result = priv->getObject();
186         if (!result) {
187                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null.");
188         }
189         return result;
190 }
191
192 JSObjectRef JSContact::constructor(JSContextRef context,
193                 JSObjectRef constructor,
194                 size_t argumentCount,
195                 const JSValueRef arguments[],
196                 JSValueRef* exception)
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                         LoggerE("Argument type mismatch : 1nd argument must be ContactInit object or string");
224                         *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::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                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
239                         *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactInit object'");
240                         return NULL;
241                 } Catch(Exception) {
242                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
243                         *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::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                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
259                         *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "2nd argument must be 'ContactTextFormat'");
260                         return NULL;
261                 } Catch(InvalidArgumentException) {
262                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
263                         *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "1st argument must be vCard string");
264                         return NULL;
265                 } Catch(UnsupportedException) {
266                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
267                         *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, "Only support vCard 3.0");
268                         return NULL;
269                 } Catch(Exception) {
270                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
271                         *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
272                         return NULL;
273                 }
274         }
275         else
276         {
277                 Try {
278                         contact = ContactFactory::getInstance().createContact();
279                 } Catch(Exception) {
280                         LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
281                         *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::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                 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
292                 *exception = JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::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                 LoggerW("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                 LoggerW("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                 LoggerW("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                 LoggerW("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                 LoggerW("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                 LoggerW("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         }
461         Catch(WrtDeviceApis::Commons::Exception)
462         {
463                 LoggerW("trying to set incorrect value");
464                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
465         }
466
467         return true;
468 }
469
470 JSValueRef JSContact::getAddresses(JSContextRef context,
471                 JSObjectRef object,
472                 JSStringRef propertyName,
473                 JSValueRef* exception)
474 {
475         Try
476         {
477                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
478                 if (!priv) {
479                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
480                 }
481                 JSContextRef gContext = priv->getContext();
482                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
483                 ContactPtr contact = getPrivData(object);
484
485                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
486                 if(newContactT->addressesJSObjIsSet()){
487                         return newContactT->getAddressesJSObj();
488                 }else{
489                         JSValueRef tempJSValue = newContactT->getAddressesJSValue();
490                         tempJSValue = converter->toJSValueRef(newContactT->getAddresses());
491
492                         JSObjectRef convertedJSObject = newContactT->getAddressesJSObj();
493                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
494                         newContactT->setAddressesJSObj(true, convertedJSObject);
495
496                         JSValueProtect(gContext, convertedJSObject);
497                         newContactT->setContext(gContext);
498                         return tempJSValue;
499                 }
500         }
501         Catch(WrtDeviceApis::Commons::Exception)
502         {
503                 LoggerW("trying to get incorrect value");
504         }
505
506         return JSValueMakeUndefined(context);
507 }
508
509 bool JSContact::setAddresses(JSContextRef context,
510                 JSObjectRef object,
511                 JSStringRef propertyName,
512                 JSValueRef value,
513                 JSValueRef* exception)
514 {
515         Try
516         {
517                 ContactPtr contact = getPrivData(object);
518                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
519                 contact->setAddresses(converter->toContactAddressArray(value));
520                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
521                 newContactT->resetAddressesJSObj();
522         }
523         Catch(WrtDeviceApis::Commons::Exception)
524         {
525                 LoggerW("trying to set incorrect value");
526                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
527         }
528
529         return true;
530 }
531
532 JSValueRef JSContact::getPhotoURI(JSContextRef context,
533                 JSObjectRef object,
534                 JSStringRef propertyName,
535                 JSValueRef* exception)
536 {
537         Try
538         {
539                 ContactConverterFactory::ConverterType converter =
540                                 ContactConverterFactory::getConverter(context);
541                 ContactPtr contact = getPrivData(object);
542                 if(!contact->getPhotoURIIsSet())
543                         return JSValueMakeNull(context);
544                 else
545                         return converter->toJSValueRef(contact->getPhotoURI());
546         }
547         Catch(WrtDeviceApis::Commons::Exception)
548         {
549                 LoggerW("trying to get incorrect value");
550         }
551
552         return JSValueMakeUndefined(context);
553 }
554
555 bool JSContact::setPhotoURI(JSContextRef context,
556                 JSObjectRef object,
557                 JSStringRef propertyName,
558                 JSValueRef value,
559                 JSValueRef* exception)
560 {
561         Try
562         {
563                 ContactPtr contact = getPrivData(object);
564                 ContactConverterFactory::ConverterType converter =
565                                 ContactConverterFactory::getConverter(context);
566                 BasicValidator validator =
567                                 BasicValidatorFactory::getValidator(context, exception);
568                 if(validator->isNullOrUndefined(value))
569                         contact->unsetPhotoURI();
570                 else
571                         contact->setPhotoURI(converter->toString(value));
572         }
573         Catch(WrtDeviceApis::Commons::Exception)
574         {
575                 LoggerW("trying to set incorrect value");
576                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
577         }
578
579         return true;
580 }
581
582 JSValueRef JSContact::getPhoneNumbers(JSContextRef context,
583                 JSObjectRef object,
584                 JSStringRef propertyName,
585                 JSValueRef* exception)
586 {
587         Try
588         {
589                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
590                 if (!priv) {
591                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
592                 }
593                 JSContextRef gContext = priv->getContext();
594                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
595                 ContactPtr contact = getPrivData(object);
596
597                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
598                 if(newContactT->numbersJSObjIsSet()){
599                         return newContactT->getNumbersJSObj();
600                 }else{
601                         JSValueRef tempJSValue = newContactT->getNumbersJSValue();
602                         tempJSValue = converter->toJSValueRef(newContactT->getPhoneNumbers());
603
604                         JSObjectRef convertedJSObject = newContactT->getNumbersJSObj();
605                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
606                         newContactT->setNumbersJSObj(true, convertedJSObject);
607
608                         JSValueProtect(gContext, convertedJSObject);
609                         newContactT->setContext(gContext);
610                         return tempJSValue;
611                 }
612         }
613         Catch(WrtDeviceApis::Commons::Exception)
614         {
615                 LoggerW("trying to get incorrect value");
616         }
617
618         return JSValueMakeUndefined(context);
619 }
620
621 bool JSContact::setPhoneNumbers(JSContextRef context,
622                 JSObjectRef object,
623                 JSStringRef propertyName,
624                 JSValueRef value,
625                 JSValueRef* exception)
626 {
627         Try
628         {
629                 ContactPtr contact = getPrivData(object);
630                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
631                 contact->setPhoneNumbers(converter->toContactPhoneNumberArray(value));
632                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
633                 newContactT->resetNumbersJSObj();
634         }
635         Catch(WrtDeviceApis::Commons::Exception)
636         {
637                 LoggerW("trying to set incorrect value");
638                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
639         }
640
641         return true;
642 }
643
644 JSValueRef JSContact::getEmails(JSContextRef context,
645                 JSObjectRef object,
646                 JSStringRef propertyName,
647                 JSValueRef* exception)
648 {
649         Try
650         {
651                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
652                 if (!priv) {
653                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
654                 }
655                 JSContextRef gContext = priv->getContext();
656
657                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
658                 ContactPtr contact = getPrivData(object);
659
660                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
661                 if(newContactT->EmailsJSObjIsSet()){
662                         return newContactT->getEmailsJSObj();
663                 }else{
664                         JSValueRef tempJSValue = newContactT->getEmailsJSValue();
665                         tempJSValue = converter->toJSValueRef(newContactT->getEmails());
666
667                         JSObjectRef convertedJSObject = newContactT->getEmailsJSObj();
668                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
669                         newContactT->setEmailsJSObj(true, convertedJSObject);
670
671                         JSValueProtect(gContext, convertedJSObject);
672                         newContactT->setContext(gContext);
673                         return tempJSValue;
674                 }
675         }
676         Catch(WrtDeviceApis::Commons::Exception)
677         {
678                 LoggerW("trying to get incorrect value");
679         }
680
681         return JSValueMakeUndefined(context);
682 }
683
684 bool JSContact::setEmails(JSContextRef context,
685                 JSObjectRef object,
686                 JSStringRef propertyName,
687                 JSValueRef value,
688                 JSValueRef* exception)
689 {
690         Try
691         {
692                 ContactPtr contact = getPrivData(object);
693                 ContactConverterFactory::ConverterType converter =
694                                 ContactConverterFactory::getConverter(context);
695                 contact->setEmails(converter->toContactEmailAddressArray(value));
696                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
697                 newContactT->resetEmailsJSObj();
698         }
699         Catch(WrtDeviceApis::Commons::Exception)
700         {
701                 LoggerW("trying to set incorrect value");
702                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
703         }
704
705         return true;
706 }
707
708 JSValueRef JSContact::getBirthday(JSContextRef context,
709                 JSObjectRef object,
710                 JSStringRef propertyName,
711                 JSValueRef* exception)
712 {
713         Try
714         {
715                 ContactConverterFactory::ConverterType converter =
716                                 ContactConverterFactory::getConverter(context);
717                 ContactPtr contact = getPrivData(object);
718                 if(!contact->getBirthdayIsSet())
719                         return JSValueMakeNull(context);
720                 else
721                         return converter->toJSValueRef(contact->getBirthday());
722         }
723         Catch(WrtDeviceApis::Commons::Exception)
724         {
725                 LoggerW("trying to get incorrect value");
726         }
727
728         return JSValueMakeUndefined(context);
729 }
730
731 bool JSContact::setBirthday(JSContextRef context,
732                 JSObjectRef object,
733                 JSStringRef propertyName,
734                 JSValueRef value,
735                 JSValueRef* exception)
736 {
737         Try
738         {
739                 ContactPtr contact = getPrivData(object);
740                 ContactConverterFactory::ConverterType converter =
741                                 ContactConverterFactory::getConverter(context);
742                 BasicValidator validator =
743                                 BasicValidatorFactory::getValidator(context, exception);
744                 if(validator->isNullOrUndefined(value))
745                         contact->unsetBirthday();
746                 else
747                         contact->setBirthday(converter->toDateTm(value));
748         }
749         Catch(WrtDeviceApis::Commons::Exception)
750         {
751                 LoggerW("trying to set incorrect value");
752                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
753         }
754
755         return true;
756 }
757
758 JSValueRef JSContact::getAnniversaries(JSContextRef context,
759                 JSObjectRef object,
760                 JSStringRef propertyName,
761                 JSValueRef* exception)
762 {
763         Try
764         {
765                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
766                 if (!priv) {
767                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
768                 }
769                 JSContextRef gContext = priv->getContext();
770
771                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
772                 ContactPtr contact = getPrivData(object);
773
774                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
775                 if(newContactT->anniversariesJSObjIsSet()){
776                         return newContactT->getAnniversariesJSObj();
777                 }else{
778                         JSValueRef tempJSValue = newContactT->getAnniversariesJSValue();
779                         tempJSValue = converter->toJSValueRef(newContactT->getAnniversaries());
780
781                         JSObjectRef convertedJSObject = newContactT->getAnniversariesJSObj();
782                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
783                         newContactT->setAnniversariesJSObj(true, convertedJSObject);
784
785                         JSValueProtect(gContext, convertedJSObject);
786                         newContactT->setContext(gContext);
787                         return tempJSValue;
788                 }
789         }
790         Catch(WrtDeviceApis::Commons::Exception)
791         {
792                 LoggerW("trying to get incorrect value");
793         }
794
795         return JSValueMakeUndefined(context);
796 }
797
798 bool JSContact::setAnniversaries(JSContextRef context,
799                 JSObjectRef object,
800                 JSStringRef propertyName,
801                 JSValueRef value,
802                 JSValueRef* exception)
803 {
804         Try
805         {
806                 ContactPtr contact = getPrivData(object);
807                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
808                 contact->setAnniversaries(converter->toContactAnniversaryArray(value));
809                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
810                 newContactT->resetAnniversariesJSObj();
811         }
812         Catch(WrtDeviceApis::Commons::Exception)
813         {
814                 LoggerW("trying to set incorrect value");
815                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
816         }
817
818         return true;
819 }
820
821 JSValueRef JSContact::getOrganizations(JSContextRef context,
822                 JSObjectRef object,
823                 JSStringRef propertyName,
824                 JSValueRef* exception)
825 {
826         Try
827         {
828                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
829                 if (!priv) {
830                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
831                 }
832                 JSContextRef gContext = priv->getContext();
833
834                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
835                 ContactPtr contact = getPrivData(object);
836
837                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
838                 if(newContactT->organizationsJSObjIsSet()){
839                         return newContactT->getOrganizationsJSObj();
840                 }else{
841                         JSValueRef tempJSValue = newContactT->getOrganizationsJSValue();
842                         tempJSValue = converter->toJSValueRef(newContactT->getOrganizations());
843
844                         JSObjectRef convertedJSObject = newContactT->getOrganizationsJSObj();
845                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
846                         newContactT->setOrganizationsJSObj(true, convertedJSObject);
847
848                         JSValueProtect(gContext, convertedJSObject);
849                         newContactT->setContext(gContext);
850                         return tempJSValue;
851                 }
852         }
853         Catch(WrtDeviceApis::Commons::Exception)
854         {
855                 LoggerW("trying to get incorrect value");
856         }
857
858         return JSValueMakeUndefined(context);
859 }
860
861 bool JSContact::setOrganizations(JSContextRef context,
862                 JSObjectRef object,
863                 JSStringRef propertyName,
864                 JSValueRef value,
865                 JSValueRef* exception)
866 {
867         Try
868         {
869                 ContactPtr contact = getPrivData(object);
870                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
871                 contact->setOrganizations(converter->toContactOrganizationArray(value));
872                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
873                 newContactT->resetOrganizationsJSObj();
874         }
875         Catch(WrtDeviceApis::Commons::Exception)
876         {
877                 LoggerW("trying to set incorrect value");
878                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
879         }
880
881         return true;
882 }
883
884 JSValueRef JSContact::getNotes(JSContextRef context,
885                 JSObjectRef object,
886                 JSStringRef propertyName,
887                 JSValueRef* exception)
888 {
889         Try
890         {
891                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
892                 if (!priv) {
893                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
894                 }
895                 JSContextRef gContext = priv->getContext();
896
897                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
898                 ContactPtr contact = getPrivData(object);
899
900                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
901                 if(newContactT->notesJSObjIsSet()){
902                         return newContactT->getNotesJSObj();
903                 }else{
904                         JSValueRef tempJSValue = newContactT->getNotesJSValue();
905                         tempJSValue = converter->toJSValueRef(newContactT->getNotes());
906
907                         JSObjectRef convertedJSObject = newContactT->getNotesJSObj();
908                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
909                         newContactT->setNotesJSObj(true, convertedJSObject);
910
911                         JSValueProtect(gContext, convertedJSObject);
912                         newContactT->setContext(gContext);
913                         return tempJSValue;
914                 }
915         }
916         Catch(WrtDeviceApis::Commons::Exception)
917         {
918                 LoggerW("trying to get incorrect value");
919         }
920
921         return JSValueMakeUndefined(context);
922 }
923
924 bool JSContact::setNotes(JSContextRef context,
925                 JSObjectRef object,
926                 JSStringRef propertyName,
927                 JSValueRef value,
928                 JSValueRef* exception)
929 {
930         Try
931         {
932                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
933                 if (!priv) {
934                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
935                 }
936                 JSContextRef gContext = priv->getContext();
937                 ContactPtr contact = getPrivData(object);
938
939                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
940                 contact->setNotes(converter->toStringArray(value));
941                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
942                 newContactT->resetNotesJSObj();
943         }
944         Catch(WrtDeviceApis::Commons::Exception)
945         {
946                 LoggerW("trying to set incorrect value");
947                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
948         }
949
950         return true;
951 }
952
953 JSValueRef JSContact::getUrls(JSContextRef context,
954                 JSObjectRef object,
955                 JSStringRef propertyName,
956                 JSValueRef* exception)
957 {
958         Try
959         {
960                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
961                 if (!priv) {
962                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
963                 }
964                 JSContextRef gContext = priv->getContext();
965
966                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
967                 ContactPtr contact = getPrivData(object);
968
969                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
970                 if(newContactT->urlsJSObjIsSet()){
971                         return newContactT->getUrlsJSObj();
972                 }else{
973                         JSValueRef tempJSValue = newContactT->getUrlsJSValue();
974                         tempJSValue = converter->toJSValueRef(newContactT->getUrls());
975
976                         JSObjectRef convertedJSObject = newContactT->getUrlsJSObj();
977                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
978                         newContactT->setUrlsJSObj(true, convertedJSObject);
979
980                         JSValueProtect(gContext, convertedJSObject);
981                         newContactT->setContext(gContext);
982                         return tempJSValue;
983                 }
984         }
985         Catch(WrtDeviceApis::Commons::Exception)
986         {
987                 LoggerW("trying to get incorrect value");
988         }
989
990         return JSValueMakeUndefined(context);
991 }
992
993 bool JSContact::setUrls(JSContextRef context,
994                 JSObjectRef object,
995                 JSStringRef propertyName,
996                 JSValueRef value,
997                 JSValueRef* exception)
998 {
999         Try
1000         {
1001                 ContactPtr contact = getPrivData(object);
1002                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1003                 contact->setUrls(converter->toContactWebSiteArray(value));
1004                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
1005                 newContactT->resetUrlsJSObj();
1006         }
1007         Catch(WrtDeviceApis::Commons::Exception)
1008         {
1009                 LoggerW("trying to set incorrect value");
1010                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
1011         }
1012
1013         return true;
1014 }
1015
1016 JSValueRef JSContact::getRingtoneURI(JSContextRef context,
1017                 JSObjectRef object,
1018                 JSStringRef propertyName,
1019                 JSValueRef* exception)
1020 {
1021         Try
1022         {
1023                 ContactConverterFactory::ConverterType converter =
1024                                 ContactConverterFactory::getConverter(context);
1025                 ContactPtr contact = getPrivData(object);
1026                 if(!contact->getRingtoneURIIsSet())
1027                         return JSValueMakeNull(context);
1028                 else
1029                         return converter->toJSValueRef(contact->getRingtoneURI());
1030         }
1031         Catch(WrtDeviceApis::Commons::Exception)
1032         {
1033                 LoggerW("trying to get incorrect value");
1034         }
1035
1036         return JSValueMakeUndefined(context);
1037 }
1038
1039 bool JSContact::setRingtoneURI(JSContextRef context,
1040                 JSObjectRef object,
1041                 JSStringRef propertyName,
1042                 JSValueRef value,
1043                 JSValueRef* exception)
1044 {
1045         Try
1046         {
1047                 ContactPtr contact = getPrivData(object);
1048                 ContactConverterFactory::ConverterType converter =
1049                                 ContactConverterFactory::getConverter(context);
1050                 BasicValidator validator =
1051                                 BasicValidatorFactory::getValidator(context, exception);
1052                 if(validator->isNullOrUndefined(value))
1053                         contact->unsetRingtoneURI();
1054                 else
1055                         contact->setRingtoneURI(converter->toString(value));
1056         }
1057         Catch(WrtDeviceApis::Commons::Exception)
1058         {
1059                 LoggerW("trying to set incorrect value");
1060                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
1061         }
1062
1063         return true;
1064 }
1065
1066 JSValueRef JSContact::getGroupIds(JSContextRef context,
1067                 JSObjectRef object,
1068                 JSStringRef propertyName,
1069                 JSValueRef* exception)
1070 {
1071         Try
1072         {
1073                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
1074                 if (!priv) {
1075                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
1076                 }
1077                 JSContextRef gContext = priv->getContext();
1078
1079                 ContactConverterFactory::ConverterType converter =
1080                                 ContactConverterFactory::getConverter(gContext);
1081                 ContactPtr contact = getPrivData(object);
1082                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
1083
1084                 if(newContactT->groupIdsJSObjIsSet()){
1085                         return newContactT->getGroupIdsJSObj();
1086                 }else{
1087                         JSValueRef tempJSValue = newContactT->getGroupIdsJSValue();
1088                         tempJSValue = converter->toJSValueRef(newContactT->getGroupIds());
1089
1090                         JSObjectRef convertedJSObject = newContactT->getGroupIdsJSObj();
1091                         convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
1092                         newContactT->setGroupIdsJSObj(true, convertedJSObject);
1093
1094                         JSValueProtect(gContext, convertedJSObject);
1095                         newContactT->setContext(gContext);
1096                         return tempJSValue;
1097                 }
1098         }
1099         Catch(WrtDeviceApis::Commons::Exception)
1100         {
1101                 LoggerW("trying to get incorrect value");
1102         }
1103
1104         return JSValueMakeUndefined(context);
1105 }
1106
1107 bool JSContact::setGroupIds(JSContextRef context,
1108                 JSObjectRef object,
1109                 JSStringRef propertyName,
1110                 JSValueRef value,
1111                 JSValueRef* exception)
1112 {
1113         Try
1114         {
1115                 ContactPtr contact = getPrivData(object);
1116                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1117                 contact->setGroupIds(converter->toStringArray(value));
1118                 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
1119                 newContactT->resetGroupIdsJSObj();
1120         }
1121         Catch(WrtDeviceApis::Commons::Exception)
1122         {
1123                 LoggerW("trying to set incorrect value");
1124                 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch");
1125         }
1126
1127         return true;
1128 }
1129
1130 JSValueRef JSContact::convertToString(JSContextRef context,
1131                 JSObjectRef object,
1132                 JSObjectRef thisObject,
1133                 size_t argumentCount,
1134                 const JSValueRef arguments[],
1135                 JSValueRef* exception)
1136 {
1137         LoggerD("entered");
1138         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1139         ContactPtr contact(NULL);
1140
1141         Try     {
1142                 contact = getPrivData(thisObject);
1143                 if (contact == NULL) {
1144                         ThrowMsg(InvalidArgumentException, "No private object.");
1145                 }
1146         } Catch(Exception) {
1147                 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
1148                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1149         }
1150
1151 //      AceSecurityStatus status = CONTACT_CHECK_ACCESS(
1152 //      CONTACT_FUNCTION_API_CONVERT_TO_STRING);
1153 //      TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1154
1155         std::string format;
1156         if(argumentCount > 0){
1157         ArgumentValidator validator(context, argumentCount, arguments);
1158         try     {
1159                 format = validator.toString(0, false);
1160         } catch (const TypeMismatchException& err ) {
1161                 return JSWebAPIErrorFactory::postException(context, exception, err);
1162         } catch(const BasePlatformException& err) {
1163                 return JSWebAPIErrorFactory::postException(context, exception, err);
1164         } catch(const ConversionException& err) {
1165                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1166         } catch(const NullPointerException& err) {
1167                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1168         }
1169         }else{
1170                 format = "VCARD_30";
1171         }
1172
1173         std::string vCard;
1174         Try {
1175                 vCard = contact->convertToString(format);
1176         } Catch(ConversionException) {
1177                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1178                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
1179         } Catch(UnsupportedException) {
1180                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1181                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, "Only support vCard 3.0");
1182         } Catch(Exception) {
1183                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1184                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1185         }
1186
1187         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1188         JSValueRef result;
1189         Try {
1190                 result = converter->toJSValueRef(vCard);
1191         } Catch(Exception) {
1192                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1193                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1194         }
1195         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1196         return result;
1197 }
1198
1199 JSValueRef JSContact::clone(JSContextRef context,
1200                 JSObjectRef object,
1201                 JSObjectRef thisObject,
1202                 size_t argumentCount,
1203                 const JSValueRef arguments[],
1204                 JSValueRef* exception)
1205 {
1206         LoggerD("entered");
1207         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1208         ContactPtr contact(NULL);
1209
1210         Try     {
1211                 contact = getPrivData(thisObject);
1212                 if (contact == NULL) {
1213                         ThrowMsg(InvalidArgumentException, "No private object.");
1214                 }
1215         } Catch(Exception) {
1216                 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
1217                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1218         }
1219
1220 //      AceSecurityStatus status = CONTACT_CHECK_ACCESS(
1221 //      CONTACT_FUNCTION_API_CONVERT_TO_STRING);
1222 //      TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1223
1224         ContactPtr clonedContact(NULL);
1225         Try {
1226                 clonedContact = contact->clone();
1227         } Catch(Exception) {
1228                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1229                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1230         }
1231
1232         JSValueRef result;
1233         Try {
1234                 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(thisObject));
1235                 if (!priv) {
1236                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
1237                 }
1238                 JSContextRef gContext = priv->getContext();
1239                 result = createJSObject(gContext, clonedContact);
1240         } Catch(Exception) {
1241                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1242                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1243         }
1244         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1245         return result;
1246 }
1247
1248 } // Contact
1249 } // DeviceAPI