什么是“呼叫上下文”? [英] What is a "calling context?"

查看:115
本文介绍了什么是“呼叫上下文”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ECMA-262 5.1小节 10.4.2 10.4.2.1 指的是呼叫上下文。这似乎没有在文档中的任何其他地方描述。

ECMA-262 5.1 subsections 10.4.2 and 10.4.2.1 refer to a "calling context." This doesn't appear to be described anywhere else in the document.

引用规范,强调我的:


10.4.2输入Eval代码

10.4.2 Entering Eval Code

当控制进入eval代码的执行上下文时,执行以下步骤:

The following steps are performed when control enters the execution context for eval code:


  1. 如果没有调用上下文,或者未通过直接调用(15.1.2.1.1)评估eval代码然后,eval函数,

  1. If there is no calling context or if the eval code is not being evaluated by a direct call (15.1.2.1.1) to the eval function then,







10.4.2.1严格模式限制

10.4.2.1 Strict Mode Restrictions

eval代码无法在调用eval的调用上下文的变量环境中实例化变量或函数绑定如果调用上下文的代码或eval代码是严格的代码。相反,此类绑定在新的VariableEnvironment中实例化,只能通过eval代码访问。

The eval code cannot instantiate variable or function bindings in the variable environment of the calling context that invoked the eval if either the code of the calling context or the eval code is strict code. Instead such bindings are instantiated in a new VariableEnvironment that is only accessible to the eval code.




  • 这些段落中呼叫上下文的含义是什么?我认为它指的是之前的堆栈顶部的执行上下文调用 eval ;任何人都可以验证这个吗?

    • What does "calling context" mean in these paragraphs? I would assume it refers to the Execution Context at the top of the stack just before eval is called; can anyone verify this?

      没有呼叫上下文?是什么意思?有人可以提供一个代码或条件的示例,可能导致调用 eval 而没有调用上下文?

      What does it mean to have "no calling context?" Can someone provide an example of code or conditions that could result in a call to eval with no calling context?

      推荐答案

      调用上下文是指本机 eval 函数的上下文从...调用。

      The "calling context" refers to the context which the native eval function is being called from.

      如果从某些本机代码执行 eval (例如,运行本机函数)当由于某种原因使用 eval 完成时执行代码,然后它将没有上下文,然后指定在全局范围内运行。上下文仅引用ECMAScript可执行代码。

      If you are executing eval from some native code (for example, you run a native function which executes code when completed using eval for some reason or another), then it would have no context, which is then specified to run under the global scope. The context only refers to ECMAScript executable code.

      但是,调用上下文是指调用它的执行上下文中的变量和指令。例如,它只知道eval在检查调用上下文时是否可以作为严格代码工作。

      However, the calling context refers to the variables and directives in the execution context of where it is called. For example, it only knows that eval is meant to work as strict code if it checks the calling context.

      这可以通过ES-Discuss中的一个非常类似的问题来澄清邮件列表, Brendan Eich (JavaScript的创建者)回复:

      This is clarified by a very similar question in the ES-Discuss mailing list, where Brendan Eich (the creator of JavaScript) responds:


      ES3说:

      ES3 says:


      10.2.2评估代码



      当控件进入
      eval代码的执行上下文时,前一个活动执行上下文(称为
      调用上下文)用于确定作用域链,变量
      对象,以及此值。如果没有调用上下文,则初始化范围链,变量实例化和
      确定此值的
      与全局代码一样。

      10.2.2 Eval Code

      When control enters an execution context for eval code, the previous active execution context, referred to as the calling context, is used to determine the scope chain, the variable object, and the this value. If there is no calling context, then initialising the scope chain, variable instantiation, and determination of the this value are performed just as for global code.

      我对如果没有调用上下文感到困惑。怎么可能出现
      的可能性?如果没有人调用它会如何调用 eval

      I am baffled by "If there is no calling context". How could the possibility arise? How would eval get called if no one calls it?



      回复:



      Response:


      来自本机代码的调用,即主机程序。

      A call from native code, the "host" program.

      某些浏览器支持间接 eval ,允许这样:

      Some browsers support indirect eval, allowing this:

      setTimeout(eval, 0, "alert('hi mom')");
      

      使用的窗口是 setTimeout 是在
      范围链中找到的,所以

      The window used is the one in which setTimeout was found along the scope chain, so

      myFrame.setTimeout(eval, 0, "alert(x)");
      

      应该显示 myFrame.x ,而不是调用框架或窗口的 x

      should show myFrame.x, not the calling frame or window's x.

      注意:此实例中的myFrame 引用框架的全局范围。

      Note: myFrame in this instance refers to the frame's global scope.

      这篇关于什么是“呼叫上下文”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