初始的全局执行环境是否在JavaScript中弹出调用堆栈? [英] Is the initial global execution context ever popped off the call stack in JavaScript?

查看:85
本文介绍了初始的全局执行环境是否在JavaScript中弹出调用堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否在JavaScript中弹出了初始全局执行上下文调用堆栈?我正在谈论堆栈底部的执行上下文。

Is the "initial global execution context" ever popped off the call stack in JavaScript? I am talking about the execution context that is at the bottom of the stack at all times.

如果是这样,我认为这意味着它先被推到堆栈上回调是从Job Queue中获取的。

If so, I presume this means it is pushed onto the stack first before a callback is picked up off the Job Queue?

或者,是否是 [[Scope]]。outer chain每当回调被推送到堆栈时,它可以访问全局环境?

Alternatively, is it the [[Scope]].outer chain that provides access to the global environment whenever a callback is pushed onto the stack?

推荐答案


是初始全局执行上下文在JavaScript中弹出调用堆栈?我正在谈论堆栈底部的执行上下文。

Is the "initial global execution context" ever popped off the call stack in JavaScript? I am talking about the execution context that is at the bottom of the stack at all times.

是的,是的。空执行上下文堆栈是任何要运行的工作

Yes, it is. An empty execution context stack is the requirement for any jobs to run.

然而,没有像初始全局执行上下文这样的东西,因为堆栈可以是空的,没有一个

However, there is no such thing like an "initial global execution context", and since the stack can be empty there is no single context that is at the bottom of the stack all the time.

全局执行上下文是在 ScriptEvaluations 。每个脚本都有自己的 scriptCxt ,但所有这些脚本在共享领域都具有相同的全局环境记录。尽管如此,这些 scriptCtx 不在堆栈的底部。

"Global execution contexts" are created in ScriptEvaluations. Every script does have its own scriptCxt, yet all of them in a shared realm carry the same global environment records. These scriptCtxs are not at the bottom at the stack, though.

一个初始执行上下文堆栈底部是在 ECMAScript初始化过程。这是非常无意义的,因为它不包含新的领域,只能作为国际和全球对象的初始化,但它也用于启动作业队列。

An "initial execution context" that sits at the bottom of the stack is created in the ECMAScript Initialisation process. It is pretty meaningless, for it does not hold anything but the new realm and only serves as the context for the initialisation of the realm and global object, but it is also used to start off the job queues.


如果是这样,我认为这意味着在Job Queue之前的回调被取消之前先把它推到堆栈上?

If so, I presume this means it is pushed onto the stack first before a callback is picked up off the Job Queue?

是的确。我们可以从 NextJob 的说明中看到这一点算法步骤。这些是在ECMAScript初始化和每个作业结束时执行的,基本上如下所示:

Yes indeed. We can see this from the instructions for the NextJob algorithm steps. These are performed at the end of the ECMAScript initialisation and end of every job, and basically read as follows:


  1. 挂起当前的执行上下文从堆栈中弹出,使堆栈为空。

  2. 从任何队列获取下一个作业。如果没有更多,请按照要求进行操作(即通常会关闭该过程)。

  3. 创建一个新的,空的(除了作业的领域)上下文 newContext 并将其放在堆栈的底部

  4. 在此上下文中执行选定的作业(最后以NextJob开头)

  1. Suspend the current execution context and pop it from the stack so that the stack is empty.
  2. Get the next job from any queue. If there are no more, proceed as you want (i.e. typically shuts down the process).
  3. Create a new, empty (except for the realm of the job) context newContext and put it at the bottom of the stack
  4. Execute the selected job in this context (which starts over NextJob in the end)

这些上下文用作每个作业的基础,包含所有执行过程。在 PromiseJobs 中,它们直接使用,而在模块和脚本评估作业中,其他上下文将被推送到堆栈上,用于保存与其执行代码的相应环境记录。

These contexts serve as the base for every job, containing all execution that ever happens. In PromiseJobs, they are used rather directly, while in module- and script evaluation jobs other contexts will be pushed on the stack that serve to hold the respective environment records with whom the code should be executed.


或者,是否是[[Scope]]。外链,只要回调推送到堆栈,就可以访问全局环境?

Alternatively, is it the [[Scope]].outer chain that provides access to the global environment whenever a callback is pushed onto the stack?

是的确。范围链(不要与执行上下文堆栈混淆)确实提供了从每个范围链结尾处的全球环境的访问。

Yes indeed. The scope chain (that is not to be confused with the execution context stack) does provide access from everywhere to the global environment, which sits at the end of every scope chain.

这篇关于初始的全局执行环境是否在JavaScript中弹出调用堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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