Unscopeable

Andreas Rossberg rossberg at google.com
Thu Aug 22 02:59:58 PDT 2013


On 21 August 2013 16:02, Erik Arvidsson <erik.arvidsson at gmail.com> wrote:
> Here is a proof of concept using Proxy (Spidermonkey only)
>
> http://jsbin.com/AWIs/2/edit
>
> It rewrites the `with (expr)` with `with (createUnscopeable(expr))`
> where createUnscopeable returns a proxy that filters out the black
> listed property names.

A small nitpick: that implementation doesn't quite work, because it
does not delegate other operations correctly. The wrapping proxy will
leak into the object as receiver. Consider:

var o = {
  __unscopeable__: ['a'],
  a: 1,
  f: function() { return 'a' in this }
}

with (createUnscopeable(o)) {
  f()  // false!
}

A proper implementation would require explicit delegation for all
receiver-aware traps. Left as an exercise. :)

/Andreas


More information about the es-discuss mailing list