Some background information:
I'm working on a V8-C++ binding library. I know I'm reinventing the wheel, but there is some tiny divergence in my objectives: It's not for Web, Node.js, etc. It's actually for a game. I'm trying using V8 as its scripting engine, and it's not something like small Web game or demos of Canvas/WebGL, I wish it could be scalable and flexible (with the help of V8 Javascript).
Thus, as you know, a complex game system needs to be fast, and it may have many classes, which I want to expose to V8. My work for the 'wheel' went smoothly, with a few troubles about template metaprogramming, but eventually I worked out some useful features e.g. class methods, attributes, ctor binding.
The requirement also indicates that I need support for properties of custom classes, for example, it's quite common that an GameObject has some Vector attributes, and I need access to them in JS. Currently I use a SetAccessor() on InstanceTemplate for attributes, and I assigned a default getter/setter pair for it. The setter is quite simple (just fetch, convert the value, and assign to the pointer in InternalField). But things become different for getter.
Currently I store an ObjectTemplate and NewInstance() every time I return object from getters.
I'm also reading sources of other libraries on this. Famous ones like v8-juices and v8pp, uses a std::map/unordered_map that seems store every instances of certain class that referenced in JS. I think that it's kind of "dirty" but it seems quite fast. In fact, it's about two time faster than mine (while my library faster than v8pp in object creation, setter, etc. So the getter is the only problem left.).
Some projects involved in bindings, like Node.js, Atom Electron, etc., just 'avoids' this problem, since most of data inside Web/Client application is just numbers/strings, they have no need of this, and it's not so performance critical too.
I also have experience of using Lua with binding of C++. It's quite efficient, since creation of userdata(a datatype of Lua representing C data/pointer) is fast, then you just set a metatable to it, done! But in V8, an instantiation of object is needed, which is relatively costly.
Is there any better solution?