Search code examples
ecmascript-6ecmascript-2016ecmascript-next

What difference between the "set of ECMAScript execution contexts" and "execution context stack" in ECMAScript


In ecma262 we can find next part:

An agent comprises a set of ECMAScript execution contexts, an execution context stack, a running execution context, an Agent Record, and an executing thread. Except for the executing thread, the constituents of an agent belong exclusively to that agent.

What is the set of ECMAScript execution contexts? And what difference between set of ECMAScript execution contexts and execution context stack?


Solution

  • What is the set of ECMAScript execution contexts?

    That means essentially "all execution contexts that exist".

    And what difference between set of ECMAScript execution contexts and execution context stack?

    The stack is explicitly the stack of execution contexts that have been created as code is executed. The execution context stack has entries pushed and popped from it in many places throughout the spec as functions are entered and exited.

    As an example of where this difference can be seem, a new execution context will be created for an async function when it initially runs, and then popped from the stack when the function returns or awaits something. After it is popped, it is not part of the stack anymore and the async function is suspended, but will still exist as long as the function is waiting for something else and could thus be pushed back onto the stack later, so would still be part of the "set of ECMAScript execution contexts".