indirect eval spec too severe?

Mark S. Miller erights at google.com
Sun Jan 18 18:03:47 PST 2009


On Sun, Jan 18, 2009 at 12:47 PM, Mark S. Miller <erights at google.com> wrote:

> The Mountain View draft says:
>
>
>> 15.1.2    Function Properties of the Global Object
>> 15.1.2.1    eval (x)
>> When the eval function is called with one argument x, the following steps
>> are taken:
>> [...]
>> If the value of the eval property is used in any way other than a direct
>> call (that is, other than by the explicit use of its name as an Identifier
>> which is the MemberExpression in a CallExpression), or if the eval property
>> is assigned to, an EvalError exception may be thrown.
>>
>> 15.1.2.1.1    Strict Mode Restrictions
>> If strict mode code uses the value of the eval property any way other than
>> as a direct call (that is, other than by the explicit use of its name as an
>> Identifier which is the MemberExpression in a CallExpression), or if the
>> eval property is assigned to, an EvalError exception is thrown.
>>
>
A related difficulty, not addressed by the above spec, is shadowing. Does
the following program contain a direct call to eval (i.e., a use of the
"eval operator")?

  function foo(eval, str) {
    return eval(str);
  }

The eval variable being called here is not an alias for the "eval" property
of the global object, though it may or may not have the same value. If the
answer is that this is not a direct call, since the defining occurrence is
local, then what about the second "eval" in the following code?

  function foo(str1, str2) {
    eval(str1);
    eval(str2);
  }

Since foo may be called as foo('var eval = f', ..), the second eval may
refer to a local or to a global eval. These ambiguities defeat the goal of
distinguishing direct from indirect calls. Though the above specific problem
cannot occur if foo is strict, I propose that, for all code, one may not
define a local variable named "eval".

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


More information about the Es-discuss mailing list