2015-07-04 12:20:50 -05:00
|
|
|
// -*- mode: c++ -*-
|
2015-03-18 21:50:59 +00:00
|
|
|
#include "rr.h"
|
2015-07-04 12:20:50 -05:00
|
|
|
#include "isolate.h"
|
2015-03-18 21:50:59 +00:00
|
|
|
|
|
|
|
namespace rr {
|
|
|
|
|
|
|
|
void Isolate::Init() {
|
2015-07-06 00:36:25 -05:00
|
|
|
rb_eval_string("require 'v8/retained_objects'");
|
2015-03-18 21:50:59 +00:00
|
|
|
ClassBuilder("Isolate").
|
|
|
|
defineSingletonMethod("New", &New).
|
2015-03-20 20:47:57 +00:00
|
|
|
|
2015-07-04 12:20:50 -05:00
|
|
|
defineMethod("Dispose", &Isolate::Dispose).
|
2015-03-21 09:51:17 +00:00
|
|
|
defineMethod("Equals", &rr::Isolate::PointerEquals).
|
2015-03-20 20:47:57 +00:00
|
|
|
|
2015-03-18 21:50:59 +00:00
|
|
|
store(&Class);
|
|
|
|
}
|
|
|
|
|
2015-07-05 19:03:38 -05:00
|
|
|
|
2015-03-18 21:50:59 +00:00
|
|
|
VALUE Isolate::New(VALUE self) {
|
2015-07-05 19:03:38 -05:00
|
|
|
Isolate::IsolateData* data = new IsolateData();
|
2015-07-06 00:36:25 -05:00
|
|
|
VALUE rb_cRetainedObjects = rb_eval_string("V8::RetainedObjects");
|
|
|
|
data->retained_objects = rb_funcall(rb_cRetainedObjects, rb_intern("new"), 0);
|
|
|
|
|
2015-07-05 19:03:38 -05:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = &data->array_buffer_allocator;
|
2015-07-06 00:36:25 -05:00
|
|
|
|
2015-07-05 19:03:38 -05:00
|
|
|
Isolate isolate(v8::Isolate::New(create_params));
|
2015-07-06 00:36:25 -05:00
|
|
|
isolate->SetData(0, data);
|
2015-07-05 19:33:05 -05:00
|
|
|
isolate->AddGCPrologueCallback(&clearReferences);
|
2015-07-06 00:36:25 -05:00
|
|
|
|
2015-07-05 19:03:38 -05:00
|
|
|
return isolate;
|
2015-03-18 21:50:59 +00:00
|
|
|
}
|
|
|
|
|
2015-07-04 12:20:50 -05:00
|
|
|
VALUE Isolate::Dispose(VALUE self) {
|
2015-07-05 11:26:03 -05:00
|
|
|
Isolate isolate(self);
|
|
|
|
delete isolate.data();
|
|
|
|
isolate->Dispose();
|
2015-07-04 12:20:50 -05:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:50:59 +00:00
|
|
|
template <>
|
|
|
|
void Pointer<v8::Isolate>::unwrap(VALUE value) {
|
|
|
|
Data_Get_Struct(value, class v8::Isolate, pointer);
|
|
|
|
}
|
|
|
|
}
|