Skip to content

9 Ordinary and Exotic Objects Behaviours

9.1 Ordinary Object Internal Methods and Internal Slots

All ordinary objects have an internal slot called [[Prototype]]. The value of this internal slot is either null or an object and is used for implementing inheritance. Data properties of the [[Prototype]] object are inherited (and visible as properties of the child object) for the purposes of get access, but not for set access. Accessor properties are inherited for both get access and set access.

Every ordinary object has a Boolean-valued [[Extensible]] internal slot which is used to fulfill the extensibility-related internal method invariants specified in 6.1.7.3. Namely, once the value of an object's [[Extensible]] internal slot has been set to false, it is no longer possible to add properties to the object, to modify the value of the object's [[Prototype]] internal slot, or to subsequently change the value of [[Extensible]] to true.

In the following algorithm descriptions, assume O is an ordinary object, P is a property key value, V is any ECMAScript language value, and Desc is a Property Descriptor record.

Each ordinary object internal method delegates to a similarly-named abstract operation. If such an abstract operation depends on another internal method, then the internal method is invoked on O rather than calling the similarly-named abstract operation directly. These semantics ensure that exotic objects have their overridden internal methods invoked when ordinary object internal methods are applied to them.

9.1.1 [[GetPrototypeOf]] ( )

When the [[GetPrototypeOf]] internal method of O is called, the following steps are taken:

  1. Return ! OrdinaryGetPrototypeOf(O).

9.1.1.1 OrdinaryGetPrototypeOf ( O )

When the abstract operation OrdinaryGetPrototypeOf is called with Object O, the following steps are taken:

  1. Return O.[[Prototype]].

9.1.2 [[SetPrototypeOf]] ( V )

When the [[SetPrototypeOf]] internal method of O is called with argument V, the following steps are taken:

  1. Return ! OrdinarySetPrototypeOf(O, V).

9.1.2.1 OrdinarySetPrototypeOf ( O, V )

When the abstract operation OrdinarySetPrototypeOf is called with Object O and value V, the following steps are taken:

  1. Assert: Either Type(V) is Object or Type(V) is Null.
  2. Let extensible be O.[[Extensible]].
  3. Let current be O.[[Prototype]].
  4. If SameValue(V, current) is true, return true.
  5. If extensible is false, return false.
  6. Let p be V.
  7. Let done be false.
  8. Repeat, while done is false,
    1. If p is null, set done to true.
    2. Else if SameValue(p, O) is true, return false.
    3. Else,
      1. If p.[[GetPrototypeOf]] is not the ordinary object internal method defined in 9.1.1, set done to true.
      2. Else, set p to p.[[Prototype]].
  9. Set O.[[Prototype]] to V.
  10. Return true.
Note

The loop in step 8 guarantees that there will be no circularities in any prototype chain that only includes objects that use the ordinary object definitions for [[GetPrototypeOf]] and [[SetPrototypeOf]].

9.1.3 [[IsExtensible]] ( )

When the [[IsExtensible]] internal method of O is called, the following steps are taken:

  1. Return ! OrdinaryIsExtensible(O).

9.1.3.1 OrdinaryIsExtensible ( O )

When the abstract operation OrdinaryIsExtensible is called with Object O, the following steps are taken:

  1. Return O.[[Extensible]].

9.1.4 [[PreventExtensions]] ( )

When the [[PreventExtensions]] internal method of O is called, the following steps are taken:

  1. Return ! OrdinaryPreventExtensions(O).

9.1.4.1 OrdinaryPreventExtensions ( O )

When the abstract operation OrdinaryPreventExtensions is called with Object O, the following steps are taken:

  1. Set O.[[Extensible]] to false.
  2. Return true.

9.1.5 [[GetOwnProperty]] ( P )

When the [[GetOwnProperty]] internal method of O is called with property key P, the following steps are taken:

  1. Return ! OrdinaryGetOwnProperty(O, P).

9.1.5.1 OrdinaryGetOwnProperty ( O, P )

When the abstract operation OrdinaryGetOwnProperty is called with Object O and with property key P, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. If O does not have an own property with key P, return undefined.
  3. Let D be a newly created Property Descriptor with no fields.
  4. Let X be O's own property whose key is P.
  5. If X is a data property, then
    1. Set D.[[Value]] to the value of X's [[Value]] attribute.
    2. Set D.[[Writable]] to the value of X's [[Writable]] attribute.
  6. Else X is an accessor property,
    1. Set D.[[Get]] to the value of X's [[Get]] attribute.
    2. Set D.[[Set]] to the value of X's [[Set]] attribute.
  7. Set D.[[Enumerable]] to the value of X's [[Enumerable]] attribute.
  8. Set D.[[Configurable]] to the value of X's [[Configurable]] attribute.
  9. Return D.

9.1.6 [[DefineOwnProperty]] ( P, Desc )

When the [[DefineOwnProperty]] internal method of O is called with property key P and Property Descriptor Desc, the following steps are taken:

  1. Return ? OrdinaryDefineOwnProperty(O, P, Desc).

9.1.6.1 OrdinaryDefineOwnProperty ( O, P, Desc )

When the abstract operation OrdinaryDefineOwnProperty is called with Object O, property key P, and Property Descriptor Desc, the following steps are taken:

  1. Let current be ? O.[[GetOwnProperty]](P).
  2. Let extensible be ? IsExtensible(O).
  3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current).

9.1.6.2 IsCompatiblePropertyDescriptor ( Extensible, Desc, Current )

When the abstract operation IsCompatiblePropertyDescriptor is called with Boolean value Extensible, and Property Descriptors Desc, and Current, the following steps are taken:

  1. Return ValidateAndApplyPropertyDescriptor(undefined, undefined, Extensible, Desc, Current).

9.1.6.3 ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current )

When the abstract operation ValidateAndApplyPropertyDescriptor is called with Object O, property key P, Boolean value extensible, and Property Descriptors Desc, and current, the following steps are taken:

Note

If undefined is passed as O, only validation is performed and no object updates are performed.

  1. Assert: If O is not undefined, then IsPropertyKey(P) is true.
  2. If current is undefined, then
    1. If extensible is false, return false.
    2. Assert: extensible is true.
    3. If IsGenericDescriptor(Desc) is true or IsDataDescriptor(Desc) is true, then
      1. If O is not undefined, create an own data property named P of object O whose [[Value]], [[Writable]], [[Enumerable]] and [[Configurable]] attribute values are described by Desc. If the value of an attribute field of Desc is absent, the attribute of the newly created property is set to its default value.
    4. Else Desc must be an accessor Property Descriptor,
      1. If O is not undefined, create an own accessor property named P of object O whose [[Get]], [[Set]], [[Enumerable]] and [[Configurable]] attribute values are described by Desc. If the value of an attribute field of Desc is absent, the attribute of the newly created property is set to its default value.
    5. Return true.
  3. If every field in Desc is absent, return true.
  4. If current.[[Configurable]] is false, then
    1. If Desc.[[Configurable]] is present and its value is true, return false.
    2. If Desc.[[Enumerable]] is present and the [[Enumerable]] fields of current and Desc are the Boolean negation of each other, return false.
  5. If IsGenericDescriptor(Desc) is true, no further validation is required.
  6. Else if IsDataDescriptor(current) and IsDataDescriptor(Desc) have different results, then
    1. If current.[[Configurable]] is false, return false.
    2. If IsDataDescriptor(current) is true, then
      1. If O is not undefined, convert the property named P of object O from a data property to an accessor property. Preserve the existing values of the converted property's [[Configurable]] and [[Enumerable]] attributes and set the rest of the property's attributes to their default values.
    3. Else,
      1. If O is not undefined, convert the property named P of object O from an accessor property to a data property. Preserve the existing values of the converted property's [[Configurable]] and [[Enumerable]] attributes and set the rest of the property's attributes to their default values.
  7. Else if IsDataDescriptor(current) and IsDataDescriptor(Desc) are both true, then
    1. If current.[[Configurable]] is false and current.[[Writable]] is false, then
      1. If Desc.[[Writable]] is present and Desc.[[Writable]] is true, return false.
      2. If Desc.[[Value]] is present and SameValue(Desc.[[Value]], current.[[Value]]) is false, return false.
      3. Return true.
  8. Else IsAccessorDescriptor(current) and IsAccessorDescriptor(Desc) are both true,
    1. If current.[[Configurable]] is false, then
      1. If Desc.[[Set]] is present and SameValue(Desc.[[Set]], current.[[Set]]) is false, return false.
      2. If Desc.[[Get]] is present and SameValue(Desc.[[Get]], current.[[Get]]) is false, return false.
      3. Return true.
  9. If O is not undefined, then
    1. For each field of Desc that is present, set the corresponding attribute of the property named P of object O to the value of the field.
  10. Return true.

9.1.7 [[HasProperty]] ( P )

When the [[HasProperty]] internal method of O is called with property key P, the following steps are taken:

  1. Return ? OrdinaryHasProperty(O, P).

9.1.7.1 OrdinaryHasProperty ( O, P )

When the abstract operation OrdinaryHasProperty is called with Object O and with property key P, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Let hasOwn be ? O.[[GetOwnProperty]](P).
  3. If hasOwn is not undefined, return true.
  4. Let parent be ? O.[[GetPrototypeOf]]().
  5. If parent is not null, then
    1. Return ? parent.[[HasProperty]](P).
  6. Return false.

9.1.8 [[Get]] ( P, Receiver )

When the [[Get]] internal method of O is called with property key P and ECMAScript language value Receiver, the following steps are taken:

  1. Return ? OrdinaryGet(O, P, Receiver).

9.1.8.1 OrdinaryGet ( O, P, Receiver )

When the abstract operation OrdinaryGet is called with Object O, property key P, and ECMAScript language value Receiver, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Let desc be ? O.[[GetOwnProperty]](P).
  3. If desc is undefined, then
    1. Let parent be ? O.[[GetPrototypeOf]]().
    2. If parent is null, return undefined.
    3. Return ? parent.[[Get]](P, Receiver).
  4. If IsDataDescriptor(desc) is true, return desc.[[Value]].
  5. Assert: IsAccessorDescriptor(desc) is true.
  6. Let getter be desc.[[Get]].
  7. If getter is undefined, return undefined.
  8. Return ? Call(getter, Receiver).

9.1.9 [[Set]] ( P, V, Receiver )

When the [[Set]] internal method of O is called with property key P, value V, and ECMAScript language value Receiver, the following steps are taken:

  1. Return ? OrdinarySet(O, P, V, Receiver).

9.1.9.1 OrdinarySet ( O, P, V, Receiver )

When the abstract operation OrdinarySet is called with Object O, property key P, value V, and ECMAScript language value Receiver, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Let ownDesc be ? O.[[GetOwnProperty]](P).
  3. Return OrdinarySetWithOwnDescriptor(O, P, V, Receiver, ownDesc).

9.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc )

When the abstract operation OrdinarySetWithOwnDescriptor is called with Object O, property key P, value V, ECMAScript language value Receiver, and Property Descriptor (or undefined) ownDesc, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. If ownDesc is undefined, then
    1. Let parent be ? O.[[GetPrototypeOf]]().
    2. If parent is not null, then
      1. Return ? parent.[[Set]](P, V, Receiver).
    3. Else,
      1. Set ownDesc to the PropertyDescriptor { [[Value]]: undefined, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
  3. If IsDataDescriptor(ownDesc) is true, then
    1. If ownDesc.[[Writable]] is false, return false.
    2. If Type(Receiver) is not Object, return false.
    3. Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P).
    4. If existingDescriptor is not undefined, then
      1. If IsAccessorDescriptor(existingDescriptor) is true, return false.
      2. If existingDescriptor.[[Writable]] is false, return false.
      3. Let valueDesc be the PropertyDescriptor { [[Value]]: V }.
      4. Return ? Receiver.[[DefineOwnProperty]](P, valueDesc).
    5. Else Receiver does not currently have a property P,
      1. Return ? CreateDataProperty(Receiver, P, V).
  4. Assert: IsAccessorDescriptor(ownDesc) is true.
  5. Let setter be ownDesc.[[Set]].
  6. If setter is undefined, return false.
  7. Perform ? Call(setter, Receiver, « V »).
  8. Return true.

9.1.10 [[Delete]] ( P )

When the [[Delete]] internal method of O is called with property key P, the following steps are taken:

  1. Return ? OrdinaryDelete(O, P).

9.1.10.1 OrdinaryDelete ( O, P )

When the abstract operation OrdinaryDelete is called with Object O and property key P, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Let desc be ? O.[[GetOwnProperty]](P).
  3. If desc is undefined, return true.
  4. If desc.[[Configurable]] is true, then
    1. Remove the own property with name P from O.
    2. Return true.
  5. Return false.

9.1.11 [[OwnPropertyKeys]] ( )

When the [[OwnPropertyKeys]] internal method of O is called, the following steps are taken:

  1. Return ! OrdinaryOwnPropertyKeys(O).

9.1.11.1 OrdinaryOwnPropertyKeys ( O )

