mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
allow v8_ref to have multiple named references to other ruby objects
This commit is contained in:
parent
f1222786cf
commit
abb23b2fac
2 changed files with 23 additions and 14 deletions
|
@ -2,25 +2,37 @@
|
|||
#include "stdio.h"
|
||||
using namespace v8;
|
||||
|
||||
|
||||
v8_ref::v8_ref(Handle<void> object, VALUE ref) : handle(Persistent<void>::New(object)), references(ref) {
|
||||
|
||||
v8_ref::v8_ref(Handle<void> object, VALUE ref) : handle(Persistent<void>::New(object)) {
|
||||
this->references = rb_hash_new();
|
||||
this->set("default", ref);
|
||||
}
|
||||
|
||||
v8_ref::~v8_ref() {
|
||||
handle.Dispose();
|
||||
}
|
||||
|
||||
void v8_ref_mark(v8_ref* ref) {
|
||||
if (ref->references != 0) {
|
||||
rb_gc_mark(ref->references);
|
||||
void v8_ref::set(const char *name, VALUE ref) {
|
||||
if (ref != 0 && RTEST(ref)) {
|
||||
rb_hash_aset(this->references, rb_str_new2(name), ref);
|
||||
}
|
||||
}
|
||||
|
||||
void v8_ref_free(v8_ref* ref) {
|
||||
delete ref;
|
||||
namespace {
|
||||
void gc_mark(v8_ref* ref) {
|
||||
rb_gc_mark(ref->references);
|
||||
}
|
||||
|
||||
void gc_free(v8_ref* ref) {
|
||||
delete ref;
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
return Data_Wrap_Struct(ruby_class, gc_mark, gc_free, new v8_ref(handle, ref));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -11,15 +11,12 @@ struct v8_ref {
|
|||
//the referenced object
|
||||
v8_ref(v8::Handle<void> object, VALUE ref = 0);
|
||||
virtual ~v8_ref();
|
||||
void set(const char *name, VALUE ref);
|
||||
v8::Persistent<void> handle;
|
||||
VALUE references;
|
||||
};
|
||||
|
||||
|
||||
//memory management
|
||||
void v8_ref_mark(v8_ref* ref);
|
||||
void v8_ref_free(v8_ref* ref);
|
||||
|
||||
void rr_v8_ref_setref(VALUE handle, const char *name, VALUE ref);
|
||||
VALUE V8_Ref_Create(VALUE ruby_class, v8::Handle<void> handle, VALUE ref = 0);
|
||||
|
||||
template <class T> v8::Local<T> V8_Ref_Get(VALUE object) {
|
||||
|
|
Loading…
Add table
Reference in a new issue