19 Fundamental Objects

19.1 Object Objects

19.1.1 The Object Constructor

The Object constructor is the %Object% intrinsic object and the initial value of the Object property of the global object. When called as a constructor it creates a new ordinary object. When Object is called as a function rather than as a constructor, it performs a type conversion.

The Object constructor is designed to be subclassable. It may be used as the value of an extends clause of a class definition.

19.1.1.1 Object ( [ value ] )

When Object function is called with optional argument value, the following steps are taken:

  1. If NewTarget is neither undefined nor the active function, then
    1. Return OrdinaryCreateFromConstructor(NewTarget, "%ObjectPrototype%").
  2. If value is null, undefined or not supplied, return ObjectCreate(%ObjectPrototype%).
  3. Return ToObject(value).

19.1.2 Properties of the Object Constructor

The value of the [[Prototype]] internal slot of the Object constructor is the intrinsic object %FunctionPrototype%.

Besides the length property (whose value is 1), the Object constructor has the following properties:

19.1.2.1 Object.assign ( target, ...sources )

The assign function is used to copy the values of all of the enumerable own properties from one or more source objects to a target object. When the assign function is called, the following steps are taken:

  1. Let to be ToObject(target).
  2. ReturnIfAbrupt(to).
  3. If only one argument was passed, return to.
  4. Let sources be the List of argument values starting with the second argument.
  5. For each element nextSource of sources, in ascending index order,
    1. If nextSource is undefined or null, let keys be an empty List.
    2. Else,
      1. Let from be ToObject(nextSource).
      2. Let keys be from.[[OwnPropertyKeys]]().
      3. ReturnIfAbrupt(keys).
    3. Repeat for each element nextKey of keys in List order,
      1. Let desc be from.[[GetOwnProperty]](nextKey).
      2. ReturnIfAbrupt(desc).
      3. if desc is not undefined and desc.[[Enumerable]] is true, then
        1. Let propValue be Get(from, nextKey).
        2. ReturnIfAbrupt(propValue).
        3. Let status be Set(to, nextKey, propValue, true).
        4. ReturnIfAbrupt(status).
  6. Return to.

The length property of the assign method is 2.

19.1.2.2 Object.create ( O [ , Properties ] )

The create function creates a new object with a specified prototype. When the create function is called, the following steps are taken:

  1. If Type(O) is neither Object nor Null, throw a TypeError exception.
  2. Let obj be ObjectCreate(O).
  3. If the argument Properties is present and not undefined, then
    1. Return ObjectDefineProperties(obj, Properties).
  4. Return obj.

19.1.2.3 Object.defineProperties ( O, Properties )

The defineProperties function is used to add own properties and/or update the attributes of existing own properties of an object. When the defineProperties function is called, the following steps are taken:

  1. Return ObjectDefineProperties(O, Properties).

19.1.2.3.1 Runtime Semantics: ObjectDefineProperties ( O, Properties )

The abstract operation ObjectDefineProperties with arguments O and Properties performs the following steps:

  1. If Type(O) is not Object, throw a TypeError exception.
  2. Let props be ToObject(Properties).
  3. ReturnIfAbrupt(props).
  4. Let keys be props.[[OwnPropertyKeys]]().
  5. ReturnIfAbrupt(keys).
  6. Let descriptors be an empty List.
  7. Repeat for each element nextKey of keys in List order,
    1. Let propDesc be props.[[GetOwnProperty]](nextKey).
    2. ReturnIfAbrupt(propDesc).
    3. If propDesc is not undefined and propDesc.[[Enumerable]] is true, then
      1. Let descObj be Get( props, nextKey).
      2. ReturnIfAbrupt(descObj).
      3. Let desc be ToPropertyDescriptor(descObj).
      4. ReturnIfAbrupt(desc).
      5. Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors.
  8. For each pair from descriptors in list order,
    1. Let P be the first element of pair.
    2. Let desc be the second element of pair.
    3. Let status be DefinePropertyOrThrow(O,P, desc).
    4. ReturnIfAbrupt(status).
  9. Return O.

19.1.2.4 Object.defineProperty ( O, P, Attributes )

The defineProperty function is used to add an own property and/or update the attributes of an existing own property of an object. When the defineProperty function is called, the following steps are taken:

  1. If Type(O) is not Object, throw a TypeError exception.
  2. Let key be ToPropertyKey(P).
  3. ReturnIfAbrupt(key).
  4. Let desc be ToPropertyDescriptor(Attributes).
  5. ReturnIfAbrupt(desc).
  6. Let success be DefinePropertyOrThrow(O,key, desc).
  7. ReturnIfAbrupt(success).
  8. Return O.

19.1.2.5 Object.freeze ( O )

When the freeze function is called, the following steps are taken:

  1. If Type(O) is not Object, return O.
  2. Let status be SetIntegrityLevel( O, "frozen").
  3. ReturnIfAbrupt(status).
  4. If status is false, throw a TypeError exception.
  5. Return O.

19.1.2.6 Object.getOwnPropertyDescriptor ( O, P )

When the getOwnPropertyDescriptor function is called, the following steps are taken:

  1. Let obj be ToObject(O).
  2. ReturnIfAbrupt(obj).
  3. Let key be ToPropertyKey(P).
  4. ReturnIfAbrupt(key).
  5. Let desc be obj.[[GetOwnProperty]](key).
  6. ReturnIfAbrupt(desc).
  7. Return FromPropertyDescriptor(desc).

19.1.2.7 Object.getOwnPropertyNames ( O )

