#include #include "stdio.h" using namespace v8; v8_ref::v8_ref(Handle object, VALUE ref) : handle(Persistent::New(object)), references(ref) { printf("Allocating v8 reference\n"); } v8_ref::~v8_ref() { printf("Disposing v8 reference\n"); handle.Dispose(); } void v8_ref_mark(v8_ref* ref) { if (ref->references != 0) { rb_gc_mark(ref->references); } } void v8_ref_free(v8_ref* ref) { delete ref; } VALUE V8_Ref_Create(VALUE ruby_class, v8::Handle handle, VALUE ref) { return Data_Wrap_Struct(ruby_class, v8_ref_mark, v8_ref_free, new v8_ref(handle, ref)); }