ES6 proxies cannot intercept array indices

1k views Asked by At

Here is my test code (to be run using node --harmony-proxies foo.js:

var a = Proxy.create({
    get : function (proxy, prop)
    {
        return 5
    }
})


console.log(a['foo'])
console.log(a.length)
console.log(a['10'])
console.log(a[10])

Why the last 2 lines fail to print 5, why the proxy fails to intercept properties looking like integers? Is it an implementation bug or is it how it is specified? Is there a separate way to intercept array indices so I can implement my own arrays (e.g. sparse arrays)?

2

There are 2 answers

0
Andreas Rossberg On BEST ANSWER

If I read the node changelogs correctly, then node 0.6.18 is still running on V8 3.6.6, which is a fairly old version (from October 2011). In that version, support for proxies was still work in progress (as the other supported Harmony features). Don't expect proxies to function properly before V8 3.8 (from December 2011). Unfortunately, I cannot tell you when the stable version of node will upgrade beyond that.

0
AudioBubble On

As A. Rossberg indicated, that bug (and a couple of other showstoppers) are fixed in V8 3.8 (node 0.7.x is quite stable and 0.8.x nears release). If you're working with proxies though, there's still some bugs that you'll have to watch out for. This github issue has a pretty good quick overview of them: https://github.com/tvcutsem/harmony-reflect/issues/4