This document attempts to integrate the class fields, private methods and accessors, and static class features proposals into a single, coherent, orthogonal whole. This document was generated from PR #1668 using ECMA262 Compare tool.
The actual semantics of objects, in ECMAScript, are specified via algorithms called internal methods. Each object in an ECMAScript engine is associated with a set of internal methods that defines its runtime behaviour. These internal methods are not part of the ECMAScript language. They are defined by this specification purely for expository purposes. However, each object within an implementation of ECMAScript must behave as specified by the internal methods associated with it. The exact manner in which this is accomplished is determined by the implementation.
Internal method names are polymorphic. This means that different object values may perform different algorithms when a common internal method name is invoked upon them. That actual object upon which an internal method is invoked is the “target” of the invocation. If, at runtime, the implementation of an algorithm attempts to use an internal method of an object that the object does not support, a
Internal slots correspond to internal state that is associated with objects and used by various ECMAScript specification algorithms. Internal slots are not object properties and they are not inherited. Depending upon the specific internal slot specification, such state may consist of values of any
All objects have an internal slot named [[PrivateFields]], which is a
All objects have an internal slot named [[PrivateBrands]], which is a
Although this specification uses logic of a [[PrivateBrands]]
Internal methods and internal slots are identified within this specification using names enclosed in double square brackets [[ ]].
An ordinary object is an object that satisfies all of the following criteria:
An exotic object is an object that is not an
This specification recognizes different kinds of exotic objects by those objects' internal methods. An object that is behaviourally equivalent to a particular kind of
The “Signature” column of
In addition to its parameters, an internal method always has access to the object that is the target of the method invocation.
An internal method implicitly returns a
Internal Method | Signature | Description |
---|---|---|
[[GetPrototypeOf]] | ( ) → Object | Null |
Determine the object that provides inherited properties for this object. A |
[[SetPrototypeOf]] | (Object | Null) → Boolean |
Associate this object with another object that provides inherited properties. Passing |
[[IsExtensible]] | ( ) → Boolean | Determine whether it is permitted to add additional properties to this object. |
[[PreventExtensions]] | ( ) → Boolean |
Control whether new properties may be added to this object. Returns |
[[GetOwnProperty]] |
(propertyKey) → Undefined | |
Return a |
[[DefineOwnProperty]] | (propertyKey, PropertyDescriptor) → Boolean |
Create or alter the own property, whose key is propertyKey, to have the state described by PropertyDescriptor. Return |
[[HasProperty]] | (propertyKey) → Boolean | Return a Boolean value indicating whether this object already has either an own or inherited property whose key is propertyKey. |
[[Get]] | (propertyKey, Receiver) → any |
Return the value of the property whose key is propertyKey from this object. If any ECMAScript code must be executed to retrieve the property value, Receiver is used as the |
[[Set]] | (propertyKey, value, Receiver) → Boolean |
Set the value of the property whose key is propertyKey to value. If any ECMAScript code must be executed to set the property value, Receiver is used as the |
[[Delete]] | (propertyKey) → Boolean |
Remove the own property whose key is propertyKey from this object. Return |
[[OwnPropertyKeys]] |
( ) → |
Return a |
Internal Method | Signature | Description |
---|---|---|
[[Call]] |
(any, a |
Executes code associated with this object. Invoked via a function call expression. The arguments to the internal method are a |
[[Construct]] |
(a |
Creates an object. Invoked via the new operator or a super call. The first argument to the internal method is a super call. The second argument is the object to which the new operator was initially applied. Objects that implement this internal method are called constructors. A |
The semantics of the essential internal methods for ordinary objects and standard exotic objects are specified in clause
A specification type corresponds to meta-values that are used within algorithms to describe the semantics of ECMAScript language constructs and ECMAScript language types. The specification types include Reference,
The Reference Record type is used to explain the behaviour of such operators as delete
, typeof
, the assignment operators, the super
A Reference Record is a resolved name or property binding; its fields are defined by
Field Name | Value | Meaning |
---|---|---|
[[Base]] |
One of:
| The value or |
[[ReferencedName]] | The name of the binding. Always a String if [[Base]] value is an | |
[[Strict]] | Boolean | |
[[ThisValue]] | any | If not super |
The following ReferencesReference Records:
The abstract operation GetValue takes argument V. It performs the following steps when called:
The object that may be created in step
The abstract operation PutValue takes arguments V and W. It performs the following steps when called:
The object that may be created in step
The abstract operation InitializeReferencedBinding takes arguments V and W. It performs the following steps when called:
The Data Block specification type is used to describe a distinct and mutable sequence of byte-sized (8 bit) numeric values. A byte value is an
For notational convenience within this specification, an array-like syntax can be used to access the individual bytes of a Data Block value. This notation presents a Data Block value as a 0-origined
A data block that resides in memory that can be referenced from multiple agents concurrently is designated a Shared Data Block. A Shared Data Block has an identity (for the purposes of equality testing Shared Data Block values) that is address-free: it is tied not to the virtual addresses the block is mapped to in any process, but to the set of locations in memory that the block represents. Two data blocks are equal only if the sets of the locations they contain are equal; otherwise, they are not equal and the intersection of the sets of locations they contain is empty. Finally, Shared Data Blocks can be distinguished from Data Blocks.
The semantics of Shared Data Blocks is defined using Shared Data Block events by the
Shared Data Block events are modeled by Records, defined in the
The following
The PrivateField type is a
Values of the PrivateField type are
Field Name | Value | Meaning |
---|---|---|
[[PrivateFieldName]] |
a | The name of the field. |
[[PrivateFieldValue]] |
any | The value of the field. |
The ClassFieldDefinition type is a
Values of the ClassFieldDefinition type are
Field Name | Value | Meaning |
---|---|---|
[[Name]] |
a | The name of the field. |
[[Initializer]] |
an ECMAScript | The initializer of the field, if any. |
[[IsAnonymousFunctionDefinition]] | Boolean |
|
The Private Name specification type is used to describe a globally unique record which represents a private class element (field, method, or accessor). A Private Name may be installed on any ECMAScript object with
Each Private Name holds the following information:
Field | Type | Values of the [[Kind]] field for which it is present | Description |
---|---|---|---|
[[Description]] | String | All |
The string value passed to |
[[Kind]] |
| All | Indicates what the private name is used for. |
[[Brand]] | Object |
| The "original" class of the private method or accessor; checked for in the [[PrivateBrands]] internal slot of instances before access is provided. |
[[Value]] | Function |
| The value of the private method. |
[[Get]] | Function |
| The getter for a private accessor. |
[[Set]] | Function |
| The setter for a private accessor. |
The abstract operation CopyDataProperties takes arguments target, source, and excludedItems. It performs the following steps when called:
The target passed in here is always a newly created object which is not directly accessible in case of an error being thrown.
With parameter symbol.
With parameter parameters scope and privateScope.
The abstract operation NewDeclarativeEnvironment takes argument E (an
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 Table 25Table 28
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 |
Evaluation of code by the
The value of the
Execution contexts for ECMAScript code have the additional state components listed in Table 26Table 29
Component | Purpose |
---|---|
LexicalEnvironment |
Identifies the |
VariableEnvironment |
Identifies the |
PrivateEnvironment |
Identifies the |
The LexicalEnvironment and VariableEnvironment components of an execution context are always Environment Records.
Execution contexts representing the evaluation of generator objects have the additional state components listed in Table 27Table 30
Component | Purpose |
---|---|
Generator |
The generator object 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.
ECMAScript function objects encapsulate parameterized ECMAScript code closed over a lexical environment and support the dynamic evaluation of that code. An ECMAScript
In addition to [[Extensible]] and [[Prototype]], ECMAScript function objects also have the internal slots listed in Table 30Table 33
Internal Slot | Type | Description |
---|---|---|
[[Environment]] |
|
The |
[[PrivateEnvironment]] |
|
The |
[[FormalParameters]] |
| The root parse node of the source text that defines the function's formal parameter list. |
[[ECMAScriptCode]] |
| The root parse node of the source text that defines the function's body. |
[[ConstructorKind]] |
|
Whether or not the function is a derived class |
[[Realm]] |
|
The |
[[ScriptOrModule]] |
| The script or module in which the function was created. |
[[ThisMode]] |
|
Defines how this references are interpreted within the formal parameters and code body of the function. this refers to the |
[[Strict]] | Boolean |
|
[[HomeObject]] | Object |
If the function uses super , this is the object whose [[GetPrototypeOf]] provides the object where super property lookups begin.
|
[[SourceText]] | sequence of Unicode code points |
The |
[[Fields]] |
| If the function is a class with instance field declarations, this is a list of records representing those fields and their initializers. |
[[IsClassConstructor]] | Boolean |
Indicates whether the function is a class |
[[ClassFieldInitializer]] | Boolean |
|
[[PrivateBrand]] |
Object | |
If the function is a class with private methods or accessors, this is the brand to be installed on objects that are being initialized by the |
All ECMAScript function objects have the [[Call]] internal method defined here. ECMAScript functions that are also constructors in addition have the [[Construct]] internal method.
The [[Construct]] internal method of an ECMAScript
The abstract operation OrdinaryFunctionCreate takes arguments functionPrototype (an Object), sourceText (a sequence of Unicode code points), ParameterList (a and Scope (an
The abstract operation SetFunctionName takes arguments F (a keykey or
When an
The abstract operation FunctionDeclarationInstantiation takes arguments func (a
Parameter
The abstract operation PrepareForOrdinaryCall takes arguments F (a
With parameters functionObject and argumentsList (a
The
This standard specifies specific code point additions: U+0024 (DOLLAR SIGN) and U+005F (LOW LINE) are permitted anywhere in an
Unicode escape sequences are permitted in an \
preceding the u
and { }
code units, if they appear, do not contribute code points to the \
Two
The definitions of the nonterminal
The nonterminal _
via
The sets of code points with Unicode properties “ID_Start” and “ID_Continue” include, respectively, the code points with Unicode properties “Other_ID_Start” and “Other_ID_Continue”.
\
An object initializer is an expression describing the initialization of an Object, written in a form resembling a literal. It is a list of zero or more pairs of property keys and associated values, enclosed in curly brackets. The values need not be literals; they are evaluated each time the object initializer is evaluated.
In certain contexts,
In addition to describing an actual object initializer the
This production exists so that
With parameters object and enumerable.
An alternative semantics for this production is given in
When processing an instance of the production
the interpretation of
With parameters baseValue and baseReference.
It is a Syntax Error if the derived
and
The last rule means that expressions such as delete (((foo)))
produce early errors because of recursive application of the first rule.
When a delete
operator occurs within delete
operator occurs within
The object that may be created in step bc
When a
The abstract operation BlockDeclarationInstantiation takes arguments code (a
This section is extended by Annex
With parameter parameters scope and privateScope.
An anonymous export default
declaration, and its function code is therefore always
With optional parameter name.
The
With optional parameter name.
An arguments
, super
, this
, or new.target
. Any reference to arguments
, super
, this
, or new.target
within an super
, the super
is always contained within a non-super
is accessible via the scope that is captured by the
With parameter object and optional parameter functionPrototype.
With parameters object and enumerable.
The syntactic context immediately following yield
requires use of the
With parameter parameters scope and privateScope.
An anonymous export default
declaration, and its function code is therefore always
With optional parameter name.
The
With parameter parameters scope and privateScope.
An anonymous export default
declaration.
With optional parameter name.
The
A class definition is always
It is a Syntax Error if
With parameter names.
For all other grammatical productions, recurse on subexpressions/substatements, passing in the names of the caller. If all pieces return
For all other grammatical productions, recurse on all nonterminals. If any piece returns
With parameter homeObject.
With parameters object and enumerable.
With parameters classBinding and className.
await
is parsed as an
When await
is parsed as a await
may be parsed as an identifier when the [Await] parameter is absent. This includes the following contexts:
Unlike
With parameter parameters scope and privateScope.
With optional parameter name.
The
With optional parameter name.
A potential tail position call that is immediately followed by return
super
unless the source code containing super
is eval code that is being processed by a super
within The abstract operation ScriptEvaluation takes argument scriptRecord. It performs the following steps when called:
When an
The abstract operation GlobalDeclarationInstantiation takes arguments script (a
Early errors specified in
Unlike explicit var or function declarations, properties that are directly created on the
super
.
The duplicate export default
The InitializeEnvironment concrete method of a
The eval
function is the %eval% intrinsic object. When the eval
function is called with one argument x, the following steps are taken:
The abstract operation PerformEval takes arguments x, callerRealm, strictCaller, and direct. It performs the following steps when called:
eval
function.The eval code cannot instantiate variable or function bindings in the variable environment of the calling context that invoked the eval if the calling context is evaluating formal parameter initializers or if either the code of the calling context or the eval code is let
, const
, or class
declarations are always instantiated in a new LexicalEnvironment.
The abstract operation EvalDeclarationInstantiation takes arguments body, varEnv, lexEnv, privateEnv, and strict. It performs the following steps when called:
eval
will not create a global var declaration that would be shadowed by a global lexical declaration.An alternative version of this algorithm is described in
The abstract operation CreateDynamicFunction takes arguments constructor (a new
was initially applied to. args is the argument values that were passed to constructor. It performs the following steps when called:
CreateDynamicFunction defines a
Kind | Prefix |
---|---|
When processing an instance of the production
the interpretation of
When processing an instance of the production
the interpretation of
In certain circumstances when processing an instance of the production
the interpretation of
When processing an instance of the production
the interpretation of
When processing an instance of the production
the interpretation of
During
During 34.a.ii.1
During 34.b.iii
The content of subclause
The var
declarations that bind a name that is also bound by the var
declarations will assign to the corresponding catch parameter rather than the var
binding.
This modified behaviour also applies to var
and function
declarations introduced by
Step
Step 711.d.ii.4.a.i.i