upload tizen1.0 source
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Tizen / JSSortMode.cpp
index 26746bb..479e7bd 100755 (executable)
@@ -29,7 +29,6 @@
 #include <API/Filter/SortMode.h>
 #include <Tizen/Common/JSTizenExceptionFactory.h>
 #include <Tizen/Common/JSTizenException.h>
-#include <Tizen/Common/JSGlobalContextFactory.h>
 #include "FilterConverter.h"
 #include "JSSortMode.h"
 
@@ -109,16 +108,27 @@ SortModePtr JSSortMode::getSortMode(JSContextRef context, JSValueRef value)
        return priv->getObject();
 }
 
+JSObjectRef JSSortMode::createJSObject(JSContextRef context, SortModePtr privateData)
+{
+       JSSortModePriv *priv = new JSSortModePriv(context, privateData);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
 void JSSortMode::Initialize(JSContextRef context, JSObjectRef object)
 {
-//     if (!JSObjectGetPrivate(object))
-//     {
-//             SortModePtr coord(new SortMode(""));
-//             JSSortModePriv *priv = new JSSortModePriv(context, SortModePtr(coord));
-//             if (!JSObjectSetPrivate(object, priv)) {
-//                     delete priv;
-//             }
-//     }
+       if (!JSObjectGetPrivate(object))
+       {
+               SortModePtr sortMode(new SortMode(""));
+               JSSortModePriv *priv = new JSSortModePriv(context, SortModePtr(sortMode));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
 }
 
 void JSSortMode::Finalize(JSObjectRef object)
@@ -133,17 +143,6 @@ void JSSortMode::Finalize(JSObjectRef object)
        priv = NULL;
 }
 
-JSObjectRef JSSortMode::createJSObject(JSContextRef context, SortModePtr privateData)
-{
-       JSSortModePriv *priv = new JSSortModePriv(context, privateData);
-       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
-       if (NULL == jsObjectRef) {
-               LogError("object creation error");
-               return NULL;
-       }
-       return jsObjectRef;
-}
-
 SortModePtr JSSortMode::getPrivData(JSObjectRef object)
 {
        LogDebug("entered");
@@ -166,20 +165,22 @@ JSObjectRef JSSortMode::constructor(JSContextRef context,
 {
        LogDebug("entered");
 
-//     AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD);
+       bool js2ndParamIsString = false;
+
+//     AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADD);
 //     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-//     JSSortModePriv *priv = static_cast<JSSortModePriv*>(JSObjectGetPrivate(constructor));
-//     if (!priv) {
-//             ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
-//     }
-//     JSContextRef gContext = priv->getContext();
+       JSSortModePriv *priv = static_cast<JSSortModePriv*>(JSObjectGetPrivate(constructor));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       JSContextRef gContext = priv->getContext();
 
-       JSContextRef gContext = JSGlobalContextFactory::getInstance()->get();
+//     JSContextRef gContext = JSGlobalContextFactory::getInstance()->get();
 
        BasicValidator validator = BasicValidatorFactory::getValidator(gContext, exception);
        Try {
-               if (argumentCount < 1 || argumentCount > 2)
+               if (argumentCount < 1)
                        ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
 
                if (!JSValueIsString(gContext, arguments[0]))
@@ -187,12 +188,15 @@ JSObjectRef JSSortMode::constructor(JSContextRef context,
 
                if (argumentCount >= 2)
                {
-                       if (!JSValueIsString(gContext, arguments[1]) && !JSValueIsNull(gContext, arguments[1]))
+                       if (JSValueIsString(gContext, arguments[1]))
+                               js2ndParamIsString = true;
+
+                       if (!js2ndParamIsString &&
+                                       !JSValueIsNull(gContext, arguments[1]) &&
+                                       !JSValueIsUndefined(gContext, arguments[1]))
                                ThrowMsg(InvalidArgumentException, "2nd argument is not string.");
                }
 
-               // 3rd argument can be any type.
-
        } Catch(Exception ) {
                LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
                *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
@@ -213,12 +217,11 @@ JSObjectRef JSSortMode::constructor(JSContextRef context,
        }
 
        Try {
-               sortOrder = ASCENDING_SORT_ORDER;
-               if(argumentCount >= 2)
-               {
-                       if(JSValueIsString(gContext, arguments[1]))
-                               sortOrder = converter->toSortOrder(arguments[1]);
-               }
+               if(js2ndParamIsString)
+                       sortOrder = converter->toSortOrder(arguments[1]);
+               else
+                       sortOrder = ASCENDING_SORT_ORDER;
+
        } Catch(Exception) {
                LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
                *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");