Listen to any changes to an Array

James Stortz <[email protected]> Sun, 5 Aug 2018 14:13:25 -0400
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <CAE0WHd-Chhe3c=tOV9NdAMS91Ec8iDnVm+hWgGETRgg_rA6W0Q@mail.gmail.com>
 Hello,

This is my first time using the mailing list, so I apologize if I am not in
the right place.

Is there a way to listen for any changes to an array in SpiderMonkey?

From what I understand,

1.) JS_PropertyOp/DeletePropertyOp : only hooks an individual property,
i.e. index, (and only on Objects, but you can inherit Array prototype.)

2.) Array.prototype/array instance's methods : only hooks those methods,
not accessors/setters.

3.) Proxy Objects: hooks anything, but there is no MDN documentation, and
it seems a little daunting to derive from BaseProxyHandler.


If I could get Proxy Objects to work, I would use that, but I am trying to
understand how it works under the hood (to see if I could implement
something more simple on my array.) I was hoping to see some clues in
Proxy.cpp about how "set" works to listen for any changes, but didn't
figure anything out. (I feel like Proxies were added to the ES6 spec to
keep JS natives the same while augmenting them, and it seems like overkill.)


Can anybody help me?

Thanks!