[gjs] Revert "Introduce infrastructure for override modules"



commit fc903dde3d74a6c123145bded3599930d3bdefac
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Thu May 19 19:36:18 2011 +0200

    Revert "Introduce infrastructure for override modules"
    
    This reverts commit c425d9063db5ea21af5dc1ca04681e1d958dbc3d.
    Pushed by accident, needed to be split into two.

 Makefile-modules.am      |    3 --
 Makefile.am              |    3 +-
 gi/ns.c                  |   18 +++++++++-
 gi/ns.h                  |    3 +-
 gi/repo.c                |   77 ++--------------------------------------------
 gjs/jsapi-util.h         |    2 +-
 modules/overrides/Gio.js |    2 -
 7 files changed, 23 insertions(+), 85 deletions(-)
---
diff --git a/Makefile-modules.am b/Makefile-modules.am
index fb1864d..c43b2d8 100644
--- a/Makefile-modules.am
+++ b/Makefile-modules.am
@@ -3,9 +3,6 @@ dist_gjstweener_DATA =			\
 	modules/tweener/tweener.js	\
 	modules/tweener/tweenList.js
 
-dist_gjsoverride_DATA = 		\
-	modules/overrides/Gio.js
-
 dist_gjsjs_DATA +=		\
 	modules/gettext.js	\
 	modules/lang.js		\
diff --git a/Makefile.am b/Makefile.am
index b0e433a..f1a7777 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,8 +12,7 @@ TEST_PROGS =
 check_PROGRAMS = $(TEST_PROGS)
 
 gjsjsdir = @gjsjsdir@
-gjsoverridedir = $(gjsjsdir)/overrides
-gjstweenerdir = $(gjsjsdir)/tweener
+gjstweenerdir = @gjsjsdir@/tweener
 gjsnativedir = @gjsnativedir@
 
 gjs_public_includedir = $(includedir)/gjs-1.0
diff --git a/gi/ns.c b/gi/ns.c
index 1033969..b9a1ea7 100644
--- a/gi/ns.c
+++ b/gi/ns.c
@@ -287,9 +287,23 @@ ns_new(JSContext    *context,
 }
 
 JSObject*
-gjs_create_ns(JSContext    *context,
+gjs_define_ns(JSContext    *context,
+              JSObject     *in_object,
               const char   *ns_name,
               GIRepository *repo)
 {
-    return ns_new(context, ns_name, repo);
+    JSObject *ns;
+
+    ns = ns_new(context, ns_name, repo);
+
+    if (!JS_DefineProperty(context, in_object,
+                           ns_name, OBJECT_TO_JSVAL(ns),
+                           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, ns, in_object);
+
+    return ns;
 }
diff --git a/gi/ns.h b/gi/ns.h
index f717ea6..d5bf2ac 100644
--- a/gi/ns.h
+++ b/gi/ns.h
@@ -32,7 +32,8 @@
 
 G_BEGIN_DECLS
 
-JSObject* gjs_create_ns(JSContext    *context,
+JSObject* gjs_define_ns(JSContext    *context,
+                        JSObject     *in_object,
                         const char   *ns_name,
                         GIRepository *repo);
 
diff --git a/gi/repo.c b/gi/repo.c
index 955f561..a17ed4c 100644
--- a/gi/repo.c
+++ b/gi/repo.c
@@ -50,8 +50,6 @@ static struct JSClass gjs_repo_class;
 
 GJS_DEFINE_PRIV_FROM_JS(Repo, gjs_repo_class)
 
-static JSObject * lookup_override_function(JSContext *, const char *);
-
 static JSObject*
 resolve_namespace_object(JSContext  *context,
                          JSObject   *repo_obj,
@@ -63,9 +61,7 @@ resolve_namespace_object(JSContext  *context,
     JSObject *versions;
     jsval version_val;
     char *version;
-    JSObject *namespace;
-    JSObject *override;
-    jsval result;
+    JSObject *result;
 
     JS_BeginRequest(context);
 
@@ -105,33 +101,9 @@ resolve_namespace_object(JSContext  *context,
      * with the given namespace name, pointing to that namespace
      * in the repo.
      */
-    namespace = gjs_create_ns(context, ns_name, repo);
-    JS_AddObjectRoot(context, &namespace);
-
-    override = lookup_override_function(context, ns_name);
-    if (override && !JS_CallFunctionValue (context,
-                                           namespace, /* thisp */
-                                           OBJECT_TO_JSVAL(override), /* callee */
-                                           0, /* argc */
-                                           NULL, /* argv */
-                                           &result)) {
-        JS_RemoveObjectRoot(context, &namespace);
-        JS_EndRequest(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);
-
-    JS_RemoveObjectRoot(context, &namespace);
+    result = gjs_define_ns(context, repo_obj, ns_name, repo);
     JS_EndRequest(context);
-    return namespace;
+    return result;
 }
 
 /*
@@ -531,49 +503,6 @@ gjs_lookup_namespace_object(JSContext  *context,
     return gjs_lookup_namespace_object_by_name(context, ns);
 }
 
-static JSObject*
-lookup_override_function(JSContext  *context,
-                         const char *ns)
-{
-    JSObject *global;
-    jsval importer;
-    jsval overridespkg;
-    jsval module;
-    jsval function;
-
-    JS_BeginRequest(context);
-    global = gjs_get_import_global(context);
-
-    importer = JSVAL_VOID;
-    if (!gjs_object_require_property(context, global, "global object", "imports", &importer) ||
-        !JSVAL_IS_OBJECT(importer))
-        goto fail;
-
-    overridespkg = JSVAL_VOID;
-    if (!gjs_object_require_property(context, JSVAL_TO_OBJECT(importer), "importer",
-                                        "overrides", &overridespkg) ||
-        !JSVAL_IS_OBJECT(overridespkg))
-        goto fail;
-
-    module = JSVAL_VOID;
-    if (!gjs_object_require_property(context, JSVAL_TO_OBJECT(overridespkg), "GI repository object", ns, &module)
-        || !JSVAL_IS_OBJECT(module))
-        goto fail;
-
-    if (!gjs_object_require_property(context, JSVAL_TO_OBJECT(module), "override module",
-                                     "_init", &function) ||
-        !JSVAL_IS_OBJECT(function))
-        goto fail;
-
-    JS_EndRequest(context);
-    return JSVAL_TO_OBJECT(function);
-
- fail:
-    JS_ClearPendingException(context);
-    JS_EndRequest(context);
-    return NULL;
-}
-
 JSObject*
 gjs_lookup_namespace_object_by_name(JSContext      *context,
                                     const char     *ns)
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index bd3c5fe..4d61916 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -53,7 +53,7 @@ typedef struct GjsRootedArray GjsRootedArray;
  * PERMANENT: forbid deleting the prop
  * ENUMERATE: allows copyProperties to work among other reasons to have it
  */
-#define GJS_MODULE_PROP_FLAGS (JSPROP_PERMANENT | JSPROP_ENUMERATE)
+#define GJS_MODULE_PROP_FLAGS (JSPROP_READONLY | JSPROP_PERMANENT | JSPROP_ENUMERATE)
 
 /* priv_from_js_with_typecheck checks that the object is in fact an
  * instance of the specified class before accessing its private data.



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