1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

setup and teardown IsolateData with each Isolate

This commit is contained in:
Charles Lowell 2015-07-05 11:26:03 -05:00
parent b11e514b56
commit 1fac021d91
2 changed files with 31 additions and 2 deletions

View file

@ -19,7 +19,9 @@ namespace rr {
}
VALUE Isolate::Dispose(VALUE self) {
Isolate(self)->Dispose();
Isolate isolate(self);
delete isolate.data();
isolate->Dispose();
return Qnil;
}

View file

@ -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<v8::Isolate> {
public:
class IsolateData;
static void Init();
static VALUE New(VALUE self);
@ -21,11 +29,30 @@ namespace rr {
inline Isolate(v8::Isolate* isolate) : Pointer<v8::Isolate>(isolate) {}
inline Isolate(VALUE value) : Pointer<v8::Isolate>(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 {
};
};
}