[gjs] GIRepositoryNamespace: define properties early to avoid reentrancy



commit 327399a4282c0cb4c2dc2eace62368b8fc4ec263
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Wed Jun 22 20:06:03 2011 +0200

    GIRepositoryNamespace: define properties early to avoid reentrancy
    
    It could happen that an override module requires a class which
    inherits from another defined in the overridden module. In the case,
    defining the imported class would reimport the namespace and obtain
    an undefined object, causing an invalid prototype.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=622921

 gi/repo.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/gi/repo.c b/gi/repo.c
index 955f561..5c9b3a4 100644
--- a/gi/repo.c
+++ b/gi/repo.c
@@ -108,6 +108,14 @@ resolve_namespace_object(JSContext  *context,
     namespace = gjs_create_ns(context, ns_name, repo);
     JS_AddObjectRoot(context, &namespace);
 
+    /* Define the property early, to avoid reentrancy issues if
+       the override module looks for namespaces that import this */
+    if (!JS_DefineProperty(context, repo_obj,
+                           ns_name, OBJECT_TO_JSVAL(namespace),
+                           NULL, NULL,
+                           GJS_MODULE_PROP_FLAGS))
+        gjs_fatal("no memory to define ns property");
+
     override = lookup_override_function(context, ns_name);
     if (override && !JS_CallFunctionValue (context,
                                            namespace, /* thisp */
@@ -120,12 +128,6 @@ resolve_namespace_object(JSContext  *context,
         return NULL;
     }
 
-    if (!JS_DefineProperty(context, repo_obj,
-                           ns_name, OBJECT_TO_JSVAL(namespace),
-                           NULL, NULL,
-                           GJS_MODULE_PROP_FLAGS))
-        gjs_fatal("no memory to define ns property");
-
     gjs_debug(GJS_DEBUG_GNAMESPACE,
               "Defined namespace '%s' %p in GIRepository %p", ns_name, namespace, repo_obj);
 



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