tc39/proposal-structs

Breaking Proxy?

Jack-Works opened this issue · 4 comments

Proxy is designed to be non-distinguishable from normal objects. If structs are typeof === "object", then the Proxy of structs can be detected with the following code.

function isProxyOfStruct(x) {
    try {
        struct class extends x {}
        return true
    } catch {
        return false // Nah, it's a proxy
    }
}

You can already easily determine if anything is a proxy of any specific builtin, except Error, Function, and Array.

syg commented

Doesn't that example also return false for regular objects?

Doesn't that example also return false for regular objects?

Yes, I mean the "Proxy of structs".

I agree this isn't a problem because of all those Web APIs that reads internal slots directly.

Not just web; every 262 builtin (besides Error) reads internal slots, and only Function and Array effectively tunnel through proxies.