How can i get the Variable object of any execution context in the console?

How can i get the Variable object of any execution context in the console ???

1- parser ===> AST + set memory space for all of our declarations (hoisting)

2- Javascript engine create GEC which contain (this , outer environment+variable object ( declare all the globale variables and functions ))

3- interpreter / compiler start execute the GEC and when it face an invokation for a fun
it create a new execution context and then executing it and so on and so forth

So here 's an example :

var a = 10;
 
function test(x) {
  var b = 20;
};
 
test(30);

0 - declarations get hoisted by the parser

1 - engine create GEC ==> VO + this (window) + outer environment (null )

// Variable object of the global context
VO  (globalContext) = {
  a: 10,
  test: <reference to function>
};

2 - engine start executing line by line

  • Line 1 : assign 10 to a ;
  • Line 7 : call a function : ===> create a new execution context ( define VO + THIS + outer environment) ;
    // Variable object of the "test" function context
    VO(test functionContext) = {
     x: 30,
     b: 20
    };
  • Line 4 : assign 20 to b , test EC get poped off and we re done

is my logic right , ??? , please correct my steps ,
and i want to know if there’s a dev tools which allow me to check or acces the VO ??

OK, so if I’m understanding aright, by GEC you mean Global Execution Context, by VO you mean Variable Object. If that’s what you’re saying, then your question has to do with variable scope.

In answer, yes. The debugging tools with Chrome will allow you to put a breakpoint inside the test function, and actually view the test scope, as well as the global scope, at that particular point in the execution.

A great article on scope and context.

1 Like

great , but just to make sure , my steps were right , coz currently i want to know how is the JIT compiler involved in the operation

hahahaha! I just went to research how scope and context are affected by JIT compiling, found that very question on StackOverflow, and … yup. It was the OP’s question there. sigh.

Am I understanding right that your question has to do with when the function’s context is ‘popped off’ and no longer exists? If so, that is a question about garbage collection, and you might want to read StackOverflow’s answer.

As far as your logic regarding what the engine is actually doing, I believe you have it right – the interpreter hoists variables within their contexts, generates the bytecode which the engine then processes, line by line, creating functions (and contexts) as needed, and removing contexts when those functions are no longer referenced.

1 Like