On Jan 25, 12:34 am, Matthieu Riou <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Rhino supports the __define[GS]etter__ as in SpiderMonkey, which is
> great! However, it doesn't work on arrays (even though it does work on
> SM):
>
> js> a = [1,2,3]
> js> a.__defineGetter__(1, function() { print("masked!"); });
> js> a[1]
> 2
>
> This is somewhat understandable as arrays indexing has a few more
> specificities when compared to regular properties. However I think
> this is still an interesting feature.
Agreed. If SpiderMonkey implements it, then Rhino not implementing it
was just an oversight.
>
> My specific use case is that I need to proxy an array so that all
> values are loaded only on access from some backend. However I believe
> there's a whole array (pun intended) of use cases where this feature
> would be valuable, in the same way that __define[GS]etter__ is
> valuable.
>
> I've started implementing this in Rhino and it's actually not such a
> big change. I'd be happy to contribute it (just need to implement the
> lookup methods as well) but would like to know your opinion before.
> Would you accept this modification to Rhino?
Yes, thank you! Just create a bug and cc me on it. You can attach your
patch.
>
> An extension to this (which I don't believe exists in SM) could be,
> mostly for performance reasons, to support something like:
>
> a.__defineGetter__('[]', function() { print "masked!"; });
>
> This would override all index accessors, whatever the index. For large
> arrays it would be much better as you only have a single function
> definition.
>
> So what do you think about this little proposal?
Make sense to me in general, but I want to move in concert with
SpiderMonkey. Also, I haven't been tracking ES4 and we need to be
careful that we don't add features that won't be forward compatible.
Perhaps you could post to the mozilla.dev.tech.js-engine list and see
what people think there of the change?
>
> Thanks,
> Matthieu
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino