Proxies and preventExtensions: how to avoid inconsistency in a membrane?

Oriol Bugzilla oriol-bugzilla at hotmail.com
Sun Sep 4 21:06:41 UTC 2016


> Could there be a Proxy.hasBeenRevoked(proxy) method?


The Proxy constructor only accepts targets and handlers when they are objects and are not revoked proxies.

I wonder what's the point of not allowing revoked proxies but allow revocable proxies which may be revoked later.


Anyways, this allows you to check if a value is a revoked proxy: you only need to ensure that it's an object but makes Proxy throw.

I think something like this should work:


```javascript

Proxy.hasBeenRevoked = function(value) {

  if(Object(value) !== value) {

    return false; // Primitive value

  }

  try {

    new Proxy(value, value);

    return false; // Either non-proxy object or non-revoked proxy

  } catch(err) {

    return true; // Revoked proxy

  }

};

```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160904/11fa8be1/attachment-0001.html>


More information about the es-discuss mailing list