Breaking Proxy?
Jack-Works opened this issue · 4 comments
Jack-Works commented
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
}
}
ljharb commented
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?
Jack-Works commented
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.
ljharb commented
Not just web; every 262 builtin (besides Error) reads internal slots, and only Function and Array effectively tunnel through proxies.