double checking if window.eval(…) is an indirect call to eval().

# John-David Dalton (13 years ago)

So I have read the section (and the notes associated with it) over what a direct call to eval is: es5.github.com/#x15.1.2.1.1, dev.w3.org/html5/spec/Overview.html#script-s-global-object

A direct call to the eval function is one that is expressed as a CallExpression that meets the following two conditions: The Reference that is the result of evaluating the MemberExpression in the CallExpression has an environment record as its base value and its reference name is "eval". The result of calling the abstract operation GetValue with that Reference as the argument is the standard built-in function defined in 15.1.2.1.

But I am still a little unsure if window.eval(…) is a direct call or not. I have heard window.eval() is an indirect call but wanted to make sure.

I see it as <call expression><member expression> window.eval</member expression> (…) </call expression>

Wouldn't the result of evaluating the MemberExpression window.eval have global's environment record as its base and a reference name of eval? Is window.eval(..) a direct call to eval?

Thanks,

# Dmitry Soshnikov (13 years ago)

On Sat, Aug 27, 2011 at 11:13 PM, John-David Dalton < john.david.dalton at gmail.com> wrote:

So I have read the section (and the notes associated with it) over what a direct call to eval is: es5.github.com/#x15.1.2.1.1, dev.w3.org/html5/spec/Overview.html#script-s-global-object

A direct call to the eval function is one that is expressed as a CallExpression that meets the following two conditions: The Reference that is the result of evaluating the MemberExpression in the CallExpression has an environment record as its base value and its reference name is "eval". The result of calling the abstract operation GetValue with that Reference as the argument is the standard built-in function defined in 15.1.2.1.

But I am still a little unsure if window.eval(…) is a direct call or not. I have heard window.eval() is an indirect call but wanted to make sure.

I see it as <call expression><member expression> window.eval</member expression> (…) </call expression>

Wouldn't the result of evaluating the MemberExpression window.eval have global's environment record as its base and a reference name of eval?

No. It's the global object what is the base (more precisely, its DOM's proxy wrapper -- window or either the global itself), but not an environment record.

Is window.eval(..) a direct call to eval?

No, it's indirect.

dmitrysoshnikov.com/ecmascript/es5-chapter-2-strict-mode/#indirect-eval-call

Dmitry.

# John-David Dalton (13 years ago)

No. It's the global object what is the base (more precisely, its DOM's proxy wrapper -- window or either the global itself), but not an environment record.

So basically the only kind of MemberExpression allowed is a PrimaryExpression?

So writing it out is like: es5.github.com/#x8.7.1 window.eval -> GetValue(window.eval) -> window is seen as the

base so it goes to step 4 of 8.7.1 and not step 5 (which is for environment records).

ES3 makes it a bit more clear: "If 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."

Though older browsers w/ their older implementations will barf on (1, eval)(…) but not window.eval(..) for some reason.

No, it's indirect.

dmitrysoshnikov.com/ecmascript/es5-chapter-2-strict-mode/#indirect-eval-call

I knew you would chime in with a link to your post, which is why I wrote I read the notes associated with the link I posted (your post was one of the notes) :P

# Dmitry Soshnikov (13 years ago)

On Sat, Aug 27, 2011 at 11:53 PM, John-David Dalton < john.david.dalton at gmail.com> wrote:

No. It's the global object what is the base (more precisely, its DOM's proxy wrapper -- window or either the global itself), but not an environment record.

So basically the only kind of MemberExpression allowed is a PrimaryExpression?

If it will be easier for you to remember (and what is actually is written in the reference I gave), only eval call written in the following syntactic form is direct:

eval(...)

Only. All the other cases are indirect.

So writing it out is like: es5.github.com/#x8.7.1 window.eval -> GetValue(window.eval) -> window is seen as the base so it goes to step 4 of 8.7.1 and not step 5 (which is for environment records).

Right.

ES3 makes it a bit more clear: "If 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."

Yes, perhaps.

Though older browsers w/ their older implementations will barf on (1, eval)(…) but not window.eval(..) for some reason.

I think the main word is "may" why it is so. If it would "should", then maybe implementations would throw SyntaxError in both cases.

No, it's indirect.

dmitrysoshnikov.com/ecmascript/es5-chapter-2-strict-mode/#indirect-eval-call

I knew you would chime in with a link to your post, which is why I wrote I read the notes associated with the link I posted (your post was one of the notes) :P

Is there something unclear in my explanation? Want to propose to improve something?

Dmitry.

# Oliver Hunt (13 years ago)

On Aug 27, 2011, at 2:42 PM, Dmitry Soshnikov wrote:

On Sat, Aug 27, 2011 at 11:53 PM, John-David Dalton <john.david.dalton at gmail.com> wrote:

No. It's the global object what is the base (more precisely, its DOM's proxy wrapper -- window or either the global itself), but not an environment record.

So basically the only kind of MemberExpression allowed is a PrimaryExpression?

If it will be easier for you to remember (and what is actually is written in the reference I gave), only eval call written in the following syntactic form is direct:

eval(...)

Only. All the other cases are indirect.

I have a vague recollection that *monkey treats <global object>.eval(..) as a direct eval?

# John-David Dalton (13 years ago)

@Oliver Hunt

I have a vague recollection that *monkey treats <global object>.eval(..) as a direct eval?

Firefox < 4 will execute window.eval(….) as in the global execution context but will still allow access to variables that are accessible from the execution context of where window.eval was called. You can see this in the jQuery bug I mentioned here: twitter.com/#!/jdalton/status/70778564617838592

# Dmitry Soshnikov (13 years ago)

On Sun, Aug 28, 2011 at 2:06 AM, Oliver Hunt <oliver at apple.com> wrote:

On Aug 27, 2011, at 2:42 PM, Dmitry Soshnikov wrote:

On Sat, Aug 27, 2011 at 11:53 PM, John-David Dalton < john.david.dalton at gmail.com> wrote:

No. It's the global object what is the base (more precisely, its DOM's proxy wrapper -- window or either the global itself), but not an environment record.

So basically the only kind of MemberExpression allowed is a PrimaryExpression?

If it will be easier for you to remember (and what is actually is written in the reference I gave), only eval call written in the following syntactic form is direct:

eval(...)

Only. All the other cases are indirect.

I have a vague recollection that *monkey treats <global object>.eval(..) as a direct eval?

Yes, however I described the sample behavior as by the spec. Per ES5 spec, definetely it was a *monky's bug.

Dmitry.

# Brendan Eich (13 years ago)

On Aug 27, 2011, at 3:06 PM, Oliver Hunt wrote:

On Aug 27, 2011, at 2:42 PM, Dmitry Soshnikov wrote:

On Sat, Aug 27, 2011 at 11:53 PM, John-David Dalton <john.david.dalton at gmail.com> wrote:

No. It's the global object what is the base (more precisely, its DOM's proxy wrapper -- window or either the global itself), but not an environment record.

So basically the only kind of MemberExpression allowed is a PrimaryExpression?

If it will be easier for you to remember (and what is actually is written in the reference I gave), only eval call written in the following syntactic form is direct:

eval(...)

Only. All the other cases are indirect.

I have a vague recollection that *monkey treats <global object>.eval(..) as a direct eval?

Fixed a while ago:

bugzilla.mozilla.org/show_bug.cgi?id=495325

Firefox 4 and up.