7.3 Operations on Objects

7.3.1 MakeBasicObject ( internalSlotsList )

The abstract operation MakeBasicObject takes argument internalSlotsList. 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:

  1. Assert: internalSlotsList is a List of internal slot names.
  2. Let obj be a newly created object with an internal slot for each name in internalSlotsList.
  3. Set obj's essential internal methods to the default ordinary object definitions specified in 10.1.
  4. Assert: If the caller will not be overriding both obj's [[GetPrototypeOf]] and [[SetPrototypeOf]] essential internal methods, then internalSlotsList contains [[Prototype]].
  5. Assert: If the caller will not be overriding all of obj's [[SetPrototypeOf]], [[IsExtensible]], and [[PreventExtensions]] essential internal methods, then internalSlotsList contains [[Extensible]].
  6. If internalSlotsList contains [[Extensible]], set obj.[[Extensible]] to true.
  7. 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.

7.3.2 Get ( O, P )

The abstract operation Get takes arguments O (an Object) and P (a property key). It is used to retrieve the value of a specific property of an object. It performs the following steps when called:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Return ? O.[[Get]](P, O).

7.3.3 GetV ( V, P )

The abstract operation GetV takes arguments V (an ECMAScript language value) and P (a property key). It is used to retrieve the value of a specific property of an ECMAScript language value. If the value is not an object, the property lookup is performed using a wrapper object appropriate for the type of the value. It performs the following steps when called:

  1. Assert: IsPropertyKey(P) is true.
  2. Let O be ? ToObject(V).
  3. Return ? O.[[Get]](P, V).

7.3.4 Set ( O, P, V, Throw )

The abstract operation Set takes arguments O (an Object), P (a property key), V (an ECMAScript language value), and Throw (a Boolean). 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:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Assert: Type(Throw) is Boolean.
  4. Let success be ? O.[[Set]](P, V, O).
  5. If success is false and Throw is true, throw a TypeError exception.
  6. Return success.

7.3.5 CreateDataProperty ( O, P, V )

The abstract operation CreateDataProperty takes arguments O (an Object), P (a property key), and V (an ECMAScript language value). It is used to create a new own property of an object. It performs the following steps when called:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
  4. 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). It is used to create a new own property of an object. It performs the following steps when called:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }.
  4. Return ? O.[[DefineOwnProperty]](P, newDesc).
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). 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:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Let success be ? CreateDataProperty(O, P, V).
  4. If success is false, throw a TypeError exception.
  5. Return success.
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 causing this operation to throw a TypeError exception.

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). 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:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Let success be ? O.[[DefineOwnProperty]](P, desc).
  4. If success is false, throw a TypeError exception.
  5. Return success.

7.3.9 DeletePropertyOrThrow ( O, P )

The abstract operation DeletePropertyOrThrow takes arguments O (an Object) and P (a property key). 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:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Let success be ? O.[[Delete]](P).
  4. If success is false, throw a TypeError exception.
  5. Return success.

7.3.10 GetMethod ( V, P )

The abstract operation GetMethod takes arguments V (an ECMAScript language value) and P (a property key). It is used to get the value of a specific property of an ECMAScript language value when the value of the property is expected to be a function. It performs the following steps when called:

  1. Assert: IsPropertyKey(P) is true.
  2. Let func be ? GetV(V, P).
  3. If func is either undefined or null, return undefined.
  4. If IsCallable(func) is false, throw a TypeError exception.
  5. Return func.

7.3.11 HasProperty ( O, P )

The abstract operation HasProperty takes arguments O (an Object) and P (a property key) and returns a completion record which, if its [[Type]] is normal, has a [[Value]] which is a Boolean. It is used to determine whether an object has a property with the specified property key. The property may be either an own or inherited. It performs the following steps when called:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. 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 a completion record which, if its [[Type]] is normal, has a [[Value]] which is a Boolean. It is used to determine whether an object has an own property with the specified property key. It performs the following steps when called:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Let desc be ? O.[[GetOwnProperty]](P).
  4. If desc is undefined, return false.
  5. Return true.

7.3.13 Call ( F, V [ , argumentsList ] )

The abstract operation Call takes arguments F (an ECMAScript language value) and V (an ECMAScript language value) and optional argument argumentsList (a List of ECMAScript language values). It is used to call the [[Call]] internal method of a function object. F is the function object, V is an ECMAScript language value that is the this value of the [[Call]], and argumentsList is the value passed to the corresponding argument of the internal method. If argumentsList is not present, a new empty List is used as its value. It performs the following steps when called:

  1. If argumentsList is not present, set argumentsList to a new empty List.
  2. If IsCallable(F) is false, throw a TypeError exception.
  3. Return ? F.[[Call]](V, argumentsList).

