Sha256: 47f09883664a8861dc6910e7ca079ff4fd9f0a4fc9d6354f551013f4e77300e6

Contents?: true

Size: 1012 Bytes

Versions: 4

Compression:

Stored size: 1012 Bytes

Contents

#include <v8_ref.h>
#include "stdio.h"
using namespace v8;

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::set(const char *name, VALUE ref) {
  if (ref != 0 && RTEST(ref)) {
    rb_hash_aset(this->references, rb_str_new2(name), 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, gc_mark, gc_free, new v8_ref(handle, ref));
}

VALUE rr_v8_ref_create(VALUE rbclass, v8::Handle<void> handle) {
  return Data_Wrap_Struct(rbclass, gc_mark, gc_free, new v8_ref(handle));
}

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);
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
therubyracer-0.7.1 ext/v8/v8_ref.cpp
therubyracer-0.7.1.pre ext/v8/v8_ref.cpp
therubyracer-0.7.0 ext/v8/v8_ref.cpp
therubyracer-0.7.0.pre ext/v8/v8_ref.cpp