wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Contact / JSContactPhoneNumberTypeArray.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        JSContactPhoneNumberTypeArray.cpp
20  * @author      Kisub Song (kisubs.song@samsung.com)
21  * @version     0.1
22  * @brief
23  */
24
25 #include <algorithm>
26 #include <CommonsJavaScript/Converter.h>
27 #include <CommonsJavaScript/ScopedJSStringRef.h>
28 #include <JSTizenExceptionFactory.h>
29 #include <JSTizenException.h>
30 #include "ContactConverter.h"
31 #include "JSContactPhoneNumberTypeArray.h"
32 #include <Logger.h>
33
34 #define FUNCTION_CONCAT "concat"
35 #define FUNCTION_JOIN "join"
36 #define FUNCTION_POP "pop"
37 #define FUNCTION_PUSH "push"
38 #define FUNCTION_REVERSE "reverse"
39 #define FUNCTION_SHIFT "shift"
40 #define FUNCTION_SLICE "slice"
41 #define FUNCTION_SORT "sort"
42 #define FUNCTION_SPLICE "splice"
43 #define FUNCTION_TOSTRING "toString"
44 #define FUNCTION_UNSHIFT "unshift"
45 #define FUNCTION_VALUEOF "valueOf"
46 #define ARRAY "Array"
47 #define ATTRIBUTE_LENGTH "length"
48
49 namespace DeviceAPI {
50 namespace Contact {
51
52 using namespace DeviceAPI::Common;
53 using namespace WrtDeviceApis::CommonsJavaScript;
54
55 JSClassDefinition JSContactPhoneNumberTypeArray::m_classInfo = {
56         0,
57         kJSClassAttributeNone,
58         ARRAY,
59         0,
60         m_property,
61         m_function,
62         initialize,
63         finalize,
64         hasProperty,
65         getProperty,
66         setProperty,
67         deleteProperty,
68         getPropertyNames,
69         NULL, //callAsFunction,
70         NULL, //callAsConstructor,
71         NULL, //hasInstance,
72         NULL, //convertToType,
73 };
74
75 JSStaticValue JSContactPhoneNumberTypeArray::m_property[] = {
76         { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
77         { 0, 0, 0, 0 }
78 };
79
80 JSStaticFunction JSContactPhoneNumberTypeArray::m_function[] = {
81         { FUNCTION_CONCAT, concat, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
82         { FUNCTION_JOIN, join, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
83         { FUNCTION_POP, pop, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
84         { FUNCTION_PUSH, push, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
85         { FUNCTION_REVERSE, reverse, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
86         { FUNCTION_SHIFT, shift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
87         { FUNCTION_SLICE, slice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
88         { FUNCTION_SORT, sort, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
89         { FUNCTION_SPLICE, splice, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
90         { FUNCTION_TOSTRING, toString, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
91         { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
92         { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
93         { 0, 0, 0 }
94 };
95
96 JSClassRef JSContactPhoneNumberTypeArray::m_jsClassRef = JSClassCreate(
97                 JSContactPhoneNumberTypeArray::getClassInfo());
98
99 JSValueRef JSContactPhoneNumberTypeArray::getLength(JSContextRef context,
100                 JSObjectRef object,
101                 JSStringRef propertyName,
102                 JSValueRef* exception)
103 {
104         Try
105         {
106                 JSContactPhoneNumberTypeArrayPriv* priv =
107                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
108                 if (!priv) {
109                         Throw(WrtDeviceApis::Commons::NullPointerException);
110                 }
111                 ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
112                 if (typeArray) {
113                         WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
114                                         WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
115                         return converter->toJSValueRef(typeArray->size());
116                 }
117         }
118         Catch(WrtDeviceApis::Commons::Exception)
119         {
120                 LoggerE("invalid conversion");
121         }
122         return JSValueMakeUndefined(context);
123 }
124
125 JSObjectRef JSContactPhoneNumberTypeArray::createArray(JSContextRef context,
126                 const ContactPhoneNumberTypeArrayPtr &typeArray)
127 {
128         JSContactPhoneNumberTypeArrayPriv *priv = new JSContactPhoneNumberTypeArrayPriv(context, typeArray);
129         return JSObjectMake(context, getClassRef(), priv);
130 }
131
132 const JSClassDefinition* JSContactPhoneNumberTypeArray::getClassInfo()
133 {
134         return &(m_classInfo);
135 }
136
137 JSClassRef JSContactPhoneNumberTypeArray::getClassRef()
138 {
139         if (!m_jsClassRef) {
140                 m_jsClassRef = JSClassCreate(&m_classInfo);
141         }
142         return m_jsClassRef;
143 }
144
145 bool JSContactPhoneNumberTypeArray::isObjectOfClass(JSContextRef context, JSValueRef value)
146 {
147         return JSValueIsObjectOfClass(context, value, getClassRef());
148 }
149
150 ContactPhoneNumberTypeArrayPtr JSContactPhoneNumberTypeArray::getContactPhoneNumberTypeArray(JSContextRef context, JSValueRef value)
151 {
152         if (!isObjectOfClass(context, value)) {
153                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
154         }
155         JSObjectRef object = JSValueToObject(context, value, NULL);
156         if (!object) {
157                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
158         }
159         JSContactPhoneNumberTypeArrayPriv *priv = static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
160         if (!priv) {
161                 Throw(WrtDeviceApis::Commons::NullPointerException);
162         }
163         return priv->getObject();
164 }
165
166 void JSContactPhoneNumberTypeArray::initialize(JSContextRef context,
167                 JSObjectRef object)
168 {
169 }
170
171 void JSContactPhoneNumberTypeArray::finalize(JSObjectRef object)
172 {
173         JSContactPhoneNumberTypeArrayPriv* priv =
174                 static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
175         delete priv;
176         JSObjectSetPrivate(object, NULL);
177 }
178
179 bool JSContactPhoneNumberTypeArray::hasProperty(JSContextRef context,
180                 JSObjectRef object,
181                 JSStringRef propertyName)
182 {
183         WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
184                         WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
185         Try
186         {
187                 size_t index = converter->toSizeT(propertyName);
188                 JSContactPhoneNumberTypeArrayPriv* priv =
189                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
190                 if (!priv) {
191                         Throw(WrtDeviceApis::Commons::NullPointerException);
192                 }
193                 ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
194                 if (index < typeArray->size()) {
195                         return true;
196                 }
197         }
198         Catch(WrtDeviceApis::Commons::Exception)
199         {
200                 //not reporting error is intended
201         }
202         return false;
203 }
204
205 JSValueRef JSContactPhoneNumberTypeArray::getProperty(JSContextRef context,
206                 JSObjectRef object,
207                 JSStringRef propertyName,
208                 JSValueRef* exception)
209 {
210         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
211         Try
212         {
213                 size_t index = converter->toSizeT(propertyName);
214                 JSContactPhoneNumberTypeArrayPriv* priv =
215                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
216                 if (!priv) {
217                         Throw(WrtDeviceApis::Commons::NullPointerException);
218                 }
219                 ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
220                 if (index < typeArray->size()) {
221                         std::string result = converter->toContactPhoneNumberTypeStr(typeArray->at(index));
222                         if (!result.empty()) {
223                                 return converter->toJSValueRef(result);
224                         }
225                 }
226         }
227         Catch(WrtDeviceApis::Commons::Exception)
228         {
229                 LoggerE("invalid property");
230         }
231         return JSValueMakeUndefined(context);
232 }
233
234 bool JSContactPhoneNumberTypeArray::setProperty(JSContextRef context,
235                 JSObjectRef object,
236                 JSStringRef propertyName,
237                 JSValueRef value,
238                 JSValueRef* exception)
239 {
240         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
241         Try
242         {
243                 size_t index = converter->toSizeT(propertyName);
244                 std::string str;
245                 if (!JSValueIsUndefined(context, value)) {
246                         str = converter->toString(value);
247                 }
248                 JSContactPhoneNumberTypeArrayPriv* priv =
249                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
250                 if (!priv) {
251                         Throw(WrtDeviceApis::Commons::NullPointerException);
252                 }
253                 ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
254                 if (!typeArray) {
255                         Throw(WrtDeviceApis::Commons::NullPointerException);
256                 }
257                 if (typeArray->size() <= index) {
258                         typeArray->resize(index + 1);
259                 }
260                 (*typeArray)[index] = converter->toContactPhoneNumberType(str);
261                 return true;
262         }
263         Catch(WrtDeviceApis::Commons::Exception)
264         {
265                 LoggerE("error occured");
266                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
267         }
268         return false;
269 }
270
271 bool JSContactPhoneNumberTypeArray::deleteProperty(JSContextRef context,
272                 JSObjectRef object,
273                 JSStringRef propertyName,
274                 JSValueRef* exception)
275 {
276         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
277         Try
278         {
279                 size_t index = converter->toSizeT(propertyName);
280                 JSContactPhoneNumberTypeArrayPriv* priv =
281                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
282                 if (!priv) {
283                         Throw(WrtDeviceApis::Commons::NullPointerException);
284                 }
285                 ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
286                 if (!typeArray) {
287                         Throw(WrtDeviceApis::Commons::NullPointerException);
288                 }
289                 if (typeArray->size() > index) {
290                         (*typeArray)[index] = converter->toContactPhoneNumberType("");
291                 }
292                 return true;
293         }
294         Catch(WrtDeviceApis::Commons::Exception)
295         {
296                 LoggerE("error occured");
297                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
298         }
299         return false;
300 }
301
302 void JSContactPhoneNumberTypeArray::getPropertyNames(JSContextRef context,
303                 JSObjectRef object,
304                 JSPropertyNameAccumulatorRef propertyNames)
305 {
306         ContactConverterFactory::ConverterType converter =
307                         ContactConverterFactory::getConverter(context);
308         Try
309         {
310                 JSContactPhoneNumberTypeArrayPriv* priv =
311                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
312                 if (!priv) {
313                         Throw(WrtDeviceApis::Commons::NullPointerException);
314                 }
315                 ContactPhoneNumberTypeArrayPtr phoneNumbers = priv->getObject();
316
317                 int count = phoneNumbers->size();
318
319                 for(int i=0; i < count; i++)
320                 {
321                         ScopedJSStringRef name(converter->toJSStringRef(converter->toString(i)));
322                         JSPropertyNameAccumulatorAddName(propertyNames, name.get());
323                 }
324         }
325         Catch(WrtDeviceApis::Commons::Exception)
326         {
327                 LoggerE("invalid property");
328         }
329 }
330
331 JSValueRef JSContactPhoneNumberTypeArray::concat(JSContextRef context,
332                 JSObjectRef function,
333                 JSObjectRef thisObject,
334                 size_t argumentCount,
335                 const JSValueRef arguments[],
336                 JSValueRef* exception)
337 {
338         Try
339         {
340                 ContactPhoneNumberTypeArrayPtr typeArray = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
341                 JSContactPhoneNumberTypeArrayPriv *newPrivateObject = new JSContactPhoneNumberTypeArrayPriv(
342                                 context,
343                                 typeArray);
344                 JSValueRef result = JSObjectMake(context,
345                                                                                  getClassRef(), newPrivateObject);
346
347                 //copy current typeArray
348                 JSContactPhoneNumberTypeArrayPriv* priv =
349                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
350                 ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
351                 for (size_t i = 0; i < currentStrings->size(); ++i) {
352                         typeArray->push_back(currentStrings->at(i));
353                 }
354
355                 //copy submitted arrays
356                 ContactConverterFactory::ConverterType converter =
357                                                 ContactConverterFactory::getConverter(context);
358                 for (size_t i = 0; i < argumentCount; ++i) {
359                         if (!JSIsArrayValue(context, arguments[i])) {
360                                 Throw(WrtDeviceApis::Commons::ConversionException);
361                         }
362                         // process array of strings
363                         JSObjectRef arrayObj = converter->toJSObjectRef(arguments[i]);
364                         unsigned int len = JSGetArrayLength(context, arrayObj);
365                         for (unsigned int e = 0; e < len; ++e) {
366                                 JSValueRef att = JSGetArrayElement(context, arrayObj, e);
367                                 typeArray->push_back(converter->toContactPhoneNumberType(att));
368                         }
369                 }
370                 return result;
371         }
372         Catch(WrtDeviceApis::Commons::Exception)
373         {
374                 LoggerE("error occured");
375         }
376         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
377 }
378
379 JSValueRef JSContactPhoneNumberTypeArray::join(JSContextRef context,
380                 JSObjectRef function,
381                 JSObjectRef thisObject,
382                 size_t argumentCount,
383                 const JSValueRef arguments[],
384                 JSValueRef* exception)
385 {
386         Try
387         {
388                 std::string result;
389                 std::string separator(",");
390                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
391                 JSContactPhoneNumberTypeArrayPriv* priv =
392                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
393                 ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
394                 if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
395                         separator = converter->toString(arguments[0]);
396                 }
397                 for (size_t i = 0; i < currentStrings->size(); ++i) {
398                         if (i != 0) {
399                                 result += separator;
400                         }
401                         result += currentStrings->at(i);
402                 }
403                 return converter->toJSValueRef(result);
404         }
405         Catch(WrtDeviceApis::Commons::Exception)
406         {
407                 LoggerE("error occured");
408         }
409         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
410 }
411
412 JSValueRef JSContactPhoneNumberTypeArray::pop(JSContextRef context,
413                 JSObjectRef function,
414                 JSObjectRef thisObject,
415                 size_t argumentCount,
416                 const JSValueRef arguments[],
417                 JSValueRef* exception)
418 {
419         Try
420         {
421                 ContactConverterFactory::ConverterType converter =
422                                                 ContactConverterFactory::getConverter(context);
423                 JSContactPhoneNumberTypeArrayPriv* priv =
424                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
425                 ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
426                 if (currentStrings->size() > 0) {
427                         std::string result =
428                                         converter->toContactPhoneNumberTypeStr(currentStrings->at(currentStrings->size() - 1));
429                         currentStrings->pop_back();
430                         return converter->toJSValueRef(result);
431                 }
432         }
433         Catch(WrtDeviceApis::Commons::Exception)
434         {
435                 LoggerE("error occured");
436         }
437         return JSValueMakeUndefined(context);
438 }
439
440 JSValueRef JSContactPhoneNumberTypeArray::push(JSContextRef context,
441                 JSObjectRef function,
442                 JSObjectRef thisObject,
443                 size_t argumentCount,
444                 const JSValueRef arguments[],
445                 JSValueRef* exception)
446 {
447         Try
448         {
449                 ContactConverterFactory::ConverterType converter =
450                                                 ContactConverterFactory::getConverter(context);
451                 JSContactPhoneNumberTypeArrayPriv* priv =
452                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
453                 ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
454                 for (size_t i = 0; i < argumentCount; ++i) {
455                         currentStrings->push_back(converter->toContactPhoneNumberType(arguments[i]));
456                 }
457                 return converter->toJSValueRef(currentStrings->size());
458         }
459         Catch(WrtDeviceApis::Commons::Exception)
460         {
461                 LoggerE("error occured");
462         }
463         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
464 }
465
466 JSValueRef JSContactPhoneNumberTypeArray::reverse(JSContextRef context,
467                 JSObjectRef function,
468                 JSObjectRef thisObject,
469                 size_t argumentCount,
470                 const JSValueRef arguments[],
471                 JSValueRef* exception)
472 {
473         Try
474         {
475                 WrtDeviceApis::CommonsJavaScript::Converter converter(context);
476                 JSContactPhoneNumberTypeArrayPriv* priv =
477                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
478                 ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
479                 std::reverse(currentStrings->begin(), currentStrings->end());
480                 return thisObject;
481         }
482         Catch(WrtDeviceApis::Commons::Exception)
483         {
484                 LoggerE("error occured");
485         }
486         return JSValueMakeUndefined(context);
487 }
488
489 JSValueRef JSContactPhoneNumberTypeArray::shift(JSContextRef context,
490                 JSObjectRef function,
491                 JSObjectRef thisObject,
492                 size_t argumentCount,
493                 const JSValueRef arguments[],
494                 JSValueRef* exception)
495 {
496         Try
497         {
498                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
499                 JSContactPhoneNumberTypeArrayPriv* priv =
500                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
501                 ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
502                 if (currentStrings->size() > 0) {
503                         std::string result = converter->toContactPhoneNumberTypeStr(currentStrings->at(0));
504                         currentStrings->erase(currentStrings->begin());
505                         return converter->toJSValueRef(result);
506                 }
507         }
508         Catch(WrtDeviceApis::Commons::Exception)
509         {
510                 LoggerE("error occured");
511         }
512         return JSValueMakeUndefined(context);
513 }
514
515 JSValueRef JSContactPhoneNumberTypeArray::slice(JSContextRef context,
516                 JSObjectRef function,
517                 JSObjectRef thisObject,
518                 size_t argumentCount,
519                 const JSValueRef arguments[],
520                 JSValueRef* exception)
521 {
522         Try
523         {
524                 if (argumentCount < 1) {
525                         return JSValueMakeUndefined(context);
526                 }
527                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
528                 ContactPhoneNumberTypeArrayPtr typeArray = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
529                 JSContactPhoneNumberTypeArrayPriv *newPrivateObject = new JSContactPhoneNumberTypeArrayPriv(
530                                 context,
531                                 typeArray);
532                 JSValueRef result = JSObjectMake(context,
533                                                                                  getClassRef(), newPrivateObject);
534
535                 //copy current typeArray
536                 JSContactPhoneNumberTypeArrayPriv* priv =
537                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
538                 ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
539                 std::size_t first = converter->toSizeT(arguments[0]);
540                 std::size_t last = currentStrings->size() - 1;
541                 if (argumentCount > 1) {
542                         last = converter->toSizeT(arguments[1]);
543                         if (last >= currentStrings->size()) {
544                                 last = currentStrings->size() - 1;
545                         }
546                 }
547                 for (size_t i = first; i <= last; ++i) {
548                         typeArray->push_back(currentStrings->at(i));
549                 }
550
551                 return result;
552         }
553         Catch(WrtDeviceApis::Commons::Exception)
554         {
555                 LoggerE("error occured");
556         }
557         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
558 }
559
560 JSValueRef JSContactPhoneNumberTypeArray::sort(JSContextRef context,
561                 JSObjectRef function,
562                 JSObjectRef thisObject,
563                 size_t argumentCount,
564                 const JSValueRef arguments[],
565                 JSValueRef* exception)
566 {
567         Try
568         {
569                 WrtDeviceApis::CommonsJavaScript::Converter converter(context);
570                 JSContactPhoneNumberTypeArrayPriv* priv =
571                         static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
572                 ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
573                 std::sort(currentStrings->begin(), currentStrings->end());
574                 return thisObject;
575         }
576         Catch(WrtDeviceApis::Commons::Exception)
577         {
578                 LoggerE("error occured");
579         }
580         return JSValueMakeUndefined(context);
581 }
582
583 JSValueRef JSContactPhoneNumberTypeArray::splice(JSContextRef context,
584                 JSObjectRef function,
585                 JSObjectRef thisObject,
586                 size_t argumentCount,
587                 const JSValueRef arguments[],
588                 JSValueRef* exception)
589 {
590         return JSValueMakeUndefined(context);
591 }
592
593 JSValueRef JSContactPhoneNumberTypeArray::toString(JSContextRef context,
594                 JSObjectRef function,
595                 JSObjectRef thisObject,
596                 size_t argumentCount,
597                 const JSValueRef arguments[],
598                 JSValueRef* exception)
599 {
600         return join(context, function, thisObject, 0, arguments, exception);
601 }
602
603 JSValueRef JSContactPhoneNumberTypeArray::unshift(JSContextRef context,
604                 JSObjectRef function,
605                 JSObjectRef thisObject,
606                 size_t argumentCount,
607                 const JSValueRef arguments[],
608                 JSValueRef* exception)
609 {
610         return JSValueMakeUndefined(context);
611 }
612
613 JSValueRef JSContactPhoneNumberTypeArray::valueOf(JSContextRef context,
614                 JSObjectRef function,
615                 JSObjectRef thisObject,
616                 size_t argumentCount,
617                 const JSValueRef arguments[],
618                 JSValueRef* exception)
619 {
620         return JSValueMakeUndefined(context);
621 }
622
623 } // Contact
624 } // DeviceAPI