7.3.14 Construct ( F [ , argumentsList [ , newTarget ] ] )

The abstract operation Construct takes argument F (a function object) and optional arguments argumentsList and newTarget. 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:

  1. If newTarget is not present, set newTarget to F.
  2. If argumentsList is not present, set argumentsList to a new empty List.
  3. Assert: IsConstructor(F) is true.
  4. Assert: IsConstructor(newTarget) is true.
  5. Return ? F.[[Construct]](argumentsList, newTarget).
Note

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 and level. It is used to fix the set of own properties of an object. It performs the following steps when called:

  1. Assert: Type(O) is Object.
  2. Assert: level is either sealed or frozen.
  3. Let status be ? O.[[PreventExtensions]]().
  4. If status is false, return false.
  5. Let keys be ? O.[[OwnPropertyKeys]]().
  6. If level is sealed, then
    1. For each element k of keys, do
      1. Perform ? DefinePropertyOrThrow(O, k, PropertyDescriptor { [[Configurable]]: false }).
  7. Else,
    1. Assert: level is frozen.
    2. For each element k of keys, do
      1. Let currentDesc be ? O.[[GetOwnProperty]](k).
      2. If currentDesc is not undefined, then
        1. If IsAccessorDescriptor(currentDesc) is true, then
          1. Let desc be the PropertyDescriptor { [[Configurable]]: false }.
        2. Else,
          1. Let desc be the PropertyDescriptor { [[Configurable]]: false, [[Writable]]: false }.
        3. Perform ? DefinePropertyOrThrow(O, k, desc).
  8. Return true.

7.3.16 TestIntegrityLevel ( O, level )

The abstract operation TestIntegrityLevel takes arguments O and level. It is used to determine if the set of own properties of an object are fixed. It performs the following steps when called:

  1. Assert: Type(O) is Object.
  2. Assert: level is either sealed or frozen.
  3. Let extensible be ? IsExtensible(O).
  4. If extensible is true, return false.
  5. NOTE: If the object is extensible, none of its properties are examined.
  6. Let keys be ? O.[[OwnPropertyKeys]]().
  7. For each element k of keys, do
    1. Let currentDesc be ? O.[[GetOwnProperty]](k).
    2. If currentDesc is not undefined, then
      1. If currentDesc.[[Configurable]] is true, return false.
      2. If level is frozen and IsDataDescriptor(currentDesc) is true, then
        1. If currentDesc.[[Writable]] is true, return false.
  8. Return true.

7.3.17 CreateArrayFromList ( elements )

The abstract operation CreateArrayFromList takes argument elements (a List). It is used to create an Array object whose elements are provided by elements. It performs the following steps when called:

  1. Assert: elements is a List whose elements are all ECMAScript language values.
  2. Let array be ! ArrayCreate(0).
  3. Let n be 0.
  4. For each element e of elements, do
    1. Perform ! CreateDataPropertyOrThrow(array, ! ToString(𝔽(n)), e).
    2. Set n to n + 1.
  5. Return array.

7.3.18 LengthOfArrayLike ( obj )

The abstract operation LengthOfArrayLike takes argument obj. It returns the value of the "length" property of an array-like object (as a non-negative integer). It performs the following steps when called:

  1. Assert: Type(obj) is Object.
  2. Return (? ToLength(? Get(obj, "length"))).

An array-like object is any object for which this operation returns an integer rather than an abrupt completion.

Note 1
Typically, an array-like object would also have some properties with integer index names. However, that is not a requirement of this definition.
Note 2
Array objects and String objects are examples of array-like objects.

7.3.19 CreateListFromArrayLike ( obj [ , elementTypes ] )

The abstract operation CreateListFromArrayLike takes argument obj and optional argument elementTypes (a List of names of ECMAScript Language Types). 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:

  1. If elementTypes is not present, set elementTypes to « Undefined, Null, Boolean, String, Symbol, Number, BigInt, Object ».
  2. If Type(obj) is not Object, throw a TypeError exception.
  3. Let len be ? LengthOfArrayLike(obj).
  4. Let list be a new empty List.
  5. Let index be 0.
  6. Repeat, while index < len,
    1. Let indexName be ! ToString(𝔽(index)).
    2. Let next be ? Get(obj, indexName).
    3. If Type(next) is not an element of elementTypes, throw a TypeError exception.
    4. Append next as the last element of list.
    5. Set index to index + 1.
  7. Return list.

7.3.20 Invoke ( V, P [ , argumentsList ] )

