-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
重学js——执行上下文(Execution Contexts) #50
Comments
This was referenced Oct 27, 2019
Open
This was referenced Feb 27, 2020
This was referenced Mar 5, 2020
Open
This was referenced Mar 13, 2020
Open
Open
This was referenced Mar 22, 2020
This was referenced Jul 13, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Execution Contexts
执行上下文是一种规范机制,用于跟踪对代码的运行时求值,通过ECMAScript的某种实现。在任何时间点,每个实际执行代码的代理最多有一个执行上下文。这就是代理的 运行时执行上下文。
执行上下文栈用于跟踪执行上下文。运行时执行上下文总是位于栈的顶部。 当控制权从与当前运行时执行上下文关联的可执行代码转移到与执行上下文无关的可执行代码时,会创建新的执行上下文(可以认为,每个可执行代码都有与之关联的执行上下文)。最新被创建的执行上下文会被
push
到栈顶,成为运行时执行上下文。每个执行上下文至少有下表中列出的状态组成:
伪代码大致是这样的:
一旦运行时执行上下文被挂起,另一个不同的执行上下文会成为新的 运行时执行上下文 并且开始执行属于它的代码。以后某个时段,被挂起的执行上下文可能再次成为运行时执行上下文并且在它之前被挂起的地方继续计算它的代码。运行时执行上下文状态在执行上下文之间的转换通常以类似于后进先出的栈方式进行。然而,一些ECMAScript特性需要运行时执行上下文的非后进先出转换。
活跃的函数对象
运行时执行上下文领域部分的值也被称为当前领域记录(the current Realm Record)。运行时执行上下文的 Function 部分的值也被叫做 活跃的函数对象(the active function object)
ECMAScript代码的执行上下文还有额外的状态组成部分,看下表:
注意:LexicalEnvironment和VariableEnvironment全都是词法环境。
表示生成器对象求值的执行上下文有额外的状态部分,看下表:
执行上下文纯粹是一种规范机制,不需要与ECMAScript实现的任何特定工件相对应。ECMAScript代码是无法直接获取或者观察到执行上下文的。
ResolveBinding(name [ , env ])
GetThisEnvironment()
ResolveThisBinding()
拓展阅读
JavaScript深入之执行上下文栈——冴羽
注意
The text was updated successfully, but these errors were encountered: