Why is (0 || eval) not treated as indirect in Opera?

痴心易碎 提交于 2019-12-11 07:51:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!