6.2 ECMAScript Specification Types
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,
6.2.1 The List and Record Specification Types
The List type is used to explain the evaluation of argument lists (see new
expressions, in function calls, and in other algorithms where a simple ordered list of values is needed. Values of the List type are simply ordered sequences of list elements containing the individual values. These sequences may be of any length. The elements of a list may be randomly accessed using 0-origin indices. For notational convenience an array-like syntax can be used to access List elements. For example, arguments[2] is shorthand for saying the 3rd element of the List arguments.
When an algorithm iterates over the elements of a List without specifying an order, the order used is the order of the elements in the List.
For notational convenience within this specification, a literal syntax can be used to express a new List value. For example, « 1, 2 » defines a List value that has two elements each of which is initialized to a specific value. A new empty List can be expressed as « ».
The Record type is used to describe data aggregations within the algorithms of this specification. A Record type value consists of one or more named fields. The value of each field is either an ECMAScript value or an abstract value represented by a name associated with the Record type. Field names are always enclosed in double brackets, for example [[Value]].
For notational convenience within this specification, an object literal-like syntax can be used to express a Record value. For example, { [[Field1]]: 42, [[Field2]]:
In specification text and algorithms, dot notation may be used to refer to a specific field of a Record value. For example, if R is the record shown in the previous paragraph then R.[[Field2]] is shorthand for “the field of R named [[Field2]]”.
Schema for commonly used Record field combinations may be named, and that name may be used as a prefix to a literal Record value to identify the specific kind of aggregations that is being described. For example: PropertyDescriptor { [[Value]]: 42, [[Writable]]:
6.2.2 The Set and Relation Specification Types
The Set type is used to explain a collection of unordered elements for use in the
The Relation type is used to explain constraints on Sets. Values of the Relation type are Sets of ordered pairs of values from its value domain. For example, a Relation on events is a set of ordered pairs of events. For a Relation R and two values a and b in the value domain of R, a R b is shorthand for saying the ordered pair (a, b) is a member of R. A Relation is least with respect to some conditions when it is the smallest Relation that satisfies those conditions.
A strict partial order is a Relation value R that satisfies the following.
-
For all a, b, and c in R's domain:
- It is not the case that a R a, and
- If a R b and b R c, then a R c.
The two properties above are called irreflexivity and transitivity, respectively.
A strict total order is a Relation value R that satisfies the following.
-
For all a, b, and c in R's domain:
- a is identical to b or a R b or b R a, and
- It is not the case that a R a, and
- If a R b and b R c, then a R c.
The three properties above are called totality, irreflexivity, and transitivity, respectively.
6.2.3 The Completion Record Specification Type
The Completion type is a break
, continue
, return
and throw
) that perform nonlocal transfers of control.
Values of the Completion type are
Field Name | Value | Meaning |
---|---|---|
[[Type]] |
One of |
The type of completion that occurred. |
[[Value]] |
any |
The value that was produced. |
[[Target]] |
any ECMAScript string or |
The target label for directed control transfers. |
The term “abrupt completion” refers to any completion with a [[Type]] value other than
6.2.3.1 Await
Algorithm steps that say
- Let completion be
Await (value).
mean the same thing as:
- Let asyncContext be the
running execution context . - Let promise be ?
PromiseResolve (%Promise% , value). - Let stepsFulfilled be the algorithm steps defined in
Await Fulfilled Functions . - Let lengthFulfilled be the number of non-optional parameters of the function definition in
Await Fulfilled Functions . - Let onFulfilled be !
CreateBuiltinFunction (stepsFulfilled, lengthFulfilled,"" , « [[AsyncContext]] »). - Set onFulfilled.[[AsyncContext]] to asyncContext.
- Let stepsRejected be the algorithm steps defined in
Await Rejected Functions . - Let lengthRejected be the number of non-optional parameters of the function definition in
Await Rejected Functions . - Let onRejected be !
CreateBuiltinFunction (stepsRejected, lengthRejected,"" , « [[AsyncContext]] »). - Set onRejected.[[AsyncContext]] to asyncContext.
- Perform !
PerformPromiseThen (promise, onFulfilled, onRejected). - Remove asyncContext from the
execution context stack and restore theexecution context that is at the top of theexecution context stack as therunning execution context . - Set the code evaluation state of asyncContext such that when evaluation is resumed with a
Completion completion, the following steps of the algorithm that invokedAwait will be performed, with completion available. - Return.
- NOTE: This returns to the evaluation of the operation that had most previously resumed evaluation of asyncContext.
where all aliases in the above steps, with the exception of completion, are ephemeral and visible only in the steps pertaining to Await.
Await can be combined with the ?
and !
prefixes, so that for example
- Let result be ?
Await (value).
means the same thing as:
- Let result be
Await (value). ReturnIfAbrupt (result).
6.2.3.1.1 Await Fulfilled Functions
An
When an
- Let F be the
active function object . - Let asyncContext be F.[[AsyncContext]].
- Let prevContext be the
running execution context . - Suspend prevContext.
- Push asyncContext onto the
execution context stack ; asyncContext is now therunning execution context . - Resume the suspended evaluation of asyncContext using
NormalCompletion (value) as the result of the operation that suspended it. Assert : When we reach this step, asyncContext has already been removed from theexecution context stack and prevContext is the currentlyrunning execution context .- Return
undefined .
The
6.2.3.1.2 Await Rejected Functions
An
When an
- Let F be the
active function object . - Let asyncContext be F.[[AsyncContext]].
- Let prevContext be the
running execution context . - Suspend prevContext.
- Push asyncContext onto the
execution context stack ; asyncContext is now therunning execution context . - Resume the suspended evaluation of asyncContext using
ThrowCompletion (reason) as the result of the operation that suspended it. Assert : When we reach this step, asyncContext has already been removed from theexecution context stack and prevContext is the currentlyrunning execution context .- Return
undefined .
The
6.2.3.2 NormalCompletion
The abstract operation NormalCompletion with a single argument, such as:
- Return
NormalCompletion (argument).
Is a shorthand that is defined as follows:
- Return
Completion { [[Type]]:normal , [[Value]]: argument, [[Target]]:empty }.
6.2.3.3 ThrowCompletion
The abstract operation ThrowCompletion with a single argument, such as:
- Return
ThrowCompletion (argument).
Is a shorthand that is defined as follows:
- Return
Completion { [[Type]]:throw , [[Value]]: argument, [[Target]]:empty }.
6.2.3.4 UpdateEmpty ( completionRecord, value )
The abstract operation UpdateEmpty takes arguments completionRecord and value. It performs the following steps when called:
Assert : If completionRecord.[[Type]] is eitherreturn orthrow , then completionRecord.[[Value]] is notempty .- If completionRecord.[[Value]] is not
empty , returnCompletion (completionRecord). - Return
Completion { [[Type]]: completionRecord.[[Type]], [[Value]]: value, [[Target]]: completionRecord.[[Target]] }.
6.2.4 The Reference Record Specification Type
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]] | String or Symbol | The name of the binding. Always a String if [[Base]] value is an |
[[Strict]] | Boolean | |
[[ThisValue]] | any |
If not super |
The following
6.2.4.1 IsPropertyReference ( V )
The abstract operation IsPropertyReference takes argument V. It performs the following steps when called:
Assert : V is aReference Record .- If V.[[Base]] is
unresolvable , returnfalse . - If
Type (V.[[Base]]) is Boolean, String, Symbol, BigInt, Number, or Object, returntrue ; otherwise returnfalse .
6.2.4.2 IsUnresolvableReference ( V )
The abstract operation IsUnresolvableReference takes argument V. It performs the following steps when called:
Assert : V is aReference Record .- If V.[[Base]] is
unresolvable , returntrue ; otherwise returnfalse .
6.2.4.3 IsSuperReference ( V )
The abstract operation IsSuperReference takes argument V. It performs the following steps when called:
Assert : V is aReference Record .- If V.[[ThisValue]] is not
empty , returntrue ; otherwise returnfalse .
6.2.4.4 GetValue ( V )
The abstract operation GetValue takes argument V. It performs the following steps when called:
ReturnIfAbrupt (V).- If V is not a
Reference Record , return V. - If
IsUnresolvableReference (V) istrue , throw aReferenceError exception. - If
IsPropertyReference (V) istrue , then- Let baseObj be !
ToObject (V.[[Base]]). - Return ? baseObj.[[Get]](V.[[ReferencedName]],
GetThisValue (V)).
- Let baseObj be !
- Else,
- Let base be V.[[Base]].
Assert : base is anEnvironment Record .- Return ? base.GetBindingValue(V.[[ReferencedName]], V.[[Strict]]) (see
9.1 ).
The object that may be created in step
6.2.4.5 PutValue ( V, W )
The abstract operation PutValue takes arguments V and W. It performs the following steps when called:
ReturnIfAbrupt (V).ReturnIfAbrupt (W).- If V is not a
Reference Record , throw aReferenceError exception. - If
IsUnresolvableReference (V) istrue , then- If V.[[Strict]] is
true , throw aReferenceError exception. - Let globalObj be
GetGlobalObject (). - Return ?
Set (globalObj, V.[[ReferencedName]], W,false ).
- If V.[[Strict]] is
- If
IsPropertyReference (V) istrue , then- Let baseObj be !
ToObject (V.[[Base]]). - Let succeeded be ? baseObj.[[Set]](V.[[ReferencedName]], W,
GetThisValue (V)). - If succeeded is
false and V.[[Strict]] istrue , throw aTypeError exception. - Return.
- Let baseObj be !
- Else,
- Let base be V.[[Base]].
Assert : base is anEnvironment Record .- Return ? base.SetMutableBinding(V.[[ReferencedName]], W, V.[[Strict]]) (see
9.1 ).
The object that may be created in step
6.2.4.6 GetThisValue ( V )
The abstract operation GetThisValue takes argument V. It performs the following steps when called:
Assert :IsPropertyReference (V) istrue .- If
IsSuperReference (V) istrue , return V.[[ThisValue]]; otherwise return V.[[Base]].
6.2.4.7 InitializeReferencedBinding ( V, W )
The abstract operation InitializeReferencedBinding takes arguments V and W. It performs the following steps when called:
ReturnIfAbrupt (V).ReturnIfAbrupt (W).Assert : V is aReference Record .Assert :IsUnresolvableReference (V) isfalse .- Let base be V.[[Base]].
Assert : base is anEnvironment Record .- Return base.InitializeBinding(V.[[ReferencedName]], W).
6.2.5 The Property Descriptor Specification Type
The Property Descriptor type is used to explain the manipulation and reification of Object property attributes. Values of the Property Descriptor type are Records. Each field's name is an attribute name and its value is a corresponding attribute value as specified in
Property Descriptor values may be further classified as data Property Descriptors and accessor Property Descriptors based upon the existence or use of certain fields. A data Property Descriptor is one that includes any fields named either [[Value]] or [[Writable]]. An accessor Property Descriptor is one that includes any fields named either [[Get]] or [[Set]]. Any Property Descriptor may have fields named [[Enumerable]] and [[Configurable]]. A Property Descriptor value may not be both a data Property Descriptor and an accessor Property Descriptor; however, it may be neither. A generic Property Descriptor is a Property Descriptor value that is neither a data Property Descriptor nor an accessor Property Descriptor. A fully populated Property Descriptor is one that is either an accessor Property Descriptor or a data Property Descriptor and that has all of the fields that correspond to the property attributes defined in either
The following
6.2.5.1 IsAccessorDescriptor ( Desc )
The abstract operation IsAccessorDescriptor takes argument Desc (a
- If Desc is
undefined , returnfalse . - If both Desc.[[Get]] and Desc.[[Set]] are absent, return
false . - Return
true .
6.2.5.2 IsDataDescriptor ( Desc )
The abstract operation IsDataDescriptor takes argument Desc (a
- If Desc is
undefined , returnfalse . - If both Desc.[[Value]] and Desc.[[Writable]] are absent, return
false . - Return
true .
6.2.5.3 IsGenericDescriptor ( Desc )
The abstract operation IsGenericDescriptor takes argument Desc (a
- If Desc is
undefined , returnfalse . - If
IsAccessorDescriptor (Desc) andIsDataDescriptor (Desc) are bothfalse , returntrue . - Return
false .
6.2.5.4 FromPropertyDescriptor ( Desc )
The abstract operation FromPropertyDescriptor takes argument Desc (a
- If Desc is
undefined , returnundefined . - Let obj be !
OrdinaryObjectCreate (%Object.prototype% ). Assert : obj is an extensibleordinary object with no own properties.- If Desc has a [[Value]] field, then
- Perform !
CreateDataPropertyOrThrow (obj,"value" , Desc.[[Value]]).
- Perform !
- If Desc has a [[Writable]] field, then
- Perform !
CreateDataPropertyOrThrow (obj,"writable" , Desc.[[Writable]]).
- Perform !
- If Desc has a [[Get]] field, then
- Perform !
CreateDataPropertyOrThrow (obj,"get" , Desc.[[Get]]).
- Perform !
- If Desc has a [[Set]] field, then
- Perform !
CreateDataPropertyOrThrow (obj,"set" , Desc.[[Set]]).
- Perform !
- If Desc has an [[Enumerable]] field, then
- Perform !
CreateDataPropertyOrThrow (obj,"enumerable" , Desc.[[Enumerable]]).
- Perform !
- If Desc has a [[Configurable]] field, then
- Perform !
CreateDataPropertyOrThrow (obj,"configurable" , Desc.[[Configurable]]).
- Perform !
- Return obj.
6.2.5.5 ToPropertyDescriptor ( Obj )
The abstract operation ToPropertyDescriptor takes argument Obj. It performs the following steps when called:
- If
Type (Obj) is not Object, throw aTypeError exception. - Let desc be a new
Property Descriptor that initially has no fields. - Let hasEnumerable be ?
HasProperty (Obj,"enumerable" ). - If hasEnumerable is
true , then - Let hasConfigurable be ?
HasProperty (Obj,"configurable" ). - If hasConfigurable is
true , then - Let hasValue be ?
HasProperty (Obj,"value" ). - If hasValue is
true , then- Let value be ?
Get (Obj,"value" ). - Set desc.[[Value]] to value.
- Let value be ?
- Let hasWritable be ?
HasProperty (Obj,"writable" ). - If hasWritable is
true , then - Let hasGet be ?
HasProperty (Obj,"get" ). - If hasGet is
true , then- Let getter be ?
Get (Obj,"get" ). - If
IsCallable (getter) isfalse and getter is notundefined , throw aTypeError exception. - Set desc.[[Get]] to getter.
- Let getter be ?
- Let hasSet be ?
HasProperty (Obj,"set" ). - If hasSet is
true , then- Let setter be ?
Get (Obj,"set" ). - If
IsCallable (setter) isfalse and setter is notundefined , throw aTypeError exception. - Set desc.[[Set]] to setter.
- Let setter be ?
- If desc.[[Get]] is present or desc.[[Set]] is present, then
- If desc.[[Value]] is present or desc.[[Writable]] is present, throw a
TypeError exception.
- If desc.[[Value]] is present or desc.[[Writable]] is present, throw a
- Return desc.
6.2.5.6 CompletePropertyDescriptor ( Desc )
The abstract operation CompletePropertyDescriptor takes argument Desc (a
Assert : Desc is aProperty Descriptor .- Let like be the
Record { [[Value]]:undefined , [[Writable]]:false , [[Get]]:undefined , [[Set]]:undefined , [[Enumerable]]:false , [[Configurable]]:false }. - If
IsGenericDescriptor (Desc) istrue orIsDataDescriptor (Desc) istrue , then- If Desc does not have a [[Value]] field, set Desc.[[Value]] to like.[[Value]].
- If Desc does not have a [[Writable]] field, set Desc.[[Writable]] to like.[[Writable]].
- Else,
- If Desc does not have a [[Get]] field, set Desc.[[Get]] to like.[[Get]].
- If Desc does not have a [[Set]] field, set Desc.[[Set]] to like.[[Set]].
- If Desc does not have an [[Enumerable]] field, set Desc.[[Enumerable]] to like.[[Enumerable]].
- If Desc does not have a [[Configurable]] field, set Desc.[[Configurable]] to like.[[Configurable]].
- Return Desc.
6.2.6 The Environment Record Specification Type
The
6.2.7 The Abstract Closure Specification Type
The Abstract Closure specification type is used to refer to algorithm steps together with a collection of values. Abstract Closures are meta-values and are invoked using function application style such as closure(arg1, arg2). Like
In algorithm steps that create an Abstract Closure, values are captured with the verb "capture" followed by a list of aliases. When an Abstract Closure is created, it captures the value that is associated with each alias at that time. In steps that specify the algorithm to be performed when an Abstract Closure is called, each captured value is referred to by the alias that was used to capture the value.
If an Abstract Closure returns a
Abstract Closures are created inline as part of other algorithms, shown in the following example.
- Let addend be 41.
- Let closure be a new
Abstract Closure with parameters (x) that captures addend and performs the following steps when called:- Return x + addend.
- Let val be closure(1).
Assert : val is 42.
6.2.8 Data Blocks
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
6.2.8.1 CreateByteDataBlock ( size )
The abstract operation CreateByteDataBlock takes argument size (an
Assert : size ≥ 0.- Let db be a new
Data Block value consisting of size bytes. If it is impossible to create such aData Block , throw aRangeError exception. - Set all of the bytes of db to 0.
- Return db.
6.2.8.2 CreateSharedByteDataBlock ( size )
The abstract operation CreateSharedByteDataBlock takes argument size (a non-negative
Assert : size ≥ 0.- Let db be a new
Shared Data Block value consisting of size bytes. If it is impossible to create such aShared Data Block , throw aRangeError exception. - Let execution be the [[CandidateExecution]] field of the
surrounding agent 'sAgent Record . - Let eventList be the [[EventList]] field of the element in execution.[[EventsRecords]] whose [[AgentSignifier]] is
AgentSignifier (). - Let zero be « 0 ».
- For each index i of db, do
- Append
WriteSharedMemory { [[Order]]:Init , [[NoTear]]:true , [[Block]]: db, [[ByteIndex]]: i, [[ElementSize]]: 1, [[Payload]]: zero } to eventList.
- Append
- Return db.
6.2.8.3 CopyDataBlockBytes ( toBlock, toIndex, fromBlock, fromIndex, count )
The abstract operation CopyDataBlockBytes takes arguments toBlock, toIndex (a non-negative
Assert : fromBlock and toBlock are distinctData Block orShared Data Block values.- Let fromSize be the number of bytes in fromBlock.
Assert : fromIndex + count ≤ fromSize.- Let toSize be the number of bytes in toBlock.
Assert : toIndex + count ≤ toSize.- Repeat, while count > 0,
- If fromBlock is a
Shared Data Block , then- Let execution be the [[CandidateExecution]] field of the
surrounding agent 'sAgent Record . - Let eventList be the [[EventList]] field of the element in execution.[[EventsRecords]] whose [[AgentSignifier]] is
AgentSignifier (). - Let bytes be a
List whose sole element is a nondeterministically chosenbyte value . - NOTE: In implementations, bytes is the result of a non-atomic read instruction on the underlying hardware. The nondeterminism is a semantic prescription of the
memory model to describe observable behaviour of hardware with weak consistency. - Let readEvent be
ReadSharedMemory { [[Order]]:Unordered , [[NoTear]]:true , [[Block]]: fromBlock, [[ByteIndex]]: fromIndex, [[ElementSize]]: 1 }. - Append readEvent to eventList.
- Append
Chosen Value Record { [[Event]]: readEvent, [[ChosenValue]]: bytes } to execution.[[ChosenValues]]. - If toBlock is a
Shared Data Block , then- Append
WriteSharedMemory { [[Order]]:Unordered , [[NoTear]]:true , [[Block]]: toBlock, [[ByteIndex]]: toIndex, [[ElementSize]]: 1, [[Payload]]: bytes } to eventList.
- Append
- Else,
- Set toBlock[toIndex] to bytes[0].
- Let execution be the [[CandidateExecution]] field of the
- Else,
Assert : toBlock is not aShared Data Block .- Set toBlock[toIndex] to fromBlock[fromIndex].
- Set toIndex to toIndex + 1.
- Set fromIndex to fromIndex + 1.
- Set count to count - 1.
- If fromBlock is a
- Return
NormalCompletion (empty ).