A Lexical Environment is a specification type used to define the association of Identifiers to specific variables and functions based upon the lexical nesting structure of ECMAScript code. A Lexical Environment consists of an Environment Record and a possibly null reference to an outer Lexical Environment. Usually a Lexical Environment is associated with some specific syntactic structure of ECMAScript code such as a FunctionDeclaration, a BlockStatement, or a Catch clause of a TryStatement and a new Lexical Environment is created each time such code is evaluated.
An Environment Record records the identifier bindings that are created within the scope of its associated Lexical Environment. It is referred to as the Lexical Environment's EnvironmentRecord
The outer environment reference is used to model the logical nesting of Lexical Environment values. The outer reference of a (inner) Lexical Environment is a reference to the Lexical Environment that logically surrounds the inner Lexical Environment. An outer Lexical Environment may, of course, have its own outer Lexical Environment. A Lexical Environment may serve as the outer environment for multiple inner Lexical Environments. For example, if a FunctionDeclaration contains two nested FunctionDeclarations then the Lexical Environments of each of the nested functions will have as their outer Lexical Environment the Lexical Environment of the current evaluation of the surrounding function.
A global environment is a Lexical Environment which does not have an outer environment. The global
environment's outer environment reference is null. A global environment's EnvironmentRecord may be
prepopulated with identifier bindings and includes an associated global object whose properties provide some of the global environment's identifier bindings. This global object is the
value of a global environment's this
binding. As ECMAScript code is executed, additional properties may
be added to the global object and the initial properties may be modified.
A module environment is a Lexical Environment that contains the bindings for the top level declarations of a Module. It also contains the bindings that are explicitly imported by the Module. The outer environment of a module environment is a global environment.
A function environment is a Lexical Environment that corresponds to the invocation of an ECMAScript function object. A function environment may establish a new
this
binding. A function environment also captures the state necessary to support super
method
invocations.
Lexical Environments and Environment Record values are purely specification mechanisms and need not correspond to any specific artefact of an ECMAScript implementation. It is impossible for an ECMAScript program to directly access or manipulate such values.
There are two primary kinds of Environment Record values used in this specification: declarative Environment Records and object Environment Records. Declarative Environment Records are used to define the effect of ECMAScript language syntactic elements such as FunctionDeclarations, VariableDeclarations, and Catch clauses that directly associate identifier bindings with ECMAScript language values. Object Environment Records are used to define the effect of ECMAScript elements such as WithStatement that associate identifier bindings with the properties of some object. Global Environment Records and function Environment Records are specializations that are used for specifically for Script global declarations and for top-level declarations within functions.
For specification purposes Environment Record values are values of the Record specification type and can be thought of as existing in a simple object-oriented hierarchy where Environment Record is an abstract class with three concrete subclasses, declarative Environment Record, object Environment Record, and global Environment Record. Function Environment Records and module Environment Records are subclasses of declarative Environment Record. The abstract class includes the abstract specification methods defined in Table 15. These abstract methods have distinct concrete algorithms for each of the concrete subclasses.
Method | Purpose |
---|---|
HasBinding(N) | Determine if an Environment Record has a binding for the String value N. Return true if it does and false if it does not |
CreateMutableBinding(N, D) | Create a new but uninitialized mutable binding in an Environment Record. The String value N is the text of the bound name. If the optional Boolean argument D is true the binding is may be subsequently deleted. |
CreateImmutableBinding(N, S) | Create a new but uninitialized immutable binding in an Environment Record. The String value N is the text of the bound name. If S is true then attempts to access the value of the binding before it is initialized or set it after it has been initialized will always throw an exception, regardless of the strict mode setting of operations that reference that binding. S is an optional parameter that defaults to false. |
InitializeBinding(N,V) | Set the value of an already existing but uninitialized binding in an Environment Record. The String value N is the text of the bound name. V is the value for the binding and is a value of any ECMAScript language type. |
SetMutableBinding(N,V, S) | Set the value of an already existing mutable binding in an Environment Record. The String value N is the text of the bound name. V is the value for the binding and may be a value of any ECMAScript language type. S is a Boolean flag. If S is true and the binding cannot be set throw a TypeError exception. |
GetBindingValue(N,S) | Returns the value of an already existing binding from an Environment Record. The String value N is the text of the bound name. S is used to identify references originating in strict mode code or that otherwise require strict mode reference semantics. If S is true and the binding does not exist throw a ReferenceError exception. If the binding exists but is uninitialized a ReferenceError is thrown, regardless of the value of S. |
DeleteBinding(N) | Delete a binding from an Environment Record. The String value N is the text of the bound name. If a binding for N exists, remove the binding and return true. If the binding exists but cannot be removed return false. If the binding does not exist return true. |
HasThisBinding() | Determine if an Environment Record establishes a this binding. Return true if it does and false if it does not. |
HasSuperBinding() | Determine if an Environment Record establishes a super method binding. Return true if it does and false if it does not. |
WithBaseObject () | If this Environment Record is associated with a with statement, return the with object. Otherwise, return undefined. |
Each declarative Environment Record is associated with an ECMAScript program scope containing variable, constant, let, class, module, import, and/or function declarations. A declarative Environment Record binds the set of identifiers defined by the declarations contained within its scope.
The behaviour of the concrete specification methods for declarative Environment Records is defined by the following algorithms.
The concrete Environment Record method HasBinding for declarative Environment Records simply determines if the argument identifier is one of the identifiers bound by the record:
The concrete Environment Record method CreateMutableBinding for declarative Environment Records creates a new mutable binding for the name N that is uninitialized. A binding must not already exist in this Environment Record for N. If Boolean argument D is provided and has the value true the new binding is marked as being subject to deletion.
The concrete Environment Record method CreateImmutableBinding for declarative Environment Records creates a new immutable binding for the name N that is uninitialized. A binding must not already exist in this Environment Record for N. If Boolean argument S is provided and has the value true the new binding is marked as a strict binding.
The concrete Environment Record method InitializeBinding for declarative Environment Records is used to set the bound value of the current binding of the identifier whose name is the value of the argument N to the value of argument V. An uninitialized binding for N must already exist.
The concrete Environment Record method SetMutableBinding for declarative Environment Records attempts to change the bound value of the current binding of the identifier whose name is the value of the argument N to the value of argument V. A binding for N normally already exist, but in rare cases it may not. If the binding is an immutable binding, a TypeError is thrown if S is true.
NOTE An example of ECMAScript code that results in a missing binding at step 2 is:
function f(){eval("var x; x = (delete x, 0);")}
The concrete Environment Record method GetBindingValue for declarative Environment Records simply returns the value of its bound identifier whose name is the value of the argument N. If the binding exists but is uninitialized a ReferenceError is thrown, regardless of the value of S.
The concrete Environment Record method DeleteBinding for declarative Environment Records can only delete bindings that have been explicitly designated as being subject to deletion.
Regular declarative Environment Records do not provide a this
binding.
Regular declarative Environment Records do not provide a super
binding.
Declarative Environment Records always return undefined as their WithBaseObject.
Each object Environment Record is associated with an object called its binding object. An object Environment Record binds the set of string identifier names that directly correspond to the property names of its binding object. Property keys that are not strings in the form of an IdentifierName are not included in the set of bound identifiers. Both own and inherited properties are included in the set regardless of the setting of their [[Enumerable]] attribute. Because properties can be dynamically added and deleted from objects, the set of identifiers bound by an object Environment Record may potentially change as a side-effect of any operation that adds or deletes properties. Any bindings that are created as a result of such a side-effect are considered to be a mutable binding even if the Writable attribute of the corresponding property has the value false. Immutable bindings do not exist for object Environment Records.
Object Environment Records created for with
statements (13.11) can
provide their binding object as an implicit this value for use in function calls. The capability is controlled by
a withEnvironment Boolean value that is associated with each object Environment Record. By default, the value of withEnvironment is
false for any object Environment Record.
The behaviour of the concrete specification methods for object Environment Records is defined by the following algorithms.
The concrete Environment Record method HasBinding for object Environment Records determines if its associated binding object has a property whose name is the value of the argument N:
The concrete Environment Record method CreateMutableBinding for object Environment Records creates in an Environment Record's associated binding object a property whose name is the String value and initializes it to the value undefined. If Boolean argument D is provided and has the value true the new property's [[Configurable]] attribute is set to true, otherwise it is set to false.
NOTE Normally envRec will not have a binding for N but if it does, the semantics of DefinePropertyOrThrow may result in an existing binding being replaced or shadowed or cause an abrupt completion to be returned.
The concrete Environment Record method CreateImmutableBinding is never used within this specification in association with Object Environment Records.
The concrete Environment Record method InitializeBinding for object Environment Records is used to set the bound value of the current binding of the identifier whose name is the value of the argument N to the value of argument V. An uninitialized binding for N must already exist.
NOTE In this specification, all uses of CreateMutableBinding for object Environment Records are immediately followed by a call to InitializeBinding for the same name. Hence, implementations do not need to explicitly track the initialization state of individual object Environment Record bindings.
The concrete Environment Record method SetMutableBinding for object Environment Records attempts to set the value of the Environment Record's associated binding object's property whose name is the value of the argument N to the value of argument V. A property named N normally already exists but if it does not or is not currently writable, error handling is determined by the value of the Boolean argument S.
The concrete Environment Record method GetBindingValue for object Environment Records returns the value of its associated binding object's property whose name is the String value of the argument identifier N. The property should already exist but if it does not the result depends upon the value of the S argument:
The concrete Environment Record method DeleteBinding for object Environment Records can only delete bindings that correspond to properties of the environment object whose [[Configurable]] attribute have the value true.
Regular object Environment Records do not provide a this
binding.
Regular object Environment Records do not provide a super
binding.
Object Environment Records return undefined as their WithBaseObject unless their withEnvironment flag is true.
A function Environment Record is a declarative Environment Record that is used to represent the top-level scope of a function and,
if the function is not an ArrowFunction, provides a this
binding. If a function is
not an ArrowFunction function and references super
, its function Environment Record also contains the state that is used to perform
super
method invocations from within the function.
Function Environment Records have the additional state fields listed in Table 16.
Field Name | Value | Meaning |
---|---|---|
[[thisValue]] | Any | This is the this value used for this invocation of the function. |
[[thisBindingStatus]] | "lexical" | "initialized" | "uninitialized" |
If the value is "lexical" , this is an ArrowFunction and does not have a local this value. |
[[FunctionObject]] | Object | The function Object whose invocation caused this Environment Record to be created. |
[[HomeObject]] | Object | undefined | If the associated function has super property accesses and is not an ArrowFunction, [[HomeObject]] is the object that the function is bound to as a method. The default value for [[HomeObject]] is undefined. |
[[NewTarget]] | Object | undefined | If this Environment Record was created by the [[Construct]] internal method, [[NewTarget]] is the value of the [[Construct]] newTarget parameter. Otherwise, its value is undefined. |
Function Environment Records support all of the declarative Environment Record methods listed in Table 15 and share the same specifications for all of those methods except for HasThisBinding and HasSuperBinding. In addition, function Environment Records support the methods listed in Table 17:
Method | Purpose |
---|---|
BindThisValue(V) | Set the [[thisValue]] and record that it has been initialized. |
GetThisBinding() | Return the value of this Environment Record's this binding. Throws a ReferenceError if the this binding has not been initialized. |
GetSuperBase() | Return the object that is the base for super property accesses bound in this Environment Record. The object is derived from this Environment Record's [[HomeObject]] field. The value undefined indicates that super property accesses will produce runtime errors. |
The behaviour of the additional concrete specification methods for function Environment Records is defined by the following algorithms:
"lexical"
."initialized"
, throw a ReferenceError
exception."initialized"
."lexical"
, return false; otherwise, return
true."lexical"
, return false."lexical"
."uninitialized"
, throw a ReferenceError
exception.A global Environment Record is used to represent the outer most scope that is shared by all of the ECMAScript Script elements that are processed in a common Realm (8.2). A global Environment Record provides the bindings for built-in globals (clause 18), properties of the global object, and for all top-level declarations (13.2.8, 13.2.10) that occur within a Script.
A global Environment Record is logically a single record but it is specified as a composite encapsulating an object Environment Record and a declarative Environment Record. The object Environment Record has as its base object the global object of the associated Realm. This global object is the value returned by the global Environment Record’s GetThisBinding concrete method. The object Environment Record component of a global Environment Record contains the bindings for all built-in globals (clause 18) and all bindings introduced by a FunctionDeclaration, GeneratorDeclaration, or VariableStatement contained in global code. The bindings for all other ECMAScript declarations in global code are contained in the declarative Environment Record component of the global Environment Record.
Properties may be created directly on a global object. Hence, the object Environment Record component of a global Environment Record may contain both bindings created explicitly by FunctionDeclaration, GeneratorDeclaration, or VariableDeclaration declarations and binding created implicitly as properties of the global object. In order to identify which bindings were explicitly created using declarations, a global Environment Record maintains a list of the names bound using its CreateGlobalVarBindings and CreateGlobalFunctionBindings concrete methods.
Global Environment Records have the additional fields listed in Table 18 and the additional methods listed in Table 19.
Field Name | Value | Meaning |
---|---|---|
[[ObjectRecord]] | Object Environment Record | Binding object is the global object. It contains global built-in bindings as well as FunctionDeclaration, GeneratorDeclaration, and VariableDeclaration bindings in global code for the associated Realm. |
[[DeclarativeRecord]] | Declarative Environment Record | Contains bindings for all declarations in global code for the associated Realm code except for FunctionDeclaration, GeneratorDeclaration, and VariableDeclaration bindings. |
[[VarNames]] | List of String | The string names bound by FunctionDeclaration, GeneratorDeclaration, and VariableDeclaration declarations in global code for the associated Realm. |
Method | Purpose |
---|---|
GetThisBinding() | Return the value of this Environment Record's this binding. |
HasVarDeclaration (N) | Determines if the argument identifier has a binding in this Environment Record that was created using a VariableDeclaration, FunctionDeclaration, or GeneratorDeclaration. |
HasLexicalDeclaration (N) | Determines if the argument identifier has a binding in this Environment Record that was created using a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. |
HasRestrictedGlobalProperty (N) | Determines if the argument is the name of a global object property that may not be shadowed by a global lexically binding. |
CanDeclareGlobalVar (N) | Determines if a corresponding CreateGlobalVarBinding call would succeed if called for the same argument N. |
CanDeclareGlobalFunction (N) | Determines if a corresponding CreateGlobalFunctionBinding call would succeed if called for the same argument N. |
CreateGlobalVarBinding(N, D) | Used to create and initialize to undefined a global var binding in the [[ObjectRecord]] component of a global Environment Record. The binding will be a mutable binding. The corresponding global object property will have attribute values appropriate for a var . The String value N is the bound name. If D is true the binding may be deleted. Logically equivalent to CreateMutableBinding followed by a SetMutableBinding but it allows var declarations to receive special treatment. |
CreateGlobalFunctionBinding(N, V, D) | Create and initialize a global function binding in the [[ObjectRecord]] component of a global Environment Record. The binding will be a mutable binding. The corresponding global object property will have attribute values appropriate for a function . The String value N is the bound name. V is the initialization value. If the optional Boolean argument D is true the binding is may be deleted. Logically equivalent to CreateMutableBinding followed by a SetMutableBinding but it allows function declarations to receive special treatment. |
The behaviour of the concrete specification methods for global Environment Records is defined by the following algorithms.
The concrete Environment Record method HasBinding for global Environment Records simply determines if the argument identifier is one of the identifiers bound by the record:
The concrete Environment Record method CreateMutableBinding for global Environment Records creates a new mutable binding for the name N that is uninitialized. The binding is created in the associated DeclarativeRecord. A binding for N must not already exist in the DeclarativeRecord. If Boolean argument D is provided and has the value true the new binding is marked as being subject to deletion.
The concrete Environment Record method CreateImmutableBinding for global Environment Records creates a new immutable binding for the name N that is uninitialized. A binding must not already exist in this Environment Record for N. If Boolean argument S is provided and has the value true the new binding is marked as a strict binding.
The concrete Environment Record method InitializeBinding for global Environment Records is used to set the bound value of the current binding of the identifier whose name is the value of the argument N to the value of argument V. An uninitialized binding for N must already exist.
The concrete Environment Record method SetMutableBinding for global Environment Records attempts to change the bound value of the current binding of the identifier whose name is the value of the argument N to the value of argument V. If the binding is an immutable binding, a TypeError is thrown if S is true. A property named N normally already exists but if it does not or is not currently writable, error handling is determined by the value of the Boolean argument S.
The concrete Environment Record method GetBindingValue for global Environment Records returns the value of its bound identifier whose name is the value of the argument N. If the binding is an uninitialized binding throw a ReferenceError exception. A property named N normally already exists but if it does not or is not currently writable, error handling is determined by the value of the Boolean argument S.
The concrete Environment Record method DeleteBinding for global Environment Records can only delete bindings that have been explicitly designated as being subject to deletion.
Global Environment Records always provide a
this
binding whose value is the associated global object.
Global Environment Records always return undefined as their WithBaseObject.
The concrete Environment Record method HasVarDeclaration for global Environment Records determines if the argument identifier has a binding in this record that was created using a VariableStatement or a FunctionDeclaration :
The concrete Environment Record method HasLexicalDeclaration for global Environment Records determines if the argument identifier has a binding in this record that was created using a lexical declaration such as a LexicalDeclaration or a ClassDeclaration :
The concrete Environment Record method HasRestrictedGlobalProperty for global Environment Records determines if the argument identifier is the name of a property of the global object that must not be shadowed by a global lexically binding:
NOTE Properties may exist upon a global object that were directly created rather than being
declared using a var or function declaration. A global lexical binding may not be created that has the same name as a
non-configurable property of the global object. The global property undefined
is an example of such a
property.
The concrete Environment Record method CanDeclareGlobalVar for global Environment Records determines if a corresponding CreateGlobalVarBinding call would succeed if called for the same argument N. Redundant var declarations and var declarations for pre-existing global object properties are allowed.
The concrete Environment Record method CanDeclareGlobalFunction for global Environment Records determines if a corresponding CreateGlobalFunctionBinding call would succeed if called for the same argument N.
The concrete Environment Record method CreateGlobalVarBinding for global Environment Records creates and initializes a mutable binding in the associated object Environment Record and records the bound name in the associated [[VarNames]] List. If a binding already exists, it is reused and assumed to be initialized.
The concrete Environment Record method CreateGlobalFunctionBinding for global Environment Records creates and initializes a mutable binding in the associated object Environment Record and records the bound name in the associated [[VarNames]] List. If a binding already exists, it is replaced.
NOTE Global function declarations are always represented as own properties of the global object. If possible, an existing own property is reconfigured to have a standard set of attribute values. Steps 10-12 are equivalent to what calling the InitializeBinding concrete method would do and if globalObject is a Proxy will produce the same sequence of Proxy trap calls.
A module Environment Record is a declarative Environment Record that is used to represent the outer scope of an ECMAScript Module. In additional to normal mutable and immutable bindings, module Environment Records also provide immutable import bindings which are bindings that provide indirect access to a target binding that exists in another Environment Record.
Module Environment Records support all of the declarative Environment Record methods listed in Table 15 and share the same specifications for all of those methods except for GetBindingValue, DeleteBinding, HasThisBinding and GetThisBinding. In addition, module Environment Records support the methods listed in Table 20:
Method | Purpose |
---|---|
CreateImportBinding(N, M, N2 ) | Create an immutable indirect binding in a module Environment Record. The String value N is the text of the bound name. M is a Module Record (see 15.2.1.15), and N2 is a binding that exists in M's module Environment Record. |
GetThisBinding() | Return the value of this Environment Record's this binding. |
The behaviour of the additional concrete specification methods for module Environment Records are defined by the following algorithms:
The concrete Environment Record method GetBindingValue for module Environment Records returns the value of its bound identifier whose name is the value of the argument N. However, if the binding is an indirect binding the value of the target binding is returned. If the binding exists but is uninitialized a ReferenceError is thrown, regardless of the value of S.
NOTE Because a Module is always strict mode code, calls to GetBindingValue should always pass true as the value of S.
The concrete Environment Record method DeleteBinding for module Environment Records refuses to delete bindings.
NOTE Because the bindings of a module Environment Record are not deletable.
Module Environment Records provide a this
binding.
The concrete Environment Record method CreateImportBinding for module Environment Records creates a new initialized immutable indirect binding for the name N. A binding must not already exist in this Environment Record for N. M is a Module Record (see 15.2.1.15), and N2 is the name of a binding that exists in M's module Environment Record. Accesses to the value of the new binding will indirectly access the bound value of value of the target binding.
The following abstract operations are used in this specification to operate upon lexical environments:
The abstract operation GetIdentifierReference is called with a Lexical Environment lex, a String name, and a Boolean flag strict. The value of lex may be null. When called, the following steps are performed:
When the abstract operation NewDeclarativeEnvironment is called with a Lexical Environment as argument E the following steps are performed:
When the abstract operation NewObjectEnvironment is called with an Object O and a Lexical Environment E as arguments, the following steps are performed:
When the abstract operation NewFunctionEnvironment is called with arguments F and newTarget the following steps are performed:
"lexical"
."uninitialized"
.When the abstract operation NewGlobalEnvironment is called with an ECMAScript Object G as its argument, the following steps are performed:
When the abstract operation NewModuleEnvironment is called with a Lexical Environment argument E the following steps are performed:
Before it is evaluated, all ECMAScript code must be associated with a Realm. Conceptually, a realm consists of a set of intrinsic objects, an ECMAScript global environment, all of the ECMAScript code that is loaded within the scope of that global environment, and other associated state and resources.
A Realm is specified as a Record with the fields specified in Table 21:
Field Name | Value | Meaning |
---|---|---|
[[intrinsics]] | Record whose field names are intrinsic keys and whose values are objects | These are the intrinsic values used by code associated with this Realm |
[[globalThis]] | Object | The global object for this Realm |
[[globalEnv]] | Lexical Environment | The global environment for this Realm |
[[templateMap]] | A List of Record { [[strings]]: List, [[array]]: Object}. | Template objects are canonicalized separately for each Realm using its [[templateMap]]. Each [[strings]] value is a List containing, in source text order, the raw String values of a TemplateLiteral that has been evaluated. The associated [[array]] value is the corresponding template object that is passed to a tag function. |
An implementation may define other, implementation specific fields.
The abstract operation CreateRealm with no arguments performs the following steps:
When the abstract operation CreateIntrinsics with argument realmRec performs the following steps:
The abstract operation SetRealmGlobalObject with arguments realmRec and globalObj performs the following steps:
The abstract operation SetDefaultGlobalBindings with argument realmRec performs the following steps:
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 that is actually executing code. This is known as the running execution context. A stack is used to track execution contexts. The running execution context is always the top element of this stack. A new execution context is created whenever control is transferred from the executable code associated with the currently running execution context to executable code that is not associated with that execution context. The newly created execution context is pushed onto the stack and becomes the running execution context.
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 Table 22.
Component | Purpose |
---|---|
code evaluation state | Any state needed to perform, suspend, and resume evaluation of the code associated with this execution context. |
Function | If this execution context is evaluating the code of a function object, then the value of this component is that function object. If the context is evaluating the code of a Script or Module, the value is null. |
Realm | The Realm from which associated code accesses ECMAScript resources. |
Evaluation of code by the running execution context may be suspended at various points defined within this specification. Once the running execution context has been suspended a different execution context may become the running execution context and commence evaluating its code. At some later time a suspended execution context may again become the running execution context and continue evaluating its code at the point where it had previously been suspended. Transition of the running execution context status among execution contexts usually occurs in stack-like last-in/first-out manner. However, some ECMAScript features require non-LIFO transitions of the running execution context.
The value of the Realm component of the running execution context is also called the current Realm. The value of the Function component of the running execution context is also called the active function object.
Execution contexts for ECMAScript code have the additional state components listed in Table 23.
Component | Purpose |
---|---|
LexicalEnvironment | Identifies the Lexical Environment used to resolve identifier references made by code within this execution context. |
VariableEnvironment | Identifies the Lexical Environment whose EnvironmentRecord holds bindings created by VariableStatements within this execution context. |
The LexicalEnvironment and VariableEnvironment components of an execution context are always Lexical Environments. When an execution context is created its LexicalEnvironment and VariableEnvironment components initially have the same value.
Execution contexts representing the evaluation of generator objects have the additional state components listed in Table 24.
Component | Purpose |
---|---|
Generator | The GeneratorObject that this execution context is evaluating. |
In most situations only the running execution context (the top of the execution context stack) is directly manipulated by algorithms within this specification. Hence when the terms “LexicalEnvironment”, and “VariableEnvironment” are used without qualification they are in reference to those components of the running execution context.
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.
The ResolveBinding abstract operation is used to determine the binding of name passed as a String value. The optional argument env can be used to explicitly provide the Lexical Environment that is to be searched for the binding. During execution of ECMAScript code, ResolveBinding is performed using the following algorithm:
NOTE The result of ResolveBinding is always a Reference value with its referenced name component equal to the name argument.
The abstract operation GetThisEnvironment finds
the Environment Record that currently supplies the binding of the keyword
this
. GetThisEnvironment performs the following steps:
NOTE The loop in step 2 will always terminate because the list of environments always ends with
the global environment which has a this
binding.
The abstract operation ResolveThisBinding determines the binding of the keyword this
using the LexicalEnvironment of the running
execution context. ResolveThisBinding performs the following steps:
The abstract operation GetNewTarget determines the NewTarget value using the LexicalEnvironment of the running execution context. GetNewTarget performs the following steps:
The abstract operation GetGlobalObject returns the global object used by the currently running execution context. GetGlobalObject performs the following steps:
A Job is an abstract operation that initiates an ECMAScript computation when no other ECMAScript computation is currently in progress. A Job abstract operation may be defined to accept an arbitrary set of job parameters.
Execution of a Job can be initiated only when there is no running execution context and the execution context stack is empty. A PendingJob is a request for the future execution of a Job. A PendingJob is an internal Record whose fields are specified in Table 25. Once execution of a Job is initiated, the Job always executes to completion. No other Job may be initiated until the currently running Job completes. However, the currently running Job or external events may cause the enqueuing of additional PendingJobs that may be initiated sometime after completion of the currently running Job.
Field Name | Value | Meaning |
---|---|---|
[[Job]] | The name of a Job abstract operation | This is the abstract operation that is performed when execution of this PendingJob is initiated. Jobs are abstract operations that use NextJob rather than Return to indicate that they have completed. |
[[Arguments]] | A List | The List of argument values that are to be passed to [[Job]] when it is activated. |
[[Realm]] | A Realm Record | The Realm for the initial execution context when this Pending Job is initiated. |
[[HostDefined]] | Any, default value is undefined. | Field reserved for use by host environments that need to associate additional information with a pending Job. |
A Job Queue is a FIFO queue of PendingJob records. Each Job Queue has a name and the full set of available Job Queues are defined by an ECMAScript implementation. Every ECMAScript implementation has at least the Job Queues defined in Table 26.
Name | Purpose |
---|---|
ScriptJobs | Jobs that validate and evaluate ECMAScript Script and Module source text. See clauses 10 and 15. |
PromiseJobs | Jobs that are responses to the settlement of a Promise (see 25.4). |
A request for the future execution of a Job is made by enqueueing, on a Job Queue, a PendingJob record that includes a Job abstract operation name and any necessary argument values. When there is no running execution context and the execution context stack is empty, the ECMAScript implementation removes the first PendingJob from a Job Queue and uses the information contained in it to create an execution context and starts execution of the associated Job abstract operation.
The PendingJob records from a single Job Queue are always initiated in FIFO order. This specification does not define the order in which multiple Job Queues are serviced. An ECMAScript implementation may interweave the FIFO evaluation of the PendingJob records of a Job Queue with the evaluation of the PendingJob records of one or more other Job Queues. An implementation must define what occurs when there are no running execution context and all Job Queues are empty.
NOTE Typically an ECMAScript implementation will have its Job Queues pre-initialized with at least one PendingJob and one of those Jobs will be the first to be executed. An implementation might choose to free all resources and terminate if the current Job completes and all Job Queues are empty. Alternatively, it might choose to wait for a some implementation specific agent or mechanism to enqueue new PendingJob requests.
The following abstract operations are used to create and manage Jobs and Job Queues:
The EnqueueJob abstract operation requires three arguments: queueName, job, and arguments. It performs the following steps:
An algorithm step such as:
is used in Job abstract operations in place of:
Job abstract operations must not contain a Return step or a ReturnIfAbrupt step. The NextJob result operation is equivalent to the following steps:
An ECMAScript implementation performs the following steps prior to the execution of any Jobs or the evaluation of any ECMAScript code:
"ScriptJobs"
, ScriptEvaluationJob, « sourceText »)."ScriptJobs"
, TopLevelModuleEvaluationJob, « sourceText
»).The abstract operation InitializeHostDefinedRealm with parameter realm performs the following steps: