9.4 Execution Contexts
An execution context is a specification device that is used to track the runtime evaluation of code by an ECMAScript implementation. At any point in time, there is at most one execution context per
The execution context stack is used to track execution contexts. The
An execution context contains whatever implementation specific state is necessary to track the execution progress of its associated code. Each execution context has at least the state components listed in
Component | Purpose |
---|---|
code evaluation state |
Any state needed to perform, suspend, and resume evaluation of the code associated with this |
Function |
If this |
|
The |
ScriptOrModule |
The |
The value of the
ECMAScript code execution contexts have the additional state components listed in
Component | Purpose |
---|---|
LexicalEnvironment |
Identifies the |
VariableEnvironment |
Identifies the |
PrivateEnvironment |
Identifies the |
The LexicalEnvironment and VariableEnvironment components of an execution context are always
Execution contexts representing the evaluation of Generators have the additional state components listed in
Component | Purpose |
---|---|
Generator |
The Generator that this |
In most situations only the
An execution context is purely a specification mechanism and need not correspond to any particular artefact of an ECMAScript implementation. It is impossible for ECMAScript code to directly access or observe an execution context.
9.4.1 GetActiveScriptOrModule ( )
The abstract operation GetActiveScriptOrModule takes no arguments and returns a
- If the
execution context stack is empty, returnnull . - Let ec be the topmost
execution context on theexecution context stack whose ScriptOrModule component is notnull . - If no such
execution context exists, returnnull . Otherwise, return ec's ScriptOrModule.
9.4.2 ResolveBinding ( name [ , env ] )
The abstract operation ResolveBinding takes argument name (a String) and optional argument env (an
- If env is not present or env is
undefined , then- Set env to the
running execution context 's LexicalEnvironment.
- Set env to the
Assert : env is anEnvironment Record .- If the
source text matched by the syntactic production that is being evaluated is contained instrict mode code , let strict betrue ; else let strict befalse . - Return ?
GetIdentifierReference (env, name, strict).
The result of ResolveBinding is always a
9.4.3 GetThisEnvironment ( )
The abstract operation GetThisEnvironment takes no arguments and returns an this
. It performs the following steps when called:
- Let env be the
running execution context 's LexicalEnvironment. - Repeat,
- Let exists be env.HasThisBinding().
- If exists is
true , return env. - Let outer be env.[[OuterEnv]].
Assert : outer is notnull .- Set env to outer.
The loop in step this
binding.
9.4.4 ResolveThisBinding ( )
The abstract operation ResolveThisBinding takes no arguments and returns either a this
using the LexicalEnvironment of the
- Let envRec be
GetThisEnvironment (). - Return ? envRec.GetThisBinding().
9.4.5 GetNewTarget ( )
The abstract operation GetNewTarget takes no arguments and returns an Object or
- Let envRec be
GetThisEnvironment (). Assert : envRec has a [[NewTarget]] field.- Return envRec.[[NewTarget]].
9.4.6 GetGlobalObject ( )
The abstract operation GetGlobalObject takes no arguments and returns an Object. It returns the
- Let currentRealm be
the current Realm Record . - Return currentRealm.[[GlobalObject]].