2009-12-07 02:20:16 -05:00
|
|
|
#include <v8_ref.h>
|
|
|
|
#include "stdio.h"
|
|
|
|
using namespace v8;
|
|
|
|
|
2009-12-07 02:44:18 -05:00
|
|
|
|
2009-12-11 12:11:05 -05:00
|
|
|
v8_ref::v8_ref(Handle<void> object, VALUE ref) : handle(Persistent<void>::New(object)), references(ref) {
|
2009-12-16 08:03:57 -05:00
|
|
|
//printf("Allocating v8 reference\n");
|
2009-12-07 02:20:16 -05:00
|
|
|
}
|
|
|
|
|
2009-12-07 09:06:06 -05:00
|
|
|
v8_ref::~v8_ref() {
|
2009-12-16 08:03:57 -05:00
|
|
|
//printf("Disposing v8 reference\n");
|
2009-12-07 09:36:40 -05:00
|
|
|
handle.Dispose();
|
2009-12-07 02:20:16 -05:00
|
|
|
}
|
|
|
|
|
2009-12-07 09:06:06 -05:00
|
|
|
void v8_ref_mark(v8_ref* ref) {
|
2009-12-11 12:11:05 -05:00
|
|
|
if (ref->references != 0) {
|
|
|
|
rb_gc_mark(ref->references);
|
|
|
|
}
|
2009-12-07 02:20:16 -05:00
|
|
|
}
|
|
|
|
|
2009-12-07 09:06:06 -05:00
|
|
|
void v8_ref_free(v8_ref* ref) {
|
2009-12-07 02:20:16 -05:00
|
|
|
delete ref;
|
|
|
|
}
|
|
|
|
|
2009-12-13 10:08:55 -05:00
|
|
|
VALUE V8_Ref_Create(VALUE ruby_class, v8::Handle<void> handle, VALUE ref) {
|
|
|
|
return Data_Wrap_Struct(ruby_class, v8_ref_mark, v8_ref_free, new v8_ref(handle, ref));
|
|
|
|
}
|