When the abstract operation OrdinaryOwnPropertyKeys is called with Object O, the following steps are taken:

  1. Let keys be a new empty List.
  2. For each own property key P of O that is an array index, in ascending numeric index order, do
    1. Add P as the last element of keys.
  3. For each own property key P of O that is a String but is not an array index, in ascending chronological order of property creation, do
    1. Add P as the last element of keys.
  4. For each own property key P of O that is a Symbol, in ascending chronological order of property creation, do
    1. Add P as the last element of keys.
  5. Return keys.

9.1.12 ObjectCreate ( proto [ , internalSlotsList ] )

The abstract operation ObjectCreate with argument proto (an object or null) is used to specify the runtime creation of new ordinary objects. The optional argument internalSlotsList is a List of the names of additional internal slots that must be defined as part of the object. If the list is not provided, a new empty List is used. This abstract operation performs the following steps:

  1. If internalSlotsList is not present, set internalSlotsList to a new empty List.
  2. Let obj be a newly created object with an internal slot for each name in internalSlotsList.
  3. Set obj's essential internal methods to the default ordinary object definitions specified in 9.1.
  4. Set obj.[[Prototype]] to proto.
  5. Set obj.[[Extensible]] to true.
  6. Return obj.

9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )

The abstract operation OrdinaryCreateFromConstructor creates an ordinary object whose [[Prototype]] value is retrieved from a constructor's prototype property, if it exists. Otherwise the intrinsic named by intrinsicDefaultProto is used for [[Prototype]]. The optional internalSlotsList is a List of the names of additional internal slots that must be defined as part of the object. If the list is not provided, a new empty List is used. This abstract operation performs the following steps:

  1. Assert: intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object.
  2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
  3. Return ObjectCreate(proto, internalSlotsList).

9.1.14 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )

The abstract operation GetPrototypeFromConstructor determines the [[Prototype]] value that should be used to create an object corresponding to a specific constructor. The value is retrieved from the constructor's prototype property, if it exists. Otherwise the intrinsic named by intrinsicDefaultProto is used for [[Prototype]]. This abstract operation performs the following steps:

  1. Assert: intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object.
  2. Assert: IsCallable(constructor) is true.
  3. Let proto be ? Get(constructor, "prototype").
  4. If Type(proto) is not Object, then
    1. Let realm be ? GetFunctionRealm(constructor).
    2. Set proto to realm's intrinsic object named intrinsicDefaultProto.
  5. Return proto.
Note

If constructor does not supply a [[Prototype]] value, the default value that is used is obtained from the realm of the constructor function rather than from the running execution context.

9.2 ECMAScript Function Objects

ECMAScript function objects encapsulate parameterized ECMAScript code closed over a lexical environment and support the dynamic evaluation of that code. An ECMAScript function object is an ordinary object and has the same internal slots and the same internal methods as other ordinary objects. The code of an ECMAScript function object may be either strict mode code (10.2.1) or non-strict code. An ECMAScript function object whose code is strict mode code is called a strict function. One whose code is not strict mode code is called a non-strict function.

ECMAScript function objects have the additional internal slots listed in Table 27.

Internal Slot Type Description
[[Environment]] Lexical Environment The Lexical Environment that the function was closed over. Used as the outer environment when evaluating the code of the function.
[[FormalParameters]] Parse Node The root parse node of the source text that defines the function's formal parameter list.
[[FunctionKind]] String Either "normal", "classConstructor", "generator", "async", or "async generator".
[[ECMAScriptCode]] Parse Node The root parse node of the source text that defines the function's body.
[[ConstructorKind]] String Either "base" or "derived".
[[Realm]] Realm Record The realm in which the function was created and which provides any intrinsic objects that are accessed when evaluating the function.
[[ScriptOrModule]] Script Record or Module Record The script or module in which the function was created.
[[ThisMode]] (lexical, strict, global) Defines how this references are interpreted within the formal parameters and code body of the function. lexical means that this refers to the this value of a lexically enclosing function. strict means that the this value is used exactly as provided by an invocation of the function. global means that a this value of undefined is interpreted as a reference to the global object.
[[Strict]] Boolean true if this is a strict function, false if this is a non-strict function.
[[HomeObject]] Object If the function uses super, this is the object whose [[GetPrototypeOf]] provides the object where super property lookups begin.
[[SourceText]] String The source text that defines the function.

All ECMAScript function objects have the [[Call]] internal method defined here. ECMAScript functions that are also constructors in addition have the [[Construct]] internal method.

9.2.1 [[Call]] ( thisArgument, argumentsList )

The [[Call]] internal method for an ECMAScript function object F is called with parameters thisArgument and argumentsList, a List of ECMAScript language values. The following steps are taken:

  1. Assert: F is an ECMAScript function object.
  2. If F.[[FunctionKind]] is "classConstructor", throw a TypeError exception.
  3. Let callerContext be the running execution context.
  4. Let calleeContext be PrepareForOrdinaryCall(F, undefined).
  5. Assert: calleeContext is now the running execution context.
  6. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument).
  7. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
  8. Remove calleeContext from the execution context stack and restore callerContext as the running execution context.
  9. If result.[[Type]] is return, return NormalCompletion(result.[[Value]]).
  10. ReturnIfAbrupt(result).
  11. Return NormalCompletion(undefined).
Note

When calleeContext is removed from the execution context stack in step 8 it must not be destroyed if it is suspended and retained for later resumption by an accessible generator object.

9.2.1.1 PrepareForOrdinaryCall ( F, newTarget )

When the abstract operation PrepareForOrdinaryCall is called with function object F and ECMAScript language value newTarget, the following steps are taken:

  1. Assert: Type(newTarget) is Undefined or Object.
  2. Let callerContext be the running execution context.
  3. Let calleeContext be a new ECMAScript code execution context.
  4. Set the Function of calleeContext to F.
  5. Let calleeRealm be F.[[Realm]].
  6. Set the Realm of calleeContext to calleeRealm.
  7. Set the ScriptOrModule of calleeContext to F.[[ScriptOrModule]].
  8. Let localEnv be NewFunctionEnvironment(F, newTarget).
  9. Set the LexicalEnvironment of calleeContext to localEnv.
  10. Set the VariableEnvironment of calleeContext to localEnv.
  11. If callerContext is not already suspended, suspend callerContext.
  12. Push calleeContext onto the execution context stack; calleeContext is now the running execution context.
  13. NOTE: Any exception objects produced after this point are associated with calleeRealm.
  14. Return calleeContext.

9.2.1.2 OrdinaryCallBindThis ( F, calleeContext, thisArgument )

When the abstract operation OrdinaryCallBindThis is called with function object F, execution context calleeContext, and ECMAScript value thisArgument, the following steps are taken:

  1. Let thisMode be F.[[ThisMode]].
  2. If thisMode is lexical, return NormalCompletion(undefined).
  3. Let calleeRealm be F.[[Realm]].
  4. Let localEnv be the LexicalEnvironment of calleeContext.
  5. If thisMode is strict, let thisValue be thisArgument.
  6. Else,
    1. If thisArgument is undefined or null, then
      1. Let globalEnv be calleeRealm.[[GlobalEnv]].
      2. Let globalEnvRec be globalEnv's EnvironmentRecord.
      3. Assert: globalEnvRec is a global Environment Record.
      4. Let thisValue be globalEnvRec.[[GlobalThisValue]].
    2. Else,
      1. Let thisValue be ! ToObject(thisArgument).
      2. NOTE: ToObject produces wrapper objects using calleeRealm.
  7. Let envRec be localEnv's EnvironmentRecord.
  8. Assert: envRec is a function Environment Record.
  9. Assert: The next step never returns an abrupt completion because envRec.[[ThisBindingStatus]] is not "initialized".
  10. Return envRec.BindThisValue(thisValue).

9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList )

When the abstract operation OrdinaryCallEvaluateBody is called with function object F and List argumentsList, the following steps are taken:

  1. Return the result of EvaluateBody of the parsed code that is F.[[ECMAScriptCode]] passing F and argumentsList as the arguments.

9.2.2 [[Construct]] ( argumentsList, newTarget )

The [[Construct]] internal method for an ECMAScript function object F is called with parameters argumentsList and newTarget. argumentsList is a possibly empty List of ECMAScript language values. The following steps are taken:

  1. Assert: F is an ECMAScript function object.
  2. Assert: Type(newTarget) is Object.
  3. Let callerContext be the running execution context.
  4. Let kind be F.[[ConstructorKind]].
  5. If kind is "base", then
    1. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget, "%ObjectPrototype%").
  6. Let calleeContext be PrepareForOrdinaryCall(F, newTarget).
  7. Assert: calleeContext is now the running execution context.
  8. If kind is "base", perform OrdinaryCallBindThis(F, calleeContext, thisArgument).
  9. Let constructorEnv be the LexicalEnvironment of calleeContext.
  10. Let envRec be constructorEnv's EnvironmentRecord.
  11. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
  12. Remove calleeContext from the execution context stack and restore callerContext as the running execution context.
  13. If result.[[Type]] is return, then
    1. If Type(result.[[Value]]) is Object, return NormalCompletion(result.[[Value]]).
    2. If kind is "base", return NormalCompletion(thisArgument).
    3. If result.[[Value]] is not undefined, throw a TypeError exception.
  14. Else, ReturnIfAbrupt(result).
  15. Return ? envRec.GetThisBinding().

9.2.3 FunctionAllocate ( functionPrototype, strict, functionKind )

The abstract operation FunctionAllocate requires the three arguments functionPrototype, strict and functionKind. FunctionAllocate performs the following steps:

  1. Assert: Type(functionPrototype) is Object.
  2. Assert: functionKind is either "normal", "non-constructor", "generator", "async", or "async generator".
  3. If functionKind is "normal", let needsConstruct be true.
  4. Else, let needsConstruct be false.
  5. If functionKind is "non-constructor", set functionKind to "normal".
  6. Let F be a newly created ECMAScript function object with the internal slots listed in Table 27. All of those internal slots are initialized to undefined.
  7. Set F's essential internal methods to the default ordinary object definitions specified in 9.1.
  8. Set F.[[Call]] to the definition specified in 9.2.1.
  9. If needsConstruct is true, then
    1. Set F.[[Construct]] to the definition specified in 9.2.2.
    2. Set F.[[ConstructorKind]] to "base".
  10. Set F.[[Strict]] to strict.
  11. Set F.[[FunctionKind]] to functionKind.
  12. Set F.[[Prototype]] to functionPrototype.
  13. Set F.[[Extensible]] to true.
  14. Set F.[[Realm]] to the current Realm Record.
  15. Return F.

9.2.4 FunctionInitialize ( F, kind, ParameterList, Body, Scope )

The abstract operation FunctionInitialize requires the arguments: a function object F, kind which is one of (Normal, Method, Arrow), a parameter list Parse Node specified by ParameterList, a body Parse Node specified by Body, a Lexical Environment specified by Scope. FunctionInitialize performs the following steps:

  1. Let len be the ExpectedArgumentCount of ParameterList.
  2. Perform ! SetFunctionLength(F, len).
  3. Let Strict be F.[[Strict]].
  4. Set F.[[Environment]] to Scope.
  5. Set F.[[FormalParameters]] to ParameterList.
  6. Set F.[[ECMAScriptCode]] to Body.
  7. Set F.[[ScriptOrModule]] to GetActiveScriptOrModule().
  8. If kind is Arrow, set F.[[ThisMode]] to lexical.
  9. Else if Strict is true, set F.[[ThisMode]] to strict.
  10. Else, set F.[[ThisMode]] to global.
  11. Return F.

9.2.5 FunctionCreate ( kind, ParameterList, Body, Scope, Strict [ , prototype ] )

The abstract operation FunctionCreate requires the arguments: kind which is one of (Normal, Method, Arrow), a parameter list Parse Node specified by ParameterList, a body Parse Node specified by Body, a Lexical Environment specified by Scope, a Boolean flag Strict, and optionally, an object prototype. FunctionCreate performs the following steps:

  1. If prototype is not present, then
    1. Set prototype to the intrinsic object %FunctionPrototype%.
  2. If kind is not Normal, let allocKind be "non-constructor".
  3. Else, let allocKind be "normal".
  4. Let F be FunctionAllocate(prototype, Strict, allocKind).
  5. Return FunctionInitialize(F, kind, ParameterList, Body, Scope).

9.2.6 GeneratorFunctionCreate ( kind, ParameterList, Body, Scope, Strict )

The abstract operation GeneratorFunctionCreate requires the arguments: kind which is one of (Normal, Method), a parameter list Parse Node specified by ParameterList, a body Parse Node specified by Body, a Lexical Environment specified by Scope, and a Boolean flag Strict. GeneratorFunctionCreate performs the following steps:

  1. Let functionPrototype be the intrinsic object %Generator%.
  2. Let F be FunctionAllocate(functionPrototype, Strict, "generator").
  3. Return FunctionInitialize(F, kind, ParameterList, Body, Scope).

9.2.7 AsyncGeneratorFunctionCreate ( kind, ParameterList, Body, Scope, Strict )

