2015-07-04 12:20:50 -05:00
|
|
|
// -*- mode: c++ -*-
|
2015-03-18 21:50:59 +00:00
|
|
|
#ifndef RR_ISOLATE
|
|
|
|
#define RR_ISOLATE
|
|
|
|
|
|
|
|
namespace rr {
|
2015-07-04 12:20:50 -05:00
|
|
|
/**
|
|
|
|
* V8::C::Isolate
|
|
|
|
*
|
|
|
|
* Represents a fully encapsulated V8 virtual machine. Allocated
|
|
|
|
* from Ruby by calling `V8::C::Isolate::New()`
|
|
|
|
*
|
2015-07-05 11:26:03 -05:00
|
|
|
* 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`
|
|
|
|
*
|
2015-07-04 12:20:50 -05:00
|
|
|
* Note: You must call `Dispose()` on the isolate for its resources
|
2015-07-05 11:26:03 -05:00
|
|
|
* to be released, otherwise, it will be leaked.
|
2015-07-04 12:20:50 -05:00
|
|
|
*/
|
2015-03-18 21:50:59 +00:00
|
|
|
class Isolate : public Pointer<v8::Isolate> {
|
|
|
|
public:
|
2015-07-05 11:26:03 -05:00
|
|
|
class IsolateData;
|
2015-03-18 21:50:59 +00:00
|
|
|
static void Init();
|
2015-03-21 09:51:17 +00:00
|
|
|
|
2015-03-18 21:50:59 +00:00
|
|
|
static VALUE New(VALUE self);
|
|
|
|
|
|
|
|
inline Isolate(v8::Isolate* isolate) : Pointer<v8::Isolate>(isolate) {}
|
|
|
|
inline Isolate(VALUE value) : Pointer<v8::Isolate>(value) {}
|
|
|
|
|
2015-07-05 11:26:03 -05:00
|
|
|
/**
|
|
|
|
* Converts the v8::Isolate into a Ruby Object, while setting up
|
|
|
|
* its book keeping data. E.g.
|
|
|
|
* VALUE rubyObject = Isolate(v8::Isolate::New());
|
|
|
|
*/
|
2015-03-18 21:50:59 +00:00
|
|
|
inline operator VALUE() {
|
2015-07-05 11:26:03 -05:00
|
|
|
pointer->SetData(0, new IsolateData());
|
2015-07-04 12:20:50 -05:00
|
|
|
return Data_Wrap_Struct(Class, 0, 0, pointer);
|
2015-03-18 21:50:59 +00:00
|
|
|
}
|
|
|
|
|
2015-07-05 11:26:03 -05:00
|
|
|
/**
|
|
|
|
* Access the book-keeping data. e.g.
|
|
|
|
*
|
|
|
|
* Isolate(self).data();
|
|
|
|
*/
|
|
|
|
inline IsolateData* data() {
|
|
|
|
return (IsolateData*)pointer->GetData(0);
|
|
|
|
}
|
|
|
|
|
2015-07-04 12:20:50 -05:00
|
|
|
static VALUE Dispose(VALUE self);
|
2015-07-05 11:26:03 -05:00
|
|
|
|
|
|
|
class IsolateData {
|
|
|
|
|
|
|
|
};
|
2015-03-18 21:50:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|