summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiovanni Campagna <gcampagna@src.gnome.org>2011-06-22 20:06:03 +0200
committerGiovanni Campagna <gcampagna@src.gnome.org>2011-06-23 22:34:15 +0200
commit327399a4282c0cb4c2dc2eace62368b8fc4ec263 (patch)
treed7e7238fd5368eeba128b975f6683c0a5136c110
parent452dfc70c59ad3bd03bbac28215a8bbac90c6cff (diff)
downloadgjs-327399a4282c0cb4c2dc2eace62368b8fc4ec263.tar.gz
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
-rw-r--r--gi/repo.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/gi/repo.c b/gi/repo.c
index 955f5614..5c9b3a43 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);