gjs r35 - in trunk: examples gi



Author: jobi
Date: Wed Oct 22 14:09:27 2008
New Revision: 35
URL: http://svn.gnome.org/viewvc/gjs?rev=35&view=rev

Log:
Bug 557398 â Allow requiring namespace version

	* gi/repo.c: Add imports.gi.versions object, allows to
	specify required version for each namespace.


Modified:
   trunk/examples/clutter.js
   trunk/gi/repo.c

Modified: trunk/examples/clutter.js
==============================================================================
--- trunk/examples/clutter.js	(original)
+++ trunk/examples/clutter.js	Wed Oct 22 14:09:27 2008
@@ -1,3 +1,4 @@
+imports.gi.versions.clutter = '0.8';
 const Clutter = imports.gi.clutter;
 
 Clutter.init(null, null);

Modified: trunk/gi/repo.c
==============================================================================
--- trunk/gi/repo.c	(original)
+++ trunk/gi/repo.c	Wed Oct 22 14:09:27 2008
@@ -59,17 +59,40 @@
     GIRepository *repo;
     GError *error;
     char *fixed_ns_name;
+    JSContext *load_context;
+    jsval versions_val;
+    JSObject *versions;
+    jsval version_val;
+    const char *version;
+
+    load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
+    if (!gjs_object_require_property(load_context, repo_obj, "versions", &versions_val) ||
+        !JSVAL_IS_OBJECT(versions_val)) {
+        gjs_throw(context, "No 'versions' property in GI repository object");
+        return NULL;
+    }
+
+    versions = JSVAL_TO_OBJECT(versions_val);
 
     fixed_ns_name = gjs_fix_ns_name(ns_name);
 
+    version = NULL;
+    if (JS_GetProperty(load_context, versions, ns_name, &version_val) &&
+        JSVAL_IS_STRING(version_val)) {
+        version = gjs_string_get_ascii(version_val);
+    } else if (JS_GetProperty(load_context, versions, fixed_ns_name, &version_val) &&
+               JSVAL_IS_STRING(version_val)) {
+        version = gjs_string_get_ascii(version_val);
+    }
+
     repo = g_irepository_get_default();
 
     error = NULL;
-    g_irepository_require(repo, fixed_ns_name, NULL, 0, &error);
+    g_irepository_require(repo, fixed_ns_name, version, 0, &error);
     if (error != NULL) {
         gjs_throw(context,
-                  "Requiring %s fixed as %s: %s",
-                  ns_name, fixed_ns_name, error->message);
+                  "Requiring %s fixed as %s, version %s: %s",
+                  ns_name, fixed_ns_name, version?version:"none", error->message);
         g_error_free(error);
         g_free(fixed_ns_name);
         return JS_FALSE;
@@ -218,6 +241,7 @@
 {
     JSObject *repo;
     JSObject *global;
+    JSObject *versions;
 
     /* We have to define the class in the global object so we can JS_ConstructObject */
 
@@ -262,6 +286,16 @@
         return JS_FALSE;
     }
 
+    versions = JS_ConstructObject(context, NULL, NULL, NULL);
+
+    JS_DefineProperty(context, repo,
+                      "versions",
+                      OBJECT_TO_JSVAL(versions),
+                      NULL, NULL,
+                      JSPROP_PERMANENT);
+
+    g_assert(gjs_object_has_property(context, repo, "versions"));
+
     /* FIXME - hack to make namespaces load, since
      * gobject-introspection does not yet search a path properly.
      */



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