Skip to content

Commit 18c936b

Browse files
committed
function.cc: prepare trampoline stuff
1 parent c14ea02 commit 18c936b

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/function.cc

+21-21
Original file line numberDiff line numberDiff line change
@@ -555,20 +555,28 @@ class TrampolineInfo {
555555
GICallableInfo *info;
556556
GIScopeType scope_type;
557557

558-
TrampolineInfo(Handle<Function> function,
559-
GICallableInfo *info,
560-
GIScopeType scope_type);
558+
TrampolineInfo(Local<Function> function, GICallableInfo *info, GIScopeType scope_type);
561559

562560
void Dispose();
563-
static void Call(ffi_cif *cif, void *result, void **args, void *data);
564561
void *GetClosure();
562+
563+
static void Call(ffi_cif *cif, void *result, void **args, void *data);
565564
};
566565

566+
TrampolineInfo::TrampolineInfo(Local<Function> function,
567+
GICallableInfo *info,
568+
GIScopeType scope_type) {
569+
this->closure = g_callable_info_prepare_closure (info, &cif, TrampolineInfo::Call, this);
570+
this->persistent.Reset(Isolate::GetCurrent(), function);
571+
this->info = g_base_info_ref (info);
572+
this->scope_type = scope_type;
573+
}
574+
567575
void TrampolineInfo::Dispose() {
568-
persistent = nullptr;
576+
persistent.Reset();
569577
g_base_info_unref (info);
570578
g_callable_info_free_closure (info, closure);
571-
};
579+
}
572580

573581
void TrampolineInfo::Call(ffi_cif *cif,
574582
void *result,
@@ -577,7 +585,7 @@ void TrampolineInfo::Call(ffi_cif *cif,
577585
TrampolineInfo *trampoline = (TrampolineInfo *) data;
578586

579587
int argc = g_callable_info_get_n_args (trampoline->info);
580-
Handle<Value> argv[argc];
588+
Local<Value> argv[argc];
581589

582590
for (int i = 0; i < argc; i++) {
583591
GIArgInfo arg_info;
@@ -587,25 +595,17 @@ void TrampolineInfo::Call(ffi_cif *cif,
587595
argv[i] = GIArgumentToV8 (&type_info, (GIArgument *) &args[i]);
588596
}
589597

590-
Handle<Function> func = trampoline->func;
591-
/* Provide a bogus "this" function. Any interested callers should
592-
* bind their callbacks to what they're intersted in... */
593-
Handle<Object> this_obj = func;
594-
Handle<Value> return_value = func->Call (this_obj, argc, argv);
598+
Local<Function> func = Nan::New<Function> (trampoline->persistent);
599+
Local<Object> this_obj = func;
600+
601+
Local<Value> return_value = func->Call (this_obj, argc, argv);
602+
595603
GITypeInfo type_info;
596604
g_callable_info_load_return_type (trampoline->info, &type_info);
605+
597606
V8ToGIArgument (&type_info, (GIArgument *) &result, return_value,
598607
g_callable_info_may_return_null (trampoline->info));
599608
}
600-
601-
TrampolineInfo::TrampolineInfo(Handle<Function> function,
602-
GICallableInfo *info,
603-
GIScopeType scope_type) {
604-
this->closure = g_callable_info_prepare_closure (info, &cif, Call, this);
605-
this->func = Persistent<Function>::New (function);
606-
this->info = g_base_info_ref (info);
607-
this->scope_type = scope_type;
608-
}
609609
#endif
610610

611611
};

0 commit comments

Comments
 (0)