JavaScript Set appears to be entirely incompatible with JavaScript proxies, attempting to Proxy()
a Set()
var p = new Proxy(new Set(), {
add(target, val, receiver) {
console.log('in add: ', target, val, receiver)
}
})
p.add(55)
results in a VMError:
Uncaught TypeError: Method Set.prototype.add called on incompatible receiver [object Object]
at Proxy.add (native)
at <anonymous>:1:3
In fact, proxying a Set()
in any way breaks it categorically - even if our proxy handler does nothing at all! Compare p = new Proxy({}, {})
vs p = new Proxy(new Set(), {})
. (This applies both in Firefox (52.0.2) and Chromium (57.0.2987.133).)
I can't seem to find a credible reference or documentation for this, why cannot JavaScript Proxy
a Set
object and why is it hitting a VM Error?
add
trap in proxies. It looks like you're looking for a subclass, not a proxy (which is not aSet
and can't be used with Set methods){}
cause VMErrors for a Set Proxy?Map
s andSet
s work alike. And really, it does look like you're looking to interceptadd
method calls, for which subclasses are the easiest solution.Proxy
is incompatible withSet
? Why does it cause a VMError even on an empty handler? No where in my question does it ask "how do I intercept add calls".