Remove use of a global variable for JSContext on WidgetInterface plugin
authorTae-Jeong Lee <taejeong.lee@samsung.com>
Mon, 1 Jul 2013 07:01:54 +0000 (16:01 +0900)
committerTae-Jeong Lee <taejeong.lee@samsung.com>
Mon, 1 Jul 2013 11:41:07 +0000 (20:41 +0900)
[Issue#] N_SE-43838
[Problem] Initializing code of WidgetInterface Object has been randomly crashed.
          Unique WidgetInterface Object per page is not created.
[Cause] Current WidgetInterface Plugin is using only one global JSContextRef for every created pages.
[Solution] code regarding global variable for JSContextRef is removed

Change-Id: Ia8ce55c378c0800751517ea22246ced998632d2e

src/standards/W3C/Widget/JSWidget.cpp
src/standards/W3C/Widget/JSWidget.h
src/standards/W3C/Widget/plugin_initializer.cpp

index 8a6843c..f4b9684 100644 (file)
@@ -32,6 +32,9 @@
 #include <LocalStorage/LocalStorageMgr.h>
 #include <Commons/WrtAccess/WrtAccess.h>
 
+// temporary
+extern "C" JSGlobalContextRef JSContextGetGlobalContext(JSContextRef ctx);
+
 #define CATCH_EXCEPTION_NO_MODIFABLE \
     Catch(Commons::LocalStorageValueNoModifableException) { \
         LogError("The item is read only"); \
@@ -232,12 +235,17 @@ const JSClassDefinition* JSWidget::getClassInfo()
 
 JSClassRef JSWidget::m_jsClassRef = JSClassCreate(JSWidget::getClassInfo());
 
-JSContextRef JSWidget::m_globalContext = NULL;
-
 void JSWidget::initialize(JSContextRef context,
                           JSObjectRef object)
 {
-    LogDebug("entered. Context : " << context << ", Object: " << object);
+    JSGlobalContextRef g_context = JSContextGetGlobalContext(context);
+
+    LogDebug("entered. Context : " << context << "(global:" << g_context << "), Object: " << object);
+
+    if (context != g_context)
+    {
+        context = g_context;
+    }
 
     JSWidgetPrivateObject* priv =
         static_cast<JSWidgetPrivateObject*>(JSObjectGetPrivate(object));
@@ -295,18 +303,6 @@ void JSWidget::finalize(JSObjectRef object)
     }
 }
 
-void JSWidget::acquireGlobalContext(java_script_context_t global_context,
-                                    js_object_instance_t /*iframe*/,
-                                    js_object_instance_t /*object*/)
-{
-    if (!m_globalContext) {
-        m_globalContext = static_cast<JSContextRef>(global_context);
-        LogInfo("Global context acquired.");
-    } else {
-        LogInfo("Global context already set.");
-    }
-}
-
 JSValueRef JSWidget::getAuthor(JSContextRef context,
                                JSObjectRef object,
                                JSStringRef /*propertyName*/,
@@ -550,12 +546,7 @@ JSObjectRef JSWidget::callAsConstructor(JSContextRef context,
                                         JSValueRef* /*exception*/)
 {
     LogDebug("widget constructor");
-    if (!m_globalContext) {
-        LogError("Global context not set. Creating 'widget' object with "
-                 "local context!");
-        return JSObjectMake(context, JSWidget::getClassRef(), NULL);
-    }
-    return JSObjectMake(m_globalContext, JSWidget::getClassRef(), NULL);
+    return JSObjectMake(context, JSWidget::getClassRef(), NULL);
 }
 
 #undef CATCH_EXCEPTION_NO_MODIFABLE
index c0bf403..f1f979c 100644 (file)
@@ -49,18 +49,6 @@ class JSWidget
                                          const JSValueRef arguments[],
                                          JSValueRef* exception);
 
-    /**
-     * This function will acquire global context which is used later to
-     * keep JSValueProtect/Unprotect functionality working.
-     * This is workaround for JSCore semantic: when an object is created with
-     * JSObjectMakeConstructor a context passed to createCallback function
-     * is different (shorter lifecycle) than global context, so JSValueUnprotect
-     * called in finalize may fail because of invalid context.
-     */
-    static void acquireGlobalContext(java_script_context_t global_context,
-                                     js_object_instance_t iframe,
-                                     js_object_instance_t object);
-
   private:
     /**
      * The callback invoked when an object is first created.
@@ -86,11 +74,6 @@ class JSWidget
 
     static JSClassRef m_jsClassRef;
 
-    /**
-     * Global context acquired by acquireGlobalContext() function.
-     */
-    static JSContextRef m_globalContext;
-
     // getters for properties
     static JSValueRef getAuthor(JSContextRef context,
                                 JSObjectRef object,
index d296869..10cdea6 100644 (file)
@@ -44,7 +44,7 @@ class_definition_options_t WidgetOptions = {
     JS_CLASS,
     CREATE_INSTANCE,
     NONE_NOTICE,
-    USE_OVERLAYED, //ignored
+    IGNORED,
     NULL,
     NULL,
     NULL
@@ -53,9 +53,9 @@ class_definition_options_t WidgetOptions = {
 class_definition_options_t WidgetInterfaceOptions = {
     JS_INTERFACE,
     CREATE_INSTANCE,
-    ALWAYS_NOTICE,
-    USE_OVERLAYED, //ignored
-    JSWidget::acquireGlobalContext,
+    NONE_NOTICE,
+    IGNORED, //ignored
+    NULL,
     NULL,
     NULL
 };