The abstract operation Invoke takes arguments V (an ECMAScript language value) and P (a property key) and optional argument argumentsList (a List of ECMAScript language values). It is used to call a method property of an ECMAScript language value. V serves as both the lookup point for the property and the this value of the call. argumentsList is the list of arguments values passed to the method. If argumentsList is not present, a new empty List is used as its value. It performs the following steps when called:

  1. Assert: IsPropertyKey(P) is true.
  2. If argumentsList is not present, set argumentsList to a new empty List.
  3. Let func be ? GetV(V, P).
  4. Return ? Call(func, V, argumentsList).

7.3.21 OrdinaryHasInstance ( C, O )

The abstract operation OrdinaryHasInstance takes arguments C (an ECMAScript language value) and O. 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:

  1. If IsCallable(C) is false, return false.
  2. If C has a [[BoundTargetFunction]] internal slot, then
    1. Let BC be C.[[BoundTargetFunction]].
    2. Return ? InstanceofOperator(O, BC).
  3. If Type(O) is not Object, return false.
  4. Let P be ? Get(C, "prototype").
  5. If Type(P) is not Object, throw a TypeError exception.
  6. Repeat,
    1. Set O to ? O.[[GetPrototypeOf]]().
    2. If O is null, return false.
    3. If SameValue(P, O) is true, return true.

7.3.22 SpeciesConstructor ( O, defaultConstructor )

The abstract operation SpeciesConstructor takes arguments O (an Object) and defaultConstructor (a constructor). 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:

  1. Assert: Type(O) is Object.
  2. Let C be ? Get(O, "constructor").
  3. If C is undefined, return defaultConstructor.
  4. If Type(C) is not Object, throw a TypeError exception.
  5. Let S be ? Get(C, @@species).
  6. If S is either undefined or null, return defaultConstructor.
  7. If IsConstructor(S) is true, return S.
  8. Throw a TypeError exception.

7.3.23 EnumerableOwnPropertyNames ( O, kind )

The abstract operation EnumerableOwnPropertyNames takes arguments O (an Object) and kind (one of key, value, or key+value). It performs the following steps when called:

  1. Assert: Type(O) is Object.
  2. Let ownKeys be ? O.[[OwnPropertyKeys]]().
  3. Let properties be a new empty List.
  4. For each element key of ownKeys, do
    1. If Type(key) is String, then
      1. Let desc be ? O.[[GetOwnProperty]](key).
      2. If desc is not undefined and desc.[[Enumerable]] is true, then
        1. If kind is key, append key to properties.
        2. Else,
          1. Let value be ? Get(O, key).
          2. If kind is value, append value to properties.
          3. Else,
            1. Assert: kind is key+value.
            2. Let entry be ! CreateArrayFromListkey, value »).
            3. Append entry to properties.
  5. Return properties.

7.3.24 GetFunctionRealm ( obj )

The abstract operation GetFunctionRealm takes argument obj. It performs the following steps when called:

  1. Assert: ! IsCallable(obj) is true.
  2. If obj has a [[Realm]] internal slot, then
    1. Return obj.[[Realm]].
  3. If obj is a bound function exotic object, then
    1. Let target be obj.[[BoundTargetFunction]].
    2. Return ? GetFunctionRealm(target).
  4. If obj is a Proxy exotic object, then
    1. If obj.[[ProxyHandler]] is null, throw a TypeError exception.
    2. Let proxyTarget be obj.[[ProxyTarget]].
    3. Return ? GetFunctionRealm(proxyTarget).
  5. Return the current Realm Record.
Note

Step 5 will only be reached if obj is a non-standard function exotic object that does not have a [[Realm]] internal slot.

7.3.25 CopyDataProperties ( target, source, excludedItems )

The abstract operation CopyDataProperties takes arguments target, source, and excludedItems. It performs the following steps when called:

  1. Assert: Type(target) is Object.
  2. Assert: excludedItems is a List of property keys.
  3. If source is undefined or null, return target.
  4. Let from be ! ToObject(source).
  5. Let keys be ? from.[[OwnPropertyKeys]]().
  6. For each element nextKey of keys, do
    1. Let excluded be false.
    2. For each element e of excludedItems, do
      1. If SameValue(e, nextKey) is true, then
        1. Set excluded to true.
    3. If excluded is false, then
      1. Let desc be ? from.[[GetOwnProperty]](nextKey).
      2. If desc is not undefined and desc.[[Enumerable]] is true, then
        1. Let propValue be ? Get(from, nextKey).
        2. Perform ! CreateDataPropertyOrThrow(target, nextKey, propValue).
  7. Return target.
Note

The target passed in here is always a newly created object which is not directly accessible in case of an error being thrown.