Re: Array property of custom object

Boris Zbarsky <[email protected]>
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
On 5/6/16 2:10 PM, Mihai Dobrescu wrote:
> I am not afraid to refactor everything, but still, I don't know what to do with that, sorry. Can't tell what to look for in order to implement some proxy wrapper for my classes (I feel I should re-implement them as proxies). But I fail to separate the actual sample code from the things I should re-write.

You need to define a JSClass using PROXY_CLASS_DEF (see jsfriendapi.h).

Then you need to define a proxy handler class inheriting from 
js::BaseProxyHandler and use this class when creating your objects like so:

    js::ProxyOptions options;
    options.setClass(yourJSClassPointer);
    myObj = js::NewProxyObject(cx, handlerInstance, JS::NullHandleValue,
                              theProtoYouWant, options);

and the you need to implement the various methods BaseProxyHandler 
leaves unimplemented on your proxy handler class to have whatever 
behavior it is you want.  This last bit is the part where you can take 
look at what WindowNamedPropertiesHandler and the BaseDOMProxyHandler 
class it inherits from do.

-Boris
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.