9 Executable Code and Execution Contexts
9.1 Environment Records
Environment Record is a specification type used to define the association of
Every Environment Record has an [[OuterEnv]] field, which is either
Environment Records 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.
9.1.1 The Environment Record Type Hierarchy
-
Environment Record (abstract)-
A
Declarative Environment Record is used to define the effect of ECMAScript language syntactic elements such asFunctionDeclaration s,VariableDeclaration s, andCatch clauses that directly associate identifier bindings withECMAScript language values .-
A
Function Environment Record corresponds to the invocation of an ECMAScriptfunction object , and contains bindings for the top-level declarations within that function. It may establish a newthisbinding. It also captures the state necessary to supportsupermethod invocations. -
A
Module Environment Record contains the bindings for the top-level declarations of aModule . It also contains the bindings that are explicitly imported by theModule . Its [[OuterEnv]] is aGlobal Environment Record .
-
-
An
Object Environment Record is used to define the effect of ECMAScript elements such asWithStatement that associate identifier bindings with the properties of some object. -
A
Global Environment Record is used forScript global declarations. It does not have an outer environment; its [[OuterEnv]] isnull . It may be prepopulated with identifier bindings and it includes an associatedglobal object whose properties provide some of the global environment's identifier bindings. As ECMAScript code is executed, additional properties may be added to theglobal object and the initial properties may be modified.
-
The
| Method | Purpose |
|---|---|
| HasBinding(N) |
Determine if an |
| CreateMutableBinding(N, D) |
Create a new but uninitialized mutable binding in an |
| CreateImmutableBinding(N, S) |
Create a new but uninitialized immutable binding in an |
| InitializeBinding(N, V) |
Set the value of an already existing but uninitialized binding in an |
| SetMutableBinding(N, V, S) |
Set the value of an already existing mutable binding in an |
| GetBindingValue(N, S) |
Returns the value of an already existing binding from an |
| DeleteBinding(N) |
Delete a binding from an |
| HasThisBinding() |
Determine if an this binding. Return |
| HasSuperBinding() |
Determine if an super method binding. Return |
| WithBaseObject() |
If this with statement, return the with object. Otherwise, return |
9.1.1.1 Declarative Environment Records
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.
9.1.1.1.1 HasBinding ( N )
The HasBinding concrete method of a
- If envRec has a binding for N, return
true . - Return
false .
9.1.1.1.2 CreateMutableBinding ( N, D )
The CreateMutableBinding concrete method of a
Assert : envRec does not already have a binding for N.- Create a mutable binding in envRec for N and record that it is uninitialized. If D is
true , record that the newly created binding may be deleted by a subsequent DeleteBinding call. - Return
unused .
9.1.1.1.3 CreateImmutableBinding ( N, S )
The CreateImmutableBinding concrete method of a
Assert : envRec does not already have a binding for N.- Create an immutable binding in envRec for N and record that it is uninitialized. If S is
true , record that the newly created binding is a strict binding. - Return
unused .
9.1.1.1.4 InitializeBinding ( N, V )
The InitializeBinding concrete method of a
Assert : envRec must have an uninitialized binding for N.- Set the bound value for N in envRec to V.
Record that the binding for N in envRec has been initialized.- Return
unused .
9.1.1.1.5 SetMutableBinding ( N, V, S )
The SetMutableBinding concrete method of a
- If envRec does not have a binding for N, then
- If S is
true , throw aReferenceError exception. - Perform ! envRec.CreateMutableBinding(N,
true ). - Perform ! envRec.InitializeBinding(N, V).
- Return
unused .
- If S is
- If the binding for N in envRec is a strict binding, set S to
true . - If the binding for N in envRec has not yet been initialized, throw a
ReferenceError exception. - Else if the binding for N in envRec is a mutable binding, change its bound value to V.
- Else,
Assert : This is an attempt to change the value of an immutable binding.- If S is
true , throw aTypeError exception.
- Return
unused .
An example of ECMAScript code that results in a missing binding at step
function f() { eval("var x; x = (delete x, 0);"); }
9.1.1.1.6 GetBindingValue ( N, S )
The GetBindingValue concrete method of a
Assert : envRec has a binding for N.- If the binding for N in envRec is an uninitialized binding, throw a
ReferenceError exception. - Return the value currently bound to N in envRec.
9.1.1.1.7 DeleteBinding ( N )
The DeleteBinding concrete method of a
Assert : envRec has a binding for N.- If the binding for N in envRec cannot be deleted, return
false . - Remove the binding for N from envRec.
- Return
true .
9.1.1.1.8 HasThisBinding ( )
The HasThisBinding concrete method of a
- Return
false .
A regular this binding.
9.1.1.1.9 HasSuperBinding ( )
The HasSuperBinding concrete method of a
- Return
false .
A regular super binding.
9.1.1.1.10 WithBaseObject ( )
The WithBaseObject concrete method of a
- Return
undefined .
9.1.1.2 Object Environment Records
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.
Object Environment Records created for with statements (
Object Environment Records have the additional state fields listed in
| Field Name | Value | Meaning |
|---|---|---|
| [[BindingObject]] | an Object |
The binding object of this |
| [[IsWithEnvironment]] | a Boolean |
Indicates whether this with statement.
|
The behaviour of the concrete specification methods for Object Environment Records is defined by the following algorithms.
9.1.1.2.1 HasBinding ( N )
The HasBinding concrete method of an
- Let bindingObject be envRec.[[BindingObject]].
- Let foundBinding be ?
HasProperty (bindingObject, N). - If foundBinding is
false , returnfalse . - If envRec.[[IsWithEnvironment]] is
false , returntrue . - Let unscopables be ?
Get (bindingObject, @@unscopables). - If unscopables
is an Object , then - Return
true .
9.1.1.2.2 CreateMutableBinding ( N, D )
The CreateMutableBinding concrete method of an
- Let bindingObject be envRec.[[BindingObject]].
- Perform ?
DefinePropertyOrThrow (bindingObject, N, PropertyDescriptor { [[Value]]:undefined , [[Writable]]:true , [[Enumerable]]:true , [[Configurable]]: D }). - Return
unused .
Normally envRec will not have a binding for N but if it does, the semantics of
9.1.1.2.3 CreateImmutableBinding ( N, S )
The CreateImmutableBinding concrete method of an
9.1.1.2.4 InitializeBinding ( N, V )
The InitializeBinding concrete method of an
- Perform ?
envRec.SetMutableBinding (N, V,false ). - Return
unused .
In this specification, all uses of CreateMutableBinding for
9.1.1.2.5 SetMutableBinding ( N, V, S )
The SetMutableBinding concrete method of an
- Let bindingObject be envRec.[[BindingObject]].
- Let stillExists be ?
HasProperty (bindingObject, N). - If stillExists is
false and S istrue , throw aReferenceError exception. - Perform ?
Set (bindingObject, N, V, S). - Return
unused .
9.1.1.2.6 GetBindingValue ( N, S )
The GetBindingValue concrete method of an
- Let bindingObject be envRec.[[BindingObject]].
- Let value be ?
HasProperty (bindingObject, N). - If value is
false , then- If S is
false , returnundefined ; otherwise throw aReferenceError exception.
- If S is
- Return ?
Get (bindingObject, N).
9.1.1.2.7 DeleteBinding ( N )
The DeleteBinding concrete method of an
- Let bindingObject be envRec.[[BindingObject]].
- Return ?
bindingObject.[[Delete]] (N).
9.1.1.2.8 HasThisBinding ( )
The HasThisBinding concrete method of an
- Return
false .
this binding.
9.1.1.2.9 HasSuperBinding ( )
The HasSuperBinding concrete method of an
- Return
false .
super binding.
9.1.1.2.10 WithBaseObject ( )
The WithBaseObject concrete method of an
- If envRec.[[IsWithEnvironment]] is
true , return envRec.[[BindingObject]]. - Otherwise, return
undefined .
9.1.1.3 Function Environment Records
A Function Environment Record is a this binding. If a function is not an 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
| Field Name | Value | Meaning |
|---|---|---|
| [[ThisValue]] |
an |
This is the |
| [[ThisBindingStatus]] |
|
If the value is |
| [[FunctionObject]] |
an ECMAScript |
The |
| [[NewTarget]] |
an Object or |
If this |
Function Environment Records support all of the
| Method | Purpose |
|---|---|
| BindThisValue(V) | Set the [[ThisValue]] and record that it has been initialized. |
| GetThisBinding() |
Return the value of this this binding. Throws a this binding has not been initialized.
|
| GetSuperBase() |
Return the object that is the base for super property accesses bound in this |
The behaviour of the additional concrete specification methods for Function Environment Records is defined by the following algorithms:
9.1.1.3.1 BindThisValue ( V )
The BindThisValue concrete method of a
Assert : envRec.[[ThisBindingStatus]] is notlexical .- If envRec.[[ThisBindingStatus]] is
initialized , throw aReferenceError exception. - Set envRec.[[ThisValue]] to V.
- Set envRec.[[ThisBindingStatus]] to
initialized . - Return V.
9.1.1.3.2 HasThisBinding ( )
The HasThisBinding concrete method of a
- If envRec.[[ThisBindingStatus]] is
lexical , returnfalse ; otherwise, returntrue .
9.1.1.3.3 HasSuperBinding ( )
The HasSuperBinding concrete method of a
- If envRec.[[ThisBindingStatus]] is
lexical , returnfalse . - If envRec.[[FunctionObject]].[[HomeObject]] is
undefined , returnfalse ; otherwise, returntrue .
9.1.1.3.4 GetThisBinding ( )
The GetThisBinding concrete method of a
Assert : envRec.[[ThisBindingStatus]] is notlexical .- If envRec.[[ThisBindingStatus]] is
uninitialized , throw aReferenceError exception. - Return envRec.[[ThisValue]].
9.1.1.3.5 GetSuperBase ( )
The GetSuperBase concrete method of a
- Let home be envRec.[[FunctionObject]].[[HomeObject]].
- If home is
undefined , returnundefined . Assert : homeis an Object .- Return ?
home.[[GetPrototypeOf]] ().
9.1.1.4 Global Environment Records
A Global Environment Record is used to represent the outer most scope that is shared by all of the ECMAScript
A Global Environment Record is logically a single record but it is specified as a composite encapsulating an
Properties may be created directly on a
Global Environment Records have the additional fields listed in
| Field Name | Value | Meaning |
|---|---|---|
| [[ObjectRecord]] |
an |
Binding object is the |
| [[GlobalThisValue]] | an Object |
The value returned by this in global scope. |
| [[DeclarativeRecord]] |
a |
|
| [[VarNames]] |
a |
The string names bound by |
| Method | Purpose |
|---|---|
| GetThisBinding() |
Return the value of this this binding.
|
| HasVarDeclaration (N) |
Determines if the argument identifier has a binding in this |
| HasLexicalDeclaration (N) |
Determines if the argument identifier has a binding in this |
| HasRestrictedGlobalProperty (N) |
Determines if the argument is the name of a |
| 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 var binding in the [[ObjectRecord]] component of a Global Environment Record. The binding will be a mutable binding. The corresponding var. The String value N is the bound name. If D is |
| 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 function. The String value N is the bound name. V is the initialization value. If the Boolean argument D is |
The behaviour of the concrete specification methods for Global Environment Records is defined by the following algorithms.
9.1.1.4.1 HasBinding ( N )
The HasBinding concrete method of a
- Let DclRec be envRec.[[DeclarativeRecord]].
- If ! DclRec.HasBinding(N) is
true , returntrue . - Let ObjRec be envRec.[[ObjectRecord]].
- Return ?
ObjRec.HasBinding (N).
9.1.1.4.2 CreateMutableBinding ( N, D )
The CreateMutableBinding concrete method of a
- Let DclRec be envRec.[[DeclarativeRecord]].
- If ! DclRec.HasBinding(N) is
true , throw aTypeError exception. - Return ! DclRec.CreateMutableBinding(N, D).
9.1.1.4.3 CreateImmutableBinding ( N, S )
The CreateImmutableBinding concrete method of a
- Let DclRec be envRec.[[DeclarativeRecord]].
- If ! DclRec.HasBinding(N) is
true , throw aTypeError exception. - Return ! DclRec.CreateImmutableBinding(N, S).
9.1.1.4.4 InitializeBinding ( N, V )
The InitializeBinding concrete method of a
- Let DclRec be envRec.[[DeclarativeRecord]].
- If ! DclRec.HasBinding(N) is
true , then- Return ! DclRec.InitializeBinding(N, V).
Assert : If the binding exists, it must be in theObject Environment Record .- Let ObjRec be envRec.[[ObjectRecord]].
- Return ?
ObjRec.InitializeBinding (N, V).
9.1.1.4.5 SetMutableBinding ( N, V, S )
The SetMutableBinding concrete method of a
- Let DclRec be envRec.[[DeclarativeRecord]].
- If ! DclRec.HasBinding(N) is
true , then- Return ? DclRec.SetMutableBinding(N, V, S).
- Let ObjRec be envRec.[[ObjectRecord]].
- Return ?
ObjRec.SetMutableBinding (N, V, S).
9.1.1.4.6 GetBindingValue ( N, S )
The GetBindingValue concrete method of a
- Let DclRec be envRec.[[DeclarativeRecord]].
- If ! DclRec.HasBinding(N) is
true , then- Return ? DclRec.GetBindingValue(N, S).
- Let ObjRec be envRec.[[ObjectRecord]].
- Return ?
ObjRec.GetBindingValue (N, S).
9.1.1.4.7 DeleteBinding ( N )
The DeleteBinding concrete method of a
- Let DclRec be envRec.[[DeclarativeRecord]].
- If ! DclRec.HasBinding(N) is
true , then- Return ! DclRec.DeleteBinding(N).
- Let ObjRec be envRec.[[ObjectRecord]].
- Let globalObject be ObjRec.[[BindingObject]].
- Let existingProp be ?
HasOwnProperty (globalObject, N). - If existingProp is
true , then- Let status be ?
ObjRec.DeleteBinding (N). - If status is
true and envRec.[[VarNames]] contains N, then- Remove N from envRec.[[VarNames]].
- Return status.
- Let status be ?
- Return
true .
9.1.1.4.8 HasThisBinding ( )
The HasThisBinding concrete method of a
- Return
true .
this binding.
9.1.1.4.9 HasSuperBinding ( )
The HasSuperBinding concrete method of a
- Return
false .
super binding.
9.1.1.4.10 WithBaseObject ( )
The WithBaseObject concrete method of a
- Return
undefined .
9.1.1.4.11 GetThisBinding ( )
The GetThisBinding concrete method of a
- Return envRec.[[GlobalThisValue]].
9.1.1.4.12 HasVarDeclaration ( N )
The HasVarDeclaration concrete method of a
- Let varDeclaredNames be envRec.[[VarNames]].
- If varDeclaredNames contains N, return
true . - Return
false .
9.1.1.4.13 HasLexicalDeclaration ( N )
The HasLexicalDeclaration concrete method of a
- Let DclRec be envRec.[[DeclarativeRecord]].
- Return ! DclRec.HasBinding(N).
9.1.1.4.14 HasRestrictedGlobalProperty ( N )
The HasRestrictedGlobalProperty concrete method of a
- Let ObjRec be envRec.[[ObjectRecord]].
- Let globalObject be ObjRec.[[BindingObject]].
- Let existingProp be ?
globalObject.[[GetOwnProperty]] (N). - If existingProp is
undefined , returnfalse . - If existingProp.[[Configurable]] is
true , returnfalse . - Return
true .
Properties may exist upon a
9.1.1.4.15 CanDeclareGlobalVar ( N )
The CanDeclareGlobalVar concrete method of a
- Let ObjRec be envRec.[[ObjectRecord]].
- Let globalObject be ObjRec.[[BindingObject]].
- Let hasProperty be ?
HasOwnProperty (globalObject, N). - If hasProperty is
true , returntrue . - Return ?
IsExtensible (globalObject).
9.1.1.4.16 CanDeclareGlobalFunction ( N )
The CanDeclareGlobalFunction concrete method of a
- Let ObjRec be envRec.[[ObjectRecord]].
- Let globalObject be ObjRec.[[BindingObject]].
- Let existingProp be ?
globalObject.[[GetOwnProperty]] (N). - If existingProp is
undefined , return ?IsExtensible (globalObject). - If existingProp.[[Configurable]] is
true , returntrue . - If
IsDataDescriptor (existingProp) istrue and existingProp has attribute values { [[Writable]]:true , [[Enumerable]]:true }, returntrue . - Return
false .
9.1.1.4.17 CreateGlobalVarBinding ( N, D )
The CreateGlobalVarBinding concrete method of a
- Let ObjRec be envRec.[[ObjectRecord]].
- Let globalObject be ObjRec.[[BindingObject]].
- Let hasProperty be ?
HasOwnProperty (globalObject, N). - Let extensible be ?
IsExtensible (globalObject). - If hasProperty is
false and extensible istrue , then- Perform ?
ObjRec.CreateMutableBinding (N, D). - Perform ?
ObjRec.InitializeBinding (N,undefined ).
- Perform ?
- If envRec.[[VarNames]] does not contain N, then
- Append N to envRec.[[VarNames]].
- Return
unused .
9.1.1.4.18 CreateGlobalFunctionBinding ( N, V, D )
The CreateGlobalFunctionBinding concrete method of a
- Let ObjRec be envRec.[[ObjectRecord]].
- Let globalObject be ObjRec.[[BindingObject]].
- Let existingProp be ?
globalObject.[[GetOwnProperty]] (N). - If existingProp is
undefined or existingProp.[[Configurable]] istrue , then- Let desc be the PropertyDescriptor { [[Value]]: V, [[Writable]]:
true , [[Enumerable]]:true , [[Configurable]]: D }.
- Let desc be the PropertyDescriptor { [[Value]]: V, [[Writable]]:
- Else,
- Let desc be the PropertyDescriptor { [[Value]]: V }.
- Perform ?
DefinePropertyOrThrow (globalObject, N, desc). - Perform ?
Set (globalObject, N, V,false ). - If envRec.[[VarNames]] does not contain N, then
- Append N to envRec.[[VarNames]].
- Return
unused .
Global function declarations are always represented as own properties of the
9.1.1.5 Module Environment Records
A Module Environment Record is a
Module Environment Records support all of the
| 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 |
| GetThisBinding() |
Return the value of this this binding.
|
The behaviour of the additional concrete specification methods for Module Environment Records are defined by the following algorithms:
9.1.1.5.1 GetBindingValue ( N, S )
The GetBindingValue concrete method of a
Assert : S istrue .Assert : envRec has a binding for N.- If the binding for N is an indirect binding, then
- Let M and N2 be the indirection values provided when this binding for N was created.
- Let targetEnv be M.[[Environment]].
- If targetEnv is
empty , throw aReferenceError exception. - Return ?
targetEnv.GetBindingValue (N2,true ).
- If the binding for N in envRec is an uninitialized binding, throw a
ReferenceError exception. - Return the value currently bound to N in envRec.
S will always be
9.1.1.5.2 DeleteBinding ( N )
The DeleteBinding concrete method of a
9.1.1.5.3 HasThisBinding ( )
The HasThisBinding concrete method of a
- Return
true .
this binding.
9.1.1.5.4 GetThisBinding ( )
The GetThisBinding concrete method of a
- Return
undefined .
9.1.1.5.5 CreateImportBinding ( N, M, N2 )
The CreateImportBinding concrete method of a
9.1.2 Environment Record Operations
The following
9.1.2.1 GetIdentifierReference ( env, name, strict )
The abstract operation GetIdentifierReference takes arguments env (an
- If env is
null , then- Return the
Reference Record { [[Base]]:unresolvable , [[ReferencedName]]: name, [[Strict]]: strict, [[ThisValue]]:empty }.
- Return the
- Let exists be ?
env.HasBinding (name). - If exists is
true , then- Return the
Reference Record { [[Base]]: env, [[ReferencedName]]: name, [[Strict]]: strict, [[ThisValue]]:empty }.
- Return the
- Else,
- Let outer be env.[[OuterEnv]].
- Return ? GetIdentifierReference(outer, name, strict).
9.1.2.2 NewDeclarativeEnvironment ( E )
The abstract operation NewDeclarativeEnvironment takes argument E (an
- Let env be a new
Declarative Environment Record containing no bindings. - Set env.[[OuterEnv]] to E.
- Return env.
9.1.2.3 NewObjectEnvironment ( O, W, E )
The abstract operation NewObjectEnvironment takes arguments O (an Object), W (a Boolean), and E (an
- Let env be a new
Object Environment Record . - Set env.[[BindingObject]] to O.
- Set env.[[IsWithEnvironment]] to W.
- Set env.[[OuterEnv]] to E.
- Return env.
9.1.2.4 NewFunctionEnvironment ( F, newTarget )
The abstract operation NewFunctionEnvironment takes arguments F (an ECMAScript function) and newTarget (an Object or
- Let env be a new
Function Environment Record containing no bindings. - Set env.[[FunctionObject]] to F.
- If F.[[ThisMode]] is
lexical , set env.[[ThisBindingStatus]] tolexical . - Else, set env.[[ThisBindingStatus]] to
uninitialized . - Set env.[[NewTarget]] to newTarget.
- Set env.[[OuterEnv]] to F.[[Environment]].
- Return env.
9.1.2.5 NewGlobalEnvironment ( G, thisValue )
The abstract operation NewGlobalEnvironment takes arguments G (an Object) and thisValue (an Object) and returns a
- Let objRec be
NewObjectEnvironment (G,false ,null ). - Let dclRec be
NewDeclarativeEnvironment (null ). - Let env be a new
Global Environment Record . - Set env.[[ObjectRecord]] to objRec.
- Set env.[[GlobalThisValue]] to thisValue.
- Set env.[[DeclarativeRecord]] to dclRec.
- Set env.[[VarNames]] to a new empty
List . - Set env.[[OuterEnv]] to
null . - Return env.
9.1.2.6 NewModuleEnvironment ( E )
The abstract operation NewModuleEnvironment takes argument E (an
- Let env be a new
Module Environment Record containing no bindings. - Set env.[[OuterEnv]] to E.
- Return env.
9.2 PrivateEnvironment Records
A PrivateEnvironment Record is a specification mechanism used to track
Each
| Field Name | Value Type | Meaning |
|---|---|---|
| [[OuterPrivateEnvironment]] |
a |
The |
| [[Names]] |
a |
The |
9.2.1 PrivateEnvironment Record Operations
The following
9.2.1.1 NewPrivateEnvironment ( outerPrivEnv )
The abstract operation NewPrivateEnvironment takes argument outerPrivEnv (a
- Let names be a new empty
List . - Return the
PrivateEnvironment Record { [[OuterPrivateEnvironment]]: outerPrivEnv, [[Names]]: names }.
9.2.1.2 ResolvePrivateIdentifier ( privEnv, identifier )
The abstract operation ResolvePrivateIdentifier takes arguments privEnv (a
- Let names be privEnv.[[Names]].
- For each
Private Name pn of names, do- If pn.[[Description]] is identifier, then
- Return pn.
- If pn.[[Description]] is identifier, then
- Let outerPrivEnv be privEnv.[[OuterPrivateEnvironment]].
Assert : outerPrivEnv is notnull .- Return ResolvePrivateIdentifier(outerPrivEnv, identifier).
9.3 Realms
Before it is evaluated, all ECMAScript code must be associated with a realm. Conceptually, a
A
| Field Name | Value | Meaning |
|---|---|---|
| [[Intrinsics]] |
a |
The intrinsic values used by code associated with this |
| [[GlobalObject]] |
an Object or |
The |
| [[GlobalEnv]] |
a |
The global environment for this |
| [[TemplateMap]] |
a |
Template objects are canonicalized separately for each Once a |
| [[LoadedModules]] |
a |
A map from the specifier strings imported by this
As mentioned in import() expression in a context where there is no |
| [[HostDefined]] |
anything (default value is |
Field reserved for use by |
9.3.1 CreateRealm ( )
The abstract operation CreateRealm takes no arguments and returns a
- Let realmRec be a new
Realm Record . - Perform
CreateIntrinsics (realmRec). - Set realmRec.[[GlobalObject]] to
undefined . - Set realmRec.[[GlobalEnv]] to
undefined . - Set realmRec.[[TemplateMap]] to a new empty
List . - Return realmRec.
9.3.2 CreateIntrinsics ( realmRec )
The abstract operation CreateIntrinsics takes argument realmRec (a
- Set realmRec.[[Intrinsics]] to a new
Record . - Set fields of realmRec.[[Intrinsics]] with the values listed in
Table 6 . The field names are the names listed in column one of the table. The value of each field is a new object value fully and recursively populated with property values as defined by the specification of each object in clauses19 through28 . All object property values are newly created object values. All values that are built-infunction objects are created by performingCreateBuiltinFunction (steps, length, name, slots, realmRec, prototype) where steps is the definition of that function provided by this specification, name is the initial value of the function's"name" property, length is the initial value of the function's"length" property, slots is a list of the names, if any, of the function's specified internal slots, and prototype is the specified value of the function's [[Prototype]] internal slot. The creation of the intrinsics and their properties must be ordered to avoid any dependencies upon objects that have not yet been created. - Perform
AddRestrictedFunctionProperties (realmRec.[[Intrinsics]].[[%Function.prototype% ]], realmRec). - Return
unused .
9.3.3 SetRealmGlobalObject ( realmRec, globalObj, thisValue )
The abstract operation SetRealmGlobalObject takes arguments realmRec (a
- If globalObj is
undefined , then- Let intrinsics be realmRec.[[Intrinsics]].
- Set globalObj to
OrdinaryObjectCreate (intrinsics.[[%Object.prototype% ]]).
Assert : globalObjis an Object .- If thisValue is
undefined , set thisValue to globalObj. - Set realmRec.[[GlobalObject]] to globalObj.
- Let newGlobalEnv be
NewGlobalEnvironment (globalObj, thisValue). - Set realmRec.[[GlobalEnv]] to newGlobalEnv.
- Return
unused .
9.3.4 SetDefaultGlobalBindings ( realmRec )
The abstract operation SetDefaultGlobalBindings takes argument realmRec (a
- Let global be realmRec.[[GlobalObject]].
- For each property of the Global Object specified in clause
19 , do- Let name be the String value of the
property name . - Let desc be the fully populated data
Property Descriptor for the property, containing the specified attributes for the property. For properties listed in19.2 ,19.3 , or19.4 the value of the [[Value]] attribute is the corresponding intrinsic object from realmRec. - Perform ?
DefinePropertyOrThrow (global, name, desc).
- Let name be the String value of the
- Return global.
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 execution context. |
| Function |
If this execution context is evaluating the code of a |
|
|
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 execution context is evaluating. |
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]].
9.5 Jobs and Host Operations to Enqueue Jobs
A Job is an
- At some future point in time, when there is no
running execution context and theexecution context stack is empty, the implementation must:- Perform any
host-defined preparation steps. Invoke theJob Abstract Closure .- Perform any
host-defined cleanup steps, after which theexecution context stack must be empty.
- Perform any
- Only one
Job may be actively undergoing evaluation at any point in time. - Once evaluation of a
Job starts, it must run to completion before evaluation of any otherJob starts. - The
Abstract Closure must return anormal completion , implementing its own handling of errors.
At any particular time, scriptOrModule (a
GetActiveScriptOrModule () is scriptOrModule.- If scriptOrModule is a
Script Record orModule Record , let ec be the topmostexecution context on theexecution context stack whose ScriptOrModule component is scriptOrModule. TheRealm component of ec is scriptOrModule.[[Realm]].
At any particular time, an execution is prepared to evaluate ECMAScript code if all of the following conditions are true:
- The
execution context stack is not empty. - The
Realm component of the topmostexecution context on theexecution context stack is aRealm Record .
The specific choice of
Particular kinds of
9.5.1 JobCallback Records
A JobCallback Record is a
The WHATWG HTML specification (https://html.spec.whatwg.org/), for example, uses the
JobCallback Records have the fields listed in
| Field Name | Value | Meaning |
|---|---|---|
| [[Callback]] |
a |
The function to invoke when the |
| [[HostDefined]] |
anything (default value is |
Field reserved for use by |
9.5.2 HostMakeJobCallback ( callback )
The
An implementation of HostMakeJobCallback must conform to the following requirements:
- It must return a
JobCallback Record whose [[Callback]] field is callback.
The default implementation of HostMakeJobCallback performs the following steps when called:
- Return the
JobCallback Record { [[Callback]]: callback, [[HostDefined]]:empty }.
ECMAScript
This is called at the time that the callback is passed to the function that is responsible for its being eventually scheduled and run. For example, promise.then(thenAction) calls MakeJobCallback on thenAction at the time of invoking Promise.prototype.then, not at the time of scheduling the reaction
9.5.3 HostCallJobCallback ( jobCallback, V, argumentsList )
The
An implementation of HostCallJobCallback must conform to the following requirements:
- It must perform and return the result of
Call (jobCallback.[[Callback]], V, argumentsList).
This requirement means that
The default implementation of HostCallJobCallback performs the following steps when called:
Assert :IsCallable (jobCallback.[[Callback]]) istrue .- Return ?
Call (jobCallback.[[Callback]], V, argumentsList).
ECMAScript
9.5.4 HostEnqueuePromiseJob ( job, realm )
The
An implementation of HostEnqueuePromiseJob must conform to the requirements in
- If realm is not
null , each time job is invoked the implementation must performimplementation-defined steps such that execution isprepared to evaluate ECMAScript code at the time of job's invocation. - Let scriptOrModule be
GetActiveScriptOrModule () at the time HostEnqueuePromiseJob is invoked. If realm is notnull , each time job is invoked the implementation must performimplementation-defined steps such that scriptOrModule is theactive script or module at the time of job's invocation. Jobs must run in the same order as the HostEnqueuePromiseJob invocations that scheduled them.
The realm for
9.6 InitializeHostDefinedRealm ( )
The abstract operation InitializeHostDefinedRealm takes no arguments and returns either a
- Let realm be
CreateRealm (). - Let newContext be a new
execution context . - Set the Function of newContext to
null . - Set the
Realm of newContext to realm. - Set the ScriptOrModule of newContext to
null . - Push newContext onto the
execution context stack ; newContext is now therunning execution context . - If the
host requires use of anexotic object to serve as realm'sglobal object , let global be such an object created in ahost-defined manner. Otherwise, let global beundefined , indicating that anordinary object should be created as theglobal object . - If the
host requires that thethisbinding in realm's global scope return an object other than theglobal object , let thisValue be such an object created in ahost-defined manner. Otherwise, let thisValue beundefined , indicating that realm's globalthisbinding should be theglobal object . - Perform
SetRealmGlobalObject (realm, global, thisValue). - Let globalObj be ?
SetDefaultGlobalBindings (realm). - Create any
host-defined global object properties on globalObj. - Return
unused .
9.7 Agents
An agent comprises a set of ECMAScript
An
Some web browsers share a single
While an
An agent signifier is a globally-unique opaque value used to identify an
| Field Name | Value | Meaning |
|---|---|---|
| [[LittleEndian]] | a Boolean | The default value computed for the isLittleEndian parameter when it is needed by the algorithms |
| [[CanBlock]] | a Boolean | Determines whether the |
| [[Signifier]] | an agent signifier | Uniquely identifies the |
| [[IsLockFree1]] | a Boolean | |
| [[IsLockFree2]] | a Boolean | |
| [[IsLockFree8]] | a Boolean | |
| [[CandidateExecution]] | a |
See the |
| [[KeptAlive]] | a |
Initially a new empty |
Once the values of [[Signifier]], [[IsLockFree1]], and [[IsLockFree2]] have been observed by any
The values of [[IsLockFree1]] and [[IsLockFree2]] are not necessarily determined by the hardware, but may also reflect implementation choices that can vary over time and between ECMAScript implementations.
There is no [[IsLockFree4]] field: 4-byte atomic operations are always lock-free.
In practice, if an atomic operation is implemented with any type of lock the operation is not lock-free. Lock-free does not imply wait-free: there is no upper bound on how many machine steps may be required to complete a lock-free atomic operation.
That an atomic access of size n is lock-free does not imply anything about the (perceived) atomicity of non-atomic accesses of size n, specifically, non-atomic accesses may still be performed as a sequence of several separate memory accesses. See
An
9.7.1 AgentSignifier ( )
The abstract operation AgentSignifier takes no arguments and returns an
- Let AR be the
Agent Record of thesurrounding agent . - Return AR.[[Signifier]].
9.7.2 AgentCanSuspend ( )
The abstract operation AgentCanSuspend takes no arguments and returns a Boolean. It performs the following steps when called:
- Let AR be the
Agent Record of thesurrounding agent . - Return AR.[[CanBlock]].
In some environments it may not be reasonable for a given
9.8 Agent Clusters
An agent cluster is a maximal set of
Programs within different
There may be
Every
All
If different
All
All
An embedding may deactivate (stop forward progress) or activate (resume forward progress) an
The purpose of the preceding restriction is to avoid a situation where an
The implication of the restriction is that it will not be possible to share memory between
An embedding may terminate an
Prior to any evaluation of any ECMAScript code by any
All
An agent cluster is a specification mechanism and need not correspond to any particular artefact of an ECMAScript implementation.
9.9 Forward Progress
For an
An
Implementations must ensure that:
- every unblocked
agent with a dedicatedexecuting thread eventually makes forward progress - in a set of
agents that share anexecuting thread , oneagent eventually makes forward progress - an
agent does not cause anotheragent to become blocked except via explicit APIs that provide blocking.
This, along with the liveness guarantee in the
9.10 Processing Model of WeakRef and FinalizationRegistry Targets
9.10.1 Objectives
This specification does not make any guarantees that any object or symbol will be garbage collected. Objects or symbols which are not
The semantics of
-
When
WeakRef.prototype.derefis called, the referent (ifundefined is not returned) is kept alive so that subsequent, synchronous accesses also return the same value. This list is reset when synchronous work is done using theClearKeptObjects abstract operation. -
When an object or symbol which is registered with a
FinalizationRegistry becomes unreachable, a call of theFinalizationRegistry 's cleanup callback may eventually be made, after synchronous ECMAScript execution completes. TheFinalizationRegistry cleanup is performed with theCleanupFinalizationRegistry abstract operation.
Neither of these actions (
Some ECMAScript implementations include garbage collector implementations which run in the background, including when ECMAScript is idle. Letting the
9.10.2 Liveness
For some set of objects and/or symbols S a hypothetical WeakRef-oblivious execution with respect to S is an execution whereby the abstract operation
At any point during evaluation, a set of objects and/or symbols S is considered live if either of the following conditions is met:
-
Any element in S is included in any
agent 's [[KeptAlive]]List . - There exists a valid future hypothetical WeakRef-oblivious execution with respect to S that observes the identity of any value in S.
Presence of an object or a symbol in a field, an internal slot, or a property does not imply that the value is live. For example if the value in question is never passed back to the program, then it cannot be observed.
This is the case for keys in a WeakMap, members of a WeakSet, as well as the [[WeakRefTarget]] and [[UnregisterToken]] fields of a
The above definition implies that, if a key in a WeakMap is not live, then its corresponding value is not necessarily live either.
9.10.3 Execution
At any time, if a set of objects and/or symbols S is not
- For each element value of S, do
- For each
WeakRef ref such that ref.[[WeakRefTarget]] is value, do- Set ref.[[WeakRefTarget]] to
empty .
- Set ref.[[WeakRefTarget]] to
- For each
FinalizationRegistry fg such that fg.[[Cells]] contains aRecord cell such that cell.[[WeakRefTarget]] is value, do- Set cell.[[WeakRefTarget]] to
empty . - Optionally, perform
HostEnqueueFinalizationRegistryCleanupJob (fg).
- Set cell.[[WeakRefTarget]] to
- For each WeakMap map such that map.[[WeakMapData]] contains a
Record r such that r.[[Key]] is value, do- Set r.[[Key]] to
empty . - Set r.[[Value]] to
empty .
- Set r.[[Key]] to
- For each WeakSet set such that set.[[WeakSetData]] contains value, do
- Replace the element of set.[[WeakSetData]] whose value is value with an element whose value is
empty .
- Replace the element of set.[[WeakSetData]] whose value is value with an element whose value is
- For each
Together with the definition of liveness, this clause prescribes optimizations that an implementation may apply regarding
It is possible to access an object without observing its identity. Optimizations such as dead variable elimination and scalar replacement on properties of non-escaping objects whose identity is not observed are allowed. These optimizations are thus allowed to observably empty
On the other hand, if an object's identity is observable, and that object is in the [[WeakRefTarget]] internal slot of a
Because calling
Implementations are not obligated to empty
If an implementation chooses a non-
9.10.4 Host Hooks
9.10.4.1 HostEnqueueFinalizationRegistryCleanupJob ( finalizationRegistry )
The
Let cleanupJob be a new
- Let cleanupResult be
Completion (CleanupFinalizationRegistry (finalizationRegistry)). - If cleanupResult is an
abrupt completion , perform anyhost-defined steps for reporting the error. - Return
unused .
An implementation of HostEnqueueFinalizationRegistryCleanupJob schedules cleanupJob to be performed at some future time, if possible. It must also conform to the requirements in
9.11 ClearKeptObjects ( )
The abstract operation ClearKeptObjects takes no arguments and returns
- Let agentRecord be the
surrounding agent 'sAgent Record . - Set agentRecord.[[KeptAlive]] to a new empty
List . - Return
unused .
9.12 AddToKeptObjects ( value )
The abstract operation AddToKeptObjects takes argument value (an Object or a Symbol) and returns
- Let agentRecord be the
surrounding agent 'sAgent Record . - Append value to agentRecord.[[KeptAlive]].
- Return
unused .
9.13 CleanupFinalizationRegistry ( finalizationRegistry )
The abstract operation CleanupFinalizationRegistry takes argument finalizationRegistry (a
Assert : finalizationRegistry has [[Cells]] and [[CleanupCallback]] internal slots.- Let callback be finalizationRegistry.[[CleanupCallback]].
- While finalizationRegistry.[[Cells]] contains a
Record cell such that cell.[[WeakRefTarget]] isempty , an implementation may perform the following steps:- Choose any such cell.
- Remove cell from finalizationRegistry.[[Cells]].
- Perform ?
HostCallJobCallback (callback,undefined , « cell.[[HeldValue]] »).
- Return
unused .
9.14 CanBeHeldWeakly ( v )
The abstract operation CanBeHeldWeakly takes argument v (an
- If v
is an Object , returntrue . - If v
is a Symbol andKeyForSymbol (v) isundefined , returntrue . - Return
false .
A language value without