pmed / v8pp

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

Indexed access #124

Open ayles opened 4 years ago

ayles commented 4 years ago

What about setting indexed accessor on class_? (Simulating array behaviour, for examle). I tried to write it myself but I have no complete idea how to do it right. Maybe something like set_indexed_accessor(accessor<Getter, Setter>)? (Like property_ for set) So I need some recommendations and I'll try to do it.

pmed commented 4 years ago

Hi,

I like the idea and some time ago there was a request for this feature in #47. Unfortunately, I've never used indexed accessors, so they are still not implemented.

A possible implementation could be generalized both for indexed and named property accessors, and it would be good to support also lambdas, similar to the current property accessor implementation. The next version (in c++17 branch) has no set_ prefixed bind functions, so it could be named as indexer(getter, setter).

Anyway, a pull request is greatly welcomed 😃

ayles commented 4 years ago

Hmmmm.

I implemented indexer in c++17 as indexer(getter, setter), but there is one problem... Idk should I add support for (...query, deleter, enumerator). If should, it will be implementation separated from property, so I'm here with this question =)

pmed commented 4 years ago

As I understand from comments to v8::IndexedPropertyHandlerConfiguration only getter is required, so other callbacks are optional. But as a generic solution, it would be nice to support them in the v8pp.

The property has a specialisation for read-only case with only a pointer to getter function. This allows to have sizeof(property) == sizeof(void*) with no extra memory management for v8::External data storage.

Similar way may be used for a new indexed_property implementation.