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

Ben Aston

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.

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

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

Bergi

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.

"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.

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.

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

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. 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)

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.

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

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

From Dev

Is it possible for Global Execution Context to pop off the execution stack?

From Dev

Javascript Call Stack / Execution Context reference

From Dev

Recursive function returning final result before all recursive calls are popped off the call stack

From Dev

global and local variable execution context in javascript

From Dev

How are void methods popped from the call stack?

From Dev

.NET CLI: How is a local variable popped off the stack if not on top?

From Dev

JS Call Stack with context

From Dev

Execution context and the execution context object in Javascript

From Dev

Isolated execution context in JavaScript

From Dev

Javascript Execution Context

From Dev

Specify global context in JavaScript

From Dev

Javascript: why do callback functions with global execution context have access to scoped variables?

From Dev

Javascript: why do callback functions with global execution context have access to scoped variables?

From Dev

variable scope and javascript execution context

From Dev

Variable environment of execution context JavaScript

From Dev

variable scope and javascript execution context

From Dev

Call stack variables in javascript

From Dev

Would there ever be a need to add ...IfExists operator to Condition Operators on 'AWS Global Condition Context Keys'?

From Dev

Stop execution of a GCD, when the ViewController is popped

From Dev

Popping prototypes off a stack in javascript results in undefined

From Dev

How to setup variable to point to global object – independent of context execution?

From Dev

No execution context even when I have import ExecutionContex.global

From Dev

Function arguments in execution context and scope in JavaScript

From Dev

Does the comma operator influence the execution context in Javascript?

From Dev

Issue with this Javascript code (I think with the execution context)

From Dev

How to call javascript function on initial page load

From Dev

Binding functions in Javascript that operate in the global context

From Dev

Was there ever a need to have the stack be executable?

Related Related

  1. 1

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

  2. 2

    Is it possible for Global Execution Context to pop off the execution stack?

  3. 3

    Javascript Call Stack / Execution Context reference

  4. 4

    Recursive function returning final result before all recursive calls are popped off the call stack

  5. 5

    global and local variable execution context in javascript

  6. 6

    How are void methods popped from the call stack?

  7. 7

    .NET CLI: How is a local variable popped off the stack if not on top?

  8. 8

    JS Call Stack with context

  9. 9

    Execution context and the execution context object in Javascript

  10. 10

    Isolated execution context in JavaScript

  11. 11

    Javascript Execution Context

  12. 12

    Specify global context in JavaScript

  13. 13

    Javascript: why do callback functions with global execution context have access to scoped variables?

  14. 14

    Javascript: why do callback functions with global execution context have access to scoped variables?

  15. 15

    variable scope and javascript execution context

  16. 16

    Variable environment of execution context JavaScript

  17. 17

    variable scope and javascript execution context

  18. 18

    Call stack variables in javascript

  19. 19

    Would there ever be a need to add ...IfExists operator to Condition Operators on 'AWS Global Condition Context Keys'?

  20. 20

    Stop execution of a GCD, when the ViewController is popped

  21. 21

    Popping prototypes off a stack in javascript results in undefined

  22. 22

    How to setup variable to point to global object – independent of context execution?

  23. 23

    No execution context even when I have import ExecutionContex.global

  24. 24

    Function arguments in execution context and scope in JavaScript

  25. 25

    Does the comma operator influence the execution context in Javascript?

  26. 26

    Issue with this Javascript code (I think with the execution context)

  27. 27

    How to call javascript function on initial page load

  28. 28

    Binding functions in Javascript that operate in the global context

  29. 29

    Was there ever a need to have the stack be executable?

HotTag

Archive