Pass an environment to eval()?

Mark S. Miller erights at google.com
Sat Sep 28 17:53:24 PDT 2013


On Sat, Sep 28, 2013 at 2:49 PM, Axel Rauschmayer <axel at rauschma.de> wrote:

> Has this feature ever been considered?
>
> For example:
>
> ```
> $ var env = { __proto__: window, foo: 1 };
> $ eval('var bar = foo+1', env);
> $ env.bar
> 2
> ```
>

See the "confine" function at <
https://code.google.com/p/google-caja/source/browse/trunk/src/com/google/caja/ses/startSES.js#855>,
also documented in section 2.3 of <
http://research.google.com/pubs/pub40673.html>.



>
> Useful for writing interpreters and more convenient for interacting with
> evaluated code than improvising something equivalent via `Function`.
>
> Axel
>
> --
> Dr. Axel Rauschmayer
> axel at rauschma.de
>
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>


-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130928/a5039a3c/attachment-0001.html>


More information about the es-discuss mailing list