Update wrt-plugins-common_0.3.53
[framework/web/wrt-plugins-common.git] / src / CommonsJavaScript / JSCallbackManager.cpp
index db5dce7..21d278a 100644 (file)
@@ -68,6 +68,7 @@ JSCallbackManager::JSCallbackManager(JSContextRef context,
         JSObjectRef onError) :
     m_onSuccess(NULL),
     m_onError(NULL),
+    m_object(NULL),
     m_context(context)
 {
     LogDebug("entered");
@@ -87,21 +88,27 @@ JSCallbackManager::~JSCallbackManager()
     if (m_onError) {
         JSValueUnprotect(m_context, m_onError);
     }
+
+    if (m_object) {
+        JSValueUnprotect(m_context, m_object);
+    }
 }
 
 void JSCallbackManager::setOnSuccess(JSValueRef onSuccess)
 {
     LogDebug("entered");
-    if (onSuccess) {
-        if (m_onSuccess != NULL) {
-            JSValueUnprotect(m_context, m_onSuccess);
-        }
+    if (m_onSuccess != NULL) {
+        JSValueUnprotect(m_context, m_onSuccess);
+    }
 
+    if (onSuccess) {
         m_onSuccess = JSValueToObject(m_context, onSuccess, NULL);
+    } else {
+        m_onSuccess = NULL;
+    }
 
-        if (m_onSuccess != NULL) {
-            JSValueProtect(m_context, m_onSuccess);
-        }
+    if (m_onSuccess != NULL) {
+        JSValueProtect(m_context, m_onSuccess);
     }
 }
 
@@ -114,16 +121,18 @@ JSValueRef JSCallbackManager::getOnSuccess() const
 void JSCallbackManager::setOnError(JSValueRef onError)
 {
     LogDebug("entered");
-    if (onError) {
-        if (m_onError != NULL) {
-            JSValueUnprotect(m_context, m_onError);
-        }
+    if (m_onError != NULL) {
+        JSValueUnprotect(m_context, m_onError);
+    }
 
+    if (onError) {
         m_onError = JSValueToObject(m_context, onError, NULL);
+    } else {
+        m_onError = NULL;
+    }
 
-        if (m_onError != NULL) {
-            JSValueProtect(m_context, m_onError);
-        }
+    if (m_onError != NULL) {
+        JSValueProtect(m_context, m_onError);
     }
 }
 
@@ -133,6 +142,26 @@ JSValueRef JSCallbackManager::getOnError() const
     return m_onError;
 }
 
+void JSCallbackManager::setObject(JSObjectRef object)
+{
+    LogDebug("entered");
+    if (m_object != NULL) {
+        JSValueUnprotect(m_context, m_object);
+    }
+
+    m_object = object;
+
+    if (m_object != NULL) {
+        JSValueProtect(m_context, m_object);
+    }
+}
+
+JSObjectRef JSCallbackManager::getObject() const
+{
+    LogDebug("entered");
+    return m_object;
+}
+
 void JSCallbackManager::setContext(JSContextRef context)
 {
     LogDebug("entered");