6 ECMAScript Data Types and Values
Algorithms within this specification manipulate values each of which has an associated
Within this specification, the notation “
6.1 ECMAScript Language Types
An ECMAScript language type corresponds to values that are directly manipulated by an ECMAScript programmer using the ECMAScript language. The ECMAScript language types are Undefined, Null, Boolean, String, Symbol, Number, and Object. An ECMAScript language value is a value that is characterized by an ECMAScript language type.
6.1.1 The Undefined Type
The Undefined
6.1.2 The Null Type
The Null
6.1.3 The Boolean Type
The Boolean
6.1.4 The String Type
The String
ECMAScript operations that do not interpret String contents apply no further semantics. Operations that do interpret String values treat each element as a single UTF-16 code unit. However, ECMAScript does not restrict the value of or relationships between these code units, so operations that further interpret String contents as sequences of Unicode code points encoded in UTF-16 must account for ill-formed subsequences. Such operations apply special treatment to every code unit with a numeric value in the inclusive range 0xD800 to 0xDBFF (defined by the Unicode Standard as a leading surrogate, or more formally as a high-surrogate code unit) and every code unit with a numeric value in the inclusive range 0xDC00 to 0xDFFF (defined as a trailing surrogate, or more formally as a low-surrogate code unit) using the following rules:
-
A code unit that is not a
leading surrogate and not atrailing surrogate is interpreted as a code point with the same value. -
A sequence of two code units, where the first code unit c1 is a
leading surrogate and the second code unit c2 atrailing surrogate , is a surrogate pair and is interpreted as a code point with the value (c1 - 0xD800) × 0x400 + (c2 - 0xDC00) + 0x10000. (See10.1.2 ) -
A code unit that is a
leading surrogate ortrailing surrogate , but is not part of asurrogate pair , is interpreted as a code point with the same value.
The function String.prototype.normalize (see String.prototype.localeCompare (see
The rationale behind this design was to keep the implementation of Strings as simple and high-performing as possible. If ECMAScript source text is in Normalized Form C, string literals are guaranteed to also be normalized, as long as they do not contain any Unicode escape sequences.
In this specification, the phrase "the string-concatenation of A, B, ..." (where each argument is a String value, a code unit, or a sequence of code units) denotes the String value whose sequence of code units is the concatenation of the code units (in order) of each of the arguments (in order).
6.1.5 The Symbol Type
The Symbol
Each possible Symbol value is unique and immutable.
Each Symbol value immutably holds an associated value called [[Description]] that is either
6.1.5.1 Well-Known Symbols
Well-known symbols are built-in Symbol values that are explicitly referenced by algorithms of this specification. They are typically used as the keys of properties whose values serve as extension points of a specification algorithm. Unless otherwise specified, well-known symbols values are shared by all realms (
Within this specification a well-known symbol is referred to by using a notation of the form @@name, where “name” is one of the values listed in
| Specification Name | [[Description]] | Value and Purpose |
|---|---|---|
| @@asyncIterator |
"Symbol.asyncIterator"
|
A method that returns the default AsyncIterator for an object. Called by the semantics of the for-await-of statement.
|
| @@hasInstance |
"Symbol.hasInstance"
|
A method that determines if a instanceof operator.
|
| @@isConcatSpreadable |
"Symbol.isConcatSpreadable"
|
A Boolean valued property that if true indicates that an object should be flattened to its array elements by Array.prototype.concat |
| @@iterator |
"Symbol.iterator"
|
A method that returns the default Iterator for an object. Called by the semantics of the for-of statement. |
| @@match |
"Symbol.match"
|
A regular expression method that matches the regular expression against a string. Called by the String.prototype.match |
| @@replace |
"Symbol.replace"
|
A regular expression method that replaces matched substrings of a string. Called by the String.prototype.replace |
| @@search |
"Symbol.search"
|
A regular expression method that returns the index within a string that matches the regular expression. Called by the String.prototype.search |
| @@species |
"Symbol.species"
|
A function valued property that is the |
| @@split |
"Symbol.split"
|
A regular expression method that splits a string at the indices that match the regular expression. Called by the String.prototype.split |
| @@toPrimitive |
"Symbol.toPrimitive"
|
A method that converts an object to a corresponding primitive value. Called by the |
| @@toStringTag |
"Symbol.toStringTag"
|
A String valued property that is used in the creation of the default string description of an object. Accessed by the built-in method Object.prototype.toString |
| @@unscopables |
"Symbol.unscopables"
|
An object valued property whose own and inherited property names are property names that are excluded from the with environment bindings of the associated object.
|
6.1.6 The Number Type
The Number NaN.) In some implementations, external code might be able to detect a difference between various Not-a-Number values, but such behaviour is implementation-dependent; to ECMAScript code, all
There are two other special values, called +Infinity (or simply Infinity) and -Infinity.)
The other 18437736874454810624 (that is,
Note that there is both a +0 (or simply 0) and -0.)
The 18437736874454810622 (that is,
18428729675200069632 (that is,
where s is +1 or -1, m is a positive integer less than 253 but not less than 252, and e is an integer ranging from -1074 to 971, inclusive.
The remaining 9007199254740990 (that is,
where s is +1 or -1, m is a positive integer less than 252, and e is -1074.
Note that all the positive and negative integers whose magnitude is no greater than 253 are representable in the Number
A finite number has an odd significand if it is nonzero and the integer m used to express it (in one of the two forms shown above) is odd. Otherwise, it has an even significand.
In this specification, the phrase “the Number value for x” where x represents an exact real mathematical quantity (which might even be an irrational number such as π) means a Number value chosen in the following manner. Consider the set of all finite values of the Number
Some ECMAScript operators deal only with integers in specific ranges such as
6.1.7 The Object Type
An Object is logically a collection of properties. Each property is either a data property, or an accessor property:
-
A data property associates a key value with an
ECMAScript language value and a set of Boolean attributes. -
An accessor property associates a key value with one or two accessor functions, and a set of Boolean attributes. The accessor functions are used to store or retrieve an
ECMAScript language value that is associated with the property.
Properties are identified using key values. A property key value is either an ECMAScript String value or a Symbol value. All String and Symbol values, including the empty string, are valid as property keys. A property name is a property key that is a String value.
An integer index is a String-valued property key that is a canonical numeric String (see
Property keys are used to access properties and their values. There are two kinds of access for properties: get and set, corresponding to value retrieval and assignment, respectively. The properties accessible via get and set access includes both own properties that are a direct part of an object and inherited properties which are provided by another associated object via a property inheritance relationship. Inherited properties may be either own or inherited properties of the associated object. Each own property of an object must each have a key value that is distinct from the key values of the other own properties of that object.
All objects are logically collections of properties, but there are multiple forms of objects that differ in their semantics for accessing and manipulating their properties. Ordinary objects are the most common form of objects and have the default object semantics. An exotic object is any form of object whose property semantics differ in any way from the default semantics.
6.1.7.1 Property Attributes
Attributes are used in this specification to define and explain the state of Object properties. A
| Attribute Name | Value Domain | Description |
|---|---|---|
| [[Value]] |
Any |
The value retrieved by a get access of the property. |
| [[Writable]] | Boolean |
If |
| [[Enumerable]] | Boolean |
If |
| [[Configurable]] | Boolean |
If |
An
| Attribute Name | Value Domain | Description |
|---|---|---|
| [[Get]] | Object | Undefined |
If the value is an Object it must be a |
| [[Set]] | Object | Undefined |
If the value is an Object it must be a |
| [[Enumerable]] | Boolean |
If |
| [[Configurable]] | Boolean |
If |
If the initial values of a property's attributes are not explicitly specified by this specification, the default value defined in
| Attribute Name | Default Value |
|---|---|
| [[Value]] |
|
| [[Get]] |
|
| [[Set]] |
|
| [[Writable]] |
|
| [[Enumerable]] |
|
| [[Configurable]] |
|
6.1.7.2 Object Internal Methods and Internal Slots
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
Internal methods and internal slots are identified within this specification using names enclosed in double square brackets [[ ]].
The “Signature” column of
| 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 |
|
| [[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 or super operators. The first argument to the internal method is a list containing the arguments of the operator. 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
6.1.7.3 Invariants of the Essential Internal Methods
The Internal Methods of Objects of an ECMAScript engine must conform to the list of invariants specified below. Ordinary ECMAScript Objects as well as all standard exotic objects in this specification maintain these invariants. ECMAScript Proxy objects maintain these invariants by means of runtime checks on the result of traps invoked on the [[ProxyHandler]] object.
Any implementation provided exotic objects must also maintain these invariants for those objects. Violation of these invariants may cause ECMAScript code to have unpredictable behaviour and create security issues. However, violation of these invariants must never compromise the memory safety of an implementation.
An implementation must not allow these invariants to be circumvented in any manner such as by providing alternative interfaces that implement the functionality of the essential internal methods without enforcing their invariants.
Definitions:
- The target of an internal method is the object upon which the internal method is called.
- A target is non-extensible if it has been observed to return false from its [[IsExtensible]] internal method, or true from its [[PreventExtensions]] internal method.
- A non-existent property is a property that does not exist as an own property on a non-extensible target.
-
All references to
SameValue are according to the definition of theSameValue algorithm.
[[GetPrototypeOf]] ( )
-
The
Type of the return value must be either Object or Null. -
If target is non-extensible, and [[GetPrototypeOf]] returns a value v, then any future calls to [[GetPrototypeOf]] should return the
SameValue as v.
An object's prototype chain should have finite length (that is, starting from any object, recursively applying the [[GetPrototypeOf]] internal method to its result should eventually lead to the value null). However, this requirement is not enforceable as an object level invariant if the prototype chain includes any exotic objects that do not use the ordinary object definition of [[GetPrototypeOf]]. Such a circular prototype chain may result in infinite loops when accessing object properties.
[[SetPrototypeOf]] (V)
-
The
Type of the return value must be Boolean. -
If target is non-extensible, [[SetPrototypeOf]] must return false, unless V is the
SameValue as the target's observed [[GetPrototypeOf]] value.
[[IsExtensible]] ( )
-
The
Type of the return value must be Boolean. - If [[IsExtensible]] returns false, all future calls to [[IsExtensible]] on the target must return false.
[[PreventExtensions]] ( )
-
The
Type of the return value must be Boolean. - If [[PreventExtensions]] returns true, all future calls to [[IsExtensible]] on the target must return false and the target is now considered non-extensible.
[[GetOwnProperty]] (P)
-
The
Type of the return value must be eitherProperty Descriptor or Undefined. -
If the
Type of the return value isProperty Descriptor , the return value must be a complete property descriptor (see6.2.5.6 ). -
If a property P is described as a
data property with Desc.[[Value]] equal to v and Desc.[[Writable]] and Desc.[[Configurable]] are both false, then theSameValue must be returned for the Desc.[[Value]] attribute of the property on all future calls to [[GetOwnProperty]] ( P ). - If P's attributes other than [[Writable]] may change over time or if the property might disappear, then P's [[Configurable]] attribute must be true.
- If the [[Writable]] attribute may change from false to true, then the [[Configurable]] attribute must be true.
- If the target is non-extensible and P is non-existent, then all future calls to [[GetOwnProperty]] (P) on the target must describe P as non-existent (i.e. [[GetOwnProperty]] (P) must return undefined).
As a consequence of the third invariant, if a property is described as a
[[DefineOwnProperty]] (P, Desc)
-
The
Type of the return value must be Boolean. -
[[DefineOwnProperty]] must return false if P has previously been observed as a non-configurable own property of the target, unless either:
-
P is a non-configurable writable own
data property . A non-configurable writabledata property can be changed into a non-configurable non-writabledata property . -
All attributes in Desc are the
SameValue as P's attributes.
-
P is a non-configurable writable own
- [[DefineOwnProperty]] (P, Desc) must return false if target is non-extensible and P is a non-existent own property. That is, a non-extensible target object cannot be extended with new properties.
[[HasProperty]] ( P )
-
The
Type of the return value must be Boolean. - If P was previously observed as a non-configurable data or accessor own property of the target, [[HasProperty]] must return true.
[[Get]] (P, Receiver)
-
If P was previously observed as a non-configurable, non-writable own
data property of the target with value v, then [[Get]] must return theSameValue . -
If P was previously observed as a non-configurable own
accessor property of the target whose [[Get]] attribute is undefined, the [[Get]] operation must return undefined.
[[Set]] ( P, V, Receiver)
-
The
Type of the return value must be Boolean. -
If P was previously observed as a non-configurable, non-writable own
data property of the target, then [[Set]] must return false unless V is theSameValue as P's [[Value]] attribute. -
If P was previously observed as a non-configurable own
accessor property of the target whose [[Set]] attribute is undefined, the [[Set]] operation must return false.
[[Delete]] ( P )
-
The
Type of the return value must be Boolean. -
If P was previously observed to be a non-configurable own data or
accessor property of the target, [[Delete]] must return false.
[[OwnPropertyKeys]] ( )
-
The return value must be a
List . - The returned list must not contain any duplicate entries.
-
The
Type of each element of the returnedList is either String or Symbol. -
The returned
List must contain at least the keys of all non-configurable own properties that have previously been observed. -
If the object is non-extensible, the returned
List must contain only the keys of all own properties of the object that are observable using [[GetOwnProperty]].
[[Construct]] ( )
-
The
Type of the return value must be Object.
6.1.7.4 Well-Known Intrinsic Objects
Well-known intrinsics are built-in objects that are explicitly referenced by the algorithms of this specification and which usually have
Within this specification a reference such as
| Intrinsic Name | Global Name | ECMAScript Language Association |
|---|---|---|
|
|
Array
|
The Array |
|
|
ArrayBuffer
|
The ArrayBuffer |
|
|
ArrayBuffer.prototype
|
The initial value of the prototype |
|
|
The prototype of Array iterator objects ( |
|
|
|
Array.prototype
|
The initial value of the prototype |
| %ArrayProto_entries% |
Array.prototype.entries
|
The initial value of the entries |
| %ArrayProto_forEach% |
Array.prototype.forEach
|
The initial value of the forEach |
| %ArrayProto_keys% |
Array.prototype.keys
|
The initial value of the keys |
| %ArrayProto_values% |
Array.prototype.values
|
The initial value of the values |
|
|
The prototype of async-from-sync iterator objects ( |
|
|
|
The |
|
|
|
The initial value of the prototype |
|
|
|
The initial value of the prototype property of |
|
|
|
The |
|
|
|
The initial value of the prototype property of |
|
|
|
An object that all standard built-in async iterator objects indirectly inherit from | |
|
|
Atomics
|
The Atomics object ( |
|
|
Boolean
|
The Boolean |
|
|
Boolean.prototype
|
The initial value of the prototype |
|
|
DataView
|
The DataView |
|
|
DataView.prototype
|
The initial value of the prototype |
|
|
Date
|
The Date |
|
|
Date.prototype
|
The initial value of the prototype |
|
|
decodeURI
|
The decodeURI function ( |
|
|
decodeURIComponent
|
The decodeURIComponent function ( |
|
|
encodeURI
|
The encodeURI function ( |
|
|
encodeURIComponent
|
The encodeURIComponent function ( |
|
|
Error
|
The Error |
|
|
Error.prototype
|
The initial value of the prototype |
|
|
eval
|
The eval function ( |
|
|
EvalError
|
The EvalError |
|
|
EvalError.prototype
|
The initial value of the prototype |
|
|
Float32Array
|
The Float32Array |
|
|
Float32Array.prototype
|
The initial value of the prototype |
|
|
Float64Array
|
The Float64Array |
|
|
Float64Array.prototype
|
The initial value of the prototype |
|
|
Function
|
The Function |
|
|
Function.prototype
|
The initial value of the prototype |
|
|
The initial value of the prototype |
|
|
|
The |
|
|
|
The initial value of the prototype |
|
|
|
Int8Array
|
The Int8Array |
|
|
Int8Array.prototype
|
The initial value of the prototype |
|
|
Int16Array
|
The Int16Array |
|
|
Int16Array.prototype
|
The initial value of the prototype |
|
|
Int32Array
|
The Int32Array |
|
|
Int32Array.prototype
|
The initial value of the prototype |
|
|
isFinite
|
The isFinite function ( |
|
|
isNaN
|
The isNaN function ( |
|
|
An object that all standard built-in iterator objects indirectly inherit from | |
|
|
JSON
|
The JSON object ( |
|
|
JSON.parse
|
The initial value of the parse |
|
|
Map
|
The Map |
|
|
The prototype of Map iterator objects ( |
|
|
|
Map.prototype
|
The initial value of the prototype |
|
|
Math
|
The Math object ( |
|
|
Number
|
The Number |
|
|
Number.prototype
|
The initial value of the prototype |
|
|
Object
|
The Object |
|
|
Object.prototype
|
The initial value of the prototype |
| %ObjProto_toString% |
Object.prototype.toString
|
The initial value of the toString |
| %ObjProto_valueOf% |
Object.prototype.valueOf
|
The initial value of the valueOf |
|
|
parseFloat
|
The parseFloat function ( |
|
|
parseInt
|
The parseInt function ( |
|
|
Promise
|
The Promise |
|
|
Promise.prototype
|
The initial value of the prototype |
| %PromiseProto_then% |
Promise.prototype.then
|
The initial value of the then |
| %Promise_all% |
Promise.all
|
The initial value of the all |
| %Promise_reject% |
Promise.reject
|
The initial value of the reject |
| %Promise_resolve% |
Promise.resolve
|
The initial value of the resolve |
|
|
Proxy
|
The Proxy |
|
|
RangeError
|
The RangeError |
|
|
RangeError.prototype
|
The initial value of the prototype |
|
|
ReferenceError
|
The ReferenceError |
|
|
ReferenceError.prototype
|
The initial value of the prototype |
|
|
Reflect
|
The Reflect object ( |
|
|
RegExp
|
The RegExp |
|
|
RegExp.prototype
|
The initial value of the prototype |
|
|
Set
|
The Set |
|
|
The prototype of |
|
|
|
Set.prototype
|
The initial value of the prototype |
|
|
SharedArrayBuffer
|
The SharedArrayBuffer |
|
|
SharedArrayBuffer.prototype
|
The initial value of the prototype |
|
|
String
|
The String |
|
|
The prototype of String iterator objects ( |
|
|
|
String.prototype
|
The initial value of the prototype |
|
|
Symbol
|
The Symbol |
|
|
Symbol.prototype
|
The initial value of the prototype |
|
|
SyntaxError
|
The SyntaxError |
|
|
SyntaxError.prototype
|
The initial value of the prototype |
|
|
A |
|
|
|
The super class of all typed Array constructors ( |
|
|
|
The initial value of the prototype |
|
|
|
TypeError
|
The TypeError |
|
|
TypeError.prototype
|
The initial value of the prototype |
|
|
Uint8Array
|
The Uint8Array |
|
|
Uint8Array.prototype
|
The initial value of the prototype |
|
|
Uint8ClampedArray
|
The Uint8ClampedArray |
|
|
Uint8ClampedArray.prototype
|
The initial value of the prototype |
|
|
Uint16Array
|
The Uint16Array |
|
|
Uint16Array.prototype
|
The initial value of the prototype |
|
|
Uint32Array
|
The Uint32Array |
|
|
Uint32Array.prototype
|
The initial value of the prototype |
|
|
URIError
|
The URIError |
|
|
URIError.prototype
|
The initial value of the prototype |
|
|
WeakMap
|
The WeakMap |
|
|
WeakMap.prototype
|
The initial value of the prototype |
|
|
WeakSet
|
The WeakSet |
|
|
WeakSet.prototype
|
The initial value of the prototype |
6.2 ECMAScript Specification Types
A specification
6.2.1 The List and Record Specification Types
The List new expressions, in function calls, and in other algorithms where a simple ordered list of values is needed. Values of 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
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
The Relation
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, in order, irreflexivity and transitivity.
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, in order, totality, irreflexivity, and transitivity.
6.2.3 The Completion Record Specification Type
The Completion break, continue, return and throw) that perform nonlocal transfers of control.
Values of the Completion
| Field Name | Value | Meaning |
|---|---|---|
| [[Type]] |
One of |
The |
| [[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(promise).
mean the same thing as:
- Let asyncContext be the
running execution context . - Let promiseCapability be !
NewPromiseCapability (%Promise% ). - Perform !
Call (promiseCapability.[[Resolve]],undefined , « promise »). - Let stepsFulfilled be the algorithm steps defined in
Await Fulfilled Functions . - Let onFulfilled be
CreateBuiltinFunction (stepsFulfilled, « [[AsyncContext]] »). Set onFulfilled.[[AsyncContext]] to asyncContext.- Let stepsRejected be the algorithm steps defined in
Await Rejected Functions . - Let onRejected be
CreateBuiltinFunction (stepsRejected, « [[AsyncContext]] »). Set onRejected.[[AsyncContext]] to asyncContext.- Let throwawayCapability be !
NewPromiseCapability (%Promise% ). Set throwawayCapability.[[Promise]].[[PromiseIsHandled]] totrue .- Perform !
PerformPromiseThen (promiseCapability.[[Promise]], onFulfilled, onRejected, throwawayCapability). - 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 aCompletion completion, the following steps of the algorithm that invoked Await will be performed, with completion available.
where all variables 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 value be ? Await(promise).
means the same thing as:
- Let value be Await(promise).
ReturnIfAbrupt (value).
6.2.3.1.1 Await Fulfilled Functions
An
When an
- 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 length property of an
6.2.3.1.2 Await Rejected Functions
An
When an
- 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 length property of an
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 with arguments completionRecord and value performs the following steps:
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 Specification Type
The Reference delete, typeof, the assignment operators, the super keyword and other language features. For example, the left-hand operand of an assignment is expected to produce a reference.
A Reference is a resolved name or property binding. A Reference consists of three components, the base value component, the referenced name component, and the Boolean-valued strict reference flag. The base value component is either
A Super Reference is a Reference that is used to represent a name binding that was expressed using the super keyword. A
The following
6.2.4.1 GetBase ( V )
6.2.4.2 GetReferencedName ( V )
6.2.4.3 IsStrictReference ( V )
6.2.4.4 HasPrimitiveBase ( V )
6.2.4.5 IsPropertyReference ( V )
Assert :Type (V) isReference .- If either the base value component of V is an Object or
HasPrimitiveBase (V) istrue , returntrue ; otherwise returnfalse .
6.2.4.6 IsUnresolvableReference ( V )
6.2.4.7 IsSuperReference ( V )
6.2.4.8 GetValue ( V )
ReturnIfAbrupt (V).- If
Type (V) is notReference , return V. - Let base be
GetBase (V). - If
IsUnresolvableReference (V) istrue , throw aReferenceError exception. - If
IsPropertyReference (V) istrue , then- If
HasPrimitiveBase (V) istrue , then - Return ? base.[[Get]](
GetReferencedName (V),GetThisValue (V)).
- If
- Else base must be an
Environment Record ,- Return ? base.GetBindingValue(
GetReferencedName (V),IsStrictReference (V)) (see8.1.1 ).
- Return ? base.GetBindingValue(
The object that may be created in step 5.a.ii is not accessible outside of the above abstract operation and the ordinary object [[Get]] internal method. An implementation might choose to avoid the actual creation of the object.
6.2.4.9 PutValue ( V, W )
ReturnIfAbrupt (V).ReturnIfAbrupt (W).- If
Type (V) is notReference , throw aReferenceError exception. - Let base be
GetBase (V). - If
IsUnresolvableReference (V) istrue , then- If
IsStrictReference (V) istrue , then- Throw a
ReferenceError exception.
- Throw a
- Let globalObj be
GetGlobalObject (). - Return ?
Set (globalObj,GetReferencedName (V), W,false ).
- If
- Else if
IsPropertyReference (V) istrue , then- If
HasPrimitiveBase (V) istrue , then - Let succeeded be ? base.[[Set]](
GetReferencedName (V), W,GetThisValue (V)). - If succeeded is
false andIsStrictReference (V) istrue , throw aTypeError exception. - Return.
- If
- Else base must be an
Environment Record ,- Return ? base.SetMutableBinding(
GetReferencedName (V), W,IsStrictReference (V)) (see8.1.1 ).
- Return ? base.SetMutableBinding(
The object that may be created in step 6.a.ii is not accessible outside of the above algorithm and the ordinary object [[Set]] internal method. An implementation might choose to avoid the actual creation of that object.
6.2.4.10 GetThisValue ( V )
Assert :IsPropertyReference (V) istrue .- If
IsSuperReference (V) istrue , then- Return the value of the thisValue component of the reference V.
- Return
GetBase (V).
6.2.4.11 InitializeReferencedBinding ( V, W )
ReturnIfAbrupt (V).ReturnIfAbrupt (W).Assert :Type (V) isReference .Assert :IsUnresolvableReference (V) isfalse .- Let base be
GetBase (V). Assert : base is anEnvironment Record .- Return base.InitializeBinding(
GetReferencedName (V), W).
6.2.5 The Property Descriptor Specification Type
The Property Descriptor
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 )
When the abstract operation IsAccessorDescriptor is called with
- If Desc is
undefined , returnfalse . - If both Desc.[[Get]] and Desc.[[Set]] are absent, return
false . - Return
true .
6.2.5.2 IsDataDescriptor ( Desc )
When the abstract operation IsDataDescriptor is called with
- If Desc is
undefined , returnfalse . - If both Desc.[[Value]] and Desc.[[Writable]] are absent, return
false . - Return
true .
6.2.5.3 IsGenericDescriptor ( Desc )
When the abstract operation IsGenericDescriptor is called with
- If Desc is
undefined , returnfalse . - If
IsAccessorDescriptor (Desc) andIsDataDescriptor (Desc) are bothfalse , returntrue . - Return
false .
6.2.5.4 FromPropertyDescriptor ( Desc )
When the abstract operation FromPropertyDescriptor is called with
- If Desc is
undefined , returnundefined . - Let obj be
ObjectCreate (%ObjectPrototype% ). Assert : obj is an extensible ordinary object with no own properties.- If Desc has a [[Value]] field, then
- Perform
CreateDataProperty (obj,"value", Desc.[[Value]]).
- Perform
- If Desc has a [[Writable]] field, then
- Perform
CreateDataProperty (obj,"writable", Desc.[[Writable]]).
- Perform
- If Desc has a [[Get]] field, then
- Perform
CreateDataProperty (obj,"get", Desc.[[Get]]).
- Perform
- If Desc has a [[Set]] field, then
- Perform
CreateDataProperty (obj,"set", Desc.[[Set]]).
- Perform
- If Desc has an [[Enumerable]] field, then
- Perform
CreateDataProperty (obj,"enumerable", Desc.[[Enumerable]]).
- Perform
- If Desc has a [[Configurable]] field, then
- Perform
CreateDataProperty (obj,"configurable", Desc.[[Configurable]]).
- Perform
Assert : All of the aboveCreateDataProperty operations returntrue .- Return obj.
6.2.5.5 ToPropertyDescriptor ( Obj )
When the abstract operation ToPropertyDescriptor is called with object Obj, the following steps are taken:
- 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 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 )
When the abstract operation CompletePropertyDescriptor is called with
Assert : Desc is aProperty Descriptor .- Let like be
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 Lexical Environment and Environment Record Specification Types
The
6.2.7 Data Blocks
The Data Block specification
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 integer-indexed sequence of bytes. For example, if db is a 5 byte Data Block value then db[2] can be used to access its 3rd byte.
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.7.1 CreateByteDataBlock ( size )
When the abstract operation CreateByteDataBlock is called with integer argument size, the following steps are taken:
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.7.2 CreateSharedByteDataBlock ( size )
When the abstract operation CreateSharedByteDataBlock is called with integer argument size, the following steps are taken:
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.[[EventLists]] 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.7.3 CopyDataBlockBytes ( toBlock, toIndex, fromBlock, fromIndex, count )
When the abstract operation CopyDataBlockBytes is called, the following steps are taken:
Assert : fromBlock and toBlock are distinctData Block orShared Data Block values.Assert : fromIndex, toIndex, and count are integer values ≥ 0.- 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.[[EventLists]] whose [[AgentSignifier]] is
AgentSignifier (). - Let bytes be a
List of length 1 that contains a nondeterministically chosen byte 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].
- Increment toIndex and fromIndex each by 1.
- Decrement count by 1.
- If fromBlock is a
- Return
NormalCompletion (empty ).