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 an abrupt 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 @@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.
If argument is +0𝔽, -0𝔽, or NaN, return false; otherwise return true.
String
If argument is the empty String (its length is 0), return false; otherwise return true.
Symbol
Return true.
BigInt
If argument is 0ℤ, return false; otherwise return true.
Object
Return true.
Note
An alternate algorithm related to the [[IsHTMLDDA]] internal slot is mandated in section B.3.6.1.
7.1.3 ToNumeric ( value )
The abstract operation ToNumeric takes argument value and returns either a normal completion containing either a Number or a BigInt, or an abrupt 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).
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𝔽.)
Unlike the other ECMAScript integer conversion abstract operation, ToUint8Clamp rounds rather than truncates non-integral values and does not convert +∞𝔽 to +0𝔽. ToUint8Clamp does “round half to even” tie-breaking. This differs from Math.round which does “round half up” tie-breaking.
7.1.13 ToBigInt ( argument )
The abstract operation ToBigInt takes argument argument and returns either a normal completion containing a BigInt or an abrupt 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 ToBigInt64 takes argument argument and returns either a normal completion containing a BigInt or an abrupt completion. It converts argument to one of 264 BigInt values in the range ℤ(-263) through ℤ(263-1), inclusive. It performs the following steps when called:
The abstract operation ToBigUint64 takes argument argument and returns either a normal completion containing a BigInt or an abrupt completion. It converts argument to one of 264 BigInt values in the range 0ℤ through the BigInt value for ℤ(264-1), inclusive. It performs the following steps when called:
The abstract operation CanonicalNumericIndexString takes argument argument (a String) and returns a Number or undefined. It returns argument converted to a Number value if it is a String representation of a Number that would be produced by ToString, or the string "-0". Otherwise, it returns undefined. It performs the following steps when called:
The abstract operation IsArray takes argument argument and returns either a normal completion containing a Boolean or an abrupt completion. 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 an abrupt completion. It is used to determine whether additional properties can be added to O. It performs the following steps when called:
Return ? O.[[IsExtensible]]().
7.2.6 IsIntegralNumber ( argument )
The abstract operation IsIntegralNumber takes argument argument and returns a Boolean. It determines if argument is a finite integral Number value. It performs the following steps when called:
If floor(abs(ℝ(argument))) ≠ abs(ℝ(argument)), return false.
Return true.
7.2.7 IsPropertyKey ( argument )
The abstract operation IsPropertyKey takes argument argument (an ECMAScript language value) and returns a Boolean. It determines if argument is a value that may be used as a property key. It performs the following steps when called:
The abstract operation IsRegExp takes argument argument and returns either a normal completion containing a Boolean or an abrupt completion. It performs the following steps when called:
If matcher is not undefined, return ToBoolean(matcher).
If argument has a [[RegExpMatcher]] internal slot, return true.
Return false.
7.2.9 IsStringPrefix ( p, q )
The abstract operation IsStringPrefix takes arguments p (a String) and q (a String) and returns a Boolean. It determines if p is a prefix of q. 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.11 SameValue ( x, y )
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:
If Type(x) is different from Type(y), return false.
This algorithm differs from the IsStrictlyEqual Algorithm by treating all NaN values as equivalent and by differentiating +0𝔽 from -0𝔽.
7.2.12 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:
If Type(x) is different from Type(y), return false.
SameValueZero differs from SameValue only in that it treats +0𝔽 and -0𝔽 as equivalent.
7.2.13 SameValueNonNumeric ( x, y )
The abstract operation SameValueNonNumeric takes arguments x (an ECMAScript language value, but not a Number or a BigInt) and y (an ECMAScript language value, but not a Number or a BigInt) and returns a Boolean. It performs the following steps when called:
If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices), return true; otherwise, return false.
If x and y are both the same Symbol value, return true; otherwise, return false.
If x and y are the same Object value, return true. Otherwise, return false.
7.2.14 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 an abrupt 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:
Let k be the smallest non-negative integer such that the code unit at index k within px is different from the code unit at index k within py. (There must be such a k, for neither String is a prefix of the other.)
Let m be the integer that is the numeric value of the code unit at index k within px.
Let n be the integer that is the numeric value of the code unit at index k within py.
If m < n, return true. Otherwise, return false.
Else,
If Type(px) is BigInt and Type(py) is String, then
Assert: Type(nx) is BigInt and Type(ny) is Number, or Type(nx) is Number and Type(ny) is BigInt.
If nx or ny is NaN, return undefined.
If nx is -∞𝔽 or ny is +∞𝔽, return true.
If nx is +∞𝔽 or ny is -∞𝔽, return false.
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 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 could test as unequal. In effect this algorithm assumes that both Strings are already in normalized form. Also, note that for strings containing supplementary characters, lexicographic ordering on sequences of UTF-16 code unit values differs from that on sequences of code point values.
If Type(x) is BigInt and Type(y) is Number, or if Type(x) is Number and Type(y) is BigInt, then
If x or y are any of NaN, +∞𝔽, or -∞𝔽, return false.
If ℝ(x) = ℝ(y), return true; otherwise return false.
Return false.
7.2.16 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 comparison x === y. It performs the following steps when called:
If Type(x) is different from Type(y), return false.
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:
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 an abrupt 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 CreateMethodProperty ( O, P, V )
The abstract operation CreateMethodProperty 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 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 }.
Perform ! O.[[DefineOwnProperty]](P, newDesc).
Return unused.
Note
This abstract operation creates a property whose attributes are set to the same defaults used for built-in methods and methods defined using class declaration syntax. 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.7 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 containing a Boolean or an abrupt 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.8 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 and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return false causing this operation to throw a TypeError exception.
7.3.9 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 an abrupt 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.10 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 an abrupt 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.12 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 an abrupt 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.13 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 an abrupt 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 and newTarget (a constructor) and returns either a normal completion containing an Object or an abrupt 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.16 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 an abrupt 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 an abrupt 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.18 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 an abrupt 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 and optional argument elementTypes (a List of names of ECMAScript Language Types) and returns either a normal completion containing a List or an abrupt completion. It is used to create a List value whose elements are provided by the indexed properties of obj. elementTypes contains the names of ECMAScript Language Types that are allowed for element values of the List that is created. It performs the following steps when called:
If elementTypes is not present, set elementTypes to « Undefined, Null, Boolean, String, Symbol, Number, BigInt, Object ».
If Type(obj) is not Object, throw a TypeError exception.
The abstract operation OrdinaryHasInstance takes arguments C (an ECMAScript language value) and O and returns either a normal completion containing a Boolean or an abrupt 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.23 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 an abrupt 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@@species property cannot be found starting from O. It performs the following steps when called:
The abstract operation EnumerableOwnPropertyNames takes arguments O (an Object) and kind (key, value, or key+value) and returns either a normal completion containing a List or an abrupt completion. 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.27 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 PrivateElement whose [[Key]] is P, then
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 an abrupt completion. It performs the following steps when called:
Let methods be the value of constructor.[[PrivateMethods]].
Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]).
Else,
Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « value »).
If Type(result) is not Object, throw a TypeError exception.
Return result.
7.4.4 IteratorComplete ( iterResult )
The abstract operation IteratorComplete takes argument iterResult (an Object) and returns either a normal completion containing a Boolean or an abrupt 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 false, or an abrupt completion. It requests the next value from iteratorRecord.[[Iterator]] by calling iteratorRecord.[[NextMethod]] and returns either false 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 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:
Assert: Type(iteratorRecord.[[Iterator]]) is Object.
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:
Assert: Type(iteratorRecord.[[Iterator]]) is Object.
If innerResult.[[Type]] is normal, set innerResult to Completion(Await(innerResult.[[Value]])).
If completion.[[Type]] is throw, return ? completion.
If innerResult.[[Type]] is throw, return ? innerResult.
If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception.
Return ? completion.
7.4.10 CreateIterResultObject ( value, done )
The abstract operation CreateIterResultObject 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) and returns an Iterator Record. It creates an Iterator (27.1.1.2) object record whose next method 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: