2011-04-07 12:49:47 -04:00
|
|
|
|
|
|
|
#include "rr.h"
|
2011-04-08 10:54:57 -04:00
|
|
|
#include "v8_handle.h"
|
2011-04-07 12:49:47 -04:00
|
|
|
|
|
|
|
using namespace v8;
|
|
|
|
|
2011-04-08 10:54:57 -04:00
|
|
|
v8_handle::v8_handle(Handle<void> handle) : handle(Persistent<void>::New(handle)) {}
|
|
|
|
|
|
|
|
v8_handle::~v8_handle() {
|
|
|
|
handle.Dispose();
|
|
|
|
handle.Clear();
|
|
|
|
}
|
|
|
|
|
2011-04-07 12:49:47 -04:00
|
|
|
namespace {
|
2011-04-08 10:54:57 -04:00
|
|
|
void gc_mark(v8_handle* handle) {}
|
|
|
|
|
|
|
|
void gc_free(v8_handle* handle) {
|
|
|
|
delete handle;
|
|
|
|
}
|
2011-04-07 12:49:47 -04:00
|
|
|
|
|
|
|
VALUE New(VALUE self, VALUE handle) {
|
2011-04-08 10:54:57 -04:00
|
|
|
if (RTEST(handle)) {
|
2011-04-11 00:19:26 -04:00
|
|
|
Persistent<void> that = rr_v8_handle<void>(handle);
|
|
|
|
return rr_v8_handle_new(self, that);
|
2011-04-08 10:54:57 -04:00
|
|
|
} else {
|
|
|
|
return rr_v8_handle_new(self, Handle<void>());
|
|
|
|
}
|
2011-04-07 12:49:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE IsEmpty(VALUE self) {
|
2011-04-08 10:54:57 -04:00
|
|
|
return rr_v82rb(rr_v8_handle<void>(self).IsEmpty());
|
2011-04-07 12:49:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Clear(VALUE self) {
|
2011-04-08 10:54:57 -04:00
|
|
|
rr_v8_handle<void>(self).Clear();
|
2011-04-07 12:49:47 -04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE Dispose(VALUE self) {
|
2011-04-08 10:54:57 -04:00
|
|
|
rr_v8_handle<void>(self).Dispose();
|
2011-04-07 12:49:47 -04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NoopWeakReferenceCallback(Persistent<Value> object, void* parameter) {}
|
|
|
|
|
|
|
|
VALUE MakeWeak(VALUE self) {
|
2011-04-08 10:54:57 -04:00
|
|
|
rr_v8_handle<void>(self).MakeWeak(0, NoopWeakReferenceCallback);
|
2011-04-07 12:49:47 -04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE ClearWeak(VALUE self) {
|
2011-04-08 10:54:57 -04:00
|
|
|
rr_v8_handle<void>(self).ClearWeak();
|
2011-04-07 12:49:47 -04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE IsNearDeath(VALUE self) {
|
2011-04-08 10:54:57 -04:00
|
|
|
return rr_v82rb(rr_v8_handle<void>(self).IsNearDeath());
|
2011-04-07 12:49:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE IsWeak(VALUE self) {
|
2011-04-08 10:54:57 -04:00
|
|
|
return rr_v82rb(rr_v8_handle<void>(self).IsWeak());
|
2011-04-07 12:49:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rr_init_handle() {
|
|
|
|
VALUE HandleClass = rr_define_class("Handle");
|
|
|
|
rr_define_singleton_method(HandleClass, "New", New, 1);
|
|
|
|
rr_define_method(HandleClass, "IsEmpty", IsEmpty, 0);
|
|
|
|
rr_define_method(HandleClass, "Clear", Clear, 0);
|
|
|
|
rr_define_method(HandleClass, "Dispose", Dispose, 0);
|
|
|
|
rr_define_method(HandleClass, "MakeWeak", MakeWeak, 0);
|
|
|
|
rr_define_method(HandleClass, "ClearWeak", ClearWeak, 0);
|
|
|
|
rr_define_method(HandleClass, "IsNearDeath", IsNearDeath, 0);
|
|
|
|
rr_define_method(HandleClass, "IsWeak", IsWeak, 0);
|
2011-04-08 10:54:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE rr_v8_handle_new(VALUE klass, v8::Handle<void> handle) {
|
|
|
|
return Data_Wrap_Struct(klass, gc_mark, gc_free, new v8_handle(handle));
|
2011-04-07 12:49:47 -04:00
|
|
|
}
|
|
|
|
|