[seed] Convert GValue to basic types whenever it's possible.



commit 2614bdf076f5e90e1ce91ca3d86b540322f98d17
Author: Danilo Cesar Lemes de Paula <danilo cesar collabora co uk>
Date:   Wed Jun 8 12:03:09 2016 -0300

    Convert GValue to basic types whenever it's possible.
    
    GValues are cool, but not soo cool on javascrip.
    So, whenever we can we should translate GValue to their basic types
    before returning them to the JavaScript engine.

 libseed/seed-types.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/libseed/seed-types.c b/libseed/seed-types.c
index 51208e0..ebbac23 100644
--- a/libseed/seed-types.c
+++ b/libseed/seed-types.c
@@ -1063,6 +1063,27 @@ seed_value_from_gi_argument_full(JSContextRef ctx,
                 g_base_info_unref(interface);
                 return seed_value_from_long(ctx, arg->v_long, exception);
             } else if (interface_type == GI_INFO_TYPE_STRUCT) {
+
+                // Trying to find out if this struct can be converted into GValue
+                // If it can be converted, just send the converted value back to JS context instead
+                // of the GValue itself.
+                GType gtype = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*)interface);
+                if (G_TYPE_IS_INSTANTIATABLE(gtype) ||
+                    G_TYPE_IS_INTERFACE(gtype))
+                   gtype = G_TYPE_FROM_INSTANCE(arg->v_pointer);
+
+                SEED_NOTE(INVOCATION, "gtype of INTERFACE is %s", g_type_name(gtype));
+                if (g_type_is_a(gtype, G_TYPE_VALUE)) {
+                    JSValueRef ret;
+                    // We're using seed_value_from_gvalue_for_signal with NULL signal handler
+                    // the current code will only handle basic types.
+                    if ((ret = seed_value_from_gvalue_for_signal(ctx, arg->v_pointer, exception, NULL, 0))) {
+                        g_base_info_unref(interface);
+                        return ret;
+                    }
+                }
+
+
                 JSValueRef strukt;
 
                 strukt = seed_make_struct(ctx, arg->v_pointer, interface);


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