2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "JSContactAddress.h"
19 #include "ContactAddress.h"
20 #include "ContactUtil.h"
23 #include <TimeTracer.h>
25 #include <ArgumentValidator.h>
32 using namespace DeviceAPI::Common;
34 struct ContactAddressHolder {
35 ContactAddressPtr ptr;
39 const char* CONTACT_CONTACT_ADDRESS = "ContactAddress";
41 const char* CONTACT_CONTACT_ADDRESS_COUNTRY = "country";
42 const char* CONTACT_CONTACT_ADDRESS_REGION = "region";
43 const char* CONTACT_CONTACT_ADDRESS_CITY = "city";
44 const char* CONTACT_CONTACT_ADDRESS_STREET_ADDRESS = "streetAddress";
45 const char* CONTACT_CONTACT_ADDRESS_ADDITIONAL_INFORMATION = "additionalInformation";
46 const char* CONTACT_CONTACT_ADDRESS_POSTAL_CODE = "postalCode";
47 const char* CONTACT_CONTACT_ADDRESS_IS_DEFAULT = "isDefault";
48 const char* CONTACT_CONTACT_ADDRESS_TYPES = "types";
49 const char* CONTACT_CONTACT_ADDRESS_LABEL = "label";
52 JSClassDefinition JSContactAddress::m_classInfo = {
54 kJSClassAttributeNone,
55 CONTACT_CONTACT_ADDRESS,
57 JSContactAddress::m_property,
59 JSContactAddress::initialize,
60 JSContactAddress::finalize,
64 NULL, //deleteProperty,
65 NULL, //getPropertyNames,
69 NULL, //convertToType,
72 JSStaticValue JSContactAddress::m_property[] = {
73 { CONTACT_CONTACT_ADDRESS_COUNTRY, getCountry, setCountry, kJSPropertyAttributeDontDelete },
74 { CONTACT_CONTACT_ADDRESS_REGION, getRegion, setRegion, kJSPropertyAttributeDontDelete },
75 { CONTACT_CONTACT_ADDRESS_CITY, getCity, setCity, kJSPropertyAttributeDontDelete },
76 { CONTACT_CONTACT_ADDRESS_STREET_ADDRESS, getStreetAddress, setStreetAddress, kJSPropertyAttributeDontDelete },
77 { CONTACT_CONTACT_ADDRESS_ADDITIONAL_INFORMATION, getAdditionalInformation, setAdditionalInformation, kJSPropertyAttributeDontDelete },
78 { CONTACT_CONTACT_ADDRESS_POSTAL_CODE, getPostalCode, setPostalCode, kJSPropertyAttributeDontDelete },
79 { CONTACT_CONTACT_ADDRESS_IS_DEFAULT, getIsDefault, setIsDefault, kJSPropertyAttributeDontDelete },
80 { CONTACT_CONTACT_ADDRESS_TYPES, getTypes, setTypes, kJSPropertyAttributeDontDelete },
81 { CONTACT_CONTACT_ADDRESS_LABEL, getLabel, setLabel, kJSPropertyAttributeDontDelete },
85 const JSClassDefinition* JSContactAddress::getClassInfo()
90 JSClassRef JSContactAddress::m_jsClassRef = JSClassCreate(JSContactAddress::getClassInfo());
92 JSClassRef DLL_EXPORT JSContactAddress::getClassRef()
95 m_jsClassRef = JSClassCreate(&m_classInfo);
100 ContactAddressPtr JSContactAddress::getPrivateObject(JSContextRef context, JSValueRef value)
102 if (!JSValueIsObjectOfClass(context, value, getClassRef())) {
103 LOGE("Type mismatch");
104 throw TypeMismatchException("Type mismatch");
107 JSObjectRef object = JSUtil::JSValueToObject(context, value);
108 ContactAddressHolder* priv = static_cast<ContactAddressHolder*>(JSObjectGetPrivate(object));
110 LOGE("Priv is null");
111 throw UnknownException("Priv is null");
116 void JSContactAddress::setPrivateObject(JSObjectRef object, ContactAddressPtr native)
118 ContactAddressHolder* priv = static_cast<ContactAddressHolder*>(JSObjectGetPrivate(object));
120 LOGE("Priv is null");
121 throw UnknownException("Priv is null");
126 JSObjectRef JSContactAddress::makeJSObject(JSContextRef context,
127 ContactAddressPtr native)
130 LOGE("Native is null");
131 throw UnknownException("Native is null");
134 ContactAddressHolder* priv = new(std::nothrow) ContactAddressHolder();
136 LOGE("Priv is null");
137 throw UnknownException("Priv is null");
141 JSObjectRef obj = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
145 void JSContactAddress::initialize(JSContextRef context, JSObjectRef object)
150 void JSContactAddress::finalize(JSObjectRef object)
153 ContactAddressHolder* priv = static_cast<ContactAddressHolder*>(JSObjectGetPrivate(object));
155 JSObjectSetPrivate(object, NULL);
161 JSObjectRef DLL_EXPORT JSContactAddress::constructor(JSContextRef context,
162 JSObjectRef constructor,
163 size_t argumentCount,
164 const JSValueRef arguments[],
165 JSValueRef* exception)
169 ArgumentValidator validator(context, argumentCount, arguments);
171 JSObjectRef jsObjRef = JSObjectMake(context, getClassRef(), NULL);
173 JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
174 JSObjectSetProperty(context, jsObjRef, ctorName, constructor, kJSPropertyAttributeReadOnly
175 | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
176 JSStringRelease(ctorName);
179 JSObjectRef dictionary = NULL;
180 dictionary = validator.toObject(0, true);
182 ContactAddressPtr priv = ContactAddressPtr(new(std::nothrow) ContactAddress());
184 LOGE("Priv is null");
185 throw UnknownException("Priv is null");
189 JSValueRef country = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_COUNTRY);
190 JSValueRef region = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_REGION);
191 JSValueRef city = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_CITY);
192 JSValueRef street_address = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_STREET_ADDRESS);
193 JSValueRef additional_information = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_ADDITIONAL_INFORMATION);
194 JSValueRef postal_code = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_POSTAL_CODE);
195 JSValueRef is_default = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_IS_DEFAULT);
196 JSValueRef address_types = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_TYPES);
197 JSValueRef label = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_LABEL);
199 if (!JSValueIsUndefined(context, country)
200 && !JSValueIsNull(context, country)) {
201 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_COUNTRY, JSUtil::JSValueToString(context, country));
203 if (!JSValueIsUndefined(context, region)
204 && !JSValueIsNull(context, region)) {
205 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_REGION, JSUtil::JSValueToString(context, region));
207 if (!JSValueIsUndefined(context, city)
208 && !JSValueIsNull(context, city)) {
209 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_CITY, JSUtil::JSValueToString(context, city));
211 if (!JSValueIsUndefined(context, street_address)
212 && !JSValueIsNull(context, street_address)) {
213 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_STREETADDR, JSUtil::JSValueToString(context, street_address));
215 if (!JSValueIsUndefined(context, additional_information)
216 && !JSValueIsNull(context, additional_information)) {
217 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_ADDITIONALINFO, JSUtil::JSValueToString(context, additional_information));
219 if (!JSValueIsUndefined(context, postal_code)
220 && !JSValueIsNull(context, postal_code)) {
221 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_POSTALCODE, JSUtil::JSValueToString(context, postal_code));
223 if (!JSValueIsUndefined(context, is_default)) {
224 priv->setIsDefault(JSUtil::JSValueToBoolean(context, is_default));
226 if (!JSValueIsUndefined(context, address_types)) {
227 std::vector<std::string> str_types = JSUtil::JSArrayToStringVector(context, address_types);
228 size_t size = str_types.size();
230 for (size_t i = 0; i < size; i++) {
231 // Verification if string is actual from ContactEmailAddressType
232 ContactUtil::stringToContactAddressType(str_types[i]);
234 priv->setTypes(str_types);
237 if (!JSValueIsUndefined(context, label)
238 && !JSValueIsNull(context, label)) {
239 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_LABEL, JSUtil::JSValueToString(context, label));
243 ContactAddressHolder* holder = new(std::nothrow) ContactAddressHolder();
245 LOGE("Holder is null");
246 throw UnknownException("Holder is null");
249 JSObjectSetPrivate(jsObjRef, static_cast<void*>(holder));
251 catch (const BasePlatformException &error) {
252 LOGE("ContactAddress creation failed: %s", error.getMessage().c_str());
255 LOGE("ContactAddress creation failed");
261 JSValueRef JSContactAddress::getCountry(JSContextRef context,
263 JSStringRef propertyName,
264 JSValueRef* exception)
268 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
270 LOGE("Priv is null");
271 throw UnknownException("Priv is null");
273 if (!priv->isSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_COUNTRY)) {
274 return JSValueMakeNull(context);
276 return JSUtil::toJSValueRef(context, priv->getAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_COUNTRY));
278 catch (const BasePlatformException &error) {
279 LOGE("Failed to get contact address country. %s : %s", error.getName().c_str(), error.getMessage().c_str());
282 LOGE("Unsupported error while getting contact address country.");
284 return JSValueMakeUndefined(context);
287 JSValueRef JSContactAddress::getRegion(JSContextRef context,
289 JSStringRef propertyName,
290 JSValueRef* exception)
294 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
296 LOGE("Priv is null");
297 throw UnknownException("Priv is null");
299 if (!priv->isSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_REGION)) {
300 return JSValueMakeNull(context);
302 return JSUtil::toJSValueRef(context, priv->getAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_REGION));
304 catch (const BasePlatformException &error) {
305 LOGE("Failed to get contact address region. %s : %s", error.getName().c_str(), error.getMessage().c_str());
308 LOGE("Unsupported error while getting contact address region.");
310 return JSValueMakeUndefined(context);
313 JSValueRef JSContactAddress::getCity(JSContextRef context,
315 JSStringRef propertyName,
316 JSValueRef* exception)
320 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
322 LOGE("Priv is null");
323 throw UnknownException("Priv is null");
325 if (!priv->isSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_CITY)) {
326 return JSValueMakeNull(context);
328 return JSUtil::toJSValueRef(context, priv->getAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_CITY));
330 catch (const BasePlatformException &error) {
331 LOGE("Failed to get contact address city. %s : %s", error.getName().c_str(), error.getMessage().c_str());
334 LOGE("Unsupported error while getting contact address city.");
336 return JSValueMakeUndefined(context);
339 JSValueRef JSContactAddress::getStreetAddress(JSContextRef context,
341 JSStringRef propertyName,
342 JSValueRef* exception)
346 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
348 LOGE("Priv is null");
349 throw UnknownException("Priv is null");
351 if (!priv->isSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_STREETADDR)) {
352 return JSValueMakeNull(context);
354 return JSUtil::toJSValueRef(context, priv->getAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_STREETADDR));
356 catch (const BasePlatformException &error) {
357 LOGE("Failed to get contact address street address. %s : %s", error.getName().c_str(), error.getMessage().c_str());
360 LOGE("Unsupported error while getting contact address street address.");
362 return JSValueMakeUndefined(context);
365 JSValueRef JSContactAddress::getAdditionalInformation(JSContextRef context,
367 JSStringRef propertyName,
368 JSValueRef* exception)
372 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
374 LOGE("Priv is null");
375 throw UnknownException("Priv is null");
377 if (!priv->isSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_ADDITIONALINFO)) {
378 return JSValueMakeNull(context);
380 return JSUtil::toJSValueRef(context, priv->getAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_ADDITIONALINFO));
382 catch (const BasePlatformException &error) {
383 LOGE("Failed to get contact address additional information. %s : %s", error.getName().c_str(), error.getMessage().c_str());
386 LOGE("Unsupported error while getting contact address additional information.");
388 return JSValueMakeUndefined(context);
391 JSValueRef JSContactAddress::getPostalCode(JSContextRef context,
393 JSStringRef propertyName,
394 JSValueRef* exception)
398 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
400 LOGE("Priv is null");
401 throw UnknownException("Priv is null");
403 if (!priv->isSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_POSTALCODE)) {
404 return JSValueMakeNull(context);
406 return JSUtil::toJSValueRef(context, priv->getAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_POSTALCODE));
408 catch (const BasePlatformException &error) {
409 LOGE("Failed to get contact address postal code. %s : %s", error.getName().c_str(), error.getMessage().c_str());
412 LOGE("Unsupported error while getting contact address postal code.");
414 return JSValueMakeUndefined(context);
417 JSValueRef JSContactAddress::getIsDefault(JSContextRef context,
419 JSStringRef propertyName,
420 JSValueRef* exception)
424 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
426 LOGE("Priv is null");
427 throw UnknownException("Priv is null");
429 return JSUtil::toJSValueRef(context, priv->getIsDefault());
431 catch (const BasePlatformException &error) {
432 LOGE("Failed to get contact address is default flag. %s : %s", error.getName().c_str(), error.getMessage().c_str());
435 LOGE("Unsupported error while getting contact address is default flag.");
437 return JSValueMakeUndefined(context);
440 JSValueRef JSContactAddress::getTypes(JSContextRef context,
442 JSStringRef propertyName,
443 JSValueRef* exception)
447 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
449 LOGE("Priv is null");
450 throw UnknownException("Priv is null");
452 return priv->getJSTypes(GlobalContextManager::getInstance()->getGlobalContext(context));
454 catch (const BasePlatformException &error) {
455 LOGE("Failed to get contact address types. %s : %s", error.getName().c_str(), error.getMessage().c_str());
458 LOGE("Unsupported error while getting contact address types.");
460 return JSValueMakeUndefined(context);
463 JSValueRef JSContactAddress::getLabel(JSContextRef context,
465 JSStringRef propertyName,
466 JSValueRef* exception)
470 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
472 LOGE("Priv is null");
473 throw UnknownException("Priv is null");
475 if(!priv->isSet(CONTACT_ADDRESS_ATTRIBUTE_LABEL)) {
476 return JSValueMakeNull(context);
478 return JSUtil::toJSValueRef(context, priv->getAttribute(CONTACT_ADDRESS_ATTRIBUTE_LABEL));
480 catch (const BasePlatformException &error) {
481 LOGE("Failed to get contact address label. %s : %s", error.getName().c_str(), error.getMessage().c_str());
484 LOGE("Unsupported error while getting contact address label.");
486 return JSValueMakeUndefined(context);
489 bool JSContactAddress::setCountry(JSContextRef context,
491 JSStringRef propertyName,
493 JSValueRef* exception)
497 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
499 LOGE("Priv is null");
500 throw UnknownException("Priv is null");
502 if (JSValueIsNull(context, value)) {
503 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_COUNTRY, "");
504 priv->setIsSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_COUNTRY, false);
507 std::string _value = JSUtil::JSValueToString(context, value);
508 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_COUNTRY, _value);
510 catch (const BasePlatformException &error) {
511 LOGE("Failed to set contact address country. %s : %s", error.getName().c_str(), error.getMessage().c_str());
514 LOGE("Unsupported error while setting contact address country.");
519 bool JSContactAddress::setRegion(JSContextRef context,
521 JSStringRef propertyName,
523 JSValueRef* exception)
527 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
529 LOGE("Priv is null");
530 throw UnknownException("Priv is null");
532 if (JSValueIsNull(context, value)) {
533 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_REGION, "");
534 priv->setIsSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_REGION, false);
537 std::string _value = JSUtil::JSValueToString(context, value);
538 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_REGION, _value);
540 catch (const BasePlatformException &error) {
541 LOGE("Failed to set contact address region. %s : %s", error.getName().c_str(), error.getMessage().c_str());
544 LOGE("Unsupported error while setting contact address region.");
549 bool JSContactAddress::setCity(JSContextRef context,
551 JSStringRef propertyName,
553 JSValueRef* exception)
557 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
559 LOGE("Priv is null");
560 throw UnknownException("Priv is null");
562 if (JSValueIsNull(context, value)) {
563 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_CITY, "");
564 priv->setIsSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_CITY, false);
567 std::string _value = JSUtil::JSValueToString(context, value);
568 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_CITY, _value);
570 catch (const BasePlatformException &error) {
571 LOGE("Failed to set contact address city. %s : %s", error.getName().c_str(), error.getMessage().c_str());
574 LOGE("Unsupported error while setting contact address city.");
579 bool JSContactAddress::setStreetAddress(JSContextRef context,
581 JSStringRef propertyName,
583 JSValueRef* exception)
587 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
589 LOGE("Priv is null");
590 throw UnknownException("Priv is null");
592 if (JSValueIsNull(context, value)) {
593 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_STREETADDR, "");
594 priv->setIsSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_STREETADDR, false);
597 std::string _value = JSUtil::JSValueToString(context, value);
598 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_STREETADDR, _value);
600 catch (const BasePlatformException &error) {
601 LOGE("Failed to set contact address street address. %s : %s", error.getName().c_str(), error.getMessage().c_str());
604 LOGE("Unsupported error while setting contact address street address.");
609 bool JSContactAddress::setAdditionalInformation(JSContextRef context,
611 JSStringRef propertyName,
613 JSValueRef* exception)
617 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
619 LOGE("Priv is null");
620 throw UnknownException("Priv is null");
622 if (JSValueIsNull(context, value)) {
623 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_ADDITIONALINFO, "");
624 priv->setIsSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_ADDITIONALINFO, false);
627 std::string _value = JSUtil::JSValueToString(context, value);
628 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_ADDITIONALINFO, _value);
630 catch (const BasePlatformException &error) {
631 LOGE("Failed to set contact address additional information. %s : %s", error.getName().c_str(), error.getMessage().c_str());
634 LOGE("Unsupported error while setting contact address additional information.");
639 bool JSContactAddress::setPostalCode(JSContextRef context,
641 JSStringRef propertyName,
643 JSValueRef* exception)
647 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
649 LOGE("Priv is null");
650 throw UnknownException("Priv is null");
652 if (JSValueIsNull(context, value)) {
653 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_POSTALCODE, "");
654 priv->setIsSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_POSTALCODE, false);
657 std::string _value = JSUtil::JSValueToString(context, value);
658 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_POSTALCODE, _value);
660 catch (const BasePlatformException &error) {
661 LOGE("Failed to set contact address postal code. %s : %s", error.getName().c_str(), error.getMessage().c_str());
664 LOGE("Unsupported error while setting contact address postal code.");
669 bool JSContactAddress::setIsDefault(JSContextRef context,
671 JSStringRef propertyName,
673 JSValueRef* exception)
677 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
679 LOGE("Priv is null");
680 throw UnknownException("Priv is null");
682 bool is_default = JSUtil::JSValueToBoolean(context, value);
683 priv->setIsDefault(is_default);
685 catch (const BasePlatformException &error) {
686 LOGE("Failed to set contact address is default flag. %s : %s", error.getName().c_str(), error.getMessage().c_str());
689 LOGE("Unsupported error while setting contact address is default flag.");
694 bool JSContactAddress::setTypes(JSContextRef context,
696 JSStringRef propertyName,
698 JSValueRef* exception)
702 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
704 LOGE("Priv is null");
705 throw UnknownException("Priv is null");
707 std::vector<std::string> str_types = JSUtil::JSArrayToStringVector(context, value);
708 size_t size = str_types.size();
710 for (size_t i = 0; i < size; i++) {
711 // Verification if string is actual from ContactEmailAddressType
712 ContactUtil::stringToContactAddressType(str_types[i]);
714 priv->setTypes(str_types);
717 catch (const BasePlatformException &error) {
718 LOGE("Failed to set contact address types. %s : %s", error.getName().c_str(), error.getMessage().c_str());
721 LOGE("Unsupported error while setting contact address types.");
726 bool JSContactAddress::setLabel(JSContextRef context,
728 JSStringRef propertyName,
730 JSValueRef* exception)
734 ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
736 LOGE("Priv is null");
737 throw UnknownException("Priv is null");
739 if (JSValueIsNull(context, value)) {
740 priv->setIsSet(CONTACT_ADDRESS_ATTRIBUTE_LABEL, false);
743 std::string _value = JSUtil::JSValueToString(context, value);
744 priv->setAttribute(CONTACT_ADDRESS_ATTRIBUTE_LABEL, _value);
746 catch (const BasePlatformException &error) {
747 LOGE("Failed to set contact address label. %s : %s", error.getName().c_str(), error.getMessage().c_str());
750 LOGE("Unsupported error while setting contact address label.");