When the getOwnPropertyNames function is called, the following steps are taken:

  1. Return GetOwnPropertyKeys(O, String).

19.1.2.8 Object.getOwnPropertySymbols ( O )

When the getOwnPropertySymbols function is called with argument O, the following steps are taken:

  1. Return GetOwnPropertyKeys(O, Symbol).

19.1.2.8.1 Runtime Semantics: GetOwnPropertyKeys ( O, Type )

The abstract operation GetOwnPropertyKeys is called with arguments O and Type where O is an Object and Type is one of the ECMAScript specification types String or Symbol. The following steps are taken:

  1. Let obj be ToObject(O).
  2. ReturnIfAbrupt(obj).
  3. Let keys be obj.[[OwnPropertyKeys]]().
  4. ReturnIfAbrupt(keys).
  5. Let nameList be a new empty List.
  6. Repeat for each element nextKey of keys in List order,
    1. If Type(nextKey) is Type, then
      1. Append nextKey as the last element of nameList.
  7. Return CreateArrayFromList(nameList).

19.1.2.9 Object.getPrototypeOf ( O )

When the getPrototypeOf function is called with argument O, the following steps are taken:

  1. Let obj be ToObject(O).
  2. ReturnIfAbrupt(obj).
  3. Return obj.[[GetPrototypeOf]]().

19.1.2.10 Object.is ( value1, value2 )

When the is function is called with arguments value1 and value2 the following steps are taken:

  1. Return SameValue(value1, value2).

19.1.2.11 Object.isExtensible ( O )

When the isExtensible function is called with argument O, the following steps are taken:

  1. If Type(O) is not Object, return false.
  2. Return IsExtensible(O).

19.1.2.12 Object.isFrozen ( O )

When the isFrozen function is called with argument O, the following steps are taken:

  1. If Type(O) is not Object, return true.
  2. Return TestIntegrityLevel(O, "frozen").

19.1.2.13 Object.isSealed ( O )

When the isSealed function is called with argument O, the following steps are taken:

  1. If Type(O) is not Object, return true.
  2. Return TestIntegrityLevel(O, "sealed").

19.1.2.14 Object.keys ( O )

When the keys function is called with argument O, the following steps are taken:

  1. Let obj be ToObject(O).
  2. ReturnIfAbrupt(obj).
  3. Let nameList be EnumerableOwnNames(obj).
  4. ReturnIfAbrupt(nameList).
  5. Return CreateArrayFromList(nameList).

If an implementation defines a specific order of enumeration for the for-in statement, the same order must be used for the elements of the array returned in step 4.

19.1.2.15 Object.preventExtensions ( O )

When the preventExtensions function is called, the following steps are taken:

  1. If Type(O) is not Object, return O.
  2. Let status be O.[[PreventExtensions]]().
  3. ReturnIfAbrupt(status).
  4. If status is false, throw a TypeError exception.
  5. Return O.

19.1.2.16 Object.prototype

The initial value of Object.prototype is the intrinsic object %ObjectPrototype% (19.1.3).

