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
Where ECMAScript operations interpret String values, each element is interpreted as a single UTF-16 code unit. However, ECMAScript does not place any restrictions or requirements on the sequence of code units in a String value, so they may be ill-formed when interpreted as UTF-16 code unit sequences. Operations that do not interpret String contents treat them as sequences of undifferentiated 16-bit unsigned integers. 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.
Some operations interpret String contents as UTF-16 encoded Unicode code points. In that case the interpretation is:
- A code unit in the range 0 to 0xD7FF or in the range 0xE000 to 0xFFFF is interpreted as a code point with the same value.
-
A sequence of two code units, where the first code unit c1 is in the range 0xD800 to 0xDBFF and the second code unit c2 is in the range 0xDC00 to 0xDFFF, is a surrogate pair and is interpreted as a code point with the value (c1 - 0xD800) × 0x400 + (c2 - 0xDC00) + 0x10000. (See
10.1.2 ) - A code unit that is in the range 0xD800 to 0xDFFF, but is not part of a surrogate pair, is interpreted as a code point with the same value.
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 |
|---|---|---|
| @@hasInstance |
"Symbol.hasInstance"
|
A method that determines if a constructor object recognizes an object as one of the constructor's instances. Called by the semantics of the 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 constructor function that is used to create derived objects. |
| @@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 nonzero 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 data property associates a key value with the attributes listed in
| 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 accessor property associates a key value with the attributes listed in
| Attribute Name | Value Domain | Description |
|---|---|---|
| [[Get]] | Object | Undefined |
If the value is an Object it must be a function object. The function's [[Call]] internal method ( |
| [[Set]] | Object | Undefined |
If the value is an Object it must be a function object. The function's [[Call]] internal method ( |
| [[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 function object is not necessarily a constructor and such non-constructor function objects do not have a [[Construct]] internal method.
|
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 the
SameValue 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 data property and it may return different values over time, then either or both of the Desc.[[Writable]] and Desc.[[Configurable]] attributes must be true even if no mechanism to change the value is exposed via the other internal methods.
[[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 writable data property can be changed into a non-configurable non-writable data property.
-
All attributes in Desc are the
SameValue as P's attributes.
- [[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 the
SameValue . - 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 the
SameValue 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
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 constructor ( |
|
|
ArrayBuffer
|
The ArrayBuffer constructor ( |
|
|
ArrayBuffer.prototype
|
The initial value of the prototype data property of |
|
|
The prototype of Array iterator objects ( |
|
|
|
Array.prototype
|
The initial value of the prototype data property of |
| %ArrayProto_values% |
Array.prototype.values
|
The initial value of the values data property of |
|
|
The constructor of async function objects ( |
|
|
|
The initial value of the prototype data property of |
|
|
|
Atomics
|
The Atomics object ( |
|
|
Boolean
|
The Boolean constructor ( |
|
|
Boolean.prototype
|
The initial value of the prototype data property of |
|
|
DataView
|
The DataView constructor ( |
|
|
DataView.prototype
|
The initial value of the prototype data property of |
|
|
Date
|
The Date constructor ( |
|
|
Date.prototype
|
The initial value of the prototype data property of |
|
|
decodeURI
|
The decodeURI function ( |
|
|
decodeURIComponent
|
The decodeURIComponent function ( |
|
|
encodeURI
|
The encodeURI function ( |
|
|
encodeURIComponent
|
The encodeURIComponent function ( |
|
|
Error
|
The Error constructor ( |
|
|
Error.prototype
|
The initial value of the prototype data property of |
|
|
eval
|
The eval function ( |
|
|
EvalError
|
The EvalError constructor ( |
|
|
EvalError.prototype
|
The initial value of the prototype property of |
|
|
Float32Array
|
The Float32Array constructor ( |
|
|
Float32Array.prototype
|
The initial value of the prototype data property of |
|
|
Float64Array
|
The Float64Array constructor ( |
|
|
Float64Array.prototype
|
The initial value of the prototype data property of |
|
|
Function
|
The Function constructor ( |
|
|
Function.prototype
|
The initial value of the prototype data property of |
|
|
The initial value of the prototype property of |
|
|
|
The constructor of generator objects ( |
|
|
|
The initial value of the prototype property of |
|
|
|
Int8Array
|
The Int8Array constructor ( |
|
|
Int8Array.prototype
|
The initial value of the prototype data property of |
|
|
Int16Array
|
The Int16Array constructor ( |
|
|
Int16Array.prototype
|
The initial value of the prototype data property of |
|
|
Int32Array
|
The Int32Array constructor ( |
|
|
Int32Array.prototype
|
The initial value of the prototype data property of |
|
|
isFinite
|
The isFinite function ( |
|
|
isNaN
|
The isNaN function ( |
|
|
An object that all standard built-in iterator objects indirectly inherit from | |
|
|
JSON
|
The JSON object ( |
|
|
Map
|
The Map constructor ( |
|
|
The prototype of Map iterator objects ( |
|
|
|
Map.prototype
|
The initial value of the prototype data property of |
|
|
Math
|
The Math object ( |
|
|
Number
|
The Number constructor ( |
|
|
Number.prototype
|
The initial value of the prototype property of |
|
|
Object
|
The Object constructor ( |
|
|
Object.prototype
|
The initial value of the prototype data property of |
| %ObjProto_toString% |
Object.prototype.toString
|
The initial value of the toString data property of |
| %ObjProto_valueOf% |
Object.prototype.valueOf
|
The initial value of the valueOf data property of |
|
|
parseFloat
|
The parseFloat function ( |
|
|
parseInt
|
The parseInt function ( |
|
|
Promise
|
The Promise constructor ( |
|
|
Promise.prototype
|
The initial value of the prototype data property of |
|
|
Proxy
|
The Proxy constructor ( |
|
|
RangeError
|
The RangeError constructor ( |
|
|
RangeError.prototype
|
The initial value of the prototype property of |
|
|
ReferenceError
|
The ReferenceError constructor ( |
|
|
ReferenceError.prototype
|
The initial value of the prototype property of |
|
|
Reflect
|
The Reflect object ( |
|
|
RegExp
|
The RegExp constructor ( |
|
|
RegExp.prototype
|
The initial value of the prototype data property of |
|
|
Set
|
The Set constructor ( |
|
|
The prototype of |
|
|
|
Set.prototype
|
The initial value of the prototype data property of |
|
|
SharedArrayBuffer
|
The SharedArrayBuffer constructor ( |
|
|
SharedArrayBuffer.prototype
|
The initial value of the prototype data property of |
|
|
String
|
The String constructor ( |
|
|
The prototype of String iterator objects ( |
|
|
|
String.prototype
|
The initial value of the prototype data property of |
|
|
Symbol
|
The Symbol constructor ( |
|
|
Symbol.prototype
|
The initial value of the prototype data property of |
|
|
SyntaxError
|
The SyntaxError constructor ( |
|
|
SyntaxError.prototype
|
The initial value of the prototype property of |
|
|
A function object that unconditionally throws a new instance of |
|
|
|
The super class of all typed Array constructors ( |
|
|
|
The initial value of the prototype property of |
|
|
|
TypeError
|
The TypeError constructor ( |
|
|
TypeError.prototype
|
The initial value of the prototype property of |
|
|
Uint8Array
|
The Uint8Array constructor ( |
|
|
Uint8Array.prototype
|
The initial value of the prototype data property of |
|
|
Uint8ClampedArray
|
The Uint8ClampedArray constructor ( |
|
|
Uint8ClampedArray.prototype
|
The initial value of the prototype data property of |
|
|
Uint16Array
|
The Uint16Array constructor ( |
|
|
Uint16Array.prototype
|
The initial value of the prototype data property of |
|
|
Uint32Array
|
The Uint32Array constructor ( |
|
|
Uint32Array.prototype
|
The initial value of the prototype data property of |
|
|
URIError
|
The URIError constructor ( |
|
|
URIError.prototype
|
The initial value of the prototype property of |
|
|
WeakMap
|
The WeakMap constructor ( |
|
|
WeakMap.prototype
|
The initial value of the prototype data property of |
|
|
WeakSet
|
The WeakSet constructor ( |
|
|
WeakSet.prototype
|
The initial value of the prototype data property of |
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 conditions.
- 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 conditions.
- For all a, b, and c in R's domain:
- 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 | 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 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.2 Implicit Completion Values
The algorithms of this specification often implicitly return
- Return
"Infinity".
means the same thing as:
- Return
NormalCompletion ("Infinity").
However, if the value expression of a “return” statement is a
The abstract operation
Assert : completionRecord is aCompletion Record .- Return completionRecord as the
Completion Record of this abstract operation.
A “return” statement without a value in an algorithm step means the same thing as:
- Return
NormalCompletion (undefined ).
Any reference to a
6.2.3.3 Throw an Exception
Algorithms steps that say to throw an exception, such as
- Throw a
TypeError exception.
mean the same things as:
- Return
Completion {[[Type]]:throw , [[Value]]: a newly createdTypeError object, [[Target]]:empty }.
6.2.3.4 ReturnIfAbrupt
Algorithms steps that say or are otherwise equivalent to:
- ReturnIfAbrupt(argument).
mean the same thing as:
- If argument is an
abrupt completion , return argument. - Else if argument is a
Completion Record , let argument be argument.[[Value]].
Algorithms steps that say or are otherwise equivalent to:
- ReturnIfAbrupt(AbstractOperation()).
mean the same thing as:
- Let hygienicTemp be AbstractOperation().
- If hygienicTemp is an
abrupt completion , return hygienicTemp. - Else if hygienicTemp is a
Completion Record , let hygienicTemp be hygienicTemp.[[Value]].
Where hygienicTemp is ephemeral and visible only in the steps pertaining to ReturnIfAbrupt.
Algorithms steps that say or are otherwise equivalent to:
- Let result be AbstractOperation(ReturnIfAbrupt(argument)).
mean the same thing as:
- If argument is an
abrupt completion , return argument. - If argument is a
Completion Record , let argument be argument.[[Value]]. - Let result be AbstractOperation(argument).
6.2.3.5 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 represents a name binding that was expressed using the super keyword. A
The following abstract operations are used in this specification to access the components of references:
- GetBase(V). Returns the base value component of the reference V.
- GetReferencedName(V). Returns the referenced name component of the reference V.
- IsStrictReference(V). Returns the strict reference flag of the reference V.
-
HasPrimitiveBase(V). Returns
true ifType (V's base value component) is Boolean, String, Symbol, or Number; otherwise returnsfalse . -
IsPropertyReference(V). Returns
true if either the base value component of the reference V is an object orHasPrimitiveBase (V) istrue ; otherwise returnsfalse . -
IsUnresolvableReference(V). Returns
true if the base value component of the reference V isundefined ; otherwise returnsfalse . -
IsSuperReference(V). Returns
true if the reference V has a thisValue component; otherwise returnsfalse .
The following abstract operations are used in this specification to operate on references:
6.2.4.1 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.2 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.3 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.4 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 abstract operations are used in this specification to operate upon Property Descriptor values:
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 abstract operations are used in this specification to operate upon Data Block values:
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
WriteSharedMemory { [[Order]]:"Unordered", [[NoTear]]:true , [[Block]]: toBlock, [[ByteIndex]]: toIndex, [[ElementSize]]: 1, [[Payload]]: bytes } to eventList. - Append
Chosen Value Record { [[Event]]: readEvent, [[ChosenValue]]: bytes } to execution.[[ChosenValues]].
- Let execution be the [[CandidateExecution]] field of the
- Otherwise, set toBlock[toIndex] to fromBlock[fromIndex].
- Increment toIndex and fromIndex each by 1.
- Decrement count by 1.
- If fromBlock is a
- Return
NormalCompletion (empty ).