Re: Array property of custom object

Mihai Dobrescu <[email protected]>
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
On Tuesday, May 3, 2016 at 6:12:03 PM UTC+3, Boris Zbarsky wrote:
> On 5/3/16 3:25 AM, Mihai Dobrescu wrote:
> > ....well, I did not say js::proxies.
> 
> OK, let's not use "proxy" without clearly stating which of the many 
> meanings we're using, because that way lies only frustration.
> 
> > I could ask also, how do you know should be done? For any of these, simple and array properties. If you do it from scratch, what is your approach?
> 
> Let me try to state this more clearly.
> 
> If you want |var x = obj.arr| to return an object that will call code 
> you control when x[5] is read or set, and the precise set of property 
> names for which you want your code to be called is not known up front, 
> then obj.arr needs to be a js::Proxy.  The proxy handler's methods are 
> what will get called when x[5] is read or set.
> 
> If you do know the precise set of property names you care about up front 
> (e.g. you want your code to be called for x[N] where 0 <= N < 100, but 
> don't want your code called when N is 101), then you can get away with 
> defining a bunch of accessor properties on obj.arr instead of using a 
> js::Proxy.  Obviously for large N this could have deleterious memory 
> effects.
> 
> Does that help?
> 
> -Boris

Well, I think I was right, though. I did used all the juice of SpiderMonkey similarly to a js::proxy, as I had used the private data functionality and customized all ops as far as I could... although I did not use the js::proxy itself.

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.
Will it make possible to simply iterate too?
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.