This property has the attributes {[[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.1.2.17 Object.seal ( O )

When the seal function is called, the following steps are taken:

  1. If Type(O) is not Object, return O.
  2. Let status be SetIntegrityLevel( O, "sealed").
  3. ReturnIfAbrupt(status).
  4. If status is false, throw a TypeError exception.
  5. Return O.

19.1.2.18 Object.setPrototypeOf ( O, proto )

When the setPrototypeOf function is called with arguments O and proto, the following steps are taken:

  1. Let O be RequireObjectCoercible(O).
  2. ReturnIfAbrupt(O).
  3. If Type(proto) is neither Object nor Null, throw a TypeError exception.
  4. If Type(O) is not Object, return O.
  5. Let status be O.[[SetPrototypeOf]](proto).
  6. ReturnIfAbrupt(status).
  7. If status is false, throw a TypeError exception.
  8. Return O.

19.1.3 Properties of the Object Prototype Object

The Object prototype object is the intrinsic object %ObjectPrototype%. The Object prototype object is an ordinary object.

The value of the [[Prototype]] internal slot of the Object prototype object is null and the initial value of the [[Extensible]] internal slot is true.

19.1.3.1 Object.prototype.constructor

The initial value of Object.prototype.constructor is the intrinsic object %Object%.

19.1.3.2 Object.prototype.hasOwnProperty ( V )

When the hasOwnProperty method is called with argument V, the following steps are taken:

  1. Let P be ToPropertyKey(V).
  2. ReturnIfAbrupt(P).
  3. Let O be ToObject(this value).
  4. ReturnIfAbrupt(O).
  5. Return HasOwnProperty(O, P).

NOTE The ordering of steps 1 and 3 is chosen to ensure that any exception that would have been thrown by step 1 in previous editions of this specification will continue to be thrown even if the this value is undefined or null.

19.1.3.3 Object.prototype.isPrototypeOf ( V )

When the isPrototypeOf method is called with argument V, the following steps are taken:

  1. If Type(V) is not Object, return false.
  2. Let O be ToObject(this value).
  3. ReturnIfAbrupt(O).
  4. Repeat
    1. Let V be V.[[GetPrototypeOf]]().
    2. If V is null, return false
    3. If SameValue(O, V) is true, return true.

NOTE The ordering of steps 1 and 2 preserves the behaviour specified by previous editions of this specification for the case where V is not an object and the this value is undefined or null.

19.1.3.4 Object.prototype.propertyIsEnumerable ( V )

When the propertyIsEnumerable method is called with argument V, the following steps are taken:

  1. Let P be ToPropertyKey(V).
  2. ReturnIfAbrupt(P).
  3. Let O be ToObject(this value).
  4. ReturnIfAbrupt(O).
  5. Let desc be O.[[GetOwnProperty]](P).
  6. ReturnIfAbrupt(desc).
  7. If desc is undefined, return false.
  8. Return the value of desc.[[Enumerable]].

NOTE 1 This method does not consider objects in the prototype chain.

NOTE 2 The ordering of steps 1 and 3 is chosen to ensure that any exception that would have been thrown by step 1 in previous editions of this specification will continue to be thrown even if the this value is undefined or null.

19.1.3.5 Object.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )

When the toLocaleString method is called, the following steps are taken:

  1. Let O be the this value.
  2. Return Invoke(O, "toString").

The optional parameters to this function are not used but are intended to correspond to the parameter pattern used by ECMA-402 toLocalString functions. Implementations that do not include ECMA-402 support must not use those parameter positions for other purposes.

The length property of the toLocaleString method is 0.

NOTE 1 This function provides a generic toLocaleString implementation for objects that have no locale-specific toString behaviour. Array, Number, Date, and Typed Arrays provide their own locale-sensitive toLocaleString methods.

NOTE 2 ECMA-402 intentionally does not provide an alternative to this default implementation.

19.1.3.6 Object.prototype.toString ( )

When the toString method is called, the following steps are taken:

  1. If the this value is undefined, return "[object Undefined]".
  2. If the this value is null, return "[object Null]".
  3. Let O be ToObject(this value).
  4. Let isArray be IsArray(O).
  5. ReturnIfAbrupt(isArray).
  6. If isArray is true, let builtinTag be "Array".
  7. Else, if O is an exotic String object, let builtinTag be "String".
  8. Else, if O has an [[ParameterMap]] internal slot, let builtinTag be "Arguments".
  9. Else, if O has a [[Call]] internal method, let builtinTag be "Function".
  10. Else, if O has an [[ErrorData]] internal slot, let builtinTag be "Error".
  11. Else, if O has a [[BooleanData]] internal slot, let builtinTag be "Boolean".
  12. Else, if O has a [[NumberData]] internal slot, let builtinTag be "Number".
  13. Else, if O has a [[DateValue]] internal slot, let builtinTag be "Date".
  14. Else, if O has a [[RegExpMatcher]] internal slot, let builtinTag be "RegExp".
  15. Else, let builtinTag be "Object".
  16. Let tag be Get (O, @@toStringTag).
  17. ReturnIfAbrupt(tag).
  18. If Type(tag) is not String, let tag be builtinTag.
  19. Return the String that is the result of concatenating "[object ", tag, and "]".

This function is the %ObjProto_toString% intrinsic object.

NOTE Historically, this function 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 @@toStringTag in ways that will invalidate the reliability of such legacy type tests.

19.1.3.7 Object.prototype.valueOf ( )

When the valueOf method is called, the following steps are taken:

  1. Return ToObject(this value).

19.1.4 Properties of Object Instances

Object instances have no special properties beyond those inherited from the Object prototype object.

19.2 Function Objects

19.2.1 The Function Constructor

The Function constructor is the %Function% intrinsic object and the initial value of the Function property of the global object. When Function is called as a function rather than as a constructor, it creates and initializes a new Function object. Thus the function call Function() is equivalent to the object creation expression new Function() with the same arguments.

The Function constructor is designed to be subclassable. It may be used as the value of an extends clause of a class definition. Subclass constructors that intend to inherit the specified Function behaviour must include a super call to the Function constructor to create and initialize a subclass instances with the internal slots necessary for built-in function behaviour. All ECMAScript syntactic forms for defining function objects create instances of Function. There is no syntactic means to create instances of Function subclasses except for the built-in Generator Function subclass.

19.2.1.1 Function ( p1, p2, … , pn, body )

The last argument specifies the body (executable code) of a function; any preceding arguments specify formal parameters.

When the Function function is called with some arguments p1, p2, … , pn, body (where n might be 0, that is, there are no “p” arguments, and where body might also not be provided), the following steps are taken:

  1. Let C be the active function object.
  2. Let args be the argumentsList that was passed to this function by [[Call]] or [[Construct]].
  3. Return CreateDynamicFunction(C, NewTarget, "normal", args).

NOTE 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")

19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args)

The abstract operation CreateDynamicFunction is called with arguments constructor, newTarget, kind, and args. constructor is the constructor function that is performing this action, newTarget is the constructor that new was initially applied to, kind is either "normal" or "generator", and args is a List containing the actual argument values that were passed to constructor. The following steps are taken:

  1. If newTarget is undefined, let newTarget be constructor.
  2. If kind is "normal", then
    1. Let goal be the grammar symbol FunctionBody.
    2. Let parameterGoal be the grammar symbol FormalParameters.
    3. Let fallbackProto be "%FunctionPrototype%".
  3. Else,
    1. Let goal be the grammar symbol GeneratorBody.
    2. Let parameterGoal be the grammar symbol FormalParameters[Yield].
    3. Let fallbackProto be "%Generator%".
  4. Let argCount be the number of elements in args.
  5. Let P be the empty String.
  6. If argCount = 0, let bodyText be the empty String.
  7. Else if argCount = 1, let bodyText be args[0].
  8. Else argCount > 1,
    1. Let firstArg be args[0].
    2. Let P be ToString(firstArg).
    3. ReturnIfAbrupt(P).
    4. Let k be 1.
    5. Repeat, while k < argCount-1
      1. Let nextArg be args[k].
      2. Let nextArgString be ToString(nextArg).
      3. ReturnIfAbrupt(nextArgString).
      4. Let P be the result of concatenating the previous value of P, the String "," (a comma), and nextArgString.
      5. Increase k by 1.
    6. Let bodyText be args[k].
  9. Let bodyText be ToString(bodyText).
  10. ReturnIfAbrupt(bodyText).
  11. Let body be the result of parsing bodyText, interpreted as UTF-16 encoded Unicode text as described in 6.1.4, using goal as the goal symbol. Throw a SyntaxError exception if the parse fails or if any static semantics errors are detected.
  12. If bodyText is strict mode code (see 10.2.1) then let strict be true, else let strict be false.
  13. Let parameters be the result of parsing P, interpreted as UTF-16 encoded Unicode text as described in 6.1.4, using parameterGoal as the goal symbol. Throw a SyntaxError exception if the parse fails or if any static semantics errors are detected. If strict is true, the Early Error rules for StrictFormalParameters : FormalParameters are applied.
  14. If any element of the BoundNames of parameters also occurs in the LexicallyDeclaredNames of body, throw a SyntaxError exception.
  15. If body Contains SuperCall is true, throw a SyntaxError exception.
  16. If parameters Contains SuperCall is true, throw a SyntaxError exception.
  17. If body Contains SuperProperty is true, throw a SyntaxError exception.
  18. If parameters Contains SuperProperty is true, throw a SyntaxError exception.
  19. If kind is "generator", then
    1. If parameters Contains YieldExpression is true, throw a SyntaxError exception.
  20. If strict is true, then
    1. If BoundNames of parameters contains any duplicate elements, throw a SyntaxError exception.
  21. Let proto be GetPrototypeFromConstructor(newTarget, fallbackProto).
  22. ReturnIfAbrupt(proto).
  23. Let F be FunctionAllocate(proto, strict, kind).
  24. Let realmF be the value of F’s [[Realm]] internal slot.
  25. Let scope be realmF.[[globalEnv]].
  26. Perform FunctionInitialize(F, Normal, parameters, body, scope).
  27. If kind is "generator", then
    1. Let prototype be ObjectCreate(%GeneratorPrototype%).
    2. Perform MakeConstructor(F, true, prototype).
  28. Else, perform MakeConstructor(F).
  29. Perform SetFunctionName(F, "anonymous").
  30. Return F.

NOTE A prototype property is automatically created for every function created using CreateDynamicFunction , to provide for the possibility that the function will be used as a constructor.

19.2.2 Properties of the Function Constructor

The Function constructor is itself a built-in function object. The value of the [[Prototype]] internal slot of the Function constructor is %FunctionPrototype%, the intrinsic Function prototype object (19.2.3).

The value of the [[Extensible]] internal slot of the Function constructor is true.

The Function constructor has the following properties:

19.2.2.1 Function.length

This is a data property with a value of 1. This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.

19.2.2.2 Function.prototype

The value of Function.prototype is %FunctionPrototype%, the intrinsic Function prototype object (19.2.3).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.2.3 Properties of the Function Prototype Object

The Function prototype object is the intrinsic object %FunctionPrototype%. The Function prototype object is itself a built-in function object. When invoked, it accepts any arguments and returns undefined. It does not have a [[Construct]] internal method so it is not a constructor.

NOTE The Function prototype object is specified to be a function object to ensure compatibility with ECMAScript code that was created prior to the ECMAScript 2015 specification.

The value of the [[Prototype]] internal slot of the Function prototype object is the intrinsic object %ObjectPrototype% (19.1.3). The initial value of the [[Extensible]] internal slot of the Function prototype object is true.

The Function prototype object does not have a prototype property.

The value of the length property of the Function prototype object is 0.

The value of the name property of the Function prototype object is the empty String.

19.2.3.1 Function.prototype.apply ( thisArg, argArray )

When the apply method is called on an object func with arguments thisArg and argArray, the following steps are taken:

  1. If IsCallable(func) is false, throw a TypeError exception.
  2. If argArray is null or undefined, then
    1. Return Call(func, thisArg).
  3. Let argList be CreateListFromArrayLike(argArray).
  4. ReturnIfAbrupt(argList ).
  5. Perform PrepareForTailCall().
  6. Return Call(func, thisArg, argList).

The length property of the apply method is 2.

NOTE 1 The thisArg value is passed without modification as the this value. This is a change from Edition 3, where an undefined or null thisArg is replaced with the global object and ToObject is applied to all other values and that result is passed as the this value. Even though the thisArg is passed without modification, non-strict functions still perform these transformations upon entry to the function.

NOTE 2 If func is an arrow function or a bound function then the thisArg will be ignored by the function [[Call]] in step 6.

19.2.3.2 Function.prototype.bind ( thisArg , ...args)

When the bind method is called with argument thisArg and zero or more args, it performs the following steps:

  1. Let Target be the this value.
  2. If IsCallable(Target) is false, throw a TypeError exception.
  3. Let args be a new (possibly empty) List consisting of all of the argument values provided after thisArg in order.
  4. Let F be BoundFunctionCreate(Target, thisArg, args).
  5. ReturnIfAbrupt(F).
  6. Let targetHasLength be HasOwnProperty(Target, "length").
  7. ReturnIfAbrupt(targetHasLength).
  8. If targetHasLength is true, then
    1. Let targetLen be Get(Target, "length").
    2. ReturnIfAbrupt(targetLen).
    3. If Type(targetLen) is not Number, let L be 0.
    4. Else,
      1. Let targetLen be ToInteger(targetLen).
      2. Let L be the larger of 0 and the result of targetLen minus the number of elements of args.
  9. Else let L be 0.
  10. Let status be DefinePropertyOrThrow(F, "length", PropertyDescriptor {[[Value]]: L, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true}).
  11. Assert: status is not an abrupt completion.
  12. Let targetName be Get(Target, "name").
  13. ReturnIfAbrupt(targetName).
  14. If Type(targetName) is not String, let targetName be the empty string.
  15. Perform SetFunctionName(F, targetName, "bound").
  16. Return F.

The length property of the bind method is 1.

NOTE 1 Function objects created using Function.prototype.bind are exotic objects. They also do not have a prototype property.

NOTE 2 If Target is an arrow function or a bound function then the thisArg passed to this method will not be used by subsequent calls to F.

19.2.3.3 Function.prototype.call (thisArg , ...args)

When the call method is called on an object func with argument, thisArg and zero or more args, the following steps are taken:

  1. If IsCallable(func) is false, throw a TypeError exception.
  2. Let argList be an empty List.
  3. If this method was called with more than one argument then in left to right order, starting with the second argument, append each argument as the last element of argList.
  4. Perform PrepareForTailCall().
  5. Return Call(func, thisArg, argList).

The length property of the call method is 1.

NOTE 1 The thisArg value is passed without modification as the this value. This is a change from Edition 3, where an undefined or null thisArg is replaced with the global object and ToObject is applied to all other values and that result is passed as the this value. Even though the thisArg is passed without modification, non-strict functions still perform these transformations upon entry to the function.

NOTE 2 If func is an arrow function or a bound function then the thisArg will be ignored by the function [[Call]] in step 5.

19.2.3.4 Function.prototype.constructor

The initial value of Function.prototype.constructor is the intrinsic object %Function%.

19.2.3.5 Function.prototype.toString ( )

When the toString method is called on an object func the following steps are taken:

  1. If func is a Bound Function exotic object, then
    1. Return an implementation-dependent String source code representation of func. The representation must conform to the rules below. It is implementation dependent whether the representation includes bound function information or information about the target function.
  2. If Type(func) is Object and is either a built-in function object or has an [[ECMAScriptCode]] internal slot, then
    1. Return an implementation-dependent String source code representation of func. The representation must conform to the rules below.
  3. Throw a TypeError exception.

toString Representation Requirements:

  • The string representation must have the syntax of a FunctionDeclaration, FunctionExpression, GeneratorDeclaration, GeneratorExpression, ClassDeclaration, ClassExpression, ArrowFunction, MethodDefinition, or GeneratorMethod depending upon the actual characteristics of the object.

  • The use and placement of white space, line terminators, and semicolons within the representation String is implementation-dependent.

  • If the object was defined using ECMAScript code and the returned string representation is not in the form of a MethodDefinition or GeneratorMethod then the representation must be such that if the string is evaluated, using eval in a lexical context that is equivalent to the lexical context used to create the original object, it will result in a new functionally equivalent object. In that case the returned source code must not mention freely any variables that were not mentioned freely by the original function's source code, even if these “extra” names were originally in scope.

  • If the implementation cannot produce a source code string that meets these criteria then it must return a string for which eval will throw a SyntaxError exception.

19.2.3.6 Function.prototype[@@hasInstance] ( V )

When the @@hasInstance method of an object F is called with value V, the following steps are taken:

  1. Let F be the this value.
  2. Return OrdinaryHasInstance(F, V).

The value of the name property of this function is "[Symbol.hasInstance]".

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

NOTE This is the default implementation of @@hasInstance that most functions inherit. @@hasInstance is called by the instanceof operator to determine whether a value is an instance of a specific constructor. An expression such as

   v instanceof F

evaluates as

   F[@@hasInstance](v)

A constructor function can control which objects are recognized as its instances by instanceof by exposing a different @@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.

19.2.4 Function Instances

Every function instance is an ECMAScript function object and has the internal slots listed in Table 27. Function instances created using the Function.prototype.bind method (19.2.3.2) have the internal slots listed in Table 28.

The Function instances have the following properties:

19.2.4.1 length

The value of the length property is an integer that indicates the typical number of arguments expected by the function. However, the language permits the function to be invoked with some other number of arguments. The behaviour of a function when invoked on a number of arguments other than the number specified by its length property depends on the function. This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.

19.2.4.2 name

The value of the name property is an String that is descriptive of the function. The name has no semantic significance but is typically a variable or property name that is used to refer to the function at its point of definition in ECMAScript code. This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.

Anonymous functions objects that do not have a contextual name associated with them by this specification do not have a name own property but inherit the name property of %FunctionPrototype%.

19.2.4.3 prototype

Function instances that can be used as a constructor have a prototype property. Whenever such a function instance is created another ordinary object is also created and is the initial value of the function’s prototype property. Unless otherwise specified, the value of the prototype property is used to initialize the [[Prototype]] internal slot of the object created when that function is invoked as a constructor.

This property has the attributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }.

