mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
add rr_define_finalizer() utility for adding object finalizers from C.
This commit is contained in:
parent
b0084c4c0c
commit
a671d6feda
4 changed files with 14 additions and 3 deletions
|
@ -40,6 +40,13 @@ VALUE rr_const_get(const char *name) {
|
||||||
return rb_const_get(V8_C, rb_intern(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> value) {
|
VALUE rr_v82rb(Handle<Value> value) {
|
||||||
if (value.IsEmpty()) {
|
if (value.IsEmpty()) {
|
||||||
return rr_v8_value_empty();
|
return rr_v8_value_empty();
|
||||||
|
|
|
@ -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_module(const char *name);
|
||||||
VALUE rr_define_const(const char *name, VALUE value);
|
VALUE rr_define_const(const char *name, VALUE value);
|
||||||
VALUE rr_const_get(const char *name);
|
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<v8::Value> value);
|
VALUE rr_v82rb(v8::Handle<v8::Value> value);
|
||||||
VALUE rr_v82rb(v8::Handle<v8::Boolean> value);
|
VALUE rr_v82rb(v8::Handle<v8::Boolean> value);
|
||||||
|
|
|
@ -12,8 +12,7 @@ v8_weakref::v8_weakref(VALUE object) {
|
||||||
void v8_weakref::set(VALUE value) {
|
void v8_weakref::set(VALUE value) {
|
||||||
this->object_id = rb_obj_id(value);
|
this->object_id = rb_obj_id(value);
|
||||||
VALUE data = Data_Wrap_Struct(rb_cObject, 0, 0, this);
|
VALUE data = Data_Wrap_Struct(rb_cObject, 0, 0, this);
|
||||||
VALUE finalizer = rb_proc_new((VALUE (*)(...))v8_weakref_finalize, data);
|
rr_define_finalizer(value,(void*)v8_weakref_finalize, data);
|
||||||
rb_funcall(v8_weakref_objectspace(), rb_intern("define_finalizer"), 2, value, finalizer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE v8_weakref::get() {
|
VALUE v8_weakref::get() {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <v8.h>
|
#include <v8.h>
|
||||||
#include "ruby.h"
|
#include "ruby.h"
|
||||||
|
#include "rr.h"
|
||||||
|
|
||||||
struct v8_weakref {
|
struct v8_weakref {
|
||||||
v8_weakref(VALUE object);
|
v8_weakref(VALUE object);
|
||||||
|
@ -21,6 +22,6 @@ VALUE v8_weakref_objectspace();
|
||||||
VALUE v8_weakref_nil(VALUE nil, VALUE exception);
|
VALUE v8_weakref_nil(VALUE nil, VALUE exception);
|
||||||
VALUE v8_weakref_id2ref(VALUE id);
|
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
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue