问题
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?
回答1:
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)
来源:https://stackoverflow.com/questions/12666447/why-is-0-eval-not-treated-as-indirect-in-opera