[gjs] Use separate SetPrototype() and SetParent calls



commit f0473a63dca1eb6ad9dbf8f18370ebf7ed296a64
Author: Colin Walters <walters verbum org>
Date:   Tue Sep 21 10:55:22 2010 -0400

    Use separate SetPrototype() and SetParent calls
    
    In XULRunner 1.9.3, passing a custom prototype or parent to
    JS_ConstructObject for Object fails, so work around with a separate calls
    to SetPrototype()/SetParent().
    See https://bugzilla.mozilla.org/show_bug.cgi?id=599651.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=622896

 gi/enumeration.c |    8 ++++++--
 gi/repo.c        |    5 ++++-
 gjs/importer.c   |    8 ++++++--
 modules/dbus.c   |    9 ++++++++-
 4 files changed, 24 insertions(+), 6 deletions(-)
---
diff --git a/gi/enumeration.c b/gi/enumeration.c
index 329b3a7..34f9e36 100644
--- a/gi/enumeration.c
+++ b/gi/enumeration.c
@@ -137,11 +137,15 @@ gjs_define_enumeration(JSContext    *context,
         return JS_TRUE;
     }
 
-    enum_obj = JS_ConstructObject(context, NULL, NULL,
-                                  gjs_get_import_global(context));
+    enum_obj = JS_ConstructObject(context, NULL, NULL, NULL);
     if (enum_obj == NULL)
         return JS_FALSE;
 
+    /* https://bugzilla.mozilla.org/show_bug.cgi?id=599651 means we
+     * can't just pass in the global as the parent */
+    JS_SetParent(context, enum_obj,
+                 gjs_get_import_global (context));
+
     /* Fill in enum values first, so we don't define the enum itself until we're
      * sure we can finish successfully.
      */
diff --git a/gi/repo.c b/gi/repo.c
index 7efd9f4..803238d 100644
--- a/gi/repo.c
+++ b/gi/repo.c
@@ -283,7 +283,10 @@ repo_new(JSContext *context)
         return JS_FALSE;
     }
 
-    versions = JS_ConstructObject(context, NULL, NULL, global);
+    versions = JS_ConstructObject(context, NULL, NULL, NULL);
+    /* https://bugzilla.mozilla.org/show_bug.cgi?id=599651 means we
+     * can't just pass in the global as the parent */
+    JS_SetParent(context, versions, global);
 
     JS_DefineProperty(context, repo,
                       "versions",
diff --git a/gjs/importer.c b/gjs/importer.c
index 5265e93..0c6f6f3 100644
--- a/gjs/importer.c
+++ b/gjs/importer.c
@@ -285,12 +285,16 @@ load_module_init(JSContext  *context,
         }
     }
 
-    module_obj = JS_NewObject(context, NULL, NULL,
-                              gjs_get_import_global(context));
+    module_obj = JS_NewObject(context, NULL, NULL, NULL);
     if (module_obj == NULL) {
         return JS_FALSE;
     }
 
+    /* https://bugzilla.mozilla.org/show_bug.cgi?id=599651 means we
+     * can't just pass in the global as the parent */
+    JS_SetParent(context, module_obj,
+                 gjs_get_import_global (context));
+
     /* Define module in importer for future use and to avoid module_obj
      * object to be garbage collected during the evaluation of the script */
     JS_DefineProperty(context, in_object,
diff --git a/modules/dbus.c b/modules/dbus.c
index 0222ab3..eade473 100644
--- a/modules/dbus.c
+++ b/modules/dbus.c
@@ -1750,9 +1750,16 @@ define_bus_object(JSContext  *context,
     bus_val = JSVAL_VOID;
     JS_AddValueRoot(context, &bus_val);
 
-    bus_obj = JS_ConstructObject(context, NULL, proto_obj, NULL);
+    bus_obj = JS_ConstructObject(context, NULL, NULL, NULL);
     if (bus_obj == NULL)
         goto out;
+    /* We need to use a separate call to SetPrototype to work
+     * around a SpiderMonkey bug where with clasp=NULL, the
+     * parent and proto arguments to JS_ConstructObject are
+     * lost.
+     * https://bugzilla.mozilla.org/show_bug.cgi?id=599651
+     */
+    JS_SetPrototype(context, bus_obj, proto_obj);
 
     bus_val = OBJECT_TO_JSVAL(bus_obj);
 



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