Proxy drilling once again ...

For you and anyone else writing a Proxy, I really recommend reading the NOTEs in the Proxy section of the spec. You don't need to read the algorithms themselves; every trap has a NOTE after which describes the invariants enforced for that trap. Anyone writing a Proxy must ensure that those invariants are upheld, or you'll run into TypeErrors, as you have here. Some (possibly all) of these are mentioned on MDN, but the spec is the canonical source. If you find that MDN is missing some, it's now on GitHub and easy to contribute to.

Like I said in the last thread, there's a bunch of stuff you have to decide up front when making a Proxy - this includes whether it's going to be an Array according to isArray and whether the typeof will be object or function, but also a whole bunch of other things, especially around non-configurable properties. There are some things that, by design, you simply cannot do, with a Proxy or with anything else. The only purpose of the target is to enforce this.

I doubt we're going to add any new Proxy traps. (It's not even clear that it would be web-compat to do so.) But if you want to suggest one, to have any hope at all of being in the language, you need to ensure that the trap cannot be used to violate the essential invariants. Your proposed valueOf trap looks like it would make it trivial to violate the essential invariants.

4 Likes