Proxy deleteProperty has no receiver
Reported by
andrea.g...@gmail.com,
May 18
|
||||
Issue descriptionUserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15 Steps to reproduce the problem: 1. return a proxied instance from a constructor 2. find yourself incapable to relate such proxy once without needing to directly relate the instance too 3. check this codepen and read the console https://codepen.io/WebReflection/pen/qYLrNx?editors=0010 What is the expected behavior? Being able to store in a WeakMap a proxy and intercept `delete` calls through this proxy. What went wrong? The `deleteProperty` doesn't expose the receiver so it's impossible to retrieve the involved proxy when a property is deleted. This means proxied instances need to store in a WeakMap both proxy and the instance instead of just the proxy, and it feels both wrong and error-prone. Did this work before? No Chrome version: 66.0.3359.181 Channel: stable OS Version: OS X 10.13.4 Flash Version: Thanks for considering this fix.
,
May 20
,
May 21
The [[Delete]] internal method doesn't need a receiver, so the deleteProperty trap only has two arguments. See 9.5.10-6 https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-delete-p
,
May 21
Able to reproduce the issue on Mac 10.13.3, Win-10 and Ubuntu 14.04 using chrome reported version #66.0.3359.181 and latest canary #68.0.3436.0. This is a non-regression issue as it is observed from M60 old builds. Hence, marking it as untriaged to get more inputs from dev team. Thanks...!!
,
May 21
Then it's a specification bug because it's impossible to use proxies with methods.
I've updated the example to show that within a class method:
method() {
// this here is the receiver, not the target
// hence there's no way to use proxies with classes
wm.get(this).push(`invoked method`);
}
,
May 21
FYI I have also raised the question in the ECMAScript repository: https://github.com/tc39/ecma262/issues/1198
,
May 22
AFAIK this is a wont fix with a better workaround than a dual weak map, as explained in here: https://github.com/tc39/ecma262/issues/1198#issuecomment-390804560 ``` const handlersProto = { deleteProperty(target, key) { console.log({ proxy: this.proxy }); return Reflect.deleteProperty(target, key); } }; class Foo { constructor() { const handlers = Object.create(handlersProto); const proxy = (handlers.proxy = new Proxy(this, handlers)); wm.set(proxy, []); return proxy; } } ```
,
May 25
|
||||
►
Sign in to add a comment |
||||
Comment 1 by schenney@chromium.org
, May 18