1

In strict mode, indirect calls to eval should have this bound to the global object in eval code.

10.4.2: In Edition 5, indirect calls to the eval function use the global environment as both the variable environment and lexical environment for the eval code. In Edition 3, the variable and lexical environments of the caller of an indirect eval was used as the environments for the eval code.

However, in Opera, this expression results in undefined:

(function(){'use strict'; return (0 || eval)('this'); }())

Chrome and Firefox work as expected.

I found this here: http://kangax.github.com/jstests/indirect-eval-testsuite/

Is this a browser bug? If so, is it being tracked yet?

See also Why do some forms of indirect eval fail in Opera and Safari?

Community
  • 1
  • 1
Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141
  • Try to eval something else for example alert. If it will work its an issue of opera. – Zaffy Oct 01 '12 at 01:04
  • @Zaffy I'm not sure what you mean... `alert` would work regardless of whether `this` refers to the global object. – Dagg Nabbit Oct 01 '12 at 01:14
  • Oh, sorry i thought that eval cannot be used in strict mode. My stupidity sorry. – Zaffy Oct 01 '12 at 01:17
  • Seems like a bug. Funny thing is that I ran the [test262 suite](http://test262.ecmascript.org/) in Opera, and it didn't seem to pick it up. Perhaps they're missing a test for that. I'm running it again to be certain. – I Hate Lazy Oct 01 '12 at 01:43

1 Answers1

3

Opera's ECMAScript engine seems to be doing some over-eager optimisation here, where "(0||eval)" is simplified to just "eval" before compilation. In this case, this optimisation introduces a bug because it changes the behaviour of the code.

(Internally at Opera we track this issue as CORE-47727)

hallvors
  • 6,069
  • 1
  • 25
  • 43
  • Thanks, I thought that might be the issue but it's good to hear confirmation. Do you have any idea what's going on here: http://stackoverflow.com/questions/12666272/ ? That one's really puzzling to me, because you get the same behavior in Safari, and it looks intentional, but doesn't seem to adhere to ES5. – Dagg Nabbit Oct 09 '12 at 20:51