mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
Revert "allow v8 refs to hold on to more than one ruby object."
This reverts commit 9a44d204c8
.
This commit is contained in:
parent
9a44d204c8
commit
f1222786cf
2 changed files with 13 additions and 22 deletions
|
@ -2,38 +2,25 @@
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
using namespace v8;
|
using namespace v8;
|
||||||
|
|
||||||
v8_ref::v8_ref(Handle<void> object, VALUE ref) : handle(Persistent<void>::New(object)) {
|
|
||||||
references = rb_hash_new();
|
|
||||||
this->add(ref);
|
|
||||||
}
|
|
||||||
|
|
||||||
void v8_ref::add(VALUE ref) {
|
v8_ref::v8_ref(Handle<void> object, VALUE ref) : handle(Persistent<void>::New(object)), references(ref) {
|
||||||
if (ref != 0 && RTEST(ref)) {
|
|
||||||
rb_hash_aset(references, ref, Qtrue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v8_ref::~v8_ref() {
|
v8_ref::~v8_ref() {
|
||||||
handle.Dispose();
|
handle.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
void v8_ref_mark(v8_ref* ref) {
|
||||||
//the v8_ref wraps a v8 handle so that ruby can hold a reference to it.
|
if (ref->references != 0) {
|
||||||
void gc_mark(v8_ref* ref) {
|
|
||||||
rb_gc_mark(ref->references);
|
rb_gc_mark(ref->references);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gc_free(v8_ref* ref) {
|
|
||||||
delete ref;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rr_ref_addref(VALUE data, VALUE newref) {
|
void v8_ref_free(v8_ref* ref) {
|
||||||
v8_ref * ref = 0;
|
delete ref;
|
||||||
Data_Get_Struct(data, struct v8_ref, ref);
|
|
||||||
ref->add(newref);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE V8_Ref_Create(VALUE ruby_class, v8::Handle<void> handle, VALUE ref) {
|
VALUE V8_Ref_Create(VALUE ruby_class, v8::Handle<void> handle, VALUE ref) {
|
||||||
return Data_Wrap_Struct(ruby_class, gc_mark, gc_free, new v8_ref(handle, ref));
|
return Data_Wrap_Struct(ruby_class, v8_ref_mark, v8_ref_free, new v8_ref(handle, ref));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,21 @@
|
||||||
#include <v8.h>
|
#include <v8.h>
|
||||||
#include "ruby.h"
|
#include "ruby.h"
|
||||||
|
|
||||||
|
//the v8_ref wraps a v8 handle so that ruby can hold a reference to it.
|
||||||
|
|
||||||
struct v8_ref {
|
struct v8_ref {
|
||||||
//takes a handle object and adds a new persistent handle for
|
//takes a handle object and adds a new persistent handle for
|
||||||
//the referenced object
|
//the referenced object
|
||||||
v8_ref(v8::Handle<void> object, VALUE ref = 0);
|
v8_ref(v8::Handle<void> object, VALUE ref = 0);
|
||||||
virtual ~v8_ref();
|
virtual ~v8_ref();
|
||||||
void add(VALUE ref);
|
|
||||||
v8::Persistent<void> handle;
|
v8::Persistent<void> handle;
|
||||||
VALUE references;
|
VALUE references;
|
||||||
};
|
};
|
||||||
|
|
||||||
void rr_ref_addref(VALUE handle, VALUE newref);
|
|
||||||
|
//memory management
|
||||||
|
void v8_ref_mark(v8_ref* ref);
|
||||||
|
void v8_ref_free(v8_ref* ref);
|
||||||
|
|
||||||
VALUE V8_Ref_Create(VALUE ruby_class, v8::Handle<void> handle, VALUE ref = 0);
|
VALUE V8_Ref_Create(VALUE ruby_class, v8::Handle<void> handle, VALUE ref = 0);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue