These operations are not a part of the ECMAScript language; they are defined here solely to aid the specification of the semantics of the ECMAScript language. Other, more specialized abstract operations are defined throughout this specification.
7.1 Type Conversion
The ECMAScript language implicitly performs automatic type conversion as needed. To clarify the semantics of certain constructs it is useful to define a set of conversion abstract operations. The conversion abstract operations are polymorphic; they can accept a value of any ECMAScript language type. But no other specification types are used with these operations.
The BigInt type has no implicit conversions in the ECMAScript language; programmers must call BigInt explicitly to convert values from other types.
7.1.1 ToPrimitive ( input [ , preferredType ] )
The abstract operation ToPrimitive takes argument input (an ECMAScript language value) and optional argument preferredType (string or number) and returns either a normal completion containing an ECMAScript language value or a throw completion. It converts its input argument to a non-Object type. If an object is capable of converting to more than one primitive type, it may use the optional hint preferredType to favour that type. It performs the following steps when called:
When ToPrimitive is called without a hint, then it generally behaves as if the hint were number. However, objects may over-ride this behaviour by defining a %Symbol.toPrimitive% method. Of the objects defined in this specification only Dates (see 21.4.4.45) and Symbol objects (see 20.4.3.5) over-ride the default ToPrimitive behaviour. Dates treat the absence of a hint as if the hint were string.
The abstract operation ToBoolean takes argument argument (an ECMAScript language value) and returns a Boolean. It converts argument to a value of type Boolean. It performs the following steps when called:
The abstract operation ToNumeric takes argument value (an ECMAScript language value) and returns either a normal completion containing either a Number or a BigInt, or a throw completion. It returns value converted to a Number or a BigInt. It performs the following steps when called:
The abstract operation RoundMVResult takes argument n (a mathematical value) and returns a Number. It converts n to a Number in an implementation-defined manner. For the purposes of this abstract operation, a digit is significant if it is not zero or there is a non-zero digit to its left and there is a non-zero digit to its right. For the purposes of this abstract operation, "the mathematical value denoted by" a representation of a mathematical value is the inverse of "the decimal representation of" a mathematical value. It performs the following steps when called:
If the decimal representation of n has 20 or fewer significant digits, return 𝔽(n).
Let option1 be the mathematical value denoted by the result of replacing each significant digit in the decimal representation of n after the 20th with a 0 digit.
Let option2 be the mathematical value denoted by the result of replacing each significant digit in the decimal representation of n after the 20th with a 0 digit and then incrementing it at the 20th position (with carrying as necessary).
The abstract operation ToIntegerOrInfinity takes argument argument (an ECMAScript language value) and returns either a normal completion containing either an integer, +∞, or -∞, or a throw completion. It converts argument to an integer representing its Number value with fractional part truncated, or to +∞ or -∞ when that Number value is infinite. It performs the following steps when called:
𝔽(ToIntegerOrInfinity(x)) never returns -0𝔽 for any value of x. The truncation of the fractional part is performed after converting x to a mathematical value.
Step 5 is the only difference between ToUint32 and ToInt32.
The ToUint32 abstract operation is idempotent: if applied to a result that it produced, the second application leaves that value unchanged.
ToUint32(ToInt32(x)) is the same value as ToUint32(x) for all values of x. (It is to preserve this latter property that +∞𝔽 and -∞𝔽 are mapped to +0𝔽.)
If f is even, return 𝔽(f). Otherwise, return 𝔽(f + 1).
Note
Unlike most other ECMAScript integer conversion operations, ToUint8Clamp rounds rather than truncates non-integral values. It also uses “round half to even” tie-breaking, which differs from the “round half up” tie-breaking of Math.round.
7.1.13 ToBigInt ( argument )
The abstract operation ToBigInt takes argument argument (an ECMAScript language value) and returns either a normal completion containing a BigInt or a throw completion. It converts argument to a BigInt value, or throws if an implicit conversion from Number would be required. It performs the following steps when called:
The abstract operation CanonicalNumericIndexString takes argument argument (a String) and returns a Number or undefined. If argument is either "-0" or exactly matches ToString(n) for some Number value n, it returns the respective Number value. Otherwise, it returns undefined. It performs the following steps when called:
The abstract operation IsCallable takes argument argument (an ECMAScript language value) and returns a Boolean. It determines if argument is a callable function with a [[Call]] internal method. It performs the following steps when called:
If argument has a [[Call]] internal method, return true.
Return false.
7.2.4 IsConstructor ( argument )
The abstract operation IsConstructor takes argument argument (an ECMAScript language value) and returns a Boolean. It determines if argument is a function object with a [[Construct]] internal method. It performs the following steps when called:
If argument has a [[Construct]] internal method, return true.
Return false.
7.2.5 IsExtensible ( O )
The abstract operation IsExtensible takes argument O (an Object) and returns either a normal completion containing a Boolean or a throw completion. It is used to determine whether additional properties can be added to O. It performs the following steps when called:
The abstract operation IsStringWellFormedUnicode takes argument string (a String) and returns a Boolean. It interprets string as a sequence of UTF-16 encoded code points, as described in 6.1.4, and determines whether it is a well formed UTF-16 sequence. It performs the following steps when called:
If cp.[[IsUnpairedSurrogate]] is true, return false.
Set k to k + cp.[[CodeUnitCount]].
Return true.
7.2.8 SameType ( x, y )
The abstract operation SameType takes arguments x (an ECMAScript language value) and y (an ECMAScript language value) and returns a Boolean. It determines whether or not the two arguments are the same type. It performs the following steps when called:
If x is undefined and y is undefined, return true.
The abstract operation SameValue takes arguments x (an ECMAScript language value) and y (an ECMAScript language value) and returns a Boolean. It determines whether or not the two arguments are the same value. It performs the following steps when called:
This algorithm differs from the IsStrictlyEqual Algorithm by treating all NaN values as equivalent and by differentiating +0𝔽 from -0𝔽.
7.2.10 SameValueZero ( x, y )
The abstract operation SameValueZero takes arguments x (an ECMAScript language value) and y (an ECMAScript language value) and returns a Boolean. It determines whether or not the two arguments are the same value (ignoring the difference between +0𝔽 and -0𝔽). It performs the following steps when called:
SameValueZero differs from SameValue only in that it treats +0𝔽 and -0𝔽 as equivalent.
7.2.11 SameValueNonNumber ( x, y )
The abstract operation SameValueNonNumber takes arguments x (an ECMAScript language value, but not a Number) and y (an ECMAScript language value, but not a Number) and returns a Boolean. It performs the following steps when called:
For expository purposes, some cases are handled separately within this algorithm even if it is unnecessary to do so.
Note 2
The specifics of what "x is y" means are detailed in 5.2.7.
7.2.12 IsLessThan ( x, y, LeftFirst )
The abstract operation IsLessThan takes arguments x (an ECMAScript language value), y (an ECMAScript language value), and LeftFirst (a Boolean) and returns either a normal completion containing either a Boolean or undefined, or a throw completion. It provides the semantics for the comparison x < y, returning true, false, or undefined (which indicates that at least one operand is NaN). The LeftFirst flag is used to control the order in which operations with potentially visible side-effects are performed upon x and y. It is necessary because ECMAScript specifies left to right evaluation of expressions. If LeftFirst is true, the x parameter corresponds to an expression that occurs to the left of the y parameter's corresponding expression. If LeftFirst is false, the reverse is the case and operations must be performed upon y before x. It performs the following steps when called:
If ℝ(nx) < ℝ(ny), return true; otherwise return false.
Note 1
Step 3 differs from step 1.c in the algorithm that handles the addition operator + (13.15.3) by using the logical-and operation instead of the logical-or operation.
Note 2
The comparison of Strings uses a simple lexicographic ordering on sequences of UTF-16 code unit values. There is no attempt to use the more complex, semantically oriented definitions of character or string equality and collating order defined in the Unicode specification. Therefore String values that are canonically equal according to the Unicode Standard but not in the same normalization form could test as unequal. Also note that lexicographic ordering by code unit differs from ordering by code point for Strings containing surrogate pairs.
If x is not finite or y is not finite, return false.
If ℝ(x) = ℝ(y), return true; otherwise return false.
Return false.
7.2.14 IsStrictlyEqual ( x, y )
The abstract operation IsStrictlyEqual takes arguments x (an ECMAScript language value) and y (an ECMAScript language value) and returns a Boolean. It provides the semantics for the === operator. It performs the following steps when called:
This algorithm differs from the SameValue Algorithm in its treatment of signed zeroes and NaNs.
7.3 Operations on Objects
7.3.1 MakeBasicObject ( internalSlotsList )
The abstract operation MakeBasicObject takes argument internalSlotsList (a List of internal slot names) and returns an Object. It is the source of all ECMAScript objects that are created algorithmically, including both ordinary objects and exotic objects. It factors out common steps used in creating all objects, and centralizes object creation. It performs the following steps when called:
Set internalSlotsList to the list-concatenation of internalSlotsList and « [[PrivateElements]] ».
Let obj be a newly created object with an internal slot for each name in internalSlotsList.
Set obj's essential internal methods to the default ordinary object definitions specified in 10.1.
Assert: If the caller will not be overriding both obj's [[GetPrototypeOf]] and [[SetPrototypeOf]] essential internal methods, then internalSlotsList contains [[Prototype]].
Assert: If the caller will not be overriding all of obj's [[SetPrototypeOf]], [[IsExtensible]], and [[PreventExtensions]] essential internal methods, then internalSlotsList contains [[Extensible]].
If internalSlotsList contains [[Extensible]], set obj.[[Extensible]] to true.
Return obj.
Note
Within this specification, exotic objects are created in abstract operations such as ArrayCreate and BoundFunctionCreate by first calling MakeBasicObject to obtain a basic, foundational object, and then overriding some or all of that object's internal methods. In order to encapsulate exotic object creation, the object's essential internal methods are never modified outside those operations.
The abstract operation Set takes arguments O (an Object), P (a property key), V (an ECMAScript language value), and Throw (a Boolean) and returns either a normal completion containingunused or a throw completion. It is used to set the value of a specific property of an object. V is the new value for the property. It performs the following steps when called:
Let success be ? O.[[Set]](P, V, O).
If success is false and Throw is true, throw a TypeError exception.
Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
Return ? O.[[DefineOwnProperty]](P, newDesc).
Note
This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator. Normally, the property will not already exist. If it does exist and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return false.
7.3.6 CreateDataPropertyOrThrow ( O, P, V )
The abstract operation CreateDataPropertyOrThrow takes arguments O (an Object), P (a property key), and V (an ECMAScript language value) and returns either a normal completion containingunused or a throw completion. It is used to create a new own property of an object. It throws a TypeError exception if the requested property update cannot be performed. It performs the following steps when called:
This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator. Normally, the property will not already exist. If it does exist and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return false causing this operation to throw a TypeError exception.
7.3.7 CreateNonEnumerableDataPropertyOrThrow ( O, P, V )
The abstract operation CreateNonEnumerableDataPropertyOrThrow takes arguments O (an Object), P (a property key), and V (an ECMAScript language value) and returns unused. It is used to create a new non-enumerable own property of an ordinary object. It performs the following steps when called:
Assert: O is an ordinary, extensible object with no non-configurable properties.
Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }.
This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator except it is not enumerable. Normally, the property will not already exist. If it does exist, DefinePropertyOrThrow is guaranteed to complete normally.
7.3.8 DefinePropertyOrThrow ( O, P, desc )
The abstract operation DefinePropertyOrThrow takes arguments O (an Object), P (a property key), and desc (a Property Descriptor) and returns either a normal completion containingunused or a throw completion. It is used to call the [[DefineOwnProperty]] internal method of an object in a manner that will throw a TypeError exception if the requested property update cannot be performed. It performs the following steps when called:
Let success be ? O.[[DefineOwnProperty]](P, desc).
If success is false, throw a TypeError exception.
Return unused.
7.3.9 DeletePropertyOrThrow ( O, P )
The abstract operation DeletePropertyOrThrow takes arguments O (an Object) and P (a property key) and returns either a normal completion containingunused or a throw completion. It is used to remove a specific own property of an object. It throws an exception if the property is not configurable. It performs the following steps when called:
If func is either undefined or null, return undefined.
If IsCallable(func) is false, throw a TypeError exception.
Return func.
7.3.11 HasProperty ( O, P )
The abstract operation HasProperty takes arguments O (an Object) and P (a property key) and returns either a normal completion containing a Boolean or a throw completion. It is used to determine whether an object has a property with the specified property key. The property may be either own or inherited. It performs the following steps when called:
Return ? O.[[HasProperty]](P).
7.3.12 HasOwnProperty ( O, P )
The abstract operation HasOwnProperty takes arguments O (an Object) and P (a property key) and returns either a normal completion containing a Boolean or a throw completion. It is used to determine whether an object has an own property with the specified property key. It performs the following steps when called:
The abstract operation Construct takes argument F (a constructor) and optional arguments argumentsList (a List of ECMAScript language values) and newTarget (a constructor) and returns either a normal completion containing an Object or a throw completion. It is used to call the [[Construct]] internal method of a function object. argumentsList and newTarget are the values to be passed as the corresponding arguments of the internal method. If argumentsList is not present, a new empty List is used as its value. If newTarget is not present, F is used as its value. It performs the following steps when called:
If newTarget is not present, set newTarget to F.
If argumentsList is not present, set argumentsList to a new empty List.
If newTarget is not present, this operation is equivalent to: new F(...argumentsList)
7.3.15 SetIntegrityLevel ( O, level )
The abstract operation SetIntegrityLevel takes arguments O (an Object) and level (sealed or frozen) and returns either a normal completion containing a Boolean or a throw completion. It is used to fix the set of own properties of an object. It performs the following steps when called:
The abstract operation TestIntegrityLevel takes arguments O (an Object) and level (sealed or frozen) and returns either a normal completion containing a Boolean or a throw completion. It is used to determine if the set of own properties of an object are fixed. It performs the following steps when called:
NOTE: If the object is extensible, none of its properties are examined.
Let keys be ? O.[[OwnPropertyKeys]]().
For each element k of keys, do
Let currentDesc be ? O.[[GetOwnProperty]](k).
If currentDesc is not undefined, then
If currentDesc.[[Configurable]] is true, return false.
If level is frozen and IsDataDescriptor(currentDesc) is true, then
If currentDesc.[[Writable]] is true, return false.
Return true.
7.3.17 CreateArrayFromList ( elements )
The abstract operation CreateArrayFromList takes argument elements (a List of ECMAScript language values) and returns an Array. It is used to create an Array whose elements are provided by elements. It performs the following steps when called:
The abstract operation LengthOfArrayLike takes argument obj (an Object) and returns either a normal completion containing a non-negative integer or a throw completion. It returns the value of the "length" property of an array-like object. It performs the following steps when called:
The abstract operation CreateListFromArrayLike takes argument obj (an ECMAScript language value) and optional argument validElementTypes (all or property-key) and returns either a normal completion containing a List of ECMAScript language values or a throw completion. It is used to create a List value whose elements are provided by the indexed properties of obj. validElementTypes indicates the types of values that are allowed as elements. It performs the following steps when called:
If validElementTypes is not present, set validElementTypes to all.
The abstract operation OrdinaryHasInstance takes arguments C (an ECMAScript language value) and O (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. It implements the default algorithm for determining if O inherits from the instance object inheritance path provided by C. It performs the following steps when called:
7.3.22 SpeciesConstructor ( O, defaultConstructor )
The abstract operation SpeciesConstructor takes arguments O (an Object) and defaultConstructor (a constructor) and returns either a normal completion containing a constructor or a throw completion. It is used to retrieve the constructor that should be used to create new objects that are derived from O. defaultConstructor is the constructor to use if a constructor%Symbol.species% property cannot be found starting from O. It performs the following steps when called:
The target passed in here is always a newly created object which is not directly accessible in case of an error being thrown.
7.3.26 PrivateElementFind ( O, P )
The abstract operation PrivateElementFind takes arguments O (an Object) and P (a Private Name) and returns a PrivateElement or empty. It performs the following steps when called:
If O.[[PrivateElements]] contains a PrivateElementpe such that pe.[[Key]] is P, then
If entry is not empty, throw a TypeError exception.
Append PrivateElement { [[Key]]: P, [[Kind]]: field, [[Value]]: value } to O.[[PrivateElements]].
Return unused.
7.3.28 PrivateMethodOrAccessorAdd ( O, method )
The abstract operation PrivateMethodOrAccessorAdd takes arguments O (an Object) and method (a PrivateElement) and returns either a normal completion containingunused or a throw completion. It performs the following steps when called:
Assert: method.[[Kind]] is either method or accessor.
7.3.33 InitializeInstanceElements ( O, constructor )
The abstract operation InitializeInstanceElements takes arguments O (an Object) and constructor (an ECMAScript function object) and returns either a normal completion containingunused or a throw completion. It performs the following steps when called:
Let methods be the value of constructor.[[PrivateMethods]].
The abstract operation IteratorComplete takes argument iteratorResult (an Object) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:
The abstract operation IteratorStep takes argument iteratorRecord (an Iterator Record) and returns either a normal completion containing either an Object or done, or a throw completion. It requests the next value from iteratorRecord.[[Iterator]] by calling iteratorRecord.[[NextMethod]] and returns either done indicating that the iterator has reached its end or the IteratorResult object if a next value is available. It performs the following steps when called:
The abstract operation IteratorStepValue takes argument iteratorRecord (an Iterator Record) and returns either a normal completion containing either an ECMAScript language value or done, or a throw completion. It requests the next value from iteratorRecord.[[Iterator]] by calling iteratorRecord.[[NextMethod]] and returns either done indicating that the iterator has reached its end or the value from the IteratorResult object if a next value is available. It performs the following steps when called:
The abstract operation IteratorClose takes arguments iteratorRecord (an Iterator Record) and completion (a Completion Record) and returns a Completion Record. It is used to notify an iterator that it should perform any actions it would normally perform when it has reached its completed state. It performs the following steps when called:
The abstract operation AsyncIteratorClose takes arguments iteratorRecord (an Iterator Record) and completion (a Completion Record) and returns a Completion Record. It is used to notify an async iterator that it should perform any actions it would normally perform when it has reached its completed state. It performs the following steps when called:
If innerResult.[[Value]]is not an Object, throw a TypeError exception.
Return ? completion.
7.4.14 CreateIteratorResultObject ( value, done )
The abstract operation CreateIteratorResultObject takes arguments value (an ECMAScript language value) and done (a Boolean) and returns an Object that conforms to the IteratorResult interface. It creates an object that conforms to the IteratorResult interface. It performs the following steps when called:
The abstract operation CreateListIteratorRecord takes argument list (a List of ECMAScript language values) and returns an Iterator Record. It creates an Iterator Record whose [[NextMethod]] returns the successive elements of list. It performs the following steps when called:
Let closure be a new Abstract Closure with no parameters that captures list and performs the following steps when called: