[gjs] Add GType annotations to Cairo structures



commit 9a08cfd8de37ae967a91e6747f1a31a9ea63e9a6
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun Aug 4 23:37:45 2013 +0200

    Add GType annotations to Cairo structures
    
    To get GValue marshalling we need to ensure that all
    Cairo constructors have correct $gtype properties.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=705465

 gjs/jsapi-util.h          |   22 ++++++++++++++++++----
 modules/cairo-context.cpp |    3 ++-
 modules/cairo-pattern.cpp |    3 ++-
 modules/cairo-surface.cpp |    3 ++-
 4 files changed, 24 insertions(+), 7 deletions(-)
---
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 15701cc..265ef24 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -31,6 +31,7 @@
 #include <gjs/compat.h>
 #include <gjs/runtime.h>
 #include <glib-object.h>
+#include <gi/gtype.h>
 
 G_BEGIN_DECLS
 
@@ -112,7 +113,7 @@ typedef struct GjsRootedArray GjsRootedArray;
  */
 #define GJS_DEFINE_PROTO(tn, cn) \
 GJS_NATIVE_CONSTRUCTOR_DECLARE(cn); \
-_GJS_DEFINE_PROTO_FULL(tn, cn, gjs_##cn##_constructor)
+_GJS_DEFINE_PROTO_FULL(tn, cn, gjs_##cn##_constructor, G_TYPE_NONE)
 
 /**
  * GJS_DEFINE_PROTO_ABSTRACT:
@@ -124,9 +125,16 @@ _GJS_DEFINE_PROTO_FULL(tn, cn, gjs_##cn##_constructor)
  * you won't be able to instantiate it using the new keyword
  */
 #define GJS_DEFINE_PROTO_ABSTRACT(tn, cn) \
-_GJS_DEFINE_PROTO_FULL(tn, cn, NULL)
+_GJS_DEFINE_PROTO_FULL(tn, cn, NULL, G_TYPE_NONE)
 
-#define _GJS_DEFINE_PROTO_FULL(type_name, cname, ctor) \
+#define GJS_DEFINE_PROTO_WITH_GTYPE(tn, cn, gtype)   \
+GJS_NATIVE_CONSTRUCTOR_DECLARE(cn); \
+_GJS_DEFINE_PROTO_FULL(tn, cn, gjs_##cn##_constructor, gtype)
+
+#define GJS_DEFINE_PROTO_ABSTRACT_WITH_GTYPE(tn, cn, gtype)   \
+_GJS_DEFINE_PROTO_FULL(tn, cn, NULL, gtype)
+
+#define _GJS_DEFINE_PROTO_FULL(type_name, cname, ctor, gtype) \
 extern JSPropertySpec gjs_##cname##_proto_props[]; \
 extern JSFunctionSpec gjs_##cname##_proto_funcs[]; \
 static void gjs_##cname##_finalize(JSFreeOp *fop, JSObject *obj); \
@@ -162,7 +170,8 @@ jsval gjs_##cname##_create_proto(JSContext *context, JSObject *module, const cha
     if (!JS_GetPropertyById(context, global, class_name, &rval))                       \
         return JSVAL_NULL; \
     if (JSVAL_IS_VOID(rval)) { \
-        JSObject *prototype = JS_InitClass(context, global, \
+        jsval value; \
+        JSObject *prototype = JS_InitClass(context, global,     \
                                  parent, \
                                  &gjs_##cname##_class, \
                                  ctor, \
@@ -182,6 +191,11 @@ jsval gjs_##cname##_create_proto(JSContext *context, JSObject *module, const cha
         if (!JS_DefineProperty(context, module, proto_name, \
                                rval, NULL, NULL, GJS_MODULE_PROP_FLAGS)) \
             return JSVAL_NULL; \
+        if (gtype != G_TYPE_NONE) { \
+            value = OBJECT_TO_JSVAL(gjs_gtype_create_gtype_wrapper(context, gtype)); \
+            JS_DefineProperty(context, JSVAL_TO_OBJECT(rval), "$gtype", value, \
+                              NULL, NULL, JSPROP_PERMANENT);            \
+        } \
     } \
     return rval; \
 }
diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp
index 6887f90..f55313f 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -27,6 +27,7 @@
 #include <gi/foreign.h>
 
 #include <cairo.h>
+#include <cairo-gobject.h>
 #include "cairo-private.h"
 
 #define _GJS_CAIRO_CONTEXT_DEFINE_FUNC_BEGIN(mname) \
@@ -252,7 +253,7 @@ typedef struct {
     cairo_t * cr;
 } GjsCairoContext;
 
-GJS_DEFINE_PROTO("CairoContext", cairo_context)
+GJS_DEFINE_PROTO_WITH_GTYPE("CairoContext", cairo_context, CAIRO_GOBJECT_TYPE_CONTEXT)
 GJS_DEFINE_PRIV_FROM_JS(GjsCairoContext, gjs_cairo_context_class);
 
 static void
diff --git a/modules/cairo-pattern.cpp b/modules/cairo-pattern.cpp
index e2c48c0..005c534 100644
--- a/modules/cairo-pattern.cpp
+++ b/modules/cairo-pattern.cpp
@@ -25,6 +25,7 @@
 #include <gjs/gjs-module.h>
 #include <gjs/compat.h>
 #include <cairo.h>
+#include <cairo-gobject.h>
 #include "cairo-private.h"
 
 typedef struct {
@@ -34,7 +35,7 @@ typedef struct {
     cairo_pattern_t *pattern;
 } GjsCairoPattern;
 
-GJS_DEFINE_PROTO_ABSTRACT("CairoPattern", cairo_pattern)
+GJS_DEFINE_PROTO_ABSTRACT_WITH_GTYPE("CairoPattern", cairo_pattern, CAIRO_GOBJECT_TYPE_PATTERN)
 GJS_DEFINE_PRIV_FROM_JS(GjsCairoPattern, gjs_cairo_pattern_class)
 
 static void
diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp
index 054b65d..ce8e621 100644
--- a/modules/cairo-surface.cpp
+++ b/modules/cairo-surface.cpp
@@ -26,6 +26,7 @@
 #include <gjs/compat.h>
 #include <gi/foreign.h>
 #include <cairo.h>
+#include <cairo-gobject.h>
 #include "cairo-private.h"
 
 typedef struct {
@@ -35,7 +36,7 @@ typedef struct {
     cairo_surface_t *surface;
 } GjsCairoSurface;
 
-GJS_DEFINE_PROTO_ABSTRACT("CairoSurface", cairo_surface)
+GJS_DEFINE_PROTO_ABSTRACT_WITH_GTYPE("CairoSurface", cairo_surface, CAIRO_GOBJECT_TYPE_SURFACE)
 GJS_DEFINE_PRIV_FROM_JS(GjsCairoSurface, gjs_cairo_surface_class)
 
 static void


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