The abstract operation AsyncGeneratorFunctionCreate requires the arguments: kind which is one of (Normal, Method), a parameter list Parse Node specified by ParameterList, a body Parse Node specified by Body, a Lexical Environment specified by Scope, and a Boolean flag Strict. AsyncGeneratorFunctionCreate performs the following steps:

  1. Let functionPrototype be the intrinsic object %AsyncGenerator%.
  2. Let F be ! FunctionAllocate(functionPrototype, Strict, "generator").
  3. Return ! FunctionInitialize(F, kind, ParameterList, Body, Scope).

9.2.8 AsyncFunctionCreate ( kind, parameters, body, Scope, Strict )

The abstract operation AsyncFunctionCreate requires the arguments: kind which is one of (Normal, Method, Arrow), a parameter list Parse Node specified by parameters, a body Parse Node specified by body, a Lexical Environment specified by Scope, and a Boolean flag Strict. AsyncFunctionCreate performs the following steps:

  1. Let functionPrototype be the intrinsic object %AsyncFunctionPrototype%.

9.2.9 AddRestrictedFunctionProperties ( F, realm )

The abstract operation AddRestrictedFunctionProperties is called with a function object F and Realm Record realm as its argument. It performs the following steps:

  1. Assert: realm.[[Intrinsics]].[[%ThrowTypeError%]] exists and has been initialized.
  2. Let thrower be realm.[[Intrinsics]].[[%ThrowTypeError%]].
  3. Perform ! DefinePropertyOrThrow(F, "caller", PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: true }).
  4. Return ! DefinePropertyOrThrow(F, "arguments", PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: true }).

9.2.9.1 %ThrowTypeError% ( )

The %ThrowTypeError% intrinsic is an anonymous built-in function object that is defined once for each realm. When %ThrowTypeError% is called it performs the following steps:

  1. Throw a TypeError exception.

The value of the [[Extensible]] internal slot of a %ThrowTypeError% function is false.

The "length" property of a %ThrowTypeError% function has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

9.2.10 MakeConstructor ( F [ , writablePrototype [ , prototype ] ] )

The abstract operation MakeConstructor requires a Function argument F and optionally, a Boolean writablePrototype and an object prototype. If prototype is provided it is assumed to already contain, if needed, a "constructor" property whose value is F. This operation converts F into a constructor by performing the following steps:

  1. Assert: F is an ECMAScript function object.
  2. Assert: IsConstructor(F) is true.
  3. Assert: F is an extensible object that does not have a prototype own property.
  4. If writablePrototype is not present, set writablePrototype to true.
  5. If prototype is not present, then
    1. Set prototype to ObjectCreate(%ObjectPrototype%).
    2. Perform ! DefinePropertyOrThrow(prototype, "constructor", PropertyDescriptor { [[Value]]: F, [[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: true }).
  6. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: false }).
  7. Return NormalCompletion(undefined).

9.2.11 MakeClassConstructor ( F )

The abstract operation MakeClassConstructor with argument F performs the following steps:

  1. Assert: F is an ECMAScript function object.
  2. Assert: F.[[FunctionKind]] is "normal".
  3. Set F.[[FunctionKind]] to "classConstructor".
  4. Return NormalCompletion(undefined).

9.2.12 MakeMethod ( F, homeObject )

The abstract operation MakeMethod with arguments F and homeObject configures F as a method by performing the following steps:

  1. Assert: F is an ECMAScript function object.
  2. Assert: Type(homeObject) is Object.
  3. Set F.[[HomeObject]] to homeObject.
  4. Return NormalCompletion(undefined).

9.2.13 SetFunctionName ( F, name [ , prefix ] )

The abstract operation SetFunctionName requires a Function argument F, a String or Symbol argument name and optionally a String argument prefix. This operation adds a name property to F by performing the following steps:

  1. Assert: F is an extensible object that does not have a name own property.
  2. Assert: Type(name) is either Symbol or String.
  3. Assert: If prefix is present, then Type(prefix) is String.
  4. If Type(name) is Symbol, then
    1. Let description be name's [[Description]] value.
    2. If description is undefined, set name to the empty String.
    3. Else, set name to the string-concatenation of "[", description, and "]".
  5. If prefix is present, then
    1. Set name to the string-concatenation of prefix, the code unit 0x0020 (SPACE), and name.
  6. Return ! DefinePropertyOrThrow(F, "name", PropertyDescriptor { [[Value]]: name, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }).

9.2.14 SetFunctionLength ( F, length )

The abstract operation SetFunctionLength requires a Function argument F and a Number argument length. This operation adds a "length" property to F by performing the following steps:

  1. Assert: F is an extensible object that does not have a "length" own property.
  2. Assert: Type(length) is Number.
  3. Assert: length ≥ 0 and ! ToInteger(length) is equal to length.
  4. Return ! DefinePropertyOrThrow(F, "length", PropertyDescriptor { [[Value]]: length, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }).

9.2.15 FunctionDeclarationInstantiation ( func, argumentsList )

Note 1

When an execution context is established for evaluating an ECMAScript function a new function Environment Record is created and bindings for each formal parameter are instantiated in that Environment Record. Each declaration in the function body is also instantiated. If the function's formal parameters do not include any default value initializers then the body declarations are instantiated in the same Environment Record as the parameters. If default value parameter initializers exist, a second Environment Record is created for the body declarations. Formal parameters and functions are initialized as part of FunctionDeclarationInstantiation. All other bindings are initialized during evaluation of the function body.

FunctionDeclarationInstantiation is performed as follows using arguments func and argumentsList. func is the function object for which the execution context is being established.

  1. Let calleeContext be the running execution context.
  2. Let env be the LexicalEnvironment of calleeContext.
  3. Let envRec be env's EnvironmentRecord.
  4. Let code be func.[[ECMAScriptCode]].
  5. Let strict be func.[[Strict]].
  6. Let formals be func.[[FormalParameters]].
  7. Let parameterNames be the BoundNames of formals.
  8. If parameterNames has any duplicate entries, let hasDuplicates be true. Otherwise, let hasDuplicates be false.
  9. Let simpleParameterList be IsSimpleParameterList of formals.
  10. Let hasParameterExpressions be ContainsExpression of formals.
  11. Let varNames be the VarDeclaredNames of code.
  12. Let varDeclarations be the VarScopedDeclarations of code.
  13. Let lexicalNames be the LexicallyDeclaredNames of code.
  14. Let functionNames be a new empty List.
  15. Let functionsToInitialize be a new empty List.
  16. For each d in varDeclarations, in reverse list order, do
    1. If d is neither a VariableDeclaration nor a ForBinding nor a BindingIdentifier, then
      1. Assert: d is either a FunctionDeclaration, a GeneratorDeclaration, an AsyncFunctionDeclaration, or an AsyncGeneratorDeclaration.
      2. Let fn be the sole element of the BoundNames of d.
      3. If fn is not an element of functionNames, then
        1. Insert fn as the first element of functionNames.
        2. NOTE: If there are multiple function declarations for the same name, the last declaration is used.
        3. Insert d as the first element of functionsToInitialize.
  17. Let argumentsObjectNeeded be true.
  18. If func.[[ThisMode]] is lexical, then
    1. NOTE: Arrow functions never have an arguments objects.
    2. Set argumentsObjectNeeded to false.
  19. Else if "arguments" is an element of parameterNames, then
    1. Set argumentsObjectNeeded to false.
  20. Else if hasParameterExpressions is false, then
    1. If "arguments" is an element of functionNames or if "arguments" is an element of lexicalNames, then
      1. Set argumentsObjectNeeded to false.
  21. For each String paramName in parameterNames, do
    1. Let alreadyDeclared be envRec.HasBinding(paramName).
    2. NOTE: Early errors ensure that duplicate parameter names can only occur in non-strict functions that do not have parameter default values or rest parameters.
    3. If alreadyDeclared is false, then
      1. Perform ! envRec.CreateMutableBinding(paramName, false).
      2. If hasDuplicates is true, then
        1. Perform ! envRec.InitializeBinding(paramName, undefined).
  22. If argumentsObjectNeeded is true, then
    1. If strict is true or if simpleParameterList is false, then
      1. Let ao be CreateUnmappedArgumentsObject(argumentsList).
    2. Else,
      1. NOTE: mapped argument object is only provided for non-strict functions that don't have a rest parameter, any parameter default value initializers, or any destructured parameters.
      2. Let ao be CreateMappedArgumentsObject(func, formals, argumentsList, envRec).
    3. If strict is true, then
      1. Perform ! envRec.CreateImmutableBinding("arguments", false).
    4. Else,
      1. Perform ! envRec.CreateMutableBinding("arguments", false).
    5. Call envRec.InitializeBinding("arguments", ao).
    6. Let parameterBindings be a new List of parameterNames with "arguments" appended.
  23. Else,
    1. Let parameterBindings be parameterNames.
  24. Let iteratorRecord be CreateListIteratorRecord(argumentsList).
  25. If hasDuplicates is true, then
    1. Perform ? IteratorBindingInitialization for formals with iteratorRecord and undefined as arguments.
  26. Else,
    1. Perform ? IteratorBindingInitialization for formals with iteratorRecord and env as arguments.
  27. If hasParameterExpressions is false, then
    1. NOTE: Only a single lexical environment is needed for the parameters and top-level vars.
    2. Let instantiatedVarNames be a copy of the List parameterBindings.
    3. For each n in varNames, do
      1. If n is not an element of instantiatedVarNames, then
        1. Append n to instantiatedVarNames.
        2. Perform ! envRec.CreateMutableBinding(n, false).
        3. Call envRec.InitializeBinding(n, undefined).
    4. Let varEnv be env.
    5. Let varEnvRec be envRec.
  28. Else,
    1. NOTE: A separate Environment Record is needed to ensure that closures created by expressions in the formal parameter list do not have visibility of declarations in the function body.
    2. Let varEnv be NewDeclarativeEnvironment(env).
    3. Let varEnvRec be varEnv's EnvironmentRecord.
    4. Set the VariableEnvironment of calleeContext to varEnv.
    5. Let instantiatedVarNames be a new empty List.
    6. For each n in varNames, do
      1. If n is not an element of instantiatedVarNames, then
        1. Append n to instantiatedVarNames.
        2. Perform ! varEnvRec.CreateMutableBinding(n, false).
        3. If n is not an element of parameterBindings or if n is an element of functionNames, let initialValue be undefined.
        4. Else,
          1. Let initialValue be ! envRec.GetBindingValue(n, false).
        5. Call varEnvRec.InitializeBinding(n, initialValue).
        6. NOTE: vars whose names are the same as a formal parameter, initially have the same value as the corresponding initialized parameter.
  29. NOTE: Annex B.3.3.1 adds additional steps at this point.
  30. If strict is false, then
    1. Let lexEnv be NewDeclarativeEnvironment(varEnv).
    2. NOTE: Non-strict functions use a separate lexical Environment Record for top-level lexical declarations so that a direct eval can determine whether any var scoped declarations introduced by the eval code conflict with pre-existing top-level lexically scoped declarations. This is not needed for strict functions because a strict direct eval always places all declarations into a new Environment Record.
  31. Else, let lexEnv be varEnv.
  32. Let lexEnvRec be lexEnv's EnvironmentRecord.
  33. Set the LexicalEnvironment of calleeContext to lexEnv.
  34. Let lexDeclarations be the LexicallyScopedDeclarations of code.
  35. For each element d in lexDeclarations, do
    1. NOTE: A lexically declared name cannot be the same as a function/generator declaration, formal parameter, or a var name. Lexically declared names are only instantiated here but not initialized.
    2. For each element dn of the BoundNames of d, do
      1. If IsConstantDeclaration of d is true, then
        1. Perform ! lexEnvRec.CreateImmutableBinding(dn, true).
      2. Else,
        1. Perform ! lexEnvRec.CreateMutableBinding(dn, false).
  36. For each Parse Node f in functionsToInitialize, do
    1. Let fn be the sole element of the BoundNames of f.
    2. Let fo be the result of performing InstantiateFunctionObject for f with argument lexEnv.
    3. Perform ! varEnvRec.SetMutableBinding(fn, fo, false).
  37. Return NormalCompletion(empty).
Note 2

B.3.3 provides an extension to the above algorithm that is necessary for backwards compatibility with web browser implementations of ECMAScript that predate ECMAScript 2015.

Note 3

Parameter Initializers may contain direct eval expressions. Any top level declarations of such evals are only visible to the eval code (10.2). The creation of the environment for such declarations is described in 14.1.19.

9.3 Built-in Function Objects

The built-in function objects defined in this specification may be implemented as either ECMAScript function objects (9.2) whose behaviour is provided using ECMAScript code or as implementation provided function exotic objects whose behaviour is provided in some other manner. In either case, the effect of calling such functions must conform to their specifications. An implementation may also provide additional built-in function objects that are not defined in this specification.

If a built-in function object is implemented as an exotic object it must have the ordinary object behaviour specified in 9.1. All such function exotic objects also have [[Prototype]], [[Extensible]], [[Realm]], and [[ScriptOrModule]] internal slots.

