20 Fundamental Objects
20.1 Object Objects
20.1.1 The Object Constructor
The Object
- is
%Object% . - is the initial value of the
"Object" property of theglobal object . - creates a new
ordinary object when called as aconstructor . - performs a type conversion when called as a function rather than as a
constructor . - may be used as the value of an
extendsclause of a class definition.
20.1.1.1 Object ( value )
This function performs the following steps when called:
- If NewTarget is neither
undefined nor theactive function object , then- Return ?
OrdinaryCreateFromConstructor (NewTarget," ).%Object.prototype% "
- Return ?
- If value is either
undefined ornull , returnOrdinaryObjectCreate (%Object.prototype% ). - Return !
ToObject (value).
20.1.2 Properties of the Object Constructor
The Object
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following additional properties:
20.1.2.1 Object.assign ( target, ...sources )
This function copies the values of all of the enumerable own properties from one or more source objects to a target object.
It performs the following steps when called:
The
20.1.2.2 Object.create ( proto, properties )
This function creates a new object with a specified prototype.
It performs the following steps when called:
- If proto
is not an Object and proto is notnull , throw aTypeError exception. - Let obj be
OrdinaryObjectCreate (proto). - If properties is not
undefined , then- Return ?
ObjectDefineProperties (obj, properties).
- Return ?
- Return obj.
20.1.2.3 Object.defineProperties ( obj, properties )
This function adds own properties and/or updates the attributes of existing own properties of an object.
It performs the following steps when called:
- If obj
is not an Object , throw aTypeError exception. - Return ?
ObjectDefineProperties (obj, properties).
20.1.2.3.1 ObjectDefineProperties ( obj, properties )
The abstract operation ObjectDefineProperties takes arguments obj (an Object) and properties (an
- Set properties to ?
ToObject (properties). - Let keys be ?
properties.[[OwnPropertyKeys]]() . - Let propertyDescs be a new empty
List . - For each element nextKey of keys, do
- Let currentPropertyDesc be ?
properties.[[GetOwnProperty]](nextKey) . - If currentPropertyDesc is not
undefined and currentPropertyDesc.[[Enumerable]] istrue , then- Let propertyDescObj be ?
Get (properties, nextKey). - Let propertyDesc be ?
ToPropertyDescriptor (propertyDescObj). - Append the
Record { [[Key]]: nextKey, [[Descriptor]]: propertyDesc } to propertyDescs.
- Let propertyDescObj be ?
- Let currentPropertyDesc be ?
- For each element property of propertyDescs, do
- Perform ?
DefinePropertyOrThrow (obj, property.[[Key]], property.[[Descriptor]]).
- Perform ?
- Return obj.
20.1.2.4 Object.defineProperty ( obj, key, attrs )
This function adds an own property and/or updates the attributes of an existing own property of an object.
It performs the following steps when called:
- If obj
is not an Object , throw aTypeError exception. - Let propertyKey be ?
ToPropertyKey (key). - Let propertyDesc be ?
ToPropertyDescriptor (attrs). - Perform ?
DefinePropertyOrThrow (obj, propertyKey, propertyDesc). - Return obj.
20.1.2.5 Object.entries ( obj )
This function performs the following steps when called:
- Let coerced be ?
ToObject (obj). - Let entryList be ?
EnumerableOwnProperties (coerced,key+value ). - Return
CreateArrayFromList (entryList).
20.1.2.6 Object.freeze ( obj )
This function performs the following steps when called:
- If obj
is not an Object , return obj. - Let status be ?
SetIntegrityLevel (obj,frozen ). - If status is
false , throw aTypeError exception. - Return obj.
20.1.2.7 Object.fromEntries ( iterable )
This function performs the following steps when called:
- Perform ?
RequireObjectCoercible (iterable). - Let obj be
OrdinaryObjectCreate (%Object.prototype% ). Assert : obj is an extensibleordinary object with no own properties.- Let closure be a new
Abstract Closure with parameters (key, value) that captures obj and performs the following steps when called:- Let propertyKey be ?
ToPropertyKey (key). - Perform !
CreateDataPropertyOrThrow (obj, propertyKey, value). - Return
NormalCompletion (undefined ).
- Let propertyKey be ?
- Let adder be
CreateBuiltinFunction (closure, 2,"" , « »). - Return ?
AddEntriesFromIterable (obj, iterable, adder).
20.1.2.8 Object.getOwnPropertyDescriptor ( obj, key )
This function performs the following steps when called:
- Let coerced be ?
ToObject (obj). - Let propertyKey be ?
ToPropertyKey (key). - Let propertyDesc be ?
coerced.[[GetOwnProperty]](propertyKey) . - Return
FromPropertyDescriptor (propertyDesc).
20.1.2.9 Object.getOwnPropertyDescriptors ( obj )
This function performs the following steps when called:
- Let coerced be ?
ToObject (obj). - Let ownKeys be ?
coerced.[[OwnPropertyKeys]]() . - Let descs be
OrdinaryObjectCreate (%Object.prototype% ). - For each element key of ownKeys, do
- Let propertyDesc be ?
coerced.[[GetOwnProperty]](key) . - Let propertyDescObj be
FromPropertyDescriptor (propertyDesc). - If propertyDescObj is not
undefined , perform !CreateDataPropertyOrThrow (descs, key, propertyDescObj).
- Let propertyDesc be ?
- Return descs.
20.1.2.10 Object.getOwnPropertyNames ( obj )
This function performs the following steps when called:
- Return
CreateArrayFromList (?GetOwnPropertyKeys (obj,string )).
20.1.2.11 Object.getOwnPropertySymbols ( obj )
This function performs the following steps when called:
- Return
CreateArrayFromList (?GetOwnPropertyKeys (obj,symbol )).
20.1.2.11.1 GetOwnPropertyKeys ( value, type )
The abstract operation GetOwnPropertyKeys takes arguments value (an
- Let obj be ?
ToObject (value). - Let keys be ?
obj.[[OwnPropertyKeys]]() . - Let nameList be a new empty
List . - For each element nextKey of keys, do
- If nextKey
is a Symbol and type issymbol , or if nextKeyis a String and type isstring , then- Append nextKey to nameList.
- If nextKey
- Return nameList.
20.1.2.12 Object.getPrototypeOf ( obj )
This function performs the following steps when called:
- Let coerced be ?
ToObject (obj). - Return ?
coerced.[[GetPrototypeOf]]() .
20.1.2.13 Object.groupBy ( items, callback )
callback should be a function that accepts two arguments. groupBy calls callback once for each element in items, in ascending order, and constructs a new object. Each value returned by callback is coerced to a
callback is called with two arguments: the value of the element and the index of the element.
The return value of groupBy is an object that does not inherit from
This function performs the following steps when called:
- Let groups be ?
GroupBy (items, callback,property ). - Let obj be
OrdinaryObjectCreate (null ). - For each
Record { [[Key]], [[Elements]] } g of groups, do- Let elements be
CreateArrayFromList (g.[[Elements]]). - Perform !
CreateDataPropertyOrThrow (obj, g.[[Key]], elements).
- Let elements be
- Return obj.
20.1.2.14 Object.hasOwn ( obj, key )
This function performs the following steps when called:
- Let coerced be ?
ToObject (obj). - Let propertyKey be ?
ToPropertyKey (key). - Return ?
HasOwnProperty (coerced, propertyKey).
20.1.2.15 Object.is ( value1, value2 )
This function performs the following steps when called:
- Return
SameValue (value1, value2).
20.1.2.16 Object.isExtensible ( obj )
This function performs the following steps when called:
- If obj
is not an Object , returnfalse . - Return ?
IsExtensible (obj).
20.1.2.17 Object.isFrozen ( obj )
This function performs the following steps when called:
- If obj
is not an Object , returntrue . - Return ?
TestIntegrityLevel (obj,frozen ).
20.1.2.18 Object.isSealed ( obj )
This function performs the following steps when called:
- If obj
is not an Object , returntrue . - Return ?
TestIntegrityLevel (obj,sealed ).
20.1.2.19 Object.keys ( obj )
This function performs the following steps when called:
- Let coerced be ?
ToObject (obj). - Let keyList be ?
EnumerableOwnProperties (coerced,key ). - Return
CreateArrayFromList (keyList).
20.1.2.20 Object.preventExtensions ( obj )
This function performs the following steps when called:
- If obj
is not an Object , return obj. - Let status be ?
obj.[[PreventExtensions]]() . - If status is
false , throw aTypeError exception. - Return obj.
20.1.2.21 Object.prototype
The initial value of Object.prototype is the
This property has the attributes { [[Writable]]:
20.1.2.22 Object.seal ( obj )
This function performs the following steps when called:
- If obj
is not an Object , return obj. - Let status be ?
SetIntegrityLevel (obj,sealed ). - If status is
false , throw aTypeError exception. - Return obj.
20.1.2.23 Object.setPrototypeOf ( obj, proto )
This function performs the following steps when called:
- Perform ?
RequireObjectCoercible (obj). - If proto
is not an Object and proto is notnull , throw aTypeError exception. - If obj
is not an Object , return obj. - Let status be ?
obj.[[SetPrototypeOf]](proto) . - If status is
false , throw aTypeError exception. - Return obj.
20.1.2.24 Object.values ( obj )
This function performs the following steps when called:
- Let coerced be ?
ToObject (obj). - Let valueList be ?
EnumerableOwnProperties (coerced,value ). - Return
CreateArrayFromList (valueList).
20.1.3 Properties of the Object Prototype Object
The Object prototype object:
- is
%Object.prototype% . - has an [[Extensible]] internal slot whose value is
true . - has the internal methods defined for
ordinary objects , except for the [[SetPrototypeOf]] method, which is as defined in10.4.7.1 . (Thus, it is animmutable prototype exotic object .) - has a [[Prototype]] internal slot whose value is
null .
20.1.3.1 Object.prototype.constructor
The initial value of Object.prototype.constructor is
20.1.3.2 Object.prototype.hasOwnProperty ( value )
This method performs the following steps when called:
- Let propertyKey be ?
ToPropertyKey (value). - Let obj be ?
ToObject (this value). - Return ?
HasOwnProperty (obj, propertyKey).
20.1.3.3 Object.prototype.isPrototypeOf ( value )
This method performs the following steps when called:
- If value
is not an Object , returnfalse . - Let obj be ?
ToObject (this value). - Repeat,
- Set value to ?
value.[[GetPrototypeOf]]() . - If value is
null , returnfalse . - If
SameValue (obj, value) istrue , returntrue .
- Set value to ?
20.1.3.4 Object.prototype.propertyIsEnumerable ( value )
This method performs the following steps when called:
- Let propertyKey be ?
ToPropertyKey (value). - Let obj be ?
ToObject (this value). - Let propertyDesc be ?
obj.[[GetOwnProperty]](propertyKey) . - If propertyDesc is
undefined , returnfalse . - Return propertyDesc.[[Enumerable]].
This method does not consider objects in the prototype chain.
20.1.3.5 Object.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
This method performs the following steps when called:
- Let thisValue be the
this value. - Return ?
Invoke (thisValue,"toString" ).
The optional parameters to this method are not used but are intended to correspond to the parameter pattern used by ECMA-402 toLocaleString methods. Implementations that do not include ECMA-402 support must not use those parameter positions for other purposes.
This method provides a generic toLocaleString implementation for objects that have no locale-sensitive toString behaviour. Array, Number, Date, and toLocaleString methods.
ECMA-402 intentionally does not provide an alternative to this default implementation.
20.1.3.6 Object.prototype.toString ( )
This method performs the following steps when called:
- If the
this value isundefined , return"[object Undefined]" . - If the
this value isnull , return"[object Null]" . - Let obj be !
ToObject (this value). - Let isArray be ?
IsArray (obj). - If isArray is
true , let builtinTag be"Array" . - Else if obj has a [[ParameterMap]] internal slot, let builtinTag be
"Arguments" . - Else if obj has a [[Call]] internal method, let builtinTag be
"Function" . - Else if obj has an [[ErrorData]] internal slot, let builtinTag be
"Error" . - Else if obj has a [[BooleanData]] internal slot, let builtinTag be
"Boolean" . - Else if obj has a [[NumberData]] internal slot, let builtinTag be
"Number" . - Else if obj has a [[StringData]] internal slot, let builtinTag be
"String" . - Else if obj has a [[DateValue]] internal slot, let builtinTag be
"Date" . - Else if obj has a [[RegExpMatcher]] internal slot, let builtinTag be
"RegExp" . - Else, let builtinTag be
"Object" . - Let tag be ?
Get (obj,%Symbol.toStringTag% ). - If tag
is not a String , set tag to builtinTag. - Return the
string-concatenation of"[object " , tag, and"]" .
Historically, this method was occasionally used to access the String value of the [[Class]] internal slot that was used in previous editions of this specification as a nominal type tag for various built-in objects. The above definition of toString preserves compatibility for legacy code that uses toString as a test for those specific kinds of built-in objects. It does not provide a reliable type testing mechanism for other kinds of built-in or program defined objects. In addition, programs can use
20.1.3.7 Object.prototype.valueOf ( )
This method performs the following steps when called:
- Return ?
ToObject (this value).
20.1.3.8 Object.prototype.__proto__
Object.prototype.__proto__ is an
20.1.3.8.1 get Object.prototype.__proto__
The value of the [[Get]] attribute is a built-in function that requires no arguments. It performs the following steps when called:
- Let obj be ?
ToObject (this value). - Return ?
obj.[[GetPrototypeOf]]() .
20.1.3.8.2 set Object.prototype.__proto__
The value of the [[Set]] attribute is a built-in function that takes an argument proto. It performs the following steps when called:
- Let thisValue be the
this value. - Perform ?
RequireObjectCoercible (thisValue). - If proto
is not an Object and proto is notnull , returnundefined . - If thisValue
is not an Object , returnundefined . - Let status be ?
thisValue.[[SetPrototypeOf]](proto) . - If status is
false , throw aTypeError exception. - Return
undefined .
20.1.3.9 Legacy Object.prototype Accessor Methods
20.1.3.9.1 Object.prototype.__defineGetter__ ( key, getter )
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - If
IsCallable (getter) isfalse , throw aTypeError exception. - Let propertyDesc be PropertyDescriptor { [[Get]]: getter, [[Enumerable]]:
true , [[Configurable]]:true }. - Let propertyKey be ?
ToPropertyKey (key). - Perform ?
DefinePropertyOrThrow (obj, propertyKey, propertyDesc). - Return
undefined .
20.1.3.9.2 Object.prototype.__defineSetter__ ( key, setter )
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - If
IsCallable (setter) isfalse , throw aTypeError exception. - Let propertyDesc be PropertyDescriptor { [[Set]]: setter, [[Enumerable]]:
true , [[Configurable]]:true }. - Let propertyKey be ?
ToPropertyKey (key). - Perform ?
DefinePropertyOrThrow (obj, propertyKey, propertyDesc). - Return
undefined .
20.1.3.9.3 Object.prototype.__lookupGetter__ ( key )
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let propertyKey be ?
ToPropertyKey (key). - Repeat,
- Let propertyDesc be ?
obj.[[GetOwnProperty]](propertyKey) . - If propertyDesc is not
undefined , then- If
IsAccessorDescriptor (propertyDesc) istrue , return propertyDesc.[[Get]]. - Return
undefined .
- If
- Set obj to ?
obj.[[GetPrototypeOf]]() . - If obj is
null , returnundefined .
- Let propertyDesc be ?
20.1.3.9.4 Object.prototype.__lookupSetter__ ( key )
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let propertyKey be ?
ToPropertyKey (key). - Repeat,
- Let propertyDesc be ?
obj.[[GetOwnProperty]](propertyKey) . - If propertyDesc is not
undefined , then- If
IsAccessorDescriptor (propertyDesc) istrue , return propertyDesc.[[Set]]. - Return
undefined .
- If
- Set obj to ?
obj.[[GetPrototypeOf]]() . - If obj is
null , returnundefined .
- Let propertyDesc be ?
20.1.4 Properties of Object Instances
Object instances have no special properties beyond those inherited from the
20.2 Function Objects
20.2.1 The Function Constructor
The Function
- is
%Function% . - is the initial value of the
"Function" property of theglobal object . - creates and initializes a new
function object when called as a function rather than as aconstructor . Thus the function callFunction(…)is equivalent to the object creation expressionnew Function(…)with the same arguments. - may be used as the value of an
extendsclause of a class definition. Subclassconstructors that intend to inherit the specified Function behaviour must include asupercall to the Functionconstructor to create and initialize a subclass instance with the internal slots necessary for built-in function behaviour. All ECMAScript syntactic forms for definingfunction objects create instances of Function. There is no syntactic means to create instances of Function subclasses except for the built-in GeneratorFunction, AsyncFunction, and AsyncGeneratorFunction subclasses.
20.2.1.1 Function ( ...paramArgs, bodyArg )
The last argument (if any) specifies the body (executable code) of a function; any preceding arguments specify formal parameters.
This function performs the following steps when called:
- Let ctor be the
active function object . - If bodyArg is not present, set bodyArg to the empty String.
- Return ?
CreateDynamicFunction (ctor, NewTarget,normal , paramArgs, bodyArg).
It is permissible but not necessary to have one argument for each formal parameter to be specified. For example, all three of the following expressions produce the same result:
new Function("a", "b", "c", "return a+b+c")
new Function("a, b, c", "return a+b+c")
new Function("a,b", "c", "return a+b+c")
20.2.1.1.1 CreateDynamicFunction ( ctor, newTarget, kind, paramArgs, bodyArg )
The abstract operation CreateDynamicFunction takes arguments ctor (a new was initially applied to. paramArgs and bodyArg reflect the argument values that were passed to ctor. It performs the following steps when called:
- If newTarget is
undefined , set newTarget to ctor. - If kind is
normal , then- Let prefix be
"function" . - Let exprGrammar be the grammar symbol
FunctionExpression . - Let bodyGrammar be the grammar symbol
FunctionBody .[~ Yield , ~Await ] - Let paramGrammar be the grammar symbol
FormalParameters .[~ Yield , ~Await ] - Let fallbackProto be
" .%Function.prototype% "
- Let prefix be
- Else if kind is
generator , then- Let prefix be
"function*" . - Let exprGrammar be the grammar symbol
GeneratorExpression . - Let bodyGrammar be the grammar symbol
GeneratorBody . - Let paramGrammar be the grammar symbol
FormalParameters .[+ Yield , ~Await ] - Let fallbackProto be
" .%GeneratorFunction.prototype% "
- Let prefix be
- Else if kind is
async , then- Let prefix be
"async function" . - Let exprGrammar be the grammar symbol
AsyncFunctionExpression . - Let bodyGrammar be the grammar symbol
AsyncFunctionBody . - Let paramGrammar be the grammar symbol
FormalParameters .[~ Yield , +Await ] - Let fallbackProto be
" .%AsyncFunction.prototype% "
- Let prefix be
- Else,
Assert : kind isasync-generator .- Let prefix be
"async function*" . - Let exprGrammar be the grammar symbol
AsyncGeneratorExpression . - Let bodyGrammar be the grammar symbol
AsyncGeneratorBody . - Let paramGrammar be the grammar symbol
FormalParameters .[+ Yield , +Await ] - Let fallbackProto be
" .%AsyncGeneratorFunction.prototype% "
- Let argCount be the number of elements in paramArgs.
- Let paramStrings be a new empty
List . - For each element arg of paramArgs, do
- Append ?
ToString (arg) to paramStrings.
- Append ?
- Let bodyString be ?
ToString (bodyArg). - Let currentRealm be
the current Realm Record . - Perform ?
HostEnsureCanCompileStrings (currentRealm, paramStrings, bodyString,false ). - Let paramString be the empty String.
- If argCount > 0, then
- Set paramString to paramStrings[0].
- Let k be 1.
- Repeat, while k < argCount,
- Let nextArgString be paramStrings[k].
- Set paramString to the
string-concatenation of paramString,"," (a comma), and nextArgString. - Set k to k + 1.
- Let bodyParseString be the
string-concatenation of 0x000A (LINE FEED), bodyString, and 0x000A (LINE FEED). - Let sourceString be the
string-concatenation of prefix," anonymous(" , paramString, 0x000A (LINE FEED),") {" , bodyParseString, and"}" . - Let sourceText be
StringToCodePoints (sourceString). - Let params be
ParseText (paramString, paramGrammar). - If params is a
List of errors, throw aSyntaxError exception. - Let body be
ParseText (bodyParseString, bodyGrammar). - If body is a
List of errors, throw aSyntaxError exception. NOTE : The parameters and body are parsed separately to ensure that each is valid alone. For example,new Function("/*", "*/ ) {")does not evaluate to a function.NOTE : If this step is reached, sourceText must have the syntax of exprGrammar (although the reverse implication does not hold). The purpose of the next two steps is to enforce any Early Error rules which apply to exprGrammar directly.- Let expr be
ParseText (sourceText, exprGrammar). - If expr is a
List of errors, throw aSyntaxError exception. - Let funcProto be ?
GetPrototypeFromConstructor (newTarget, fallbackProto). - Let envRecord be currentRealm.[[GlobalEnv]].
- Let privateEnv be
null . - Let func be
OrdinaryFunctionCreate (funcProto, sourceText, params, body,non-lexical-this , envRecord, privateEnv). - Perform
SetFunctionName (func,"anonymous" ). - If kind is
generator , then- Let protoProto be
OrdinaryObjectCreate (%GeneratorPrototype% ). - Perform !
DefinePropertyOrThrow (func,"prototype" , PropertyDescriptor { [[Value]]: protoProto, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }).
- Let protoProto be
- Else if kind is
async-generator , then- Let protoProto be
OrdinaryObjectCreate (%AsyncGeneratorPrototype% ). - Perform !
DefinePropertyOrThrow (func,"prototype" , PropertyDescriptor { [[Value]]: protoProto, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }).
- Let protoProto be
- Else if kind is
normal , then- Perform
MakeConstructor (func).
- Perform
NOTE : Functions whose kind isasync are not constructable and do not have a [[Construct]] internal method or a"prototype" property.- Return func.
CreateDynamicFunction defines a
20.2.2 Properties of the Function Constructor
The Function
- is itself a built-in
function object . - has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has a
"length" property whose value is1 𝔽. - has the following properties:
20.2.2.1 Function.prototype
The value of Function.prototype is the
This property has the attributes { [[Writable]]:
20.2.3 Properties of the Function Prototype Object
The Function prototype object:
- is
%Function.prototype% . - is itself a built-in
function object . - accepts any arguments and returns
undefined when invoked. - does not have a [[Construct]] internal method; it cannot be used as a
constructor with thenewoperator. - has a [[Prototype]] internal slot whose value is
%Object.prototype% . - does not have a
"prototype" property. - has a
"length" property whose value is+0 𝔽. - has a
"name" property whose value is the empty String.
The Function prototype object is specified to be a
20.2.3.1 Function.prototype.apply ( thisArg, argArray )
This method performs the following steps when called:
- Let func be the
this value. - If
IsCallable (func) isfalse , throw aTypeError exception. - If argArray is either
undefined ornull , then- Perform
PrepareForTailCall (). - Return ?
Call (func, thisArg).
- Perform
- Let argList be ?
CreateListFromArrayLike (argArray). - Perform
PrepareForTailCall (). - Return ?
Call (func, thisArg, argList).
The thisArg value is passed without modification as the
If func is either an arrow function or a
20.2.3.2 Function.prototype.bind ( thisArg, ...args )
This method performs the following steps when called:
- Let target be the
this value. - If
IsCallable (target) isfalse , throw aTypeError exception. - Let boundFunc be ?
BoundFunctionCreate (target, thisArg, args). - Let length be 0.
- Let targetHasLength be ?
HasOwnProperty (target,"length" ). - If targetHasLength is
true , then- Let targetLength be ?
Get (target,"length" ). - If targetLength
is a Number , then- If targetLength is
+∞ 𝔽, then- Set length to +∞.
- Else if targetLength is
-∞ 𝔽, then- Set length to 0.
- Else,
- Let targetLengthAsInt be !
ToIntegerOrInfinity (targetLength). Assert : targetLengthAsInt isfinite .- Let argCount be the number of elements in args.
- Set length to
max (targetLengthAsInt - argCount, 0).
- Let targetLengthAsInt be !
- If targetLength is
- Let targetLength be ?
- Perform
SetFunctionLength (boundFunc, length). - Let targetName be ?
Get (target,"name" ). - If targetName
is not a String , set targetName to the empty String. - Perform
SetFunctionName (boundFunc, targetName,"bound" ). - Return boundFunc.
Function.prototype.bind are
If target is either an arrow function or a
20.2.3.3 Function.prototype.call ( thisArg, ...args )
This method performs the following steps when called:
- Let func be the
this value. - If
IsCallable (func) isfalse , throw aTypeError exception. - Perform
PrepareForTailCall (). - Return ?
Call (func, thisArg, args).
The thisArg value is passed without modification as the
If func is either an arrow function or a
20.2.3.4 Function.prototype.constructor
The initial value of Function.prototype.constructor is
20.2.3.5 Function.prototype.toString ( )
This method performs the following steps when called:
- Let func be the
this value. - If func
is an Object , func has a [[SourceText]] internal slot, func.[[SourceText]] is a sequence of Unicode code points, andHostHasSourceTextAvailable (func) istrue , then- Return
CodePointsToString (func.[[SourceText]]).
- Return
- If func is a
built-in function object , return animplementation-defined String source code representation of func. The representation must have the syntax of aNativeFunction . Additionally, if func has an [[InitialName]] internal slot and func.[[InitialName]]is a String , the portion of the returned String that would be matched byNativeFunctionAccessor opt PropertyName must be func.[[InitialName]]. - If func
is an Object andIsCallable (func) istrue , return animplementation-defined String source code representation of func. The representation must have the syntax of aNativeFunction . - Throw a
TypeError exception.
20.2.3.6 Function.prototype [ %Symbol.hasInstance% ] ( value )
This method performs the following steps when called:
- Let thisValue be the
this value. - Return ?
OrdinaryHasInstance (thisValue, value).
This property has the attributes { [[Writable]]:
This is the default implementation of %Symbol.hasInstance% that most functions inherit. %Symbol.hasInstance% is called by the instanceof operator to determine whether a value is an instance of a specific
v instanceof F
evaluates as
F[%Symbol.hasInstance%](v)
A instanceof by exposing a different %Symbol.hasInstance% method on the function.
This property is non-writable and non-configurable to prevent tampering that could be used to globally expose the target function of a bound function.
The value of the
20.2.4 Function Instances
Every Function instance is an ECMAScript Function.prototype.bind method (
Function instances have the following properties:
20.2.4.1 length
The value of the
20.2.4.2 name
The value of the
Anonymous
20.2.4.3 prototype
Function instances that can be used as a
This property has the attributes { [[Writable]]:
Function.prototype.bind, or by evaluating a
20.2.5 HostHasSourceTextAvailable ( func )
The
An implementation of HostHasSourceTextAvailable must conform to the following requirements:
- It must be deterministic with respect to its parameters. Each time it is called with a specific func as its argument, it must return the same result.
The default implementation of HostHasSourceTextAvailable is to return
20.3 Boolean Objects
20.3.1 The Boolean Constructor
The Boolean
- is
%Boolean% . - is the initial value of the
"Boolean" property of theglobal object . - creates and initializes a new Boolean object when called as a
constructor . - performs a type conversion when called as a function rather than as a
constructor . - may be used as the value of an
extendsclause of a class definition. Subclassconstructors that intend to inherit the specified Boolean behaviour must include asupercall to the Booleanconstructor to create and initialize the subclass instance with a [[BooleanData]] internal slot.
20.3.1.1 Boolean ( value )
This function performs the following steps when called:
- Let bool be
ToBoolean (value). - If NewTarget is
undefined , return bool. - Let obj be ?
OrdinaryCreateFromConstructor (NewTarget," , « [[BooleanData]] »).%Boolean.prototype% " - Set obj.[[BooleanData]] to bool.
- Return obj.
20.3.2 Properties of the Boolean Constructor
The Boolean
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
20.3.2.1 Boolean.prototype
The initial value of Boolean.prototype is the
This property has the attributes { [[Writable]]:
20.3.3 Properties of the Boolean Prototype Object
The Boolean prototype object:
- is
%Boolean.prototype% . - is an
ordinary object . - is itself a Boolean object; it has a [[BooleanData]] internal slot with the value
false . - has a [[Prototype]] internal slot whose value is
%Object.prototype% .
20.3.3.1 Boolean.prototype.constructor
The initial value of Boolean.prototype.constructor is
20.3.3.2 Boolean.prototype.toString ( )
This method performs the following steps when called:
- Let bool be ?
ThisBooleanValue (this value). - If bool is
true , return"true" . - Return
"false" .
20.3.3.3 Boolean.prototype.valueOf ( )
This method performs the following steps when called:
- Return ?
ThisBooleanValue (this value).
20.3.3.3.1 ThisBooleanValue ( arg )
The abstract operation ThisBooleanValue takes argument arg (an
- If arg
is a Boolean , return arg. - If arg
is an Object and arg has a [[BooleanData]] internal slot, then- Let bool be arg.[[BooleanData]].
Assert : boolis a Boolean .- Return bool.
- Throw a
TypeError exception.
20.3.4 Properties of Boolean Instances
Boolean instances are
20.4 Symbol Objects
20.4.1 The Symbol Constructor
The Symbol
- is
%Symbol% . - is the initial value of the
"Symbol" property of theglobal object . - returns a new Symbol value when called as a function.
- is not intended to be used with the
newoperator. - is not intended to be subclassed.
- may be used as the value of an
extendsclause of a class definition but asupercall to it will cause an exception.
20.4.1.1 Symbol ( [ description ] )
This function performs the following steps when called:
- If NewTarget is not
undefined , throw aTypeError exception. - If description is
undefined , let descString beundefined . - Else, let descString be ?
ToString (description). - Return a new Symbol whose [[Description]] is descString.
20.4.2 Properties of the Symbol Constructor
The Symbol
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
20.4.2.1 Symbol.asyncIterator
The initial value of Symbol.asyncIterator is the well-known symbol
This property has the attributes { [[Writable]]:
20.4.2.2 Symbol.for ( key )
This function performs the following steps when called:
- Let stringKey be ?
ToString (key). - Let agentRecord be the
Agent Record of thesurrounding agent . - Let globalSymbolRegistry be agentRecord.[[GlobalSymbolRegistry]].
- For each element element of globalSymbolRegistry, do
- If element.[[Key]] is stringKey, return element.[[Symbol]].
Assert : globalSymbolRegistry does not currently contain an entry for stringKey.- Let newSymbol be a new Symbol whose [[Description]] is stringKey.
- Append the
GlobalSymbolRegistry Record { [[Key]]: stringKey, [[Symbol]]: newSymbol } to globalSymbolRegistry. - Return newSymbol.
20.4.2.3 Symbol.hasInstance
The initial value of Symbol.hasInstance is the well-known symbol
This property has the attributes { [[Writable]]:
20.4.2.4 Symbol.isConcatSpreadable
The initial value of Symbol.isConcatSpreadable is the well-known symbol
This property has the attributes { [[Writable]]:
20.4.2.5 Symbol.iterator
The initial value of Symbol.iterator is the well-known symbol
This property has the attributes { [[Writable]]:
20.4.2.6 Symbol.keyFor ( symbol )
This function performs the following steps when called:
- If symbol
is not a Symbol , throw aTypeError exception. - Return
KeyForSymbol (symbol).
20.4.2.7 Symbol.match
The initial value of Symbol.match is the well-known symbol
This property has the attributes { [[Writable]]:
20.4.2.8 Symbol.matchAll
The initial value of Symbol.matchAll is the well-known symbol
This property has the attributes { [[Writable]]:
20.4.2.9 Symbol.prototype
The initial value of Symbol.prototype is the
This property has the attributes { [[Writable]]:
20.4.2.10 Symbol.replace
The initial value of Symbol.replace is the well-known symbol
This property has the attributes { [[Writable]]:
20.4.2.11 Symbol.search
The initial value of Symbol.search is the well-known symbol
This property has the attributes { [[Writable]]:
20.4.2.12 Symbol.species
The initial value of Symbol.species is the well-known symbol
This property has the attributes { [[Writable]]:
20.4.2.13 Symbol.split
The initial value of Symbol.split is the well-known symbol
This property has the attributes { [[Writable]]:
20.4.2.14 Symbol.toPrimitive
The initial value of Symbol.toPrimitive is the well-known symbol
This property has the attributes { [[Writable]]:
20.4.2.15 Symbol.toStringTag
The initial value of Symbol.toStringTag is the well-known symbol
This property has the attributes { [[Writable]]:
20.4.2.16 Symbol.unscopables
The initial value of Symbol.unscopables is the well-known symbol
This property has the attributes { [[Writable]]:
20.4.3 Properties of the Symbol Prototype Object
The Symbol prototype object:
- is
%Symbol.prototype% . - is an
ordinary object . is not a Symbol instance and does not have a [[SymbolData]] internal slot.- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
20.4.3.1 Symbol.prototype.constructor
The initial value of Symbol.prototype.constructor is
20.4.3.2 get Symbol.prototype.description
Symbol.prototype.description is an
- Let symbol be ?
ThisSymbolValue (this value). - Return symbol.[[Description]].
20.4.3.3 Symbol.prototype.toString ( )
This method performs the following steps when called:
- Let symbol be ?
ThisSymbolValue (this value). - Return
SymbolDescriptiveString (symbol).
20.4.3.3.1 SymbolDescriptiveString ( symbol )
The abstract operation SymbolDescriptiveString takes argument symbol (a Symbol) and returns a String. It performs the following steps when called:
- Let propertyDesc be symbol.[[Description]].
- If propertyDesc is
undefined , set propertyDesc to the empty String. Assert : propertyDescis a String .- Return the
string-concatenation of"Symbol(" , propertyDesc, and")" .
20.4.3.4 Symbol.prototype.valueOf ( )
This method performs the following steps when called:
- Return ?
ThisSymbolValue (this value).
20.4.3.4.1 ThisSymbolValue ( arg )
The abstract operation ThisSymbolValue takes argument arg (an
- If arg
is a Symbol , return arg. - If arg
is an Object and arg has a [[SymbolData]] internal slot, then- Let symbol be arg.[[SymbolData]].
Assert : symbolis a Symbol .- Return symbol.
- Throw a
TypeError exception.
20.4.3.5 Symbol.prototype [ %Symbol.toPrimitive% ] ( hint )
This method is called by ECMAScript language operators to convert a Symbol object to a primitive value.
It performs the following steps when called:
- Return ?
ThisSymbolValue (this value).
The argument is ignored.
This property has the attributes { [[Writable]]:
The value of the
20.4.3.6 Symbol.prototype [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
20.4.4 Properties of Symbol Instances
Symbol instances are
20.4.5 Abstract Operations for Symbols
20.4.5.1 GlobalSymbolRegistry Records
A GlobalSymbolRegistry Record is a
GlobalSymbolRegistry Records have the fields listed in
| Field Name | Value | Usage |
|---|---|---|
| [[Key]] | a String | A string key used to globally identify a Symbol. |
| [[Symbol]] | a Symbol | A symbol that can be retrieved from any |
20.4.5.2 KeyForSymbol ( symbol )
The abstract operation KeyForSymbol takes argument symbol (a Symbol) and returns a String or
- Let agentRecord be the
Agent Record of thesurrounding agent . - Let globalSymbolRegistry be agentRecord.[[GlobalSymbolRegistry]].
- For each element element of globalSymbolRegistry, do
- If
SameValue (element.[[Symbol]], symbol) istrue , return element.[[Key]].
- If
Assert : globalSymbolRegistry does not currently contain an entry for symbol.- Return
undefined .
20.5 Error Objects
Instances of Error objects are thrown as exceptions when runtime errors occur. The Error objects may also serve as base objects for user-defined exception classes.
When an ECMAScript implementation detects a runtime error, it throws a new instance of one of the NativeError objects defined in
20.5.1 The Error Constructor
The Error
- is
%Error% . - is the initial value of the
"Error" property of theglobal object . - creates and initializes a new Error object when called as a function rather than as a
constructor . Thus the function callError(…)is equivalent to the object creation expressionnew Error(…)with the same arguments. - may be used as the value of an
extendsclause of a class definition. Subclassconstructors that intend to inherit the specified Error behaviour must include asupercall to the Errorconstructor to create and initialize subclass instances with an [[ErrorData]] internal slot.
20.5.1.1 Error ( message [ , options ] )
This function performs the following steps when called:
- If NewTarget is
undefined , let newTarget be theactive function object ; else let newTarget be NewTarget. - Let obj be ?
OrdinaryCreateFromConstructor (newTarget," , « [[ErrorData]] »).%Error.prototype% " - If message is not
undefined , then- Let messageString be ?
ToString (message). - Perform
CreateNonEnumerableDataPropertyOrThrow (obj,"message" , messageString).
- Let messageString be ?
- Perform ?
InstallErrorCause (obj, options). - Return obj.
20.5.2 Properties of the Error Constructor
The Error
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has the following properties:
20.5.2.1 Error.isError ( arg )
This function performs the following steps when called:
- If arg
is not an Object , returnfalse . - If arg does not have an [[ErrorData]] internal slot, return
false . - Return
true .
20.5.2.2 Error.prototype
The initial value of Error.prototype is the
This property has the attributes { [[Writable]]:
20.5.3 Properties of the Error Prototype Object
The Error prototype object:
- is
%Error.prototype% . - is an
ordinary object . - is not an Error instance and does not have an [[ErrorData]] internal slot.
- has a [[Prototype]] internal slot whose value is
%Object.prototype% .
20.5.3.1 Error.prototype.constructor
The initial value of Error.prototype.constructor is
20.5.3.2 Error.prototype.message
The initial value of Error.prototype.message is the empty String.
20.5.3.3 Error.prototype.name
The initial value of Error.prototype.name is
20.5.3.4 Error.prototype.toString ( )
This method performs the following steps when called:
- Let obj be the
this value. - If obj
is not an Object , throw aTypeError exception. - Let name be ?
Get (obj,"name" ). - If name is
undefined , set name to"Error" ; else set name to ?ToString (name). - Let message be ?
Get (obj,"message" ). - If message is
undefined , set message to the empty String; else set message to ?ToString (message). - If name is the empty String, return message.
- If message is the empty String, return name.
- Return the
string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE), and message.
20.5.4 Properties of Error Instances
Error instances are Object.prototype.toString and Error.isError.
20.5.5 Native Error Types Used in This Standard
A new instance of one of the NativeError objects below or of the AggregateError object is thrown when a runtime error is detected. All NativeError objects share the same structure, as described in
20.5.5.1 EvalError
The EvalError
This exception is not currently used within this specification. This object remains for compatibility with previous editions of this specification.
20.5.5.2 RangeError
The RangeError
Indicates a value that is not in the set or range of allowable values.
20.5.5.3 ReferenceError
The ReferenceError
Indicate that an invalid reference has been detected.
20.5.5.4 SyntaxError
The SyntaxError
Indicates that a parsing error has occurred.
20.5.5.5 TypeError
The TypeError
TypeError is used to indicate an unsuccessful operation when none of the other NativeError objects are an appropriate indication of the failure cause.
20.5.5.6 URIError
The URIError
Indicates that one of the global URI handling functions was used in a way that is incompatible with its definition.
20.5.6 NativeError Object Structure
Each of these objects has the structure described below, differing only in the name used as the
For each error object, references to NativeError in the definition should be replaced with the appropriate error object name from
20.5.6.1 The NativeError Constructors
Each NativeError
- creates and initializes a new NativeError object when called as a function rather than as a
constructor . A call of the object as a function is equivalent to calling it as aconstructor with the same arguments. Thus the function callNativeError(…)is equivalent to the object creation expressionnew NativeError(…)with the same arguments. - may be used as the value of an
extendsclause of a class definition. Subclassconstructors that intend to inherit the specified NativeError behaviour must include asupercall to the NativeErrorconstructor to create and initialize subclass instances with an [[ErrorData]] internal slot.
20.5.6.1.1 NativeError ( message [ , options ] )
Each NativeError function performs the following steps when called:
- If NewTarget is
undefined , let newTarget be theactive function object ; else let newTarget be NewTarget. - Let obj be ?
OrdinaryCreateFromConstructor (newTarget,"%NativeError.prototype%" , « [[ErrorData]] »). - If message is not
undefined , then- Let messageString be ?
ToString (message). - Perform
CreateNonEnumerableDataPropertyOrThrow (obj,"message" , messageString).
- Let messageString be ?
- Perform ?
InstallErrorCause (obj, options). - Return obj.
The actual value of the string passed in step
20.5.6.2 Properties of the NativeError Constructors
Each NativeError
- has a [[Prototype]] internal slot whose value is
%Error% . - has a
"name" property whose value is the String value"NativeError" . - has the following properties:
20.5.6.2.1 NativeError.prototype
The initial value of NativeError.prototype is a NativeError prototype object (
This property has the attributes { [[Writable]]:
20.5.6.3 Properties of the NativeError Prototype Objects
Each NativeError prototype object:
- is an
ordinary object . - is not an Error instance and does not have an [[ErrorData]] internal slot.
- has a [[Prototype]] internal slot whose value is
%Error.prototype% .
20.5.6.3.1 NativeError.prototype.constructor
The initial value of the
20.5.6.3.2 NativeError.prototype.message
The initial value of the
20.5.6.3.3 NativeError.prototype.name
The initial value of the
20.5.6.4 Properties of NativeError Instances
NativeError instances are Object.prototype.toString (Error.isError (
20.5.7 AggregateError Objects
20.5.7.1 The AggregateError Constructor
The AggregateError
- is
%AggregateError% . - is the initial value of the
"AggregateError" property of theglobal object . - creates and initializes a new AggregateError object when called as a function rather than as a
constructor . Thus the function callAggregateError(…)is equivalent to the object creation expressionnew AggregateError(…)with the same arguments. - may be used as the value of an
extendsclause of a class definition. Subclassconstructors that intend to inherit the specified AggregateError behaviour must include asupercall to the AggregateErrorconstructor to create and initialize subclass instances with an [[ErrorData]] internal slot.
20.5.7.1.1 AggregateError ( errors, message [ , options ] )
This function performs the following steps when called:
- If NewTarget is
undefined , let newTarget be theactive function object ; else let newTarget be NewTarget. - Let obj be ?
OrdinaryCreateFromConstructor (newTarget," , « [[ErrorData]] »).%AggregateError.prototype% " - If message is not
undefined , then- Let messageString be ?
ToString (message). - Perform
CreateNonEnumerableDataPropertyOrThrow (obj,"message" , messageString).
- Let messageString be ?
- Perform ?
InstallErrorCause (obj, options). - Let errorsList be ?
IteratorToList (?GetIterator (errors,sync )). - Perform !
DefinePropertyOrThrow (obj,"errors" , PropertyDescriptor { [[Configurable]]:true , [[Enumerable]]:false , [[Writable]]:true , [[Value]]:CreateArrayFromList (errorsList) }). - Return obj.
20.5.7.2 Properties of the AggregateError Constructor
The AggregateError
- has a [[Prototype]] internal slot whose value is
%Error% . - has the following properties:
20.5.7.2.1 AggregateError.prototype
The initial value of AggregateError.prototype is
This property has the attributes { [[Writable]]:
20.5.7.3 Properties of the AggregateError Prototype Object
The AggregateError prototype object:
- is
%AggregateError.prototype% . - is an
ordinary object . - is not an Error instance or an AggregateError instance and does not have an [[ErrorData]] internal slot.
- has a [[Prototype]] internal slot whose value is
%Error.prototype% .
20.5.7.3.1 AggregateError.prototype.constructor
The initial value of AggregateError.prototype.constructor is
20.5.7.3.2 AggregateError.prototype.message
The initial value of AggregateError.prototype.message is the empty String.
20.5.7.3.3 AggregateError.prototype.name
The initial value of AggregateError.prototype.name is
20.5.7.4 Properties of AggregateError Instances
AggregateError instances are Object.prototype.toString (Error.isError (
20.5.8 Abstract Operations for Error Objects
20.5.8.1 InstallErrorCause ( obj, options )
The abstract operation InstallErrorCause takes arguments obj (an Object) and options (an
- If options
is an Object and ?HasProperty (options,"cause" ) istrue , then- Let cause be ?
Get (options,"cause" ). - Perform
CreateNonEnumerableDataPropertyOrThrow (obj,"cause" , cause).
- Let cause be ?
- Return
unused .