Question: is auto-accessor compatible with Proxy?
Closed this issue · 3 comments
jods4 commented
Private class fields are incompatible with proxies, specifically:
class X {
#a = 3
get a() { return this.#a }
}
// a == 3
let a = new X().a
// Crash "Cannot read private member #a from an object whose class did not declare it"
let proxy = new Proxy(new X, {})
a = proxy.a
Given that the auto-accessor proposal "roughly desugars" into a get/set pair backed by a private field, should we assume that classes using auto-accessors won't be usable as proxy targets?
Or will there be some JS runtime magic that makes auto-accessor backing field different from a literal private field?
ljharb commented
I would assume/expect they have the same semantics as private fields.
pzuraq commented
@ljharb is correct, they have the same semantics as private fields, so they are not compatible with proxies.
jods4 commented
Thanks for the quick answer!