ajvincent / es-membrane

An ECMAScript implementation of a Membrane, allowing users to dynamically hide, override, or extend objects in JavaScript with controlled effects on the original objects.
ISC License
109 stars 13 forks source link

GUI: filterOwnKeys cannot apply to non-extensible values #162

Closed ajvincent closed 6 years ago

ajvincent commented 6 years ago

From source/ModifyRulesAPI.js:

    /* Defining a filter after a proxy's shadow target is not extensible
     * guarantees inconsistency.  So we must disallow that possibility.
     *
     * Note that if the proxy becomes not extensible after setting a filter,
     * that's all right.  When the proxy becomes not extensible, it then sets
     * all the proxies of the shadow target before making the shadow target not
     * extensible.
     */
ajvincent commented 6 years ago

Maybe there's a fix we can do for proxies under construction - if we can define the properties according to the filter before sealing the shadow target of the proxy, then the GUI won't need to worry about filtering non-extensible proxies.

ajvincent commented 6 years ago

Blocks #6.

ajvincent commented 6 years ago

So in detail, here's what going on:

  1. The object we want to protect is not extensible.
  2. The proxy for that object is created - and the shadow target immediately sealed.
  3. A DistortionListener triggers for the proxy, attempting to set filterOwnKeys. This is disallowed currently, resulting in an assertion failure.
  4. Assuming the previous step was successful, the proxy would be returned for use.

We need to intervene at step 2, before the shadow target is sealed.