7.3 Operations on Objects
7.3.1 MakeBasicObject ( internalSlotsList )
The abstract operation MakeBasicObject takes argument internalSlotsList (a
- 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 in10.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.
Within this specification,
7.3.2 Get ( O, P )
The abstract operation Get takes arguments O (an Object) and P (a
- Return ? O.[[Get]](P, O).
7.3.3 GetV ( V, P )
The abstract operation GetV takes arguments V (an
- Let O be ?
ToObject (V). - Return ? O.[[Get]](P, V).
7.3.4 Set ( O, P, V, Throw )
The abstract operation Set takes arguments O (an Object), P (a
- Let success be ? O.[[Set]](P, V, O).
- If success is
false and Throw istrue , throw aTypeError exception. - Return
unused .
7.3.5 CreateDataProperty ( O, P, V )
The abstract operation CreateDataProperty takes arguments O (an Object), P (a
- Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]:
true , [[Enumerable]]:true , [[Configurable]]:true }. - Return ? O.[[DefineOwnProperty]](P, newDesc).
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
7.3.6 CreateMethodProperty ( O, P, V )
The abstract operation CreateMethodProperty takes arguments O (an Object), P (a
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 !
DefinePropertyOrThrow (O, P, newDesc). - Return
unused .
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,
7.3.7 CreateDataPropertyOrThrow ( O, P, V )
The abstract operation CreateDataPropertyOrThrow takes arguments O (an Object), P (a
- Let success be ?
CreateDataProperty (O, P, V). - If success is
false , throw aTypeError exception. - Return
unused .
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
7.3.8 CreateNonEnumerableDataPropertyOrThrow ( O, P, V )
The abstract operation CreateNonEnumerableDataPropertyOrThrow takes arguments O (an Object), P (a
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 !
DefinePropertyOrThrow (O, P, newDesc). - Return
unused .
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,
7.3.9 DefinePropertyOrThrow ( O, P, desc )
The abstract operation DefinePropertyOrThrow takes arguments O (an Object), P (a
- Let success be ? O.[[DefineOwnProperty]](P, desc).
- If success is
false , throw aTypeError exception. - Return
unused .
7.3.10 DeletePropertyOrThrow ( O, P )
The abstract operation DeletePropertyOrThrow takes arguments O (an Object) and P (a
- Let success be ? O.[[Delete]](P).
- If success is
false , throw aTypeError exception. - Return
unused .
7.3.11 GetMethod ( V, P )
The abstract operation GetMethod takes arguments V (an
- Let func be ?
GetV (V, P). - If func is either
undefined ornull , returnundefined . - If
IsCallable (func) isfalse , throw aTypeError exception. - Return func.
7.3.12 HasProperty ( O, P )
The abstract operation HasProperty takes arguments O (an Object) and P (a
- Return ? O.[[HasProperty]](P).
7.3.13 HasOwnProperty ( O, P )
The abstract operation HasOwnProperty takes arguments O (an Object) and P (a
- Let desc be ? O.[[GetOwnProperty]](P).
- If desc is
undefined , returnfalse . - Return
true .
7.3.14 Call ( F, V [ , argumentsList ] )
The abstract operation Call takes arguments F (an
- If argumentsList is not present, set argumentsList to a new empty
List . - If
IsCallable (F) isfalse , throw aTypeError exception. - Return ? F.[[Call]](V, argumentsList).
7.3.15 Construct ( F [ , argumentsList [ , newTarget ] ] )
The abstract operation Construct takes argument F (a
- If newTarget is not present, set newTarget to F.
- If argumentsList is not present, set argumentsList to a new empty
List . - Return ? F.[[Construct]](argumentsList, newTarget).
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 (
- Let status be ? O.[[PreventExtensions]]().
- If status is
false , returnfalse . - Let keys be ? O.[[OwnPropertyKeys]]().
- If level is
sealed , then- For each element k of keys, do
- Perform ?
DefinePropertyOrThrow (O, k, PropertyDescriptor { [[Configurable]]:false }).
- Perform ?
- For each element k of keys, do
- Else,
Assert : level isfrozen .- For each element k of keys, do
- Let currentDesc be ? O.[[GetOwnProperty]](k).
- If currentDesc is not
undefined , then- If
IsAccessorDescriptor (currentDesc) istrue , then- Let desc be the PropertyDescriptor { [[Configurable]]:
false }.
- Let desc be the PropertyDescriptor { [[Configurable]]:
- Else,
- Let desc be the PropertyDescriptor { [[Configurable]]:
false , [[Writable]]:false }.
- Let desc be the PropertyDescriptor { [[Configurable]]:
- Perform ?
DefinePropertyOrThrow (O, k, desc).
- If
- Return
true .
7.3.17 TestIntegrityLevel ( O, level )
The abstract operation TestIntegrityLevel takes arguments O (an Object) and level (
- Let extensible be ?
IsExtensible (O). - If extensible is
true , returnfalse . - 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 , returnfalse . - If level is
frozen andIsDataDescriptor (currentDesc) istrue , then- If currentDesc.[[Writable]] is
true , returnfalse .
- If currentDesc.[[Writable]] is
- If currentDesc.[[Configurable]] is
- Return
true .
7.3.18 CreateArrayFromList ( elements )
The abstract operation CreateArrayFromList takes argument elements (a
- Let array be !
ArrayCreate (0). - Let n be 0.
- For each element e of elements, do
- Perform !
CreateDataPropertyOrThrow (array, !ToString (𝔽 (n)), e). - Set n to n + 1.
- Perform !
- Return array.
7.3.19 LengthOfArrayLike ( obj )
The abstract operation LengthOfArrayLike takes argument obj (an Object) and returns either a
An array-like object is any object for which this operation returns a
7.3.20 CreateListFromArrayLike ( obj [ , elementTypes ] )
The abstract operation CreateListFromArrayLike takes argument obj (an
- If elementTypes is not present, set elementTypes to « Undefined, Null, Boolean, String, Symbol, Number, BigInt, Object ».
- If obj
is not an Object , throw aTypeError exception. - Let len be ?
LengthOfArrayLike (obj). - Let list be a new empty
List . - Let index be 0.
- Repeat, while index < len,
- Return list.
7.3.21 Invoke ( V, P [ , argumentsList ] )
The abstract operation Invoke takes arguments V (an
7.3.22 OrdinaryHasInstance ( C, O )
The abstract operation OrdinaryHasInstance takes arguments C (an
- If
IsCallable (C) isfalse , returnfalse . - If C has a [[BoundTargetFunction]] internal slot, then
- Let BC be C.[[BoundTargetFunction]].
- Return ?
InstanceofOperator (O, BC).
- If O
is not an Object , returnfalse . - Let P be ?
Get (C,"prototype" ). - If P
is not an Object , throw aTypeError exception. - Repeat,
- Set O to ? O.[[GetPrototypeOf]]().
- If O is
null , returnfalse . - If
SameValue (P, O) istrue , returntrue .
7.3.23 SpeciesConstructor ( O, defaultConstructor )
The abstract operation SpeciesConstructor takes arguments O (an Object) and defaultConstructor (a
- Let C be ?
Get (O,"constructor" ). - If C is
undefined , return defaultConstructor. - If C
is not an Object , throw aTypeError exception. - Let S be ?
Get (C,@@species ). - If S is either
undefined ornull , return defaultConstructor. - If
IsConstructor (S) istrue , return S. - Throw a
TypeError exception.
7.3.24 EnumerableOwnProperties ( O, kind )
The abstract operation EnumerableOwnProperties takes arguments O (an Object) and kind (
- Let ownKeys be ? O.[[OwnPropertyKeys]]().
- Let results be a new empty
List . - For each element key of ownKeys, do
- If key
is a String , then- Let desc be ? O.[[GetOwnProperty]](key).
- If desc is not
undefined and desc.[[Enumerable]] istrue , then- If kind is
key , then- Append key to results.
- Else,
- Let value be ?
Get (O, key). - If kind is
value , then- Append value to results.
- Else,
Assert : kind iskey+value .- Let entry be
CreateArrayFromList (« key, value »). - Append entry to results.
- Let value be ?
- If kind is
- If key
- Return results.
7.3.25 GetFunctionRealm ( obj )
The abstract operation GetFunctionRealm takes argument obj (a
- If obj has a [[Realm]] internal slot, then
- Return obj.[[Realm]].
- If obj is a
bound function exotic object , then- Let boundTargetFunction be obj.[[BoundTargetFunction]].
- Return ?
GetFunctionRealm (boundTargetFunction).
- If obj is a
Proxy exotic object , then- Perform ?
ValidateNonRevokedProxy (obj). - Let proxyTarget be obj.[[ProxyTarget]].
- Return ?
GetFunctionRealm (proxyTarget).
- Perform ?
- Return
the current Realm Record .
Step
7.3.26 CopyDataProperties ( target, source, excludedItems )
The abstract operation CopyDataProperties takes arguments target (an Object), source (an
- If source is either
undefined ornull , returnunused . - Let from be !
ToObject (source). - Let keys be ? from.[[OwnPropertyKeys]]().
- For each element nextKey of keys, do
- Let excluded be
false . - For each element e of excludedItems, do
- If
SameValue (e, nextKey) istrue , then- Set excluded to
true .
- Set excluded to
- If
- If excluded is
false , then- Let desc be ? from.[[GetOwnProperty]](nextKey).
- If desc is not
undefined and desc.[[Enumerable]] istrue , then- Let propValue be ?
Get (from, nextKey). - Perform !
CreateDataPropertyOrThrow (target, nextKey, propValue).
- Let propValue be ?
- Let excluded be
- Return
unused .
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
- If O.[[PrivateElements]] contains a
PrivateElement pe such that pe.[[Key]] is P, then- Return pe.
- Return
empty .
7.3.28 PrivateFieldAdd ( O, P, value )
The abstract operation PrivateFieldAdd takes arguments O (an Object), P (a
- If the
host is a web browser, then- Perform ?
HostEnsureCanAddPrivateElement (O).
- Perform ?
- Let entry be
PrivateElementFind (O, P). - If entry is not
empty , throw aTypeError exception. - Append
PrivateElement { [[Key]]: P, [[Kind]]:field , [[Value]]: value } to O.[[PrivateElements]]. - Return
unused .
7.3.29 PrivateMethodOrAccessorAdd ( O, method )
The abstract operation PrivateMethodOrAccessorAdd takes arguments O (an Object) and method (a
Assert : method.[[Kind]] is eithermethod oraccessor .- If the
host is a web browser, then- Perform ?
HostEnsureCanAddPrivateElement (O).
- Perform ?
- Let entry be
PrivateElementFind (O, method.[[Key]]). - If entry is not
empty , throw aTypeError exception. - Append method to O.[[PrivateElements]].
- Return
unused .
The values for private methods and accessors are shared across instances. This operation does not create a new copy of the method or accessor.
7.3.30 HostEnsureCanAddPrivateElement ( O )
The
An implementation of HostEnsureCanAddPrivateElement must conform to the following requirements:
- If O is not a
host-defined exotic object , this abstract operation must returnNormalCompletion (unused ) and perform no other steps. - Any two calls of this abstract operation with the same argument must return the same kind of
Completion Record .
The default implementation of HostEnsureCanAddPrivateElement is to return
This abstract operation is only invoked by ECMAScript
7.3.31 PrivateGet ( O, P )
The abstract operation PrivateGet takes arguments O (an Object) and P (a
- Let entry be
PrivateElementFind (O, P). - If entry is
empty , throw aTypeError exception. - If entry.[[Kind]] is either
field ormethod , then- Return entry.[[Value]].
Assert : entry.[[Kind]] isaccessor .- If entry.[[Get]] is
undefined , throw aTypeError exception. - Let getter be entry.[[Get]].
- Return ?
Call (getter, O).
7.3.32 PrivateSet ( O, P, value )
The abstract operation PrivateSet takes arguments O (an Object), P (a
- Let entry be
PrivateElementFind (O, P). - If entry is
empty , throw aTypeError exception. - If entry.[[Kind]] is
field , then- Set entry.[[Value]] to value.
- Else if entry.[[Kind]] is
method , then- Throw a
TypeError exception.
- Throw a
- Else,
- Return
unused .
7.3.33 DefineField ( receiver, fieldRecord )
The abstract operation DefineField takes arguments receiver (an Object) and fieldRecord (a
- Let fieldName be fieldRecord.[[Name]].
- Let initializer be fieldRecord.[[Initializer]].
- If initializer is not
empty , then- Let initValue be ?
Call (initializer, receiver).
- Let initValue be ?
- Else,
- Let initValue be
undefined .
- Let initValue be
- If fieldName is a
Private Name , then- Perform ?
PrivateFieldAdd (receiver, fieldName, initValue).
- Perform ?
- Else,
Assert :IsPropertyKey (fieldName) istrue .- Perform ?
CreateDataPropertyOrThrow (receiver, fieldName, initValue).
- Return
unused .
7.3.34 InitializeInstanceElements ( O, constructor )
The abstract operation InitializeInstanceElements takes arguments O (an Object) and constructor (an ECMAScript
- Let methods be the value of constructor.[[PrivateMethods]].
- For each
PrivateElement method of methods, do- Perform ?
PrivateMethodOrAccessorAdd (O, method).
- Perform ?
- Let fields be the value of constructor.[[Fields]].
- For each element fieldRecord of fields, do
- Perform ?
DefineField (O, fieldRecord).
- Perform ?
- Return
unused .
7.3.35 AddValueToKeyedGroup ( groups, key, value )
The abstract operation AddValueToKeyedGroup takes arguments groups (a
7.3.36 GroupBy ( items, callbackfn, keyCoercion )
The abstract operation GroupBy takes arguments items (an
- Perform ?
RequireObjectCoercible (items). - If
IsCallable (callbackfn) isfalse , throw aTypeError exception. - Let groups be a new empty
List . - Let iteratorRecord be ?
GetIterator (items,sync ). - Let k be 0.
- Repeat,
- If k ≥ 253 - 1, then
- Let error be
ThrowCompletion (a newly createdTypeError object). - Return ?
IteratorClose (iteratorRecord, error).
- Let error be
- Let next be ?
IteratorStepValue (iteratorRecord). - If next is
done , then- Return groups.
- Let value be next.
- Let key be
Completion (Call (callbackfn,undefined , « value,𝔽 (k) »)). IfAbruptCloseIterator (key, iteratorRecord).- If keyCoercion is
property , then- Set key to
Completion (ToPropertyKey (key)). IfAbruptCloseIterator (key, iteratorRecord).
- Set key to
- Else,
Assert : keyCoercion iszero .- If key is
-0 𝔽, set key to+0 𝔽.
- Perform
AddValueToKeyedGroup (groups, key, value). - Set k to k + 1.
- If k ≥ 253 - 1, then