2009-12-07 02:20:16 -05:00
|
|
|
#include <v8_ref.h>
|
|
|
|
#include "stdio.h"
|
|
|
|
using namespace v8;
|
|
|
|
|
2010-06-07 03:50:33 -04:00
|
|
|
v8_ref::v8_ref(Handle<void> object) : handle(Persistent<void>::New(object)) {
|
2010-05-20 05:06:21 -04:00
|
|
|
this->references = rb_hash_new();
|
2009-12-07 02:20:16 -05:00
|
|
|
}
|
|
|
|
|
2009-12-07 09:06:06 -05:00
|
|
|
v8_ref::~v8_ref() {
|
2009-12-07 09:36:40 -05:00
|
|
|
handle.Dispose();
|
2009-12-07 02:20:16 -05:00
|
|
|
}
|
|
|
|
|
2010-05-20 05:06:21 -04:00
|
|
|
void v8_ref::set(const char *name, VALUE ref) {
|
|
|
|
if (ref != 0 && RTEST(ref)) {
|
|
|
|
rb_hash_aset(this->references, rb_str_new2(name), ref);
|
2009-12-11 12:11:05 -05:00
|
|
|
}
|
2009-12-07 02:20:16 -05:00
|
|
|
}
|
|
|
|
|
2010-05-20 05:06:21 -04:00
|
|
|
namespace {
|
|
|
|
void gc_mark(v8_ref* ref) {
|
|
|
|
rb_gc_mark(ref->references);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gc_free(v8_ref* ref) {
|
|
|
|
delete ref;
|
|
|
|
}
|
2009-12-07 02:20:16 -05:00
|
|
|
}
|
|
|
|
|
2010-05-22 02:23:22 -04:00
|
|
|
VALUE rr_v8_ref_create(VALUE rbclass, v8::Handle<void> handle) {
|
|
|
|
return Data_Wrap_Struct(rbclass, gc_mark, gc_free, new v8_ref(handle));
|
|
|
|
}
|
|
|
|
|
2010-05-20 05:06:21 -04:00
|
|
|
void rr_v8_ref_setref(VALUE handle, const char *name, VALUE newref) {
|
|
|
|
v8_ref *ref = 0;
|
|
|
|
Data_Get_Struct(handle, struct v8_ref, ref);
|
|
|
|
ref->set(name, newref);
|
2010-05-11 13:41:07 -04:00
|
|
|
}
|