Unless otherwise specified every built-in function object has the %FunctionPrototype% object as the initial value of its [[Prototype]] internal slot.

The behaviour specified for each built-in function via algorithm steps or other means is the specification of the function body behaviour for both [[Call]] and [[Construct]] invocations of the function. However, [[Construct]] invocation is not supported by all built-in functions. For each built-in function, when invoked with [[Call]], the [[Call]] thisArgument provides the this value, the [[Call]] argumentsList provides the named parameters, and the NewTarget value is undefined. When invoked with [[Construct]], the this value is uninitialized, the [[Construct]] argumentsList provides the named parameters, and the [[Construct]] newTarget parameter provides the NewTarget value. If the built-in function is implemented as an ECMAScript function object then this specified behaviour must be implemented by the ECMAScript code that is the body of the function. Built-in functions that are ECMAScript function objects must be strict functions. If a built-in constructor has any [[Call]] behaviour other than throwing a TypeError exception, an ECMAScript implementation of the function must be done in a manner that does not cause the function's [[FunctionKind]] internal slot to have the value "classConstructor".

Built-in function objects that are not identified as constructors do not implement the [[Construct]] internal method unless otherwise specified in the description of a particular function. When a built-in constructor is called as part of a new expression the argumentsList parameter of the invoked [[Construct]] internal method provides the values for the built-in constructor's named parameters.

Built-in functions that are not constructors do not have a prototype property unless otherwise specified in the description of a particular function.

If a built-in function object is not implemented as an ECMAScript function it must provide [[Call]] and [[Construct]] internal methods that conform to the following definitions:

9.3.1 [[Call]] ( thisArgument, argumentsList )

The [[Call]] internal method for a built-in function object F is called with parameters thisArgument and argumentsList, a List of ECMAScript language values. The following steps are taken:

  1. Let callerContext be the running execution context.
  2. If callerContext is not already suspended, suspend callerContext.
  3. Let calleeContext be a new ECMAScript code execution context.
  4. Set the Function of calleeContext to F.
  5. Let calleeRealm be F.[[Realm]].
  6. Set the Realm of calleeContext to calleeRealm.
  7. Set the ScriptOrModule of calleeContext to F.[[ScriptOrModule]].
  8. Perform any necessary implementation-defined initialization of calleeContext.
  9. Push calleeContext onto the execution context stack; calleeContext is now the running execution context.
  10. Let result be the Completion Record that is the result of evaluating F in an implementation-defined manner that conforms to the specification of F. thisArgument is the this value, argumentsList provides the named parameters, and the NewTarget value is undefined.
  11. Remove calleeContext from the execution context stack and restore callerContext as the running execution context.
  12. Return result.
Note

When calleeContext is removed from the execution context stack it must not be destroyed if it has been suspended and retained by an accessible generator object for later resumption.

9.3.2 [[Construct]] ( argumentsList, newTarget )

The [[Construct]] internal method for built-in function object F is called with parameters argumentsList and newTarget. The steps performed are the same as [[Call]] (see 9.3.1) except that step 10 is replaced by:

10. Let result be the Completion Record that is the result of evaluating F in an implementation-defined manner that conforms to the specification of F. The this value is uninitialized, argumentsList provides the named parameters, and newTarget provides the NewTarget value.

9.3.3 CreateBuiltinFunction ( steps, internalSlotsList [ , realm [ , prototype ] ] )

The abstract operation CreateBuiltinFunction takes arguments steps, internalSlotsList, realm, and prototype. The argument internalSlotsList is a List of the names of additional internal slots that must be defined as part of the object. CreateBuiltinFunction returns a built-in function object created by the following steps:

  1. Assert: steps is either a set of algorithm steps or other definition of a function's behaviour provided in this specification.
  2. If realm is not present, set realm to the current Realm Record.
  3. Assert: realm is a Realm Record.
  4. If prototype is not present, set prototype to realm.[[Intrinsics]].[[%FunctionPrototype%]].
  5. Let func be a new built-in function object that when called performs the action described by steps. The new function object has internal slots whose names are the elements of internalSlotsList. The initial value of each of those internal slots is undefined.
  6. Set func.[[Realm]] to realm.
  7. Set func.[[Prototype]] to prototype.
  8. Set func.[[Extensible]] to true.
  9. Set func.[[ScriptOrModule]] to null.
  10. Return func.

Each built-in function defined in this specification is created by calling the CreateBuiltinFunction abstract operation.

9.4 Built-in Exotic Object Internal Methods and Slots

This specification defines several kinds of built-in exotic objects. These objects generally behave similar to ordinary objects except for a few specific situations. The following exotic objects use the ordinary object internal methods except where it is explicitly specified otherwise below:

9.4.1 Bound Function Exotic Objects

A bound function is an exotic object that wraps another function object. A bound function is callable (it has a [[Call]] internal method and may have a [[Construct]] internal method). Calling a bound function generally results in a call of its wrapped function.

Bound function objects do not have the internal slots of ECMAScript function objects defined in Table 27. Instead they have the internal slots defined in Table 28.

Internal Slot Type Description
[[BoundTargetFunction]] Callable Object The wrapped function object.
[[BoundThis]] Any The value that is always passed as the this value when calling the wrapped function.
[[BoundArguments]] List of Any A list of values whose elements are used as the first arguments to any call to the wrapped function.

Bound function objects provide all of the essential internal methods as specified in 9.1. However, they use the following definitions for the essential internal methods of function objects.

9.4.1.1 [[Call]] ( thisArgument, argumentsList )

When the [[Call]] internal method of a bound function exotic object, F, which was created using the bind function is called with parameters thisArgument and argumentsList, a List of ECMAScript language values, the following steps are taken:

  1. Let target be F.[[BoundTargetFunction]].
  2. Let boundThis be F.[[BoundThis]].
  3. Let boundArgs be F.[[BoundArguments]].
  4. Let args be a new list containing the same values as the list boundArgs in the same order followed by the same values as the list argumentsList in the same order.
  5. Return ? Call(target, boundThis, args).

9.4.1.2 [[Construct]] ( argumentsList, newTarget )

When the [[Construct]] internal method of a bound function exotic object, F that was created using the bind function is called with a list of arguments argumentsList and newTarget, the following steps are taken:

  1. Let target be F.[[BoundTargetFunction]].
  2. Assert: IsConstructor(target) is true.
  3. Let boundArgs be F.[[BoundArguments]].
  4. Let args be a new list containing the same values as the list boundArgs in the same order followed by the same values as the list argumentsList in the same order.
  5. If SameValue(F, newTarget) is true, set newTarget to target.
  6. Return ? Construct(target, args, newTarget).

9.4.1.3 BoundFunctionCreate ( targetFunction, boundThis, boundArgs )

The abstract operation BoundFunctionCreate with arguments targetFunction, boundThis and boundArgs is used to specify the creation of new Bound Function exotic objects. It performs the following steps:

  1. Assert: Type(targetFunction) is Object.
  2. Let proto be ? targetFunction.[[GetPrototypeOf]]().
  3. Let obj be a newly created object.
  4. Set obj's essential internal methods to the default ordinary object definitions specified in 9.1.
  5. Set obj.[[Call]] as described in 9.4.1.1.
  6. If IsConstructor(targetFunction) is true, then
    1. Set obj.[[Construct]] as described in 9.4.1.2.
  7. Set obj.[[Prototype]] to proto.
  8. Set obj.[[Extensible]] to true.
  9. Set obj.[[BoundTargetFunction]] to targetFunction.
  10. Set obj.[[BoundThis]] to boundThis.
  11. Set obj.[[BoundArguments]] to boundArgs.
  12. Return obj.

9.4.2 Array Exotic Objects

An Array object is an exotic object that gives special treatment to array index property keys (see 6.1.7). A property whose property name is an array index is also called an element. Every Array object has a non-configurable "length" property whose value is always a nonnegative integer less than 232. The value of the "length" property is numerically greater than the name of every own property whose name is an array index; whenever an own property of an Array object is created or changed, other properties are adjusted as necessary to maintain this invariant. Specifically, whenever an own property is added whose name is an array index, the value of the "length" property is changed, if necessary, to be one more than the numeric value of that array index; and whenever the value of the "length" property is changed, every own property whose name is an array index whose value is not smaller than the new length is deleted. This constraint applies only to own properties of an Array object and is unaffected by "length" or array index properties that may be inherited from its prototypes.

Note

A String property name P is an array index if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 232 - 1.

Array exotic objects provide an alternative definition for the [[DefineOwnProperty]] internal method. Except for that internal method, Array exotic objects provide all of the other essential internal methods as specified in 9.1.

9.4.2.1 [[DefineOwnProperty]] ( P, Desc )

When the [[DefineOwnProperty]] internal method of an Array exotic object A is called with property key P, and Property Descriptor Desc, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. If P is "length", then
    1. Return ? ArraySetLength(A, Desc).
  3. Else if P is an array index, then
    1. Let oldLenDesc be OrdinaryGetOwnProperty(A, "length").
    2. Assert: oldLenDesc will never be undefined or an accessor descriptor because Array objects are created with a length data property that cannot be deleted or reconfigured.
    3. Let oldLen be oldLenDesc.[[Value]].
    4. Let index be ! ToUint32(P).
    5. If indexoldLen and oldLenDesc.[[Writable]] is false, return false.
    6. Let succeeded be ! OrdinaryDefineOwnProperty(A, P, Desc).
    7. If succeeded is false, return false.
    8. If indexoldLen, then
      1. Set oldLenDesc.[[Value]] to index + 1.
      2. Let succeeded be OrdinaryDefineOwnProperty(A, "length", oldLenDesc).
      3. Assert: succeeded is true.
    9. Return true.
  4. Return OrdinaryDefineOwnProperty(A, P, Desc).

9.4.2.2 ArrayCreate ( length [ , proto ] )

The abstract operation ArrayCreate with argument length (either 0 or a positive integer) and optional argument proto is used to specify the creation of new Array exotic objects. It performs the following steps:

  1. Assert: length is an integer Number ≥ 0.
  2. If length is -0, set length to +0.
  3. If length > 232 - 1, throw a RangeError exception.
  4. If proto is not present, set proto to the intrinsic object %ArrayPrototype%.
  5. Let A be a newly created Array exotic object.
  6. Set A's essential internal methods except for [[DefineOwnProperty]] to the default ordinary object definitions specified in 9.1.
  7. Set A.[[DefineOwnProperty]] as specified in 9.4.2.1.
  8. Set A.[[Prototype]] to proto.
  9. Set A.[[Extensible]] to true.
  10. Perform ! OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor { [[Value]]: length, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  11. Return A.

9.4.2.3 ArraySpeciesCreate ( originalArray, length )

The abstract operation ArraySpeciesCreate with arguments originalArray and length is used to specify the creation of a new Array object using a constructor function that is derived from originalArray. It performs the following steps:

  1. Assert: length is an integer Number ≥ 0.
  2. If length is -0, set length to +0.
  3. Let isArray be ? IsArray(originalArray).
  4. If isArray is false, return ? ArrayCreate(length).
  5. Let C be ? Get(originalArray, "constructor").
  6. If IsConstructor(C) is true, then
    1. Let thisRealm be the current Realm Record.
    2. Let realmC be ? GetFunctionRealm(C).
    3. If thisRealm and realmC are not the same Realm Record, then
      1. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, set C to undefined.
  7. If Type(C) is Object, then
    1. Set C to ? Get(C, @@species).
    2. If C is null, set C to undefined.
  8. If C is undefined, return ? ArrayCreate(length).
  9. If IsConstructor(C) is false, throw a TypeError exception.
  10. Return ? Construct(C, « length »).
Note

If originalArray was created using the standard built-in Array constructor for a realm that is not the realm of the running execution context, then a new Array is created using the realm of the running execution context. This maintains compatibility with Web browsers that have historically had that behaviour for the Array.prototype methods that now are defined using ArraySpeciesCreate.

9.4.2.4 ArraySetLength ( A, Desc )

When the abstract operation ArraySetLength is called with an Array exotic object A, and Property Descriptor Desc, the following steps are taken:

  1. If Desc.[[Value]] is absent, then
    1. Return OrdinaryDefineOwnProperty(A, "length", Desc).
  2. Let newLenDesc be a copy of Desc.
  3. Let newLen be ? ToUint32(Desc.[[Value]]).
  4. Let numberLen be ? ToNumber(Desc.[[Value]]).
  5. If newLennumberLen, throw a RangeError exception.
  6. Set newLenDesc.[[Value]] to newLen.
  7. Let oldLenDesc be OrdinaryGetOwnProperty(A, "length").
  8. Assert: oldLenDesc will never be undefined or an accessor descriptor because Array objects are created with a length data property that cannot be deleted or reconfigured.
  9. Let oldLen be oldLenDesc.[[Value]].
  10. If newLenoldLen, then
    1. Return OrdinaryDefineOwnProperty(A, "length", newLenDesc).
  11. If oldLenDesc.[[Writable]] is false, return false.
  12. If newLenDesc.[[Writable]] is absent or has the value true, let newWritable be true.
  13. Else,
    1. Need to defer setting the [[Writable]] attribute to false in case any elements cannot be deleted.
    2. Let newWritable be false.
    3. Set newLenDesc.[[Writable]] to true.
  14. Let succeeded be ! OrdinaryDefineOwnProperty(A, "length", newLenDesc).
  15. If succeeded is false, return false.
  16. Repeat, while newLen < oldLen,
    1. Decrease oldLen by 1.
    2. Let deleteSucceeded be ! A.[[Delete]](! ToString(oldLen)).
    3. If deleteSucceeded is false, then
      1. Set newLenDesc.[[Value]] to oldLen + 1.
      2. If newWritable is false, set newLenDesc.[[Writable]] to false.
      3. Perform ! OrdinaryDefineOwnProperty(A, "length", newLenDesc).
      4. Return false.
  17. If newWritable is false, then
    1. Return OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor { [[Writable]]: false }). This call will always return true.
  18. Return true.
