diff --git a/ext/v8/rr.cpp b/ext/v8/rr.cpp index 0fabcf4..355e465 100644 --- a/ext/v8/rr.cpp +++ b/ext/v8/rr.cpp @@ -40,6 +40,13 @@ VALUE rr_const_get(const char *name) { return rb_const_get(V8_C, rb_intern(name)); } +VALUE rr_define_finalizer(VALUE object, void* finalizer, VALUE data) { + VALUE finalizer_proc = rb_proc_new((VALUE (*)(...))finalizer, data); + rb_iv_set(finalizer_proc, "data", data); + VALUE ospace = rb_const_get(rb_cObject, rb_intern("ObjectSpace")); + rb_funcall(ospace, rb_intern("define_finalizer"), 2, object, finalizer_proc); +} + VALUE rr_v82rb(Handle value) { if (value.IsEmpty()) { return rr_v8_value_empty(); diff --git a/ext/v8/rr.h b/ext/v8/rr.h index e01cf3d..601f69f 100644 --- a/ext/v8/rr.h +++ b/ext/v8/rr.h @@ -11,6 +11,10 @@ VALUE rr_define_class(const char *name, VALUE superclass = rb_cObject); VALUE rr_define_module(const char *name); VALUE rr_define_const(const char *name, VALUE value); VALUE rr_const_get(const char *name); +VALUE rr_define_finalizer(VALUE object, void* finalizer, VALUE data); + +extern "C" VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE); + VALUE rr_v82rb(v8::Handle value); VALUE rr_v82rb(v8::Handle value); diff --git a/ext/v8/v8_weakref.cpp b/ext/v8/v8_weakref.cpp index e257e68..f8688ec 100644 --- a/ext/v8/v8_weakref.cpp +++ b/ext/v8/v8_weakref.cpp @@ -12,8 +12,7 @@ v8_weakref::v8_weakref(VALUE object) { void v8_weakref::set(VALUE value) { this->object_id = rb_obj_id(value); VALUE data = Data_Wrap_Struct(rb_cObject, 0, 0, this); - VALUE finalizer = rb_proc_new((VALUE (*)(...))v8_weakref_finalize, data); - rb_funcall(v8_weakref_objectspace(), rb_intern("define_finalizer"), 2, value, finalizer); + rr_define_finalizer(value,(void*)v8_weakref_finalize, data); } VALUE v8_weakref::get() { diff --git a/ext/v8/v8_weakref.h b/ext/v8/v8_weakref.h index c080fed..96458c7 100644 --- a/ext/v8/v8_weakref.h +++ b/ext/v8/v8_weakref.h @@ -3,6 +3,7 @@ #include #include "ruby.h" +#include "rr.h" struct v8_weakref { v8_weakref(VALUE object); @@ -21,6 +22,6 @@ VALUE v8_weakref_objectspace(); VALUE v8_weakref_nil(VALUE nil, VALUE exception); VALUE v8_weakref_id2ref(VALUE id); -extern "C" VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE); +// extern "C" VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE); #endif