NOTE Function objects created using Function.prototype.bind, or by evaluating a MethodDefinition (that are not a GeneratorMethod) or an ArrowFunction grammar production do not have a prototype property.

19.3 Boolean Objects

19.3.1 The Boolean Constructor

The Boolean constructor is the %Boolean% intrinsic object and the initial value of the Boolean property of the global object. When called as a constructor it creates and initializes a new Boolean object. When Boolean is called as a function rather than as a constructor, it performs a type conversion.

The Boolean constructor is designed to be subclassable. It may be used as the value of an extends clause of a class definition. Subclass constructors that intend to inherit the specified Boolean behaviour must include a super call to the Boolean constructor to create and initialize the subclass instance with a [[BooleanData]] internal slot.

19.3.1.1 Boolean ( value )

When Boolean is called with argument value, the following steps are taken:

  1. Let b be ToBoolean(value).
  2. If NewTarget is undefined, return b.
  3. Let O be OrdinaryCreateFromConstructor(NewTarget, "%BooleanPrototype%", «[[BooleanData]]» ).
  4. ReturnIfAbrupt(O).
  5. Set the value of O’s [[BooleanData]] internal slot to b.
  6. Return O.

19.3.2 Properties of the Boolean Constructor

The value of the [[Prototype]] internal slot of the Boolean constructor is the intrinsic object %FunctionPrototype% (19.2.3).