Note

In steps 3 and 4, if Desc.[[Value]] is an object then its valueOf method is called twice. This is legacy behaviour that was specified with this effect starting with the 2nd Edition of this specification.

9.4.3 String Exotic Objects

A String object is an exotic object that encapsulates a String value and exposes virtual integer-indexed data properties corresponding to the individual code unit elements of the String value. String exotic objects always have a data property named "length" whose value is the number of code unit elements in the encapsulated String value. Both the code unit data properties and the "length" property are non-writable and non-configurable.

String exotic objects have the same internal slots as ordinary objects. They also have a [[StringData]] internal slot.

String exotic objects provide alternative definitions for the following internal methods. All of the other String exotic object essential internal methods that are not defined below are as specified in 9.1.

9.4.3.1 [[GetOwnProperty]] ( P )

When the [[GetOwnProperty]] internal method of a String exotic object S is called with property key P, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Let desc be OrdinaryGetOwnProperty(S, P).
  3. If desc is not undefined, return desc.
  4. Return ! StringGetOwnProperty(S, P).

9.4.3.2 [[DefineOwnProperty]] ( P, Desc )

When the [[DefineOwnProperty]] internal method of a String exotic object S is called with property key P, and Property Descriptor Desc, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Let stringDesc be ! StringGetOwnProperty(S, P).
  3. If stringDesc is not undefined, then
    1. Let extensible be S.[[Extensible]].
    2. Return ! IsCompatiblePropertyDescriptor(extensible, Desc, stringDesc).
  4. Return ! OrdinaryDefineOwnProperty(S, P, Desc).

9.4.3.3 [[OwnPropertyKeys]] ( )

When the [[OwnPropertyKeys]] internal method of a String exotic object O is called, the following steps are taken:

  1. Let keys be a new empty List.
  2. Let str be O.[[StringData]].
  3. Assert: Type(str) is String.
  4. Let len be the length of str.
  5. For each integer i starting with 0 such that i < len, in ascending order, do
    1. Add ! ToString(i) as the last element of keys.
  6. For each own property key P of O such that P is an array index and ToInteger(P) ≥ len, in ascending numeric index order, do
    1. Add P as the last element of keys.
  7. For each own property key P of O such that Type(P) is String and P is not an array index, in ascending chronological order of property creation, do
    1. Add P as the last element of keys.
  8. For each own property key P of O such that Type(P) is Symbol, in ascending chronological order of property creation, do
    1. Add P as the last element of keys.
  9. Return keys.

9.4.3.4 StringCreate ( value, prototype )

The abstract operation StringCreate with arguments value and prototype is used to specify the creation of new String exotic objects. It performs the following steps:

  1. Assert: Type(value) is String.
  2. Let S be a newly created String exotic object.
  3. Set S.[[StringData]] to value.
  4. Set S's essential internal methods to the default ordinary object definitions specified in 9.1.
  5. Set S.[[GetOwnProperty]] as specified in 9.4.3.1.
  6. Set S.[[DefineOwnProperty]] as specified in 9.4.3.2.
  7. Set S.[[OwnPropertyKeys]] as specified in 9.4.3.3.
  8. Set S.[[Prototype]] to prototype.
  9. Set S.[[Extensible]] to true.
  10. Let length be the number of code unit elements in value.
  11. Perform ! DefinePropertyOrThrow(S, "length", PropertyDescriptor { [[Value]]: length, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }).
  12. Return S.

9.4.3.5 StringGetOwnProperty ( S, P )

The abstract operation StringGetOwnProperty called with arguments S and P performs the following steps:

  1. Assert: S is an Object that has a [[StringData]] internal slot.
  2. Assert: IsPropertyKey(P) is true.
  3. If Type(P) is not String, return undefined.
  4. Let index be ! CanonicalNumericIndexString(P).
  5. If index is undefined, return undefined.
  6. If IsInteger(index) is false, return undefined.
  7. If index = -0, return undefined.
  8. Let str be S.[[StringData]].
  9. Assert: Type(str) is String.
  10. Let len be the length of str.
  11. If index < 0 or lenindex, return undefined.
  12. Let resultStr be the String value of length 1, containing one code unit from str, specifically the code unit at index index.
  13. Return a PropertyDescriptor { [[Value]]: resultStr, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false }.

9.4.4 Arguments Exotic Objects

Most ECMAScript functions make an arguments object available to their code. Depending upon the characteristics of the function definition, its arguments object is either an ordinary object or an arguments exotic object. An arguments exotic object is an exotic object whose array index properties map to the formal parameters bindings of an invocation of its associated ECMAScript function.

Arguments exotic objects have the same internal slots as ordinary objects. They also have a [[ParameterMap]] internal slot. Ordinary arguments objects also have a [[ParameterMap]] internal slot whose value is always undefined. For ordinary argument objects the [[ParameterMap]] internal slot is only used by Object.prototype.toString (19.1.3.6) to identify them as such.

Arguments exotic objects provide alternative definitions for the following internal methods. All of the other arguments exotic object essential internal methods that are not defined below are as specified in 9.1

Note 1

The integer-indexed data properties of an arguments exotic object whose numeric name values are less than the number of formal parameters of the corresponding function object initially share their values with the corresponding argument bindings in the function's execution context. This means that changing the property changes the corresponding value of the argument binding and vice-versa. This correspondence is broken if such a property is deleted and then redefined or if the property is changed into an accessor property. If the arguments object is an ordinary object, the values of its properties are simply a copy of the arguments passed to the function and there is no dynamic linkage between the property values and the formal parameter values.

Note 2

The ParameterMap object and its property values are used as a device for specifying the arguments object correspondence to argument bindings. The ParameterMap object and the objects that are the values of its properties are not directly observable from ECMAScript code. An ECMAScript implementation does not need to actually create or use such objects to implement the specified semantics.

Note 3

Ordinary arguments objects define a non-configurable accessor property named "callee" which throws a TypeError exception on access. The "callee" property has a more specific meaning for arguments exotic objects, which are created only for some class of non-strict functions. The definition of this property in the ordinary variant exists to ensure that it is not defined in any other manner by conforming ECMAScript implementations.

Note 4

ECMAScript implementations of arguments exotic objects have historically contained an accessor property named "caller". Prior to ECMAScript 2017, this specification included the definition of a throwing "caller" property on ordinary arguments objects. Since implementations do not contain this extension any longer, ECMAScript 2017 dropped the requirement for a throwing "caller" accessor.

9.4.4.1 [[GetOwnProperty]] ( P )

The [[GetOwnProperty]] internal method of an arguments exotic object when called with a property key P performs the following steps:

  1. Let args be the arguments object.
  2. Let desc be OrdinaryGetOwnProperty(args, P).
  3. If desc is undefined, return desc.
  4. Let map be args.[[ParameterMap]].
  5. Let isMapped be ! HasOwnProperty(map, P).
  6. If isMapped is true, then
    1. Set desc.[[Value]] to Get(map, P).
  7. Return desc.

9.4.4.2 [[DefineOwnProperty]] ( P, Desc )

The [[DefineOwnProperty]] internal method of an arguments exotic object when called with a property key P and Property Descriptor Desc performs the following steps:

  1. Let args be the arguments object.
  2. Let map be args.[[ParameterMap]].
  3. Let isMapped be HasOwnProperty(map, P).
  4. Let newArgDesc be Desc.
  5. If isMapped is true and IsDataDescriptor(Desc) is true, then
    1. If Desc.[[Value]] is not present and Desc.[[Writable]] is present and its value is false, then
      1. Set newArgDesc to a copy of Desc.
      2. Set newArgDesc.[[Value]] to Get(map, P).
  6. Let allowed be ? OrdinaryDefineOwnProperty(args, P, newArgDesc).
  7. If allowed is false, return false.
  8. If isMapped is true, then
    1. If IsAccessorDescriptor(Desc) is true, then
      1. Call map.[[Delete]](P).
    2. Else,
      1. If Desc.[[Value]] is present, then
        1. Let setStatus be Set(map, P, Desc.[[Value]], false).
        2. Assert: setStatus is true because formal parameters mapped by argument objects are always writable.
      2. If Desc.[[Writable]] is present and its value is false, then
        1. Call map.[[Delete]](P).
  9. Return true.

9.4.4.3 [[Get]] ( P, Receiver )

The [[Get]] internal method of an arguments exotic object when called with a property key P and ECMAScript language value Receiver performs the following steps:

  1. Let args be the arguments object.
  2. Let map be args.[[ParameterMap]].
  3. Let isMapped be ! HasOwnProperty(map, P).
  4. If isMapped is false, then
    1. Return ? OrdinaryGet(args, P, Receiver).
  5. Else map contains a formal parameter mapping for P,
    1. Return Get(map, P).

9.4.4.4 [[Set]] ( P, V, Receiver )

The [[Set]] internal method of an arguments exotic object when called with property key P, value V, and ECMAScript language value Receiver performs the following steps:

  1. Let args be the arguments object.
  2. If SameValue(args, Receiver) is false, then
    1. Let isMapped be false.
  3. Else,
    1. Let map be args.[[ParameterMap]].
    2. Let isMapped be ! HasOwnProperty(map, P).
  4. If isMapped is true, then
    1. Let setStatus be Set(map, P, V, false).
    2. Assert: setStatus is true because formal parameters mapped by argument objects are always writable.
  5. Return ? OrdinarySet(args, P, V, Receiver).

9.4.4.5 [[Delete]] ( P )

The [[Delete]] internal method of an arguments exotic object when called with a property key P performs the following steps:

  1. Let args be the arguments object.
  2. Let map be args.[[ParameterMap]].
  3. Let isMapped be ! HasOwnProperty(map, P).
  4. Let result be ? OrdinaryDelete(args, P).
  5. If result is true and isMapped is true, then
    1. Call map.[[Delete]](P).
  6. Return result.

9.4.4.6 CreateUnmappedArgumentsObject ( argumentsList )

The abstract operation CreateUnmappedArgumentsObject called with an argument argumentsList performs the following steps:

  1. Let len be the number of elements in argumentsList.
  2. Let obj be ObjectCreate(%ObjectPrototype%, « [[ParameterMap]] »).
  3. Set obj.[[ParameterMap]] to undefined.
  4. Perform DefinePropertyOrThrow(obj, "length", PropertyDescriptor { [[Value]]: len, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }).
  5. Let index be 0.
  6. Repeat, while index < len,
    1. Let val be argumentsList[index].
    2. Perform CreateDataProperty(obj, ! ToString(index), val).
    3. Increase index by 1.
  7. Perform ! DefinePropertyOrThrow(obj, @@iterator, PropertyDescriptor { [[Value]]: %ArrayProto_values%, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }).
  8. Perform ! DefinePropertyOrThrow(obj, "callee", PropertyDescriptor { [[Get]]: %ThrowTypeError%, [[Set]]: %ThrowTypeError%, [[Enumerable]]: false, [[Configurable]]: false }).
  9. Return obj.

9.4.4.7 CreateMappedArgumentsObject ( func, formals, argumentsList, env )

