[gnode] More hackety



commit 0f919c4f682eb1a9db7d8ebfe07a600de985ac4d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Nov 27 19:23:23 2015 -0800

    More hackety

 src/function.cc |    6 +++---
 src/loop.cc     |   18 +++++++++++++-----
 src/value.cc    |    4 ++++
 test.js         |    2 +-
 4 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/src/function.cc b/src/function.cc
index e76bc4e..def9854 100644
--- a/src/function.cc
+++ b/src/function.cc
@@ -150,14 +150,12 @@ Handle<Function> MakeFunction(GIBaseInfo *info) {
 }
 
 class TrampolineInfo {
- private:
     ffi_cif cif;
     ffi_closure *closure;
     v8::Persistent<v8::Function> func;
     GICallableInfo *info;
     GIScopeType scope_type;
 
- public:
     TrampolineInfo(v8::Handle<v8::Function>  function,
                    GICallableInfo           *info,
                    GIScopeType               scope_type);
@@ -238,7 +236,9 @@ void Closure::Marshal(GClosure *base,
 
     Handle<Object> this_obj = func;
     Handle<Value> return_value = func->Call (this_obj, argc, argv);
-    V8ToGValue (g_return_value, return_value);
+
+    if (g_return_value)
+        V8ToGValue (g_return_value, return_value);
 }
 
 void Closure::Invalidated(gpointer data, GClosure *base) {
diff --git a/src/loop.cc b/src/loop.cc
index 9f9eda3..df25558 100644
--- a/src/loop.cc
+++ b/src/loop.cc
@@ -36,14 +36,22 @@ static gboolean uv_loop_source_prepare (GSource *base, int *timeout) {
     struct uv_loop_source *source = (struct uv_loop_source *) base;
     uv_update_time (source->loop);
 
+    bool loop_alive = uv_loop_alive (source->loop);
+
+    /* If the loop is dead, we can simply sleep forever until a GTK+ source
+     * (presumably) wakes us back up again. */
+    if (!loop_alive)
+        return FALSE;
+
+    /* Otherwise, check the timeout. If the timeout is 0, that means we're
+     * ready to go. Otherwise, keep sleeping until the timeout happens again. */
     int t = uv_backend_timeout (source->loop);
+    *timeout = t;
 
-    if (t == 0) {
+    if (t == 0)
         return TRUE;
-    } else {
-        *timeout = t;
+    else
         return FALSE;
-    }
 }
 
 static gboolean uv_loop_source_dispatch (GSource *base, GSourceFunc callback, gpointer user_data) {
@@ -67,7 +75,7 @@ static GSource *uv_loop_source_new (uv_loop_t *loop)
     source->loop = loop;
     g_source_add_unix_fd (&source->source,
                           uv_backend_fd (loop),
-                          (GIOCondition) (G_IO_IN | G_IO_ERR));
+                          (GIOCondition) (G_IO_IN | G_IO_OUT | G_IO_ERR));
     return &source->source;
 }
 
diff --git a/src/value.cc b/src/value.cc
index 34e7419..ab98518 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -249,6 +249,8 @@ void V8ToGValue(GValue *gvalue, Handle<Value> value) {
         String::Utf8Value str (value);
         const char *data = *str;
         g_value_set_string (gvalue, data);
+    } else if (G_VALUE_HOLDS_OBJECT (gvalue)) {
+        g_value_set_object (gvalue, GObjectFromWrapper (value));
     } else {
         g_assert_not_reached ();
     }
@@ -270,6 +272,8 @@ Handle<Value> GValueToV8(const GValue *gvalue) {
         return Number::New (g_value_get_double (gvalue));
     } else if (G_VALUE_HOLDS_STRING (gvalue)) {
         return String::New (g_value_get_string (gvalue));
+    } else if (G_VALUE_HOLDS_OBJECT (gvalue)) {
+        return WrapperFromGObject (G_OBJECT (g_value_get_object (gvalue)));
     } else {
         g_assert_not_reached ();
     }
diff --git a/test.js b/test.js
index 78a6e75..2fccb58 100644
--- a/test.js
+++ b/test.js
@@ -17,8 +17,8 @@ Gtk.init(0, null);
 
 var w = new Gtk.Window();
 var b = new Gtk.Button({ label: "Hi!" });
+b.connect('clicked', function() { console.log("BB"); });
 w.add(b);
 w.show_all();
 
-setTimeout(function() { console.log("AA"); }, 2000);
 Gtk.main();


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