[gnode] function: Put things in a struct
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnode] function: Put things in a struct
- Date: Sat, 28 Nov 2015 05:52:48 +0000 (UTC)
commit d03cf6180ad61f3f87e2260978f913068c428b43
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Fri Nov 27 12:08:07 2015 -0800
function: Put things in a struct
src/function.cc | 19 ++++++++++++++-----
1 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/src/function.cc b/src/function.cc
index cfd403e..b2d58d8 100644
--- a/src/function.cc
+++ b/src/function.cc
@@ -28,9 +28,15 @@ using namespace v8;
namespace GNodeJS {
+struct FunctionInfo {
+ GIFunctionInfo *info;
+};
+
static Handle<Value> FunctionInvoker(const Arguments &args) {
HandleScope scope;
- GIBaseInfo *info = (GIBaseInfo *) External::Unwrap (args.Data ());
+ FunctionInfo *func = (FunctionInfo *) External::Unwrap (args.Data ());
+
+ GIBaseInfo *info = func->info;
GIFunctionInfo *function_info = (GIFunctionInfo *) info;
GError *error = NULL;
@@ -94,13 +100,16 @@ static Handle<Value> FunctionInvoker(const Arguments &args) {
}
static void FunctionDestroyed(Persistent<Value> object, void *data) {
- GIBaseInfo *info = (GIBaseInfo *) data;
- g_base_info_unref (info);
+ FunctionInfo *func = (FunctionInfo *) data;
+ g_base_info_unref (func->info);
+ g_free (func);
}
Handle<Function> MakeFunction(GIBaseInfo *info) {
- Persistent<FunctionTemplate> tpl = Persistent<FunctionTemplate>::New (FunctionTemplate::New
(FunctionInvoker, External::Wrap (info)));
- tpl.MakeWeak (g_base_info_ref (info), FunctionDestroyed);
+ FunctionInfo *func = g_new0 (FunctionInfo, 1);
+ func->info = g_base_info_ref (info);
+ Persistent<FunctionTemplate> tpl = Persistent<FunctionTemplate>::New (FunctionTemplate::New
(FunctionInvoker, External::Wrap (func)));
+ tpl.MakeWeak (func, FunctionDestroyed);
Local<Function> fn = tpl->GetFunction ();
const char *function_name = g_base_info_get_name (info);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]