javascript - 为什么 (0 || eval) 在 Opera 中不被视为间接?

标签 javascript eval opera strict-mode

在严格模式下,对 eval 的间接调用应该将 this 绑定(bind)到 eval 代码中的全局对象。

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.

但是,在 Opera 中,此表达式会导致 undefined:

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

Chrome 和 Firefox 按预期工作。

我在这里找到了这个:http://kangax.github.com/jstests/indirect-eval-testsuite/

这是浏览器错误吗?如果是这样,它是否正在被跟踪?

另见 Why do some forms of indirect eval fail in Opera and Safari?

最佳答案

Opera 的 ECMAScript 引擎似乎在这里做了一些过于急切的优化,其中“(0||eval)”在编译之前被简化为“eval”。在这种情况下,这种优化引入了一个错误,因为它改变了代码的行为。

(在 Opera 内部,我们将此问题跟踪为 CORE-47727)

关于javascript - 为什么 (0 || eval) 在 Opera 中不被视为间接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12666447/

相关文章:

r - 如何在 R 中的 emmeans() 命令中评估字符串变量作为因子?

html - Opera 和 HTML5 视频

javascript - 如何将 javascript 变量放入 url 中?

javascript - 为什么 EcmaScript 5 严格模式会竭尽全力限制标识符 `eval`

javascript - Ajax:将代码注入(inject) Internet Explorer

css - -o-animation 供应商前缀是否存在?

CSS - 带显示 :table-cell and IE 的 UL LI 导航

javascript - 调用 FB.login with 获取权限在 IE 中抛出错误

javascript - 在 VUE 中查找数组中的项目时返回 undefined

javascript - 如何隐藏一个 div 并在悬停图像或文本上隐藏另一个?