Besides the length property (whose value is 1), the Boolean constructor has the following properties:

19.3.2.1 Boolean.prototype

The initial value of Boolean.prototype is the intrinsic object %BooleanPrototype% (19.3.3).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.3.3 Properties of the Boolean Prototype Object

The Boolean prototype object is the intrinsic object %BooleanPrototype%. The Boolean prototype object is an ordinary object. It is not a Boolean instance and does not have a [[BooleanData]] internal slot.

The value of the [[Prototype]] internal slot of the Boolean prototype object is the intrinsic object %ObjectPrototype% (19.1.3).

The abstract operation thisBooleanValue(value) performs the following steps:

  1. If Type(value) is Boolean, return value.
  2. If Type(value) is Object and value has a [[BooleanData]] internal slot, then
    1. Assert: value's [[BooleanData]] internal slot is a Boolean value.
    2. Return the value of value’s [[BooleanData]] internal slot.
  3. Throw a TypeError exception.

19.3.3.1 Boolean.prototype.constructor

The initial value of Boolean.prototype.constructor is the intrinsic object %Boolean%.

19.3.3.2 Boolean.prototype.toString ( )

The following steps are taken:

  1. Let b be thisBooleanValue(this value).
  2. ReturnIfAbrupt(b).
  3. If b is true, return "true"; else return "false".

