初始全局执行上下文是否曾在 JavaScript 中从调用堆栈弹出?

Is the initial global execution context ever popped off the call stack in JavaScript?

"initial global execution context" 是否曾在 JavaScript 中从调用堆栈弹出?我说的是始终位于堆栈底部的执行上下文。

如果是这样,我认为这意味着它在从作业队列中提取回调之前先被压入堆栈?

或者,是 [[Scope]].outer 链在回调被推入堆栈时提供对全局环境的访问吗?

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.

是的,是的。一个空的执行上下文堆栈是任何 jobs to run.

的要求

但是,没有像 "initial global execution context" 这样的东西,并且由于堆栈可以为空,所以没有始终位于堆栈底部的单个上下文。

"Global execution contexts" 是在 ScriptEvaluations 中创建的。每个脚本都有自己的 scriptCxt,但共享领域中的所有脚本都带有相同的 全局环境记录 。不过,这些 scriptCtx 不在堆栈的底部。

位于堆栈底部的 "initial execution context" 在 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 中创建,但它也用于启动作业队列。

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 初始化和每个作业结束时执行,基本上如下所示:

  1. 暂停当前执行上下文并将其从堆栈中弹出,使堆栈为空。
  2. 从任何队列中获取下一个作业。如果没有更多,请按需继续(即通常会关闭进程)。
  3. 创建一个新的空(作业领域除外)上下文newContext并将其放在堆栈底部
  4. 在此上下文中执行所选作业(最后从 NextJob 开始)

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

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

确实如此。范围链(不要与执行上下文堆栈混淆)确实提供了从任何地方到全局环境的访问,它位于每个范围链的末尾。