[gjs/wip/require: 24/29] ns: Add gjs_import_gi_module
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/require: 24/29] ns: Add gjs_import_gi_module
- Date: Wed, 15 Jan 2014 16:20:23 +0000 (UTC)
commit ca9587b21bcc9f41f72942e4d27f61e2270a635b
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Thu Jan 2 15:30:15 2014 -0500
ns: Add gjs_import_gi_module
This returns the bare module, and doesn't run overrides or anything like
that yet... that will have to wait until after we get our new importer
scheme working...
gi/ns.cpp | 33 ++++++++++++++++++++++++++-------
gi/ns.h | 6 ++++--
gi/repo.cpp | 25 +++++--------------------
3 files changed, 35 insertions(+), 29 deletions(-)
---
diff --git a/gi/ns.cpp b/gi/ns.cpp
index f3d116b..1a55849 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -172,9 +172,10 @@ JSFunctionSpec gjs_ns_proto_funcs[] = {
{ NULL }
};
-static JSObject*
+static JSBool
ns_new(JSContext *context,
- const char *ns_name)
+ const char *ns_name,
+ JSObject **module_out)
{
JSObject *ns;
JSObject *global;
@@ -232,12 +233,30 @@ ns_new(JSContext *context,
priv = priv_from_js(context, ns);
priv->gi_namespace = g_strdup(ns_name);
- return ns;
+ *module_out = ns;
+ return JS_TRUE;
}
-JSObject*
-gjs_create_ns(JSContext *context,
- const char *ns_name)
+gboolean
+gjs_import_gi_module(JSContext *context,
+ const char *module_name,
+ const char *module_version,
+ JSObject **module_out)
{
- return ns_new(context, ns_name);
+ GIRepository *repo = g_irepository_get_default();
+ gboolean ret = FALSE;
+ GError *error = NULL;
+
+ if (!g_irepository_require(repo, module_name, module_version, (GIRepositoryLoadFlags) 0, &error)) {
+ gjs_throw_g_error(context, error);
+ goto out;
+ }
+
+ if (!ns_new(context, module_name, module_out))
+ goto out;
+
+ ret = TRUE;
+ out:
+ g_clear_error(&error);
+ return ret;
}
diff --git a/gi/ns.h b/gi/ns.h
index c6a1b89..55d6c13 100644
--- a/gi/ns.h
+++ b/gi/ns.h
@@ -30,8 +30,10 @@
G_BEGIN_DECLS
-JSObject* gjs_create_ns(JSContext *context,
- const char *ns_name);
+gboolean gjs_import_gi_module(JSContext *context,
+ const char *module_name,
+ const char *module_version,
+ JSObject **module_out);
G_END_DECLS
diff --git a/gi/repo.cpp b/gi/repo.cpp
index fef7eae..aad08f0 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -90,9 +90,7 @@ resolve_namespace_object(JSContext *context,
jsid ns_id,
const char *ns_name)
{
- GIRepository *repo;
- GError *error;
- char *version;
+ char *version = NULL;
JSObject *override;
jsval result;
JSObject *gi_namespace = NULL;
@@ -103,27 +101,13 @@ resolve_namespace_object(JSContext *context,
if (!get_version_for_ns(context, repo_obj, ns_id, &version))
goto out;
- repo = g_irepository_get_default();
-
- error = NULL;
- g_irepository_require(repo, ns_name, version, (GIRepositoryLoadFlags) 0, &error);
- if (error != NULL) {
- gjs_throw(context,
- "Requiring %s, version %s: %s",
- ns_name, version?version:"none", error->message);
-
- g_error_free(error);
- g_free(version);
- goto out;
- }
-
- g_free(version);
-
/* Defines a property on "obj" (the javascript repo object)
* with the given namespace name, pointing to that namespace
* in the repo.
*/
- gi_namespace = gjs_create_ns(context, ns_name);
+ if (!gjs_import_gi_module(context, ns_name, version, &gi_namespace))
+ goto out;
+
JS_AddObjectRoot(context, &gi_namespace);
/* Define the property early, to avoid reentrancy issues if
@@ -149,6 +133,7 @@ resolve_namespace_object(JSContext *context,
ret = JS_TRUE;
out:
+ g_free(version);
if (gi_namespace)
JS_RemoveObjectRoot(context, &gi_namespace);
JS_EndRequest(context);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]