19.3.3.3 Boolean.prototype.valueOf ( )

The following steps are taken:

  1. Return thisBooleanValue(this value).

19.3.4 Properties of Boolean Instances

Boolean instances are ordinary objects that inherit properties from the Boolean prototype object. Boolean instances have a [[BooleanData]] internal slot. The [[BooleanData]] internal slot is the Boolean value represented by this Boolean object.

19.4 Symbol Objects

19.4.1 The Symbol Constructor

The Symbol constructor is the %Symbol% intrinsic object and the initial value of the Symbol property of the global object. When Symbol is called as a function, it returns a new Symbol value.

The Symbol constructor is not intended to be used with the new operator or to be subclassed. It may be used as the value of an extends clause of a class definition but a super call to the Symbol constructor will cause an exception.

19.4.1.1 Symbol ( [ description ] )

When Symbol is called with optional argument description, the following steps are taken:

  1. If NewTarget is not undefined, throw a TypeError exception.
  2. If description is undefined, let descString be undefined.
  3. Else, let descString be ToString(description).
  4. ReturnIfAbrupt(descString).
  5. Return a new unique Symbol value whose [[Description]] value is descString.

19.4.2 Properties of the Symbol Constructor

The value of the [[Prototype]] internal slot of the Symbol constructor is the intrinsic object %FunctionPrototype% (19.2.3).

Besides the length property (whose value is 0), the Symbol constructor has the following properties:

19.4.2.1 Symbol.for ( key )

When Symbol.for is called with argument key it performs the following steps:

  1. Let stringKey be ToString(key).
  2. ReturnIfAbrupt(stringKey).
  3. For each element e of the GlobalSymbolRegistry List,
    1. If SameValue(e.[[key]], stringKey) is true, return e.[[symbol]].
  4. Assert: GlobalSymbolRegistry does not currently contain an entry for stringKey.
  5. Let newSymbol be a new unique Symbol value whose [[Description]] value is stringKey.
  6. Append the record { [[key]]: stringKey, [[symbol]]: newSymbol } to the GlobalSymbolRegistry List.
  7. Return newSymbol.

The GlobalSymbolRegistry is a List that is globally available. It is shared by all Code Realms. Prior to the evaluation of any ECMAScript code it is initialized as an empty List. Elements of the GlobalSymbolRegistry are Records with the structure defined in Table 44.

Table 44 — GlobalSymbolRegistry Record Fields
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 Realm.

19.4.2.2 Symbol.hasInstance

The initial value of Symbol.hasInstance is the well known symbol @@hasInstance (Table 1).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.4.2.3 Symbol.isConcatSpreadable

The initial value of Symbol.isConcatSpreadable is the well known symbol @@isConcatSpreadable (Table 1).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.4.2.4 Symbol.iterator

The initial value of Symbol.iterator is the well known symbol @@iterator (Table 1).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.4.2.5 Symbol.keyFor ( sym )

When Symbol.keyFor is called with argument sym it performs the following steps:

  1. If Type(sym) is not Symbol, throw a TypeError exception.
  2. For each element e of the GlobalSymbolRegistry List (see 19.4.2.1),
    1. If SameValue(e.[[symbol]], sym) is true, return e.[[key]].
  3. Assert: GlobalSymbolRegistry does not currently contain an entry for sym.
  4. Return undefined.

