[gnode] Split out closure into separate files
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnode] Split out closure into separate files
- Date: Fri, 11 Dec 2015 19:48:48 +0000 (UTC)
commit 9b935a6b9e9cdee17945de8c1a4dbfa32fc3a0bd
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Sat Nov 28 12:55:39 2015 -0800
Split out closure into separate files
binding.gyp | 1 +
src/closure.cc | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/closure.h | 32 +++++++++++++++++++++
src/function.cc | 51 ----------------------------------
src/function.h | 1 -
src/gobject.cc | 2 +
6 files changed, 117 insertions(+), 52 deletions(-)
---
diff --git a/binding.gyp b/binding.gyp
index b1730df..ae8f925 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -8,6 +8,7 @@
"src/value.cc",
"src/function.cc",
"src/gobject.cc",
+ "src/closure.cc",
],
"cflags": [
"<!@(pkg-config --cflags gobject-introspection-1.0) -Wall -Werror",
diff --git a/src/closure.cc b/src/closure.cc
new file mode 100644
index 0000000..b8bb8fa
--- /dev/null
+++ b/src/closure.cc
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2015 Endless Mobile
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by:
+ * Jasper St. Pierre <jstpierre mecheye net>
+ */
+
+#include "function.h"
+
+#include "value.h"
+
+using namespace v8;
+
+namespace GNodeJS {
+
+struct Closure {
+ GClosure base;
+ Persistent<Function> persistent;
+
+ static void Marshal(GClosure *closure,
+ GValue *g_return_value,
+ uint argc, const GValue *g_argv,
+ gpointer invocation_hint,
+ gpointer marshal_data);
+
+ static void Invalidated(gpointer data, GClosure *closure);
+};
+
+void Closure::Marshal(GClosure *base,
+ GValue *g_return_value,
+ uint argc, const GValue *g_argv,
+ gpointer invocation_hint,
+ gpointer marshal_data) {
+ /* XXX: Any other way to get this? */
+ Isolate *isolate = Isolate::GetCurrent ();
+ HandleScope scope(isolate);
+
+ Closure *closure = (Closure *) base;
+ Handle<Function> func = Handle<Function>::New(isolate, closure->persistent);
+
+ Handle<Value> argv[argc];
+
+ for (uint i = 0; i < argc; i++)
+ argv[i] = GValueToV8 (isolate, &g_argv[i]);
+
+ Handle<Object> this_obj = func;
+ Handle<Value> return_value = func->Call (this_obj, argc, argv);
+
+ if (g_return_value)
+ V8ToGValue (g_return_value, return_value);
+}
+
+void Closure::Invalidated(gpointer data, GClosure *base) {
+ Closure *closure = (Closure *) base;
+ closure->~Closure();
+}
+
+GClosure *MakeClosure(Isolate *isolate, Handle<Function> function) {
+ Closure *closure = (Closure *) g_closure_new_simple (sizeof (*closure), NULL);
+ closure->persistent.Reset(isolate, function);
+ GClosure *gclosure = &closure->base;
+ g_closure_set_marshal (gclosure, Closure::Marshal);
+ g_closure_add_invalidate_notifier (gclosure, NULL, Closure::Invalidated);
+ return gclosure;
+}
+
+};
diff --git a/src/closure.h b/src/closure.h
new file mode 100644
index 0000000..6275f16
--- /dev/null
+++ b/src/closure.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2015 Endless Mobile
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by:
+ * Jasper St. Pierre <jstpierre mecheye net>
+ */
+
+#pragma once
+
+#include <node.h>
+#include <glib-object.h>
+
+namespace GNodeJS {
+
+GClosure *MakeClosure(v8::Isolate *isolate, v8::Handle<v8::Function> function);
+
+};
diff --git a/src/function.cc b/src/function.cc
index c55f213..b5fb38a 100644
--- a/src/function.cc
+++ b/src/function.cc
@@ -212,55 +212,4 @@ TrampolineInfo::TrampolineInfo(Handle<Function> function,
}
#endif
-struct Closure {
- GClosure base;
- Persistent<Function> persistent;
-
- static void Marshal(GClosure *closure,
- GValue *g_return_value,
- uint argc, const GValue *g_argv,
- gpointer invocation_hint,
- gpointer marshal_data);
-
- static void Invalidated(gpointer data, GClosure *closure);
-};
-
-void Closure::Marshal(GClosure *base,
- GValue *g_return_value,
- uint argc, const GValue *g_argv,
- gpointer invocation_hint,
- gpointer marshal_data) {
- /* XXX: Any other way to get this? */
- Isolate *isolate = Isolate::GetCurrent ();
- HandleScope scope(isolate);
-
- Closure *closure = (Closure *) base;
- Handle<Function> func = Handle<Function>::New(isolate, closure->persistent);
-
- Handle<Value> argv[argc];
-
- for (uint i = 0; i < argc; i++)
- argv[i] = GValueToV8 (isolate, &g_argv[i]);
-
- Handle<Object> this_obj = func;
- Handle<Value> return_value = func->Call (this_obj, argc, argv);
-
- if (g_return_value)
- V8ToGValue (g_return_value, return_value);
-}
-
-void Closure::Invalidated(gpointer data, GClosure *base) {
- Closure *closure = (Closure *) base;
- closure->~Closure();
-}
-
-GClosure *MakeClosure(Isolate *isolate, Handle<Function> function) {
- Closure *closure = (Closure *) g_closure_new_simple (sizeof (*closure), NULL);
- closure->persistent.Reset(isolate, function);
- GClosure *gclosure = &closure->base;
- g_closure_set_marshal (gclosure, Closure::Marshal);
- g_closure_add_invalidate_notifier (gclosure, NULL, Closure::Invalidated);
- return gclosure;
-}
-
};
diff --git a/src/function.h b/src/function.h
index c3835a4..4ec3923 100644
--- a/src/function.h
+++ b/src/function.h
@@ -29,6 +29,5 @@
namespace GNodeJS {
v8::Handle<v8::Function> MakeFunction(v8::Isolate *isolate, GIBaseInfo *base_info);
-GClosure *MakeClosure(v8::Isolate *isolate, v8::Handle<v8::Function> function);
};
diff --git a/src/gobject.cc b/src/gobject.cc
index b4feb47..e75f8fe 100644
--- a/src/gobject.cc
+++ b/src/gobject.cc
@@ -21,8 +21,10 @@
*/
#include "gobject.h"
+
#include "function.h"
#include "value.h"
+#include "closure.h"
using namespace v8;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]