The abstract operation CreateMappedArgumentsObject is called with object func, Parse Node formals, List argumentsList, and Environment Record env. The following steps are performed:

  1. Assert: formals does not contain a rest parameter, any binding patterns, or any initializers. It may contain duplicate identifiers.
  2. Let len be the number of elements in argumentsList.
  3. Let obj be a newly created arguments exotic object with a [[ParameterMap]] internal slot.
  4. Set obj.[[GetOwnProperty]] as specified in 9.4.4.1.
  5. Set obj.[[DefineOwnProperty]] as specified in 9.4.4.2.
  6. Set obj.[[Get]] as specified in 9.4.4.3.
  7. Set obj.[[Set]] as specified in 9.4.4.4.
  8. Set obj.[[Delete]] as specified in 9.4.4.5.
  9. Set the remainder of obj's essential internal methods to the default ordinary object definitions specified in 9.1.
  10. Set obj.[[Prototype]] to %ObjectPrototype%.
  11. Set obj.[[Extensible]] to true.
  12. Let map be ObjectCreate(null).
  13. Set obj.[[ParameterMap]] to map.
  14. Let parameterNames be the BoundNames of formals.
  15. Let numberOfParameters be the number of elements in parameterNames.
  16. Let index be 0.
  17. Repeat, while index < len,
    1. Let val be argumentsList[index].
    2. Perform CreateDataProperty(obj, ! ToString(index), val).
    3. Increase index by 1.
  18. Perform DefinePropertyOrThrow(obj, "length", PropertyDescriptor { [[Value]]: len, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }).
  19. Let mappedNames be a new empty List.
  20. Let index be numberOfParameters - 1.
  21. Repeat, while index ≥ 0,
    1. Let name be parameterNames[index].
    2. If name is not an element of mappedNames, then
      1. Add name as an element of the list mappedNames.
      2. If index < len, then
        1. Let g be MakeArgGetter(name, env).
        2. Let p be MakeArgSetter(name, env).
        3. Perform map.[[DefineOwnProperty]](! ToString(index), PropertyDescriptor { [[Set]]: p, [[Get]]: g, [[Enumerable]]: false, [[Configurable]]: true }).
    3. Decrease index by 1.
  22. Perform ! DefinePropertyOrThrow(obj, @@iterator, PropertyDescriptor { [[Value]]: %ArrayProto_values%, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }).
  23. Perform ! DefinePropertyOrThrow(obj, "callee", PropertyDescriptor { [[Value]]: func, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }).
  24. Return obj.

9.4.4.7.1 MakeArgGetter ( name, env )

The abstract operation MakeArgGetter called with String name and Environment Record env creates a built-in function object that when executed returns the value bound for name in env. It performs the following steps:

  1. Let steps be the steps of an ArgGetter function as specified below.
  2. Let getter be CreateBuiltinFunction(steps, « [[Name]], [[Env]] »).
  3. Set getter.[[Name]] to name.
  4. Set getter.[[Env]] to env.
  5. Return getter.

An ArgGetter function is an anonymous built-in function with [[Name]] and [[Env]] internal slots. When an ArgGetter function that expects no arguments is called it performs the following steps:

  1. Let f be the active function object.
  2. Let name be f.[[Name]].
  3. Let env be f.[[Env]].
  4. Return env.GetBindingValue(name, false).
Note

ArgGetter functions are never directly accessible to ECMAScript code.

9.4.4.7.2 MakeArgSetter ( name, env )

The abstract operation MakeArgSetter called with String name and Environment Record env creates a built-in function object that when executed sets the value bound for name in env. It performs the following steps:

  1. Let steps be the steps of an ArgSetter function as specified below.
  2. Let setter be CreateBuiltinFunction(steps, « [[Name]], [[Env]] »).
  3. Set setter.[[Name]] to name.
  4. Set setter.[[Env]] to env.
  5. Return setter.

An ArgSetter function is an anonymous built-in function with [[Name]] and [[Env]] internal slots. When an ArgSetter function is called with argument value it performs the following steps:

  1. Let f be the active function object.
  2. Let name be f.[[Name]].
  3. Let env be f.[[Env]].
  4. Return env.SetMutableBinding(name, value, false).
Note

ArgSetter functions are never directly accessible to ECMAScript code.

9.4.5 Integer-Indexed Exotic Objects

An Integer-Indexed exotic object is an exotic object that performs special handling of integer index property keys.

Integer-Indexed exotic objects have the same internal slots as ordinary objects and additionally [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.

Integer-Indexed exotic objects provide alternative definitions for the following internal methods. All of the other Integer-Indexed exotic object essential internal methods that are not defined below are as specified in 9.1.

9.4.5.1 [[GetOwnProperty]] ( P )

When the [[GetOwnProperty]] internal method of an Integer-Indexed exotic object O is called with property key P, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot.
  3. If Type(P) is String, then
    1. Let numericIndex be ! CanonicalNumericIndexString(P).
    2. If numericIndex is not undefined, then
      1. Let value be ? IntegerIndexedElementGet(O, numericIndex).
      2. If value is undefined, return undefined.
      3. Return a PropertyDescriptor { [[Value]]: value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: false }.
  4. Return OrdinaryGetOwnProperty(O, P).

9.4.5.2 [[HasProperty]] ( P )

When the [[HasProperty]] internal method of an Integer-Indexed exotic object O is called with property key P, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot.
  3. If Type(P) is String, then
    1. Let numericIndex be ! CanonicalNumericIndexString(P).
    2. If numericIndex is not undefined, then
      1. Let buffer be O.[[ViewedArrayBuffer]].
      2. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
      3. If IsInteger(numericIndex) is false, return false.
      4. If numericIndex = -0, return false.
      5. If numericIndex < 0, return false.
      6. If numericIndexO.[[ArrayLength]], return false.
      7. Return true.
  4. Return ? OrdinaryHasProperty(O, P).

9.4.5.3 [[DefineOwnProperty]] ( P, Desc )

When the [[DefineOwnProperty]] internal method of an Integer-Indexed exotic object O is called with property key P, and Property Descriptor Desc, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot.
  3. If Type(P) is String, then
    1. Let numericIndex be ! CanonicalNumericIndexString(P).
    2. If numericIndex is not undefined, then
      1. If IsInteger(numericIndex) is false, return false.
      2. If numericIndex = -0, return false.
      3. If numericIndex < 0, return false.
      4. Let length be O.[[ArrayLength]].
      5. If numericIndexlength, return false.
      6. If IsAccessorDescriptor(Desc) is true, return false.
      7. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is true, return false.
      8. If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is false, return false.
      9. If Desc has a [[Writable]] field and if Desc.[[Writable]] is false, return false.
      10. If Desc has a [[Value]] field, then
        1. Let value be Desc.[[Value]].
        2. Return ? IntegerIndexedElementSet(O, numericIndex, value).
      11. Return true.
  4. Return ! OrdinaryDefineOwnProperty(O, P, Desc).

9.4.5.4 [[Get]] ( P, Receiver )

When the [[Get]] internal method of an Integer-Indexed exotic object O is called with property key P and ECMAScript language value Receiver, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. If Type(P) is String, then
    1. Let numericIndex be ! CanonicalNumericIndexString(P).
    2. If numericIndex is not undefined, then
      1. Return ? IntegerIndexedElementGet(O, numericIndex).
  3. Return ? OrdinaryGet(O, P, Receiver).

9.4.5.5 [[Set]] ( P, V, Receiver )

When the [[Set]] internal method of an Integer-Indexed exotic object O is called with property key P, value V, and ECMAScript language value Receiver, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. If Type(P) is String, then
    1. Let numericIndex be ! CanonicalNumericIndexString(P).
    2. If numericIndex is not undefined, then
      1. Return ? IntegerIndexedElementSet(O, numericIndex, V).
  3. Return ? OrdinarySet(O, P, V, Receiver).

9.4.5.6 [[OwnPropertyKeys]] ( )

When the [[OwnPropertyKeys]] internal method of an Integer-Indexed exotic object O is called, the following steps are taken:

  1. Let keys be a new empty List.
  2. Assert: O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.
  3. Let len be O.[[ArrayLength]].
  4. For each integer i starting with 0 such that i < len, in ascending order, do
    1. Add ! ToString(i) as the last element of keys.
  5. For each own property key P of O such that Type(P) is String and P is not an integer index, in ascending chronological order of property creation, do
    1. Add P as the last element of keys.
  6. For each own property key P of O such that Type(P) is Symbol, in ascending chronological order of property creation, do
    1. Add P as the last element of keys.
  7. Return keys.

9.4.5.7 IntegerIndexedObjectCreate ( prototype, internalSlotsList )

The abstract operation IntegerIndexedObjectCreate with arguments prototype and internalSlotsList is used to specify the creation of new Integer-Indexed exotic objects. The argument internalSlotsList is a List of the names of additional internal slots that must be defined as part of the object. IntegerIndexedObjectCreate performs the following steps:

  1. Assert: internalSlotsList contains the names [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]].
  2. Let A be a newly created object with an internal slot for each name in internalSlotsList.
  3. Set A's essential internal methods to the default ordinary object definitions specified in 9.1.
  4. Set A.[[GetOwnProperty]] as specified in 9.4.5.1.
  5. Set A.[[HasProperty]] as specified in 9.4.5.2.
  6. Set A.[[DefineOwnProperty]] as specified in 9.4.5.3.
  7. Set A.[[Get]] as specified in 9.4.5.4.
  8. Set A.[[Set]] as specified in 9.4.5.5.
  9. Set A.[[OwnPropertyKeys]] as specified in 9.4.5.6.
  10. Set A.[[Prototype]] to prototype.
  11. Set A.[[Extensible]] to true.
  12. Return A.

9.4.5.8 IntegerIndexedElementGet ( O, index )

The abstract operation IntegerIndexedElementGet with arguments O and index performs the following steps:

  1. Assert: Type(index) is Number.
  2. Assert: O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.
  3. Let buffer be O.[[ViewedArrayBuffer]].
  4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  5. If IsInteger(index) is false, return undefined.
  6. If index = -0, return undefined.
  7. Let length be O.[[ArrayLength]].
  8. If index < 0 or indexlength, return undefined.
  9. Let offset be O.[[ByteOffset]].
  10. Let arrayTypeName be the String value of O.[[TypedArrayName]].
  11. Let elementSize be the Number value of the Element Size value specified in Table 59 for arrayTypeName.
  12. Let indexedPosition be (index × elementSize) + offset.
  13. Let elementType be the String value of the Element Type value in Table 59 for arrayTypeName.
  14. Return GetValueFromBuffer(buffer, indexedPosition, elementType, true, "Unordered").

9.4.5.9 IntegerIndexedElementSet ( O, index, value )

The abstract operation IntegerIndexedElementSet with arguments O, index, and value performs the following steps:

  1. Assert: Type(index) is Number.
  2. Assert: O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.
  3. Let numValue be ? ToNumber(value).
  4. Let buffer be O.[[ViewedArrayBuffer]].
  5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
  6. If IsInteger(index) is false, return false.
  7. If index = -0, return false.
  8. Let length be O.[[ArrayLength]].
  9. If index < 0 or indexlength, return false.
  10. Let offset be O.[[ByteOffset]].
  11. Let arrayTypeName be the String value of O.[[TypedArrayName]].
  12. Let elementSize be the Number value of the Element Size value specified in Table 59 for arrayTypeName.
  13. Let indexedPosition be (index × elementSize) + offset.
  14. Let elementType be the String value of the Element Type value in Table 59 for arrayTypeName.
  15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, "Unordered").
  16. Return true.

9.4.6 Module Namespace Exotic Objects

