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?
addtrap in proxies. It looks like you're looking for a subclass, not a proxy (which is not aSetand can't be used with Set methods) – Bergi May 12 '17 at 3:33{}cause VMErrors for a Set Proxy? – user3467349 May 12 '17 at 10:47Maps andSets work alike. And really, it does look like you're looking to interceptaddmethod calls, for which subclasses are the easiest solution. – Bergi May 12 '17 at 13:17Proxyis 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". – user3467349 May 12 '17 at 13:32