Re: Array property of custom object

Boris Zbarsky <[email protected]>
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
On 5/3/16 11:28 AM, Mihai Dobrescu wrote:
> Now, I have the question how could I use js::proxy to attain my goal, being aware of its drawbacks. I'm sure it involves memory fragmentation and cpu load.

I don't see why it would involve "memory fragmentation".

To use a js::Proxy, you define an appropriate proxy handler to do 
whatever you want.  Basically, you directly implement the various 
internal methods from the ES spec for your object.

http://mxr.mozilla.org/mozilla-central/source/dom/base/WindowNamedPropertiesHandler.cpp 
has an example of a simple proxy that you might be able to repurpose.

> Will it make possible to simply iterate too?

I don't know what you mean by "iterate" exactly, but obviously a proxy 
would allow you to do for-in enumeration (via 
getOwnEnumerablePropertyKeys) and you can always do for-of iteration by 
providing an iterator implementation for your object.

-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.