[gjs] repo: Move version getting code to its own function
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] repo: Move version getting code to its own function
- Date: Tue, 1 Oct 2013 22:37:51 +0000 (UTC)
commit 4ec46708eb89bdcb0e9b5fa5f9a4ff1292baa9f2
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Mon Jul 1 22:25:45 2013 -0400
repo: Move version getting code to its own function
This makes the code a lot easier to read.
gi/repo.c | 49 +++++++++++++++++++++++++++++++------------------
1 files changed, 31 insertions(+), 18 deletions(-)
---
diff --git a/gi/repo.c b/gi/repo.c
index 6338478..65cc5dd 100644
--- a/gi/repo.c
+++ b/gi/repo.c
@@ -56,41 +56,54 @@ GJS_DEFINE_PRIV_FROM_JS(Repo, gjs_repo_class)
static JSObject * lookup_override_function(JSContext *, jsid);
-static JSObject*
-resolve_namespace_object(JSContext *context,
- JSObject *repo_obj,
- jsid ns_id,
- const char *ns_name)
+static JSBool
+get_version_for_ns (JSContext *context,
+ JSObject *repo_obj,
+ jsid ns_id,
+ char **version)
{
- GIRepository *repo;
- GError *error;
jsid versions_name;
jsval versions_val;
JSObject *versions;
jsval version_val;
- char *version;
- JSObject *namespace;
- JSObject *override;
- jsval result;
-
- JS_BeginRequest(context);
versions_name = gjs_runtime_get_const_string(JS_GetRuntime(context),
GJS_STRING_GI_VERSIONS);
if (!gjs_object_require_property(context, repo_obj, "GI repository object", versions_name,
&versions_val) ||
!JSVAL_IS_OBJECT(versions_val)) {
gjs_throw(context, "No 'versions' property in GI repository object");
-
- JS_EndRequest(context);
- return NULL;
+ return JS_FALSE;
}
versions = JSVAL_TO_OBJECT(versions_val);
- version = NULL;
+ *version = NULL;
if (JS_GetPropertyById(context, versions, ns_id, &version_val) &&
JSVAL_IS_STRING(version_val)) {
- gjs_string_to_utf8(context, version_val, &version);
+ gjs_string_to_utf8(context, version_val, version);
+ }
+
+ return JS_TRUE;
+}
+
+static JSObject*
+resolve_namespace_object(JSContext *context,
+ JSObject *repo_obj,
+ jsid ns_id,
+ const char *ns_name)
+{
+ GIRepository *repo;
+ GError *error;
+ char *version;
+ JSObject *namespace;
+ JSObject *override;
+ jsval result;
+
+ JS_BeginRequest(context);
+
+ if (!get_version_for_ns(context, repo_obj, ns_id, &version)) {
+ JS_EndRequest(context);
+ return NULL;
}
repo = g_irepository_get_default();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]