A module namespace object is an exotic object that exposes the bindings exported from an ECMAScript Module (See 15.2.3). There is a one-to-one correspondence between the String-keyed own properties of a module namespace exotic object and the binding names exported by the Module. The exported bindings include any bindings that are indirectly exported using export * export items. Each String-valued own property key is the StringValue of the corresponding exported binding name. These are the only String-keyed properties of a module namespace exotic object. Each such property has the attributes { [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: false }. Module namespace objects are not extensible.

Module namespace objects have the internal slots defined in Table 29.

Internal Slot Type Description
[[Module]] Module Record The Module Record whose exports this namespace exposes.
[[Exports]] List of String A List containing the String values of the exported names exposed as own properties of this object. The list is ordered as if an Array of those String values had been sorted using Array.prototype.sort using undefined as comparefn.
[[Prototype]] Null This slot always contains the value null (see 9.4.6.1).

Module namespace exotic objects provide alternative definitions for all of the internal methods except [[GetPrototypeOf]], which behaves as defined in 9.1.1.

9.4.6.1 [[SetPrototypeOf]] ( V )

When the [[SetPrototypeOf]] internal method of a module namespace exotic object O is called with argument V, the following steps are taken:

  1. Return ? SetImmutablePrototype(O, V).

9.4.6.2 [[IsExtensible]] ( )

When the [[IsExtensible]] internal method of a module namespace exotic object O is called, the following steps are taken:

  1. Return false.

9.4.6.3 [[PreventExtensions]] ( )

When the [[PreventExtensions]] internal method of a module namespace exotic object O is called, the following steps are taken:

  1. Return true.

9.4.6.4 [[GetOwnProperty]] ( P )

When the [[GetOwnProperty]] internal method of a module namespace exotic object O is called with property key P, the following steps are taken:

  1. If Type(P) is Symbol, return OrdinaryGetOwnProperty(O, P).
  2. Let exports be O.[[Exports]].
  3. If P is not an element of exports, return undefined.
  4. Let value be ? O.[[Get]](P, O).
  5. Return PropertyDescriptor { [[Value]]: value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: false }.

9.4.6.5 [[DefineOwnProperty]] ( P, Desc )

When the [[DefineOwnProperty]] internal method of a module namespace exotic object O is called with property key P and Property Descriptor Desc, the following steps are taken:

  1. If Type(P) is Symbol, return OrdinaryDefineOwnProperty(O, P, Desc).
  2. Let current be ? O.[[GetOwnProperty]](P).
  3. If current is undefined, return false.
  4. If IsAccessorDescriptor(Desc) is true, return false.
  5. If Desc.[[Writable]] is present and has value false, return false.
  6. If Desc.[[Enumerable]] is present and has value false, return false.
  7. If Desc.[[Configurable]] is present and has value true, return false.
  8. If Desc.[[Value]] is present, return SameValue(Desc.[[Value]], current.[[Value]]).
  9. Return true.

9.4.6.6 [[HasProperty]] ( P )

When the [[HasProperty]] internal method of a module namespace exotic object O is called with property key P, the following steps are taken:

  1. If Type(P) is Symbol, return OrdinaryHasProperty(O, P).
  2. Let exports be O.[[Exports]].
  3. If P is an element of exports, return true.
  4. Return false.

9.4.6.7 [[Get]] ( P, Receiver )

When the [[Get]] internal method of a module namespace exotic object O is called with property key P and ECMAScript language value Receiver, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. If Type(P) is Symbol, then
    1. Return ? OrdinaryGet(O, P, Receiver).
  3. Let exports be O.[[Exports]].
  4. If P is not an element of exports, return undefined.
  5. Let m be O.[[Module]].
  6. Let binding be ! m.ResolveExport(P, « »).
  7. Assert: binding is a ResolvedBinding Record.
  8. Let targetModule be binding.[[Module]].
  9. Assert: targetModule is not undefined.
  10. Let targetEnv be targetModule.[[Environment]].
  11. If targetEnv is undefined, throw a ReferenceError exception.
  12. Let targetEnvRec be targetEnv's EnvironmentRecord.
  13. Return ? targetEnvRec.GetBindingValue(binding.[[BindingName]], true).
Note

ResolveExport is idempotent and side-effect free. An implementation might choose to pre-compute or cache the ResolveExport results for the [[Exports]] of each module namespace exotic object.

9.4.6.8 [[Set]] ( P, V, Receiver )

When the [[Set]] internal method of a module namespace exotic object O is called with property key P, value V, and ECMAScript language value Receiver, the following steps are taken:

  1. Return false.

9.4.6.9 [[Delete]] ( P )

When the [[Delete]] internal method of a module namespace exotic object O is called with property key P, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. If Type(P) is Symbol, then
    1. Return ? OrdinaryDelete(O, P).
  3. Let exports be O.[[Exports]].
  4. If P is an element of exports, return false.
  5. Return true.

9.4.6.10 [[OwnPropertyKeys]] ( )

When the [[OwnPropertyKeys]] internal method of a module namespace exotic object O is called, the following steps are taken:

  1. Let exports be a copy of O.[[Exports]].
  2. Let symbolKeys be ! OrdinaryOwnPropertyKeys(O).
  3. Append all the entries of symbolKeys to the end of exports.
  4. Return exports.

9.4.6.11 ModuleNamespaceCreate ( module, exports )

The abstract operation ModuleNamespaceCreate with arguments module, and exports is used to specify the creation of new module namespace exotic objects. It performs the following steps:

  1. Assert: module is a Module Record.
  2. Assert: module.[[Namespace]] is undefined.
  3. Assert: exports is a List of String values.
  4. Let M be a newly created object.
  5. Set M's essential internal methods to the definitions specified in 9.4.6.
  6. Set M.[[Module]] to module.
  7. Let sortedExports be a new List containing the same values as the list exports where the values are ordered as if an Array of the same values had been sorted using Array.prototype.sort using undefined as comparefn.
  8. Set M.[[Exports]] to sortedExports.
  9. Create own properties of M corresponding to the definitions in 26.3.
  10. Set module.[[Namespace]] to M.
  11. Return M.

9.4.7 Immutable Prototype Exotic Objects

An immutable prototype exotic object is an exotic object that has a [[Prototype]] internal slot that will not change once it is initialized.

Immutable prototype exotic objects have the same internal slots as ordinary objects. They are exotic only in the following internal methods. All other internal methods of immutable prototype exotic objects that are not explicitly defined below are instead defined as in ordinary objects.

9.4.7.1 [[SetPrototypeOf]] ( V )

When the [[SetPrototypeOf]] internal method of an immutable prototype exotic object O is called with argument V, the following steps are taken:

  1. Return ? SetImmutablePrototype(O, V).

9.4.7.2 SetImmutablePrototype ( O, V )

When the SetImmutablePrototype abstract operation is called with arguments O and V, the following steps are taken:

  1. Assert: Either Type(V) is Object or Type(V) is Null.
  2. Let current be ? O.[[GetPrototypeOf]]().
  3. If SameValue(V, current) is true, return true.
  4. Return false.

9.5 Proxy Object Internal Methods and Internal Slots

A proxy object is an exotic object whose essential internal methods are partially implemented using ECMAScript code. Every proxy object has an internal slot called [[ProxyHandler]]. The value of [[ProxyHandler]] is an object, called the proxy's handler object, or null. Methods (see Table 30) of a handler object may be used to augment the implementation for one or more of the proxy object's internal methods. Every proxy object also has an internal slot called [[ProxyTarget]] whose value is either an object or the null value. This object is called the proxy's target object.

Internal Method Handler Method
[[GetPrototypeOf]] getPrototypeOf
[[SetPrototypeOf]] setPrototypeOf
[[IsExtensible]] isExtensible
[[PreventExtensions]] preventExtensions
[[GetOwnProperty]] getOwnPropertyDescriptor
[[DefineOwnProperty]] defineProperty
[[HasProperty]] has
[[Get]] get
[[Set]] set
[[Delete]] deleteProperty
[[OwnPropertyKeys]] ownKeys
[[Call]] apply
[[Construct]] construct

When a handler method is called to provide the implementation of a proxy object internal method, the handler method is passed the proxy's target object as a parameter. A proxy's handler object does not necessarily have a method corresponding to every essential internal method. Invoking an internal method on the proxy results in the invocation of the corresponding internal method on the proxy's target object if the handler object does not have a method corresponding to the internal trap.

The [[ProxyHandler]] and [[ProxyTarget]] internal slots of a proxy object are always initialized when the object is created and typically may not be modified. Some proxy objects are created in a manner that permits them to be subsequently revoked. When a proxy is revoked, its [[ProxyHandler]] and [[ProxyTarget]] internal slots are set to null causing subsequent invocations of internal methods on that proxy object to throw a TypeError exception.

Because proxy objects permit the implementation of internal methods to be provided by arbitrary ECMAScript code, it is possible to define a proxy object whose handler methods violates the invariants defined in 6.1.7.3. Some of the internal method invariants defined in 6.1.7.3 are essential integrity invariants. These invariants are explicitly enforced by the proxy object internal methods specified in this section. An ECMAScript implementation must be robust in the presence of all possible invariant violations.

In the following algorithm descriptions, assume O is an ECMAScript proxy object, P is a property key value, V is any ECMAScript language value and Desc is a Property Descriptor record.

9.5.1 [[GetPrototypeOf]] ( )

When the [[GetPrototypeOf]] internal method of a Proxy exotic object O is called, the following steps are taken:

  1. Let handler be O.[[ProxyHandler]].
  2. If handler is null, throw a TypeError exception.
  3. Assert: Type(handler) is Object.
  4. Let target be O.[[ProxyTarget]].
  5. Let trap be ? GetMethod(handler, "getPrototypeOf").
  6. If trap is undefined, then
    1. Return ? target.[[GetPrototypeOf]]().
  7. Let handlerProto be ? Call(trap, handler, « target »).
  8. If Type(handlerProto) is neither Object nor Null, throw a TypeError exception.
  9. Let extensibleTarget be ? IsExtensible(target).
  10. If extensibleTarget is true, return handlerProto.
  11. Let targetProto be ? target.[[GetPrototypeOf]]().
  12. If SameValue(handlerProto, targetProto) is false, throw a TypeError exception.
  13. Return handlerProto.
Note

[[GetPrototypeOf]] for proxy objects enforces the following invariants:

  • The result of [[GetPrototypeOf]] must be either an Object or null.
  • If the target object is not extensible, [[GetPrototypeOf]] applied to the proxy object must return the same value as [[GetPrototypeOf]] applied to the proxy object's target object.

9.5.2 [[SetPrototypeOf]] ( V )

When the [[SetPrototypeOf]] internal method of a Proxy exotic object O is called with argument V, the following steps are taken:

  1. Assert: Either Type(V) is Object or Type(V) is Null.
  2. Let handler be O.[[ProxyHandler]].
  3. If handler is null, throw a TypeError exception.
  4. Assert: Type(handler) is Object.
  5. Let target be O.[[ProxyTarget]].
  6. Let trap be ? GetMethod(handler, "setPrototypeOf").
  7. If trap is undefined, then
    1. Return ? target.[[SetPrototypeOf]](V).
  8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target, V »)).
  9. If booleanTrapResult is false, return false.
  10. Let extensibleTarget be ? IsExtensible(target).
  11. If extensibleTarget is true, return true.
  12. Let targetProto be ? target.[[GetPrototypeOf]]().
  13. If SameValue(V, targetProto) is false, throw a TypeError exception.
  14. Return true.
Note

[[SetPrototypeOf]] for proxy objects enforces the following invariants:

  • The result of [[SetPrototypeOf]] is a Boolean value.
  • If the target object is not extensible, the argument value must be the same as the result of [[GetPrototypeOf]] applied to target object.

9.5.3 [[IsExtensible]] ( )

When the [[IsExtensible]] internal method of a Proxy exotic object O is called, the following steps are taken:

  1. Let handler be O.[[ProxyHandler]].
  2. If handler is null, throw a TypeError exception.
  3. Assert: Type(handler) is Object.
  4. Let target be O.[[ProxyTarget]].
  5. Let trap be ? GetMethod(handler, "isExtensible").
  6. If trap is undefined, then
    1. Return ? target.[[IsExtensible]]().
  7. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target »)).
  8. Let targetResult be ? target.[[IsExtensible]]().
  9. If SameValue(booleanTrapResult, targetResult) is false, throw a TypeError exception.
  10. Return booleanTrapResult.
Note

[[IsExtensible]] for proxy objects enforces the following invariants:

  • The result of [[IsExtensible]] is a Boolean value.
  • [[IsExtensible]] applied to the proxy object must return the same value as [[IsExtensible]] applied to the proxy object's target object with the same argument.

9.5.4 [[PreventExtensions]] ( )

When the [[PreventExtensions]] internal method of a Proxy exotic object O is called, the following steps are taken:

  1. Let handler be O.[[ProxyHandler]].
  2. If handler is null, throw a TypeError exception.
  3. Assert: Type(handler) is Object.
  4. Let target be O.[[ProxyTarget]].
  5. Let trap be ? GetMethod(handler, "preventExtensions").
  6. If trap is undefined, then
    1. Return ? target.[[PreventExtensions]]().
  7. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target »)).
  8. If booleanTrapResult is true, then
    1. Let targetIsExtensible be ? target.[[IsExtensible]]().
    2. If targetIsExtensible is true, throw a TypeError exception.
  9. Return booleanTrapResult.
Note

[[PreventExtensions]] for proxy objects enforces the following invariants:

  • The result of [[PreventExtensions]] is a Boolean value.
  • [[PreventExtensions]] applied to the proxy object only returns true if [[IsExtensible]] applied to the proxy object's target object is false.

9.5.5 [[GetOwnProperty]] ( P )

When the [[GetOwnProperty]] internal method of a Proxy exotic object O is called with property key P, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Let handler be O.[[ProxyHandler]].
  3. If handler is null, throw a TypeError exception.
  4. Assert: Type(handler) is Object.
  5. Let target be O.[[ProxyTarget]].
  6. Let trap be ? GetMethod(handler, "getOwnPropertyDescriptor").
  7. If trap is undefined, then
    1. Return ? target.[[GetOwnProperty]](P).
  8. Let trapResultObj be ? Call(trap, handler, « target, P »).
  9. If Type(trapResultObj) is neither Object nor Undefined, throw a TypeError exception.
  10. Let targetDesc be ? target.[[GetOwnProperty]](P).
  11. If trapResultObj is undefined, then
    1. If targetDesc is undefined, return undefined.
    2. If targetDesc.[[Configurable]] is false, throw a TypeError exception.
    3. Let extensibleTarget be ? IsExtensible(target).
    4. If extensibleTarget is false, throw a TypeError exception.
    5. Return undefined.
  12. Let extensibleTarget be ? IsExtensible(target).
  13. Let resultDesc be ? ToPropertyDescriptor(trapResultObj).
  14. Call CompletePropertyDescriptor(resultDesc).
  15. Let valid be IsCompatiblePropertyDescriptor(extensibleTarget, resultDesc, targetDesc).
  16. If valid is false, throw a TypeError exception.
  17. If resultDesc.[[Configurable]] is false, then
    1. If targetDesc is undefined or targetDesc.[[Configurable]] is true, then
      1. Throw a TypeError exception.
  18. Return resultDesc.
Note

