pmed / v8pp

Bind C++ functions and classes into V8 JavaScript engine
http://pmed.github.io/v8pp/
Other
898 stars 120 forks source link

Is there any way to use v8pp without v8::Isolate data slot? #26

Closed ghost closed 7 years ago

ghost commented 7 years ago

There is no available v8::Isolate data slot in Electron. (All the slots are in use.)

// NodeDebugger is stored in Isolate's data, slots 0, 1, 3 have already been
// taken by gin, blink and node, using 2 is a safe option for now.
const int kIsolateSlot = 2;

https://github.com/electron/electron/blob/28e2058ff108a20dd395ebe5374403381b6d3ff2/atom/browser/node_debugger.cc#L23-L25

pmed commented 7 years ago

Well, I was afraid this moment would come :-)

I use a data slot in V8 to store a pointer to a list of registered classes class_instances. This list should be global, especially when we have several shared libraries which use v8pp.

Consider a first.dll with a class Base exposed to V8, and second.dll with a class Derived which is inherited from Base. Both Base and Derived classes should be registered in the same class_instances list.

I need to think either how to store class_instances aside of V8 isolate data slot.

pmed commented 7 years ago

@h2so5 I've pushed changes as v1.2.0. Since this version v8pp doesn't use a data slot in v8::Isolate. To register shared classes in several projects which use v8pp, a macro V8PP_ISOLATE_DATA_SLOT should be defined in those projects.

ghost commented 7 years ago

@pmed Excellent! Thank you for your quick action 😺