Strict mode eval

Allen Wirfs-Brock allen at wirfs-brock.com
Wed May 11 14:15:30 PDT 2011


On May 11, 2011, at 11:51 AM, Mark S. Miller wrote:

> 
> 
> On Wed, May 11, 2011 at 11:41 AM, felix <felix8a at gmail.com> wrote:
> I think he's proposing that the 'eval' function would be a magical
> function that can inspect its calling environment to determine whether
> it's being called in a lexically strict context or not, and based on
> that it would act like the strict eval operator, or not.
> 
> That's exactly what I'm trying to determine. Such magical dynamic inspection of the caller's lexical context would be a form of dynamic scoping. Nowhere else in the language can a callee detect a caller's strictness.

This is the key point that I haven't seen otherwise mentioned on this thread.   Classically JS eval as implemented by browsers  required knowledge about its calling environment that generally isn't passed by a normal function call.  To make this work, either this extra information has to be passed in every call to any function (any call might be to an aliased eval call) or there has to be a dynamic scoping mechanism that allows eval to reach up the stack and get out of band information from it caller.  Neither of these were things we wanted to require of implementations in ES5.

"Direct eval"  (or the eval operator, as Oliver refers to it) is a way to (mostly) statically identify eval calls and to do special case processing to make the caller environment information available for eval processing.  "indirect evals" are just regular function calls and not special environment information is passed or otherwise made available.  So, the built-in eval function when indirectly involved is limited to using the global environment.

This has nothing to do with strict mode.

Allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110511/dbbeae58/attachment-0001.html>


More information about the es-discuss mailing list