19.4.2.6 Symbol.match

The initial value of Symbol.match is the well known symbol @@match (Table 1).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.4.2.7 Symbol.prototype

The initial value of Symbol.prototype is the intrinsic object %SymbolPrototype% (19.4.3).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.4.2.8 Symbol.replace

The initial value of Symbol.replace is the well known symbol @@replace (Table 1).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.4.2.9 Symbol.search

The initial value of Symbol.search is the well known symbol @@search (Table 1).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.4.2.10 Symbol.species

The initial value of Symbol.species is the well known symbol @@species (Table 1).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.4.2.11 Symbol.split

The initial value of Symbol.split is the well known symbol @@split (Table 1).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.4.2.12 Symbol.toPrimitive

The initial value of Symbol.toPrimitive is the well known symbol @@toPrimitive (Table 1).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.4.2.13 Symbol.toStringTag

The initial value of Symbol.toStringTag is the well known symbol @@toStringTag (Table 1).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.4.2.14 Symbol.unscopables

The initial value of Symbol.unscopables is the well known symbol @@unscopables (Table 1).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.4.3 Properties of the Symbol Prototype Object

The Symbol prototype object is the intrinsic object %SymbolPrototype%. The Symbol prototype object is an ordinary object. It is not a Symbol instance and does not have a [[SymbolData]] internal slot.

The value of the [[Prototype]] internal slot of the Symbol prototype object is the intrinsic object %ObjectPrototype% (19.1.3).

19.4.3.1 Symbol.prototype.constructor

The initial value of Symbol.prototype.constructor is the intrinsic object %Symbol%.

19.4.3.2 Symbol.prototype.toString ( )

The following steps are taken:

  1. Let s be the this value.
  2. If Type(s) is Symbol, let sym be s.
  3. Else,
    1. If Type(s) is not Object, throw a TypeError exception.
    2. If s does not have a [[SymbolData]] internal slot, throw a TypeError exception.
    3. Let sym be the value of s’s [[SymbolData]] internal slot.
  4. Return SymbolDescriptiveString(sym).

19.4.3.2.1 Runtime Semantics: SymbolDescriptiveString ( sym )

When the abstract operation SymbolDescriptiveString is called with argument sym, the following steps are taken:

  1. Assert: Type(sym) is Symbol.
  2. Let desc be sym’s [[Description]] value.
  3. If desc is undefined, let desc be the empty string.
  4. Assert: Type(desc) is String.
  5. Return the result of concatenating the strings "Symbol(", desc, and ")".

19.4.3.3 Symbol.prototype.valueOf ( )

The following steps are taken:

  1. Let s be the this value.
  2. If Type(s) is Symbol, return s.
  3. If Type(s) is not Object, throw a TypeError exception.
  4. If s does not have a [[SymbolData]] internal slot, throw a TypeError exception.
  5. Return the value of s’s [[SymbolData]] internal slot.

19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint )

This function is called by ECMAScript language operators to convert a Symbol object to a primitive value. The allowed values for hint are "default", "number", and "string".

When the @@toPrimitive method is called with argument hint, the following steps are taken:

  1. Let s be the this value.
  2. If Type(s) is Symbol, return s.
  3. If Type(s) is not Object, throw a TypeError exception.
  4. If s does not have a [[SymbolData]] internal slot, throw a TypeError exception.
  5. Return the value of s’s [[SymbolData]] internal slot.

The value of the name property of this function is "[Symbol.toPrimitive]".

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.

19.4.3.5 Symbol.prototype [ @@toStringTag ]

The initial value of the @@toStringTag property is the String value "Symbol".

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.

19.4.4 Properties of Symbol Instances

Symbol instances are ordinary objects that inherit properties from the Symbol prototype object. Symbol instances have a [[SymbolData]] internal slot. The [[SymbolData]] internal slot is the Symbol value represented by this Symbol object.

19.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.

19.5.1 The Error Constructor

The Error constructor is the %Error% intrinsic object and the initial value of the Error property of the global object. When Error is called as a function rather than as a constructor, it creates and initializes a new Error object. Thus the function call Error() is equivalent to the object creation expression new Error() with the same arguments.

The Error constructor is designed to be subclassable. It may be used as the value of an extends clause of a class definition. Subclass constructors that intend to inherit the specified Error behaviour must include a super call to the Error constructor to create and initialize subclass instances with a [[ErrorData]] internal slot.

19.5.1.1 Error ( message )

When the Error function is called with argument message the following steps are taken:

  1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
  2. Let O be OrdinaryCreateFromConstructor(newTarget, "%ErrorPrototype%", «[[ErrorData]]»).
  3. ReturnIfAbrupt(O).
  4. If message is not undefined, then
    1. Let msg be ToString(message).
    2. ReturnIfAbrupt(msg).
    3. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}.
    4. Let status be DefinePropertyOrThrow(O, "message", msgDesc).
    5. Assert: status is not an abrupt completion.
  5. Return O.

19.5.2 Properties of the Error Constructor

The value of the [[Prototype]] internal slot of the Error constructor is the intrinsic object %FunctionPrototype% (19.2.3).

Besides the length property (whose value is 1), the Error constructor has the following properties:

19.5.2.1 Error.prototype

The initial value of Error.prototype is the intrinsic object %ErrorPrototype% (19.5.3).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.5.3 Properties of the Error Prototype Object

The Error prototype object is the intrinsic object %ErrorPrototype%. The Error prototype object is an ordinary object. It is not an Error instance and does not have an [[ErrorData]] internal slot.

The value of the [[Prototype]] internal slot of the Error prototype object is the intrinsic object %ObjectPrototype% (19.1.3).

19.5.3.1 Error.prototype.constructor

The initial value of Error.prototype.constructor is the intrinsic object %Error%.

19.5.3.2 Error.prototype.message

The initial value of Error.prototype.message is the empty String.

19.5.3.3 Error.prototype.name

The initial value of Error.prototype.name is "Error".

19.5.3.4 Error.prototype.toString ( )

The following steps are taken:

  1. Let O be the this value.
  2. If Type(O) is not Object, throw a TypeError exception.
  3. Let name be Get(O, "name").
  4. ReturnIfAbrupt(name).
  5. If name is undefined, let name be "Error"; otherwise let name be ToString(name).
  6. ReturnIfAbrupt(name).
  7. Let msg be Get(O, "message").
  8. ReturnIfAbrupt(msg).
  9. If msg is undefined, let msg be the empty String; otherwise let msg be ToString(msg).
  10. ReturnIfAbrupt(msg).
  11. If name is the empty String, return msg.
  12. If msg is the empty String, return name.
  13. Return the result of concatenating name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE), and msg.

19.5.4 Properties of Error Instances

Error instances are ordinary objects that inherit properties from the Error prototype object and have an [[ErrorData]] internal slot whose value is undefined. The only specified uses of [[ErrorData]] is to identify Error and NativeError instances as Error objects within Object.prototype.toString.

19.5.5 Native Error Types Used in This Standard

A new instance of one of the NativeError objects below is thrown when a runtime error is detected. All of these objects share the same structure, as described in 19.5.6.

19.5.5.1 EvalError

This exception is not currently used within this specification. This object remains for compatibility with previous editions of this specification.

19.5.5.2 RangeError

Indicates a value that is not in the set or range of allowable values.

19.5.5.3 ReferenceError

Indicate that an invalid reference value has been detected.

19.5.5.4 SyntaxError

Indicates that a parsing error has occurred.

19.5.5.5 TypeError

Indicates the actual type of an operand is different than the expected type.

19.5.5.6 URIError

Indicates that one of the global URI handling functions was used in a way that is incompatible with its definition.

19.5.6 NativeError Object Structure

When an ECMAScript implementation detects a runtime error, it throws a new instance of one of the NativeError objects defined in 19.5.5. Each of these objects has the structure described below, differing only in the name used as the constructor name instead of NativeError, in the name property of the prototype object, and in the implementation-defined message property of the prototype object.

For each error object, references to NativeError in the definition should be replaced with the appropriate error object name from 19.5.5.

19.5.6.1 NativeError Constructors

When a NativeError constructor is called as a function rather than as a constructor, it creates and initializes a new NativeError object. A call of the object as a function is equivalent to calling it as a constructor with the same arguments. Thus the function call NativeError() is equivalent to the object creation expression new NativeError() with the same arguments.

Each NativeError constructor is designed to be subclassable. It may be used as the value of an extends clause of a class definition. Subclass constructors that intend to inherit the specified NativeError behaviour must include a super call to the NativeError constructor to create and initialize subclass instances with a [[ErrorData]] internal slot.

19.5.6.1.1 NativeError ( message )

When a NativeError function is called with argument message the following steps are taken:

  1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
  2. Let O be OrdinaryCreateFromConstructor(newTarget, "%NativeErrorPrototype%", «[[ErrorData]]» ).
  3. ReturnIfAbrupt(O).
  4. If message is not undefined, then
    1. Let msg be ToString(message).
    2. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}.
    3. Let status be DefinePropertyOrThrow(O, "message", msgDesc).
    4. Assert: status is not an abrupt completion.
  5. Return O.

The actual value of the string passed in step 2 is either "%EvalErrorPrototype%", "%RangeErrorPrototype%", "%ReferenceErrorPrototype%", "%SyntaxErrorPrototype%", "%TypeErrorPrototype%", or "%URIErrorPrototype%" corresponding to which NativeError constructor is being defined.

19.5.6.2 Properties of the NativeError Constructors

The value of the [[Prototype]] internal slot of a NativeError constructor is the intrinsic object %Error% (19.5.1).

Besides the length property (whose value is 1), each NativeError constructor has the following properties:

19.5.6.2.1 NativeError.prototype

The initial value of NativeError.prototype is a NativeError prototype object (19.5.6.3). Each NativeError constructor has a distinct prototype object.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

19.5.6.3 Properties of the NativeError Prototype Objects

Each NativeError prototype object is an ordinary object. It is not an Error instance and does not have an [[ErrorData]] internal slot.

The value of the [[Prototype]] internal slot of each NativeError prototype object is the intrinsic object %ErrorPrototype% (19.5.3).

19.5.6.3.1 NativeError.prototype.constructor

The initial value of the constructor property of the prototype for a given NativeError constructor is the corresponding intrinsic object %NativeError% (19.5.6.1).

19.5.6.3.2 NativeError.prototype.message

The initial value of the message property of the prototype for a given NativeError constructor is the empty String.

19.5.6.3.3 NativeError.prototype.name

The initial value of the name property of the prototype for a given NativeError constructor is a string consisting of the name of the constructor (the name used instead of NativeError).

19.5.6.4 Properties of NativeError Instances

NativeError instances are ordinary objects that inherit properties from their NativeError prototype object and have an [[ErrorData]] internal slot whose value is undefined. The only specified use of [[ErrorData]] is by Object.prototype.toString (19.1.3.6) to identify Error or NativeError instances.