一。ECStack
执行上下文是一个堆栈,每次进入function时,则会将该function context压入栈,当从function 退出时候,则会从ECStack弹出该Function context.
二。Global Contexts
在程序初始化时候,则会压入到ECStacks中,例如:
ECStack = [
globalContext
];
三。Function Code
当执行进入Function时,ECStack 将会push 进一个新的Item,需要注意的是,该新的Item不包含Function内部的Funtion.
(function foo(flag) { if (flag) { return; } foo(true); })(false);
当递归执行foo时候,ECStack的状况表现如下:
// first activation of foo ECStack = [ <foo> functionContext globalContext ]; // recursive activation of foo ECStack = [ <foo> functionContext – recursively <foo> functionContext globalContext ];
对于抛出未被catch的异常,将会导致从一个或者多个Context中退出。
四。Eval Code
eval 定义的变量和函数,影响的是调用该 eval的context,例如:
// influence global context eval('var x = 10'); (function foo() { // and here, variable "y" is // created in the local context // of "foo" function eval('var y = 20'); })(); alert(x); // 10 alert(y); // "y" is not defined
ECStack = [ globalContext ]; // eval('var x = 10'); ECStack.push({ context: evalContext, callingContext: globalContext }); // eval exited context ECStack.pop(); // foo funciton call ECStack.push(<foo> functionContext); // eval('var y = 20'); ECStack.push({ context: evalContext, callingContext: <foo> functionContext }); // return from eval ECStack.pop(); // return from foo ECStack.pop();