[gjs] xul2: use JS_NewCompartmentAndGlobalObject



commit 950d000d94cef63496747119e7822f9978088864
Author: Marc-Antoine Perennou <Marc-Antoine Perennou com>
Date:   Sun Jan 16 20:31:45 2011 +0100

    xul2: use JS_NewCompartmentAndGlobalObject
    
    Use JS_NewCompartmentAndGlobalObject rather than JS_NewGlobalObject
    to be sure that cx->compartment is not NULL when initializing context.
    It basicaly does the same, but it creates a temporary compartment
    before creating the global object, and then restore the previous one.
    This avoids a segfault with xulrunner from hg
    
    https://bugzilla.gnome.org/show_bug.cgi?id=639691

 configure.ac     |    3 +++
 gjs/jsapi-util.c |    6 +++++-
 2 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8f3db85..4f84e56 100644
--- a/configure.ac
+++ b/configure.ac
@@ -160,6 +160,9 @@ if `$PKG_CONFIG --exists $JS_PACKAGE '>=' 2`; then
               , [$JS_LIBS])
   AC_CHECK_LIB([mozjs], [JS_EndPC], AC_DEFINE([HAVE_JS_ENDPC], [1], [Define if we have JS_EndPC]),
               , [$JS_LIBS])
+  AC_CHECK_LIB([mozjs], [JS_NewCompartmentAndGlobalObject], 
+              AC_DEFINE([HAVE_JS_NEWCOMPARTMENTANDGLOBALOBJECT], [1], [Define if we have JS_NewCompartmentAndGlobalObject]),
+              , [$JS_LIBS])
 
 else
   AC_MSG_RESULT([no])
diff --git a/gjs/jsapi-util.c b/gjs/jsapi-util.c
index d94614c..e038762 100644
--- a/gjs/jsapi-util.c
+++ b/gjs/jsapi-util.c
@@ -255,7 +255,11 @@ gjs_init_context_standard (JSContext       *context)
 {
     JSObject *global;
 #ifdef HAVE_MOZJS_2
+#ifdef HAVE_JS_NEWCOMPARTMENTANDGLOBALOBJECT
+    global = JS_NewCompartmentAndGlobalObject(context, &global_class, NULL);
+#else
     global = JS_NewGlobalObject(context, &global_class);
+#endif /* HAVE_JS_NEWCOMPARTMENTANDGLOBALOBJECT */
     if (global == NULL)
         return FALSE;
 #else
@@ -263,7 +267,7 @@ gjs_init_context_standard (JSContext       *context)
     if (global == NULL)
         return FALSE;
     JS_SetGlobalObject(context, global);
-#endif
+#endif /* HAVE_MOZJS_2 */
     if (!JS_InitStandardClasses(context, global))
         return FALSE;
     return TRUE;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]