diff --git a/ext/v8/isolate.cc b/ext/v8/isolate.cc index 56cbce0..3592cd6 100644 --- a/ext/v8/isolate.cc +++ b/ext/v8/isolate.cc @@ -19,7 +19,9 @@ namespace rr { } VALUE Isolate::Dispose(VALUE self) { - Isolate(self)->Dispose(); + Isolate isolate(self); + delete isolate.data(); + isolate->Dispose(); return Qnil; } diff --git a/ext/v8/isolate.h b/ext/v8/isolate.h index 1e2674f..3832a00 100644 --- a/ext/v8/isolate.h +++ b/ext/v8/isolate.h @@ -9,11 +9,19 @@ namespace rr { * Represents a fully encapsulated V8 virtual machine. Allocated * from Ruby by calling `V8::C::Isolate::New()` * + * Every v8::Isolate wrapped in Ruby will have an instance of + * `IsolateData` embedded in it that can be used for bookkeeping + * between the V8 and Ruby worlds. For example, when v8 objects are + * no longer needed by ruby, they'll be enqueued for later release + * inside the V8 garbarge collection thread. This queue lives in the + * `IsolateData` + * * Note: You must call `Dispose()` on the isolate for its resources - * to be released. + * to be released, otherwise, it will be leaked. */ class Isolate : public Pointer { public: + class IsolateData; static void Init(); static VALUE New(VALUE self); @@ -21,11 +29,30 @@ namespace rr { inline Isolate(v8::Isolate* isolate) : Pointer(isolate) {} inline Isolate(VALUE value) : Pointer(value) {} + /** + * Converts the v8::Isolate into a Ruby Object, while setting up + * its book keeping data. E.g. + * VALUE rubyObject = Isolate(v8::Isolate::New()); + */ inline operator VALUE() { + pointer->SetData(0, new IsolateData()); return Data_Wrap_Struct(Class, 0, 0, pointer); } + /** + * Access the book-keeping data. e.g. + * + * Isolate(self).data(); + */ + inline IsolateData* data() { + return (IsolateData*)pointer->GetData(0); + } + static VALUE Dispose(VALUE self); + + class IsolateData { + + }; }; }