[[GetOwnProperty]] for proxy objects enforces the following invariants:

  • The result of [[GetOwnProperty]] must be either an Object or undefined.
  • A property cannot be reported as non-existent, if it exists as a non-configurable own property of the target object.
  • A property cannot be reported as non-existent, if it exists as an own property of the target object and the target object is not extensible.
  • A property cannot be reported as existent, if it does not exist as an own property of the target object and the target object is not extensible.
  • A property cannot be reported as non-configurable, if it does not exist as an own property of the target object or if it exists as a configurable own property of the target object.

9.5.6 [[DefineOwnProperty]] ( P, Desc )

When the [[DefineOwnProperty]] internal method of a Proxy exotic object O is called with property key P and Property Descriptor Desc, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Let handler be O.[[ProxyHandler]].
  3. If handler is null, throw a TypeError exception.
  4. Assert: Type(handler) is Object.
  5. Let target be O.[[ProxyTarget]].
  6. Let trap be ? GetMethod(handler, "defineProperty").
  7. If trap is undefined, then
    1. Return ? target.[[DefineOwnProperty]](P, Desc).
  8. Let descObj be FromPropertyDescriptor(Desc).
  9. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target, P, descObj »)).
  10. If booleanTrapResult is false, return false.
  11. Let targetDesc be ? target.[[GetOwnProperty]](P).
  12. Let extensibleTarget be ? IsExtensible(target).
  13. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is false, then
    1. Let settingConfigFalse be true.
  14. Else, let settingConfigFalse be false.
  15. If targetDesc is undefined, then
    1. If extensibleTarget is false, throw a TypeError exception.
    2. If settingConfigFalse is true, throw a TypeError exception.
  16. Else targetDesc is not undefined,
    1. If IsCompatiblePropertyDescriptor(extensibleTarget, Desc, targetDesc) is false, throw a TypeError exception.
    2. If settingConfigFalse is true and targetDesc.[[Configurable]] is true, throw a TypeError exception.
  17. Return true.
Note

[[DefineOwnProperty]] for proxy objects enforces the following invariants:

  • The result of [[DefineOwnProperty]] is a Boolean value.
  • A property cannot be added, if the target object is not extensible.
  • A property cannot be non-configurable, unless there exists a corresponding non-configurable own property of the target object.
  • If a property has a corresponding target object property then applying the Property Descriptor of the property to the target object using [[DefineOwnProperty]] will not throw an exception.

9.5.7 [[HasProperty]] ( P )

When the [[HasProperty]] internal method of a Proxy exotic object O is called with property key P, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Let handler be O.[[ProxyHandler]].
  3. If handler is null, throw a TypeError exception.
  4. Assert: Type(handler) is Object.
  5. Let target be O.[[ProxyTarget]].
  6. Let trap be ? GetMethod(handler, "has").
  7. If trap is undefined, then
    1. Return ? target.[[HasProperty]](P).
  8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target, P »)).
  9. If booleanTrapResult is false, then
    1. Let targetDesc be ? target.[[GetOwnProperty]](P).
    2. If targetDesc is not undefined, then
      1. If targetDesc.[[Configurable]] is false, throw a TypeError exception.
      2. Let extensibleTarget be ? IsExtensible(target).
      3. If extensibleTarget is false, throw a TypeError exception.
  10. Return booleanTrapResult.
Note

[[HasProperty]] for proxy objects enforces the following invariants:

  • The result of [[HasProperty]] is a Boolean value.
  • A property cannot be reported as non-existent, if it exists as a non-configurable own property of the target object.
  • A property cannot be reported as non-existent, if it exists as an own property of the target object and the target object is not extensible.

9.5.8 [[Get]] ( P, Receiver )

When the [[Get]] internal method of a Proxy exotic object O is called with property key P and ECMAScript language value Receiver, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Let handler be O.[[ProxyHandler]].
  3. If handler is null, throw a TypeError exception.
  4. Assert: Type(handler) is Object.
  5. Let target be O.[[ProxyTarget]].
  6. Let trap be ? GetMethod(handler, "get").
  7. If trap is undefined, then
    1. Return ? target.[[Get]](P, Receiver).
  8. Let trapResult be ? Call(trap, handler, « target, P, Receiver »).
  9. Let targetDesc be ? target.[[GetOwnProperty]](P).
  10. If targetDesc is not undefined and targetDesc.[[Configurable]] is false, then
    1. If IsDataDescriptor(targetDesc) is true and targetDesc.[[Writable]] is false, then
      1. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a TypeError exception.
    2. If IsAccessorDescriptor(targetDesc) is true and targetDesc.[[Get]] is undefined, then
      1. If trapResult is not undefined, throw a TypeError exception.
  11. Return trapResult.
Note

[[Get]] for proxy objects enforces the following invariants:

  • The value reported for a property must be the same as the value of the corresponding target object property if the target object property is a non-writable, non-configurable own data property.
  • The value reported for a property must be undefined if the corresponding target object property is a non-configurable own accessor property that has undefined as its [[Get]] attribute.

9.5.9 [[Set]] ( P, V, Receiver )

When the [[Set]] internal method of a Proxy exotic object O is called with property key P, value V, and ECMAScript language value Receiver, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Let handler be O.[[ProxyHandler]].
  3. If handler is null, throw a TypeError exception.
  4. Assert: Type(handler) is Object.
  5. Let target be O.[[ProxyTarget]].
  6. Let trap be ? GetMethod(handler, "set").
  7. If trap is undefined, then
    1. Return ? target.[[Set]](P, V, Receiver).
  8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target, P, V, Receiver »)).
  9. If booleanTrapResult is false, return false.
  10. Let targetDesc be ? target.[[GetOwnProperty]](P).
  11. If targetDesc is not undefined and targetDesc.[[Configurable]] is false, then
    1. If IsDataDescriptor(targetDesc) is true and targetDesc.[[Writable]] is false, then
      1. If SameValue(V, targetDesc.[[Value]]) is false, throw a TypeError exception.
    2. If IsAccessorDescriptor(targetDesc) is true, then
      1. If targetDesc.[[Set]] is undefined, throw a TypeError exception.
  12. Return true.
Note

[[Set]] for proxy objects enforces the following invariants:

  • The result of [[Set]] is a Boolean value.
  • Cannot change the value of a property to be different from the value of the corresponding target object property if the corresponding target object property is a non-writable, non-configurable own data property.
  • Cannot set the value of a property if the corresponding target object property is a non-configurable own accessor property that has undefined as its [[Set]] attribute.

9.5.10 [[Delete]] ( P )

When the [[Delete]] internal method of a Proxy exotic object O is called with property key P, the following steps are taken:

  1. Assert: IsPropertyKey(P) is true.
  2. Let handler be O.[[ProxyHandler]].
  3. If handler is null, throw a TypeError exception.
  4. Assert: Type(handler) is Object.
  5. Let target be O.[[ProxyTarget]].
  6. Let trap be ? GetMethod(handler, "deleteProperty").
  7. If trap is undefined, then
    1. Return ? target.[[Delete]](P).
  8. Let booleanTrapResult be ToBoolean(? Call(trap, handler, « target, P »)).
  9. If booleanTrapResult is false, return false.
  10. Let targetDesc be ? target.[[GetOwnProperty]](P).
  11. If targetDesc is undefined, return true.
  12. If targetDesc.[[Configurable]] is false, throw a TypeError exception.
  13. Return true.
Note

[[Delete]] for proxy objects enforces the following invariants:

  • The result of [[Delete]] is a Boolean value.
  • A property cannot be reported as deleted, if it exists as a non-configurable own property of the target object.

9.5.11 [[OwnPropertyKeys]] ( )

When the [[OwnPropertyKeys]] internal method of a Proxy exotic object O is called, the following steps are taken:

  1. Let handler be O.[[ProxyHandler]].
  2. If handler is null, throw a TypeError exception.
  3. Assert: Type(handler) is Object.
  4. Let target be O.[[ProxyTarget]].
  5. Let trap be ? GetMethod(handler, "ownKeys").
  6. If trap is undefined, then
    1. Return ? target.[[OwnPropertyKeys]]().
  7. Let trapResultArray be ? Call(trap, handler, « target »).
  8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, « String, Symbol »).
  9. If trapResult contains any duplicate entries, throw a TypeError exception.
  10. Let extensibleTarget be ? IsExtensible(target).
  11. Let targetKeys be ? target.[[OwnPropertyKeys]]().
  12. Assert: targetKeys is a List containing only String and Symbol values.
  13. Assert: targetKeys contains no duplicate entries.
  14. Let targetConfigurableKeys be a new empty List.
  15. Let targetNonconfigurableKeys be a new empty List.
  16. For each element key of targetKeys, do
    1. Let desc be ? target.[[GetOwnProperty]](key).
    2. If desc is not undefined and desc.[[Configurable]] is false, then
      1. Append key as an element of targetNonconfigurableKeys.
    3. Else,
      1. Append key as an element of targetConfigurableKeys.
  17. If extensibleTarget is true and targetNonconfigurableKeys is empty, then
    1. Return trapResult.
  18. Let uncheckedResultKeys be a new List which is a copy of trapResult.
  19. For each key that is an element of targetNonconfigurableKeys, do
    1. If key is not an element of uncheckedResultKeys, throw a TypeError exception.
    2. Remove key from uncheckedResultKeys.
  20. If extensibleTarget is true, return trapResult.
  21. For each key that is an element of targetConfigurableKeys, do
    1. If key is not an element of uncheckedResultKeys, throw a TypeError exception.
    2. Remove key from uncheckedResultKeys.
  22. If uncheckedResultKeys is not empty, throw a TypeError exception.
  23. Return trapResult.
Note

[[OwnPropertyKeys]] for proxy objects enforces the following invariants:

  • The result of [[OwnPropertyKeys]] is a List.
  • The returned List contains no duplicate entries.
  • The Type of each result List element is either String or Symbol.
  • The result List must contain the keys of all non-configurable own properties of the target object.
  • If the target object is not extensible, then the result List must contain all the keys of the own properties of the target object and no other values.

9.5.12 [[Call]] ( thisArgument, argumentsList )

The [[Call]] internal method of a Proxy exotic object O is called with parameters thisArgument and argumentsList, a List of ECMAScript language values. The following steps are taken:

  1. Let handler be O.[[ProxyHandler]].
  2. If handler is null, throw a TypeError exception.
  3. Assert: Type(handler) is Object.
  4. Let target be O.[[ProxyTarget]].
  5. Let trap be ? GetMethod(handler, "apply").
  6. If trap is undefined, then
    1. Return ? Call(target, thisArgument, argumentsList).
  7. Let argArray be CreateArrayFromList(argumentsList).
  8. Return ? Call(trap, handler, « target, thisArgument, argArray »).
Note

A Proxy exotic object only has a [[Call]] internal method if the initial value of its [[ProxyTarget]] internal slot is an object that has a [[Call]] internal method.

9.5.13 [[Construct]] ( argumentsList, newTarget )

The [[Construct]] internal method of a Proxy exotic object O is called with parameters argumentsList which is a possibly empty List of ECMAScript language values and newTarget. The following steps are taken:

  1. Let handler be O.[[ProxyHandler]].
  2. If handler is null, throw a TypeError exception.
  3. Assert: Type(handler) is Object.
  4. Let target be O.[[ProxyTarget]].
  5. Assert: IsConstructor(target) is true.
  6. Let trap be ? GetMethod(handler, "construct").
  7. If trap is undefined, then
    1. Return ? Construct(target, argumentsList, newTarget).
  8. Let argArray be CreateArrayFromList(argumentsList).
  9. Let newObj be ? Call(trap, handler, « target, argArray, newTarget »).
  10. If Type(newObj) is not Object, throw a TypeError exception.
  11. Return newObj.
Note 1

A Proxy exotic object only has a [[Construct]] internal method if the initial value of its [[ProxyTarget]] internal slot is an object that has a [[Construct]] internal method.

Note 2

[[Construct]] for proxy objects enforces the following invariants:

  • The result of [[Construct]] must be an Object.

9.5.14 ProxyCreate ( target, handler )

The abstract operation ProxyCreate with arguments target and handler is used to specify the creation of new Proxy exotic objects. It performs the following steps:

  1. If Type(target) is not Object, throw a TypeError exception.
  2. If target is a Proxy exotic object and target.[[ProxyHandler]] is null, throw a TypeError exception.
  3. If Type(handler) is not Object, throw a TypeError exception.
  4. If handler is a Proxy exotic object and handler.[[ProxyHandler]] is null, throw a TypeError exception.
  5. Let P be a newly created object.
  6. Set P's essential internal methods (except for [[Call]] and [[Construct]]) to the definitions specified in 9.5.
  7. If IsCallable(target) is true, then
    1. Set P.[[Call]] as specified in 9.5.12.
    2. If IsConstructor(target) is true, then
      1. Set P.[[Construct]] as specified in 9.5.13.
  8. Set P.[[ProxyTarget]] to target.
  9. Set P.[[ProxyHandler]] to handler.
  10. Return P.