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
Every ordinary object has a Boolean-valued [[Extensible]] internal slot that controls whether or not properties may be added to the object. If the value of the [[Extensible]] internal slot is
In the following algorithm descriptions, assume O is an ordinary object, P is a property key value, V is any
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:
- Return !
OrdinaryGetPrototypeOf (O).
9.1.1.1 OrdinaryGetPrototypeOf (O)
When the abstract operation OrdinaryGetPrototypeOf is called with Object O, the following steps are taken:
- Return the value of the [[Prototype]] internal slot of O.
9.1.2 [[SetPrototypeOf]] (V)
When the [[SetPrototypeOf]] internal method of O is called with argument V, the following steps are taken:
- 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:
- Assert: Either
Type (V) is Object orType (V) is Null. - Let extensible be the value of the [[Extensible]] internal slot of O.
- Let current be the value of the [[Prototype]] internal slot of O.
- If
SameValue (V, current) istrue , returntrue . - If extensible is
false , returnfalse . - Let p be V.
- Let done be
false . - Repeat while done is
false , - Set the value of the [[Prototype]] internal slot of O to V.
- Return
true .
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:
- Return !
OrdinaryIsExtensible (O).
9.1.3.1 OrdinaryIsExtensible (O)
When the abstract operation OrdinaryIsExtensible is called with Object O, the following steps are taken:
- Return the value of the [[Extensible]] internal slot of O.
9.1.4 [[PreventExtensions]] ( )
When the [[PreventExtensions]] internal method of O is called, the following steps are taken:
- Return !
OrdinaryPreventExtensions (O).
9.1.4.1 OrdinaryPreventExtensions (O)
When the abstract operation OrdinaryPreventExtensions is called with Object O, the following steps are taken:
- Set the value of the [[Extensible]] internal slot of O to
false . - 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:
- 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:
- Assert:
IsPropertyKey (P) istrue . - If O does not have an own property with key P, return
undefined . - Let D be a newly created
Property Descriptor with no fields. - Let X be O's own property whose key is P.
- If X is a data property, then
- Set D.[[Value]] to the value of X's [[Value]] attribute.
- Set D.[[Writable]] to the value of X's [[Writable]] attribute.
- Else X is an accessor property, so
- Set D.[[Get]] to the value of X's [[Get]] attribute.
- Set D.[[Set]] to the value of X's [[Set]] attribute.
- Set D.[[Enumerable]] to the value of X's [[Enumerable]] attribute.
- Set D.[[Configurable]] to the value of X's [[Configurable]] attribute.
- Return D.
9.1.6 [[DefineOwnProperty]] (P, Desc)
When the [[DefineOwnProperty]] internal method of O is called with property key P and
- 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
- Let current be ? O.[[GetOwnProperty]](P).
- Let extensible be the value of the [[Extensible]] internal slot of O.
- 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:
- 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:
This algorithm contains steps that test various fields of the
If
- Assert: If O is not
undefined , thenIsPropertyKey (P) istrue . - If current is
undefined , then- If extensible is
false , returnfalse . - Assert: extensible is
true . - If
IsGenericDescriptor (Desc) istrue orIsDataDescriptor (Desc) istrue , then- 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.
- If O is not
- Else Desc must be an accessor
Property Descriptor ,- 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.
- If O is not
- Return
true .
- If extensible is
- Return
true , if every field in Desc is absent. - Return
true , if every field in Desc also occurs in current and the value of every field in Desc is the same value as the corresponding field in current when compared using theSameValue algorithm. - If the [[Configurable]] field of current is
false , then- Return
false , if the [[Configurable]] field of Desc istrue . - Return
false , if the [[Enumerable]] field of Desc is present and the [[Enumerable]] fields of current and Desc are the Boolean negation of each other.
- Return
- If
IsGenericDescriptor (Desc) istrue , no further validation is required. - Else if
IsDataDescriptor (current) andIsDataDescriptor (Desc) have different results, then- Return
false , if the [[Configurable]] field of current isfalse . - If
IsDataDescriptor (current) istrue , then- 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.
- If O is not
- Else,
- 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.
- If O is not
- Return
- Else if
IsDataDescriptor (current) andIsDataDescriptor (Desc) are bothtrue , then- If the [[Configurable]] field of current is
false , then- Return
false , if the [[Writable]] field of current isfalse and the [[Writable]] field of Desc istrue . - If the [[Writable]] field of current is
false , then- Return
false , if the [[Value]] field of Desc is present andSameValue (Desc.[[Value]], current.[[Value]]) isfalse .
- Return
- Return
- Else the [[Configurable]] field of current is
true , so any change is acceptable.
- If the [[Configurable]] field of current is
- Else
IsAccessorDescriptor (current) andIsAccessorDescriptor (Desc) are bothtrue , - If O is not
undefined , then- 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.
- Return
true .
Step 8.b allows any field of Desc to be different from the corresponding field of current if current's [[Configurable]] field is
9.1.7 [[HasProperty]](P)
When the [[HasProperty]] internal method of O is called with property key P, the following steps are taken:
- 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:
- Assert:
IsPropertyKey (P) istrue . - Let hasOwn be ? O.[[GetOwnProperty]](P).
- If hasOwn is not
undefined , returntrue . - Let parent be ? O.[[GetPrototypeOf]]().
- If parent is not
null , then- Return ? parent.[[HasProperty]](P).
- Return
false .
9.1.8 [[Get]] (P, Receiver)
When the [[Get]] internal method of O is called with property key P and
- 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
- Assert:
IsPropertyKey (P) istrue . - Let desc be ? O.[[GetOwnProperty]](P).
- If desc is
undefined , then- Let parent be ? O.[[GetPrototypeOf]]().
- If parent is
null , returnundefined . - Return ? parent.[[Get]](P, Receiver).
- If
IsDataDescriptor (desc) istrue , return desc.[[Value]]. - Assert:
IsAccessorDescriptor (desc) istrue . - Let getter be desc.[[Get]].
- If getter is
undefined , returnundefined . - 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
- 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
- Assert:
IsPropertyKey (P) istrue . - Let ownDesc be ? O.[[GetOwnProperty]](P).
- If ownDesc is
undefined , then- Let parent be ? O.[[GetPrototypeOf]]().
- If parent is not
null , then- Return ? parent.[[Set]](P, V, Receiver).
- Else,
- Let ownDesc be the PropertyDescriptor{[[Value]]:
undefined , [[Writable]]:true , [[Enumerable]]:true , [[Configurable]]:true }.
- Let ownDesc be the PropertyDescriptor{[[Value]]:
- If
IsDataDescriptor (ownDesc) istrue , then- If ownDesc.[[Writable]] is
false , returnfalse . - If
Type (Receiver) is not Object, returnfalse . - Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P).
- If existingDescriptor is not
undefined , then- If
IsAccessorDescriptor (existingDescriptor) istrue , returnfalse . - If existingDescriptor.[[Writable]] is
false , returnfalse . - Let valueDesc be the PropertyDescriptor{[[Value]]: V}.
- Return ? Receiver.[[DefineOwnProperty]](P, valueDesc).
- If
- Else Receiver does not currently have a property P,
- Return ?
CreateDataProperty (Receiver, P, V).
- Return ?
- If ownDesc.[[Writable]] is
- Assert:
IsAccessorDescriptor (ownDesc) istrue . - Let setter be ownDesc.[[Set]].
- If setter is
undefined , returnfalse . - Perform ?
Call (setter, Receiver, « V »). - 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:
- 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:
- Assert:
IsPropertyKey (P) istrue . - Let desc be ? O.[[GetOwnProperty]](P).
- If desc is
undefined , returntrue . - If desc.[[Configurable]] is
true , then- Remove the own property with name P from O.
- Return
true .
- Return
false .
9.1.11 [[OwnPropertyKeys]] ( )
When the [[OwnPropertyKeys]] internal method of O is called, the following steps are taken:
- Return !
OrdinaryOwnPropertyKeys (O).
9.1.11.1 OrdinaryOwnPropertyKeys (O)
When the abstract operation OrdinaryOwnPropertyKeys is called with Object O, the following steps are taken:
- Let keys be a new empty
List . - For each own property key P of O that is an integer index, in ascending numeric index order
- Add P as the last element of keys.
- For each own property key P of O that is a String but is not an integer index, in ascending chronological order of property creation
- Add P as the last element of keys.
- For each own property key P of O that is a Symbol, in ascending chronological order of property creation
- Add P as the last element of keys.
- 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
- If internalSlotsList was not provided, let internalSlotsList be a new empty
List . - Let obj be a newly created object with an internal slot for each name in internalSlotsList.
- Set obj's essential internal methods to the default ordinary object definitions specified in
9.1 . - Set the [[Prototype]] internal slot of obj to proto.
- Set the [[Extensible]] internal slot of obj to
true . - 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
- 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.
- Let proto be ?
GetPrototypeFromConstructor (constructor, intrinsicDefaultProto). - 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:
- 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.
- Assert:
IsCallable (constructor) istrue . - Let proto be ?
Get (constructor,"prototype"). - If
Type (proto) is not Object, then- Let realm be ?
GetFunctionRealm (constructor). - Let proto be realm's intrinsic object named intrinsicDefaultProto.
- Let realm be ?
- Return proto.
If constructor does not supply a [[Prototype]] value, the default value that is used is obtained from the
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
ECMAScript function objects have the additional internal slots listed in
| Internal Slot |
|
Description |
|---|---|---|
| [[Environment]] |
|
The |
| [[FormalParameters]] | Parse Node | The root parse node of the source text that defines the function's formal parameter list. |
| [[FunctionKind]] | String |
Either "normal", "classConstructor" or "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]] |
|
The |
| [[ScriptOrModule]] |
|
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. this refers to the |
| [[Strict]] | Boolean |
|
| [[HomeObject]] | Object |
If the function uses super, this is the object whose [[GetPrototypeOf]] provides the object where super property lookups begin.
|
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
- Assert: F is an ECMAScript function object.
- If F's [[FunctionKind]] internal slot is
"classConstructor", throw aTypeError exception. - Let callerContext be the
running execution context . - Let calleeContext be
PrepareForOrdinaryCall (F,undefined ). - Assert: calleeContext is now the
running execution context . - Perform
OrdinaryCallBindThis (F, calleeContext, thisArgument). - Let result be
OrdinaryCallEvaluateBody (F, argumentsList). - Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - If result.[[Type]] is
return , returnNormalCompletion (result.[[Value]]). ReturnIfAbrupt (result).- Return
NormalCompletion (undefined ).
When calleeContext is removed from the
9.2.1.1 PrepareForOrdinaryCall ( F, newTarget )
When the abstract operation PrepareForOrdinaryCall is called with function object F and
- Assert:
Type (newTarget) is Undefined or Object. - Let callerContext be the
running execution context . - Let calleeContext be a new ECMAScript code
execution context . - Set the Function of calleeContext to F.
- Let calleeRealm be the value of F's [[Realm]] internal slot.
- Set the
Realm of calleeContext to calleeRealm. - Set the ScriptOrModule of calleeContext to the value of F's [[ScriptOrModule]] internal slot.
- Let localEnv be
NewFunctionEnvironment (F, newTarget). - Set the LexicalEnvironment of calleeContext to localEnv.
- Set the VariableEnvironment of calleeContext to localEnv.
- If callerContext is not already suspended, suspend callerContext.
- Push calleeContext onto the
execution context stack ; calleeContext is now therunning execution context . - NOTE Any exception objects produced after this point are associated with calleeRealm.
- Return calleeContext.
9.2.1.2 OrdinaryCallBindThis ( F, calleeContext, thisArgument )
When the abstract operation OrdinaryCallBindThis is called with function object F,
- Let thisMode be the value of F's [[ThisMode]] internal slot.
- If thisMode is
lexical , returnNormalCompletion (undefined ). - Let calleeRealm be the value of F's [[Realm]] internal slot.
- Let localEnv be the LexicalEnvironment of calleeContext.
- If thisMode is
strict , let thisValue be thisArgument. - Else,
- If thisArgument is
null orundefined , then- Let globalEnv be calleeRealm.[[GlobalEnv]].
- Let globalEnvRec be globalEnv's
EnvironmentRecord . - Let thisValue be globalEnvRec.[[GlobalThisValue]].
- Else,
- If thisArgument is
- Let envRec be localEnv's
EnvironmentRecord . - Assert: The next step never returns an
abrupt completion because envRec.[[ThisBindingStatus]] is not"initialized". - Return envRec.BindThisValue(thisValue).
9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList )
When the abstract operation OrdinaryCallEvaluateBody is called with function object F and
- Perform ?
FunctionDeclarationInstantiation (F, argumentsList). - Return the result of EvaluateBody of the parsed code that is the value of F's [[ECMAScriptCode]] internal slot passing F as the argument.
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
- Assert: F is an ECMAScript function object.
- Assert:
Type (newTarget) is Object. - Let callerContext be the
running execution context . - Let kind be F's [[ConstructorKind]] internal slot.
- If kind is
"base", then- Let thisArgument be ?
OrdinaryCreateFromConstructor (newTarget,"%ObjectPrototype%").
- Let thisArgument be ?
- Let calleeContext be
PrepareForOrdinaryCall (F, newTarget). - Assert: calleeContext is now the
running execution context . - If kind is
"base", performOrdinaryCallBindThis (F, calleeContext, thisArgument). - Let constructorEnv be the LexicalEnvironment of calleeContext.
- Let envRec be constructorEnv's
EnvironmentRecord . - Let result be
OrdinaryCallEvaluateBody (F, argumentsList). - Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - If result.[[Type]] is
return , then- If
Type (result.[[Value]]) is Object, returnNormalCompletion (result.[[Value]]). - If kind is
"base", returnNormalCompletion (thisArgument). - If result.[[Value]] is not
undefined , throw aTypeError exception.
- If
- Else,
ReturnIfAbrupt (result). - 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:
- Assert:
Type (functionPrototype) is Object. - Assert: functionKind is either
"normal","non-constructor"or"generator". - If functionKind is
"normal", let needsConstruct betrue . - Else, let needsConstruct be
false . - If functionKind is
"non-constructor", let functionKind be"normal". - Let F be a newly created ECMAScript function object with the internal slots listed in
Table 27 . All of those internal slots are initialized toundefined . - Set F's essential internal methods to the default ordinary object definitions specified in
9.1 . - Set F's [[Call]] internal method to the definition specified in
9.2.1 . - If needsConstruct is
true , then- Set F's [[Construct]] internal method to the definition specified in
9.2.2 . - Set the [[ConstructorKind]] internal slot of F to
"base".
- Set F's [[Construct]] internal method to the definition specified in
- Set the [[Strict]] internal slot of F to strict.
- Set the [[FunctionKind]] internal slot of F to functionKind.
- Set the [[Prototype]] internal slot of F to functionPrototype.
- Set the [[Extensible]] internal slot of F to
true . - Set the [[Realm]] internal slot of F to
the current Realm Record . - 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 production specified by ParameterList, a body production specified by Body, a
- Assert: F is an extensible object that does not have a
lengthown property. - Let len be the ExpectedArgumentCount of ParameterList.
- Perform !
DefinePropertyOrThrow (F,"length", PropertyDescriptor{[[Value]]: len, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:true }). - Let Strict be the value of the [[Strict]] internal slot of F.
- Set the [[Environment]] internal slot of F to the value of Scope.
- Set the [[FormalParameters]] internal slot of F to ParameterList.
- Set the [[ECMAScriptCode]] internal slot of F to Body.
- Set the [[ScriptOrModule]] internal slot of F to
GetActiveScriptOrModule (). - If kind is
Arrow , set the [[ThisMode]] internal slot of F tolexical . - Else if Strict is
true , set the [[ThisMode]] internal slot of F tostrict . - Else set the [[ThisMode]] internal slot of F to
global . - 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 production specified by ParameterList, a body production specified by Body, a
- If the prototype argument was not passed, then
- Let prototype be the intrinsic object
%FunctionPrototype% .
- Let prototype be the intrinsic object
- If kind is not
Normal , let allocKind be"non-constructor". - Else let allocKind be
"normal". - Let F be
FunctionAllocate (prototype, Strict, allocKind). - 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 production specified by ParameterList, a body production specified by Body, a
- Let functionPrototype be the intrinsic object
%Generator% . - Let F be
FunctionAllocate (functionPrototype, Strict,"generator"). - Return
FunctionInitialize (F, kind, ParameterList, Body, Scope).
9.2.7 AddRestrictedFunctionProperties ( F, realm )
The abstract operation AddRestrictedFunctionProperties is called with a function object F and
- Assert: realm.[[Intrinsics]].[[
%ThrowTypeError% ]] exists and has been initialized. - Let thrower be realm.[[Intrinsics]].[[
%ThrowTypeError% ]]. - Perform !
DefinePropertyOrThrow (F,"caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]:false , [[Configurable]]:true }). - Return !
DefinePropertyOrThrow (F,"arguments", PropertyDescriptor {[[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]:false , [[Configurable]]:true }).
9.2.7.1 %ThrowTypeError% ( )
The
- Throw a
TypeError exception.
The value of the [[Extensible]] internal slot of a
The length property of a
9.2.8 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:
- Assert: F is an ECMAScript function object.
- Assert: F has a [[Construct]] internal method.
- Assert: F is an extensible object that does not have a
prototypeown property. - If the writablePrototype argument was not provided, let writablePrototype be
true . - If the prototype argument was not provided, then
- Let prototype be
ObjectCreate (%ObjectPrototype% ). - Perform !
DefinePropertyOrThrow (prototype,"constructor", PropertyDescriptor{[[Value]]: F, [[Writable]]: writablePrototype, [[Enumerable]]:false , [[Configurable]]:true }).
- Let prototype be
- Perform !
DefinePropertyOrThrow (F,"prototype", PropertyDescriptor{[[Value]]: prototype, [[Writable]]: writablePrototype, [[Enumerable]]:false , [[Configurable]]:false }). - Return
NormalCompletion (undefined ).
9.2.9 MakeClassConstructor ( F)
The abstract operation MakeClassConstructor with argument F performs the following steps:
- Assert: F is an ECMAScript function object.
- Assert: F's [[FunctionKind]] internal slot is
"normal". - Set F's [[FunctionKind]] internal slot to
"classConstructor". - Return
NormalCompletion (undefined ).
9.2.10 MakeMethod ( F, homeObject)
The abstract operation MakeMethod with arguments F and homeObject configures F as a method by performing the following steps:
- Assert: F is an ECMAScript function object.
- Assert:
Type (homeObject) is Object. - Set the [[HomeObject]] internal slot of F to homeObject.
- Return
NormalCompletion (undefined ).
9.2.11 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:
- Assert: F is an extensible object that does not have a
nameown property. - Assert:
Type (name) is either Symbol or String. - Assert: If prefix was passed, then
Type (prefix) is String. - If
Type (name) is Symbol, then- Let description be name's [[Description]] value.
- If description is
undefined , let name be the empty String. - Else, let name be the concatenation of
"[", description, and"]".
- If prefix was passed, then
- Let name be the concatenation of prefix, code unit 0x0020 (SPACE), and name.
- Return !
DefinePropertyOrThrow (F,"name", PropertyDescriptor{[[Value]]: name, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:true }).
9.2.12 FunctionDeclarationInstantiation (func, argumentsList)
When an
FunctionDeclarationInstantiation is performed as follows using arguments func and argumentsList. func is the function object for which the
- Let calleeContext be the
running execution context . - Let env be the LexicalEnvironment of calleeContext.
- Let envRec be env's
EnvironmentRecord . - Let code be the value of the [[ECMAScriptCode]] internal slot of func.
- Let strict be the value of the [[Strict]] internal slot of func.
- Let formals be the value of the [[FormalParameters]] internal slot of func.
- Let parameterNames be the BoundNames of formals.
- If parameterNames has any duplicate entries, let hasDuplicates be
true . Otherwise, let hasDuplicates befalse . - Let simpleParameterList be IsSimpleParameterList of formals.
- Let hasParameterExpressions be ContainsExpression of formals.
- Let varNames be the VarDeclaredNames of code.
- Let varDeclarations be the VarScopedDeclarations of code.
- Let lexicalNames be the LexicallyDeclaredNames of code.
- Let functionNames be a new empty
List . - Let functionsToInitialize be a new empty
List . - For each d in varDeclarations, in reverse list order do
- If d is neither a
VariableDeclaration or aForBinding , then- Assert: d is either a
FunctionDeclaration or aGeneratorDeclaration . - Let fn be the sole element of the BoundNames of d.
- If fn is not an element of functionNames, then
- Insert fn as the first element of functionNames.
- NOTE If there are multiple
FunctionDeclaration s orGeneratorDeclaration s for the same name, the last declaration is used. - Insert d as the first element of functionsToInitialize.
- Assert: d is either a
- If d is neither a
- Let argumentsObjectNeeded be
true . - If the value of the [[ThisMode]] internal slot of func is
lexical , then- NOTE Arrow functions never have an arguments objects.
- Let argumentsObjectNeeded be
false .
- Else if
"arguments"is an element of parameterNames, then- Let argumentsObjectNeeded be
false .
- Let argumentsObjectNeeded be
- Else if hasParameterExpressions is
false , then- If
"arguments"is an element of functionNames or if"arguments"is an element of lexicalNames, then- Let argumentsObjectNeeded be
false .
- Let argumentsObjectNeeded be
- If
- For each String paramName in parameterNames, do
- Let alreadyDeclared be envRec.HasBinding(paramName).
- 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.
- If alreadyDeclared is
false , then- Perform ! envRec.CreateMutableBinding(paramName,
false ). - If hasDuplicates is
true , then- Perform ! envRec.InitializeBinding(paramName,
undefined ).
- Perform ! envRec.InitializeBinding(paramName,
- Perform ! envRec.CreateMutableBinding(paramName,
- If argumentsObjectNeeded is
true , then- If strict is
true or if simpleParameterList isfalse , then- Let ao be
CreateUnmappedArgumentsObject (argumentsList).
- Let ao be
- Else,
- 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.
- Let ao be
CreateMappedArgumentsObject (func, formals, argumentsList, envRec).
- If strict is
true , then- Perform ! envRec.CreateImmutableBinding(
"arguments",false ).
- Perform ! envRec.CreateImmutableBinding(
- Else,
- Perform ! envRec.CreateMutableBinding(
"arguments",false ).
- Perform ! envRec.CreateMutableBinding(
- Call envRec.InitializeBinding(
"arguments", ao). - Append
"arguments"to parameterNames.
- If strict is
- Let iteratorRecord be
Record {[[Iterator]]:CreateListIterator (argumentsList), [[Done]]:false }. - If hasDuplicates is
true , then- Perform ? IteratorBindingInitialization for formals with iteratorRecord and
undefined as arguments.
- Perform ? IteratorBindingInitialization for formals with iteratorRecord and
- Else,
- Perform ? IteratorBindingInitialization for formals with iteratorRecord and env as arguments.
- If hasParameterExpressions is
false , then- NOTE Only a single lexical environment is needed for the parameters and top-level vars.
- Let instantiatedVarNames be a copy of the
List parameterNames. - For each n in varNames, do
- If n is not an element of instantiatedVarNames, then
- Append n to instantiatedVarNames.
- Perform ! envRec.CreateMutableBinding(n,
false ). - Call envRec.InitializeBinding(n,
undefined ).
- If n is not an element of instantiatedVarNames, then
- Let varEnv be env.
- Let varEnvRec be envRec.
- Else,
- 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. - Let varEnv be
NewDeclarativeEnvironment (env). - Let varEnvRec be varEnv's
EnvironmentRecord . - Set the VariableEnvironment of calleeContext to varEnv.
- Let instantiatedVarNames be a new empty
List . - For each n in varNames, do
- If n is not an element of instantiatedVarNames, then
- Append n to instantiatedVarNames.
- Perform ! varEnvRec.CreateMutableBinding(n,
false ). - If n is not an element of parameterNames or if n is an element of functionNames, let initialValue be
undefined . - Else,
- Let initialValue be ! envRec.GetBindingValue(n,
false ).
- Let initialValue be ! envRec.GetBindingValue(n,
- Call varEnvRec.InitializeBinding(n, initialValue).
- NOTE vars whose names are the same as a formal parameter, initially have the same value as the corresponding initialized parameter.
- If n is not an element of instantiatedVarNames, then
- NOTE A separate
- NOTE: Annex
B.3.3.1 adds additional steps at this point. - If strict is
false , then- Let lexEnv be
NewDeclarativeEnvironment (varEnv). - NOTE: Non-strict functions use a separate lexical
Environment Record for top-level lexical declarations so that adirect 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 strictdirect eval always places all declarations into a newEnvironment Record .
- Let lexEnv be
- Else, let lexEnv be varEnv.
- Let lexEnvRec be lexEnv's
EnvironmentRecord . - Set the LexicalEnvironment of calleeContext to lexEnv.
- Let lexDeclarations be the LexicallyScopedDeclarations of code.
- For each element d in lexDeclarations do
- 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.
- For each element dn of the BoundNames of d do
- If IsConstantDeclaration of d is
true , then- Perform ! lexEnvRec.CreateImmutableBinding(dn,
true ).
- Perform ! lexEnvRec.CreateImmutableBinding(dn,
- Else,
- Perform ! lexEnvRec.CreateMutableBinding(dn,
false ).
- Perform ! lexEnvRec.CreateMutableBinding(dn,
- If IsConstantDeclaration of d is
- For each parsed grammar phrase f in functionsToInitialize, do
- Let fn be the sole element of the BoundNames of f.
- Let fo be the result of performing InstantiateFunctionObject for f with argument lexEnv.
- Perform ! varEnvRec.SetMutableBinding(fn, fo,
false ).
- Return
NormalCompletion (empty ).
Parameter
9.3 Built-in Function Objects
The built-in function objects defined in this specification may be implemented as either ECMAScript function objects (
If a built-in function object is implemented as an exotic object it must have the ordinary object behaviour specified in
Unless otherwise specified every built-in function object has the
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 "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
- Let callerContext be the
running execution context . - If callerContext is not already suspended, suspend callerContext.
- Let calleeContext be a new ECMAScript code
execution context . - Set the Function of calleeContext to F.
- Let calleeRealm be the value of F's [[Realm]] internal slot.
- Set the
Realm of calleeContext to calleeRealm. - Set the ScriptOrModule of calleeContext to the value of F's [[ScriptOrModule]] internal slot.
- Perform any necessary implementation defined initialization of calleeContext.
- Push calleeContext onto the
execution context stack ; calleeContext is now therunning execution context . - 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 thethis value, argumentsList provides the named parameters, and the NewTarget value isundefined . - Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - Return result.
When calleeContext is removed from the
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.3 CreateBuiltinFunction (realm, steps, prototype [ , internalSlotsList ])
The abstract operation CreateBuiltinFunction takes arguments realm, prototype, and steps. The optional argument internalSlotsList is a
- Assert: realm is a
Realm Record . - Assert: steps is either a set of algorithm steps or other definition of a function's behaviour provided in this specification.
- 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 . - Set the [[Realm]] internal slot of func to realm.
- Set the [[Prototype]] internal slot of func to prototype.
- Set the [[Extensible]] internal slot of func to
true . - Set the [[ScriptOrModule]] internal slot of func to
null . - Return func.
Each built-in function defined in this specification is created as if by calling the CreateBuiltinFunction abstract operation, unless otherwise specified.
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
| Internal Slot |
|
Description |
|---|---|---|
| [[BoundTargetFunction]] | Callable Object | The wrapped function object. |
| [[BoundThis]] | Any |
The value that is always passed as the |
| [[BoundArguments]] |
|
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.4.1.1 [[Call]] ( thisArgument, argumentsList)
When the [[Call]] internal method of an exotic
- Let target be the value of F's [[BoundTargetFunction]] internal slot.
- Let boundThis be the value of F's [[BoundThis]] internal slot.
- Let boundArgs be the value of F's [[BoundArguments]] internal slot.
- 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.
- Return ?
Call (target, boundThis, args).
9.4.1.2 [[Construct]] (argumentsList, newTarget)
When the [[Construct]] internal method of an exotic
- Let target be the value of F's [[BoundTargetFunction]] internal slot.
- Assert: target has a [[Construct]] internal method.
- Let boundArgs be the value of F's [[BoundArguments]] internal slot.
- 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.
- If
SameValue (F, newTarget) istrue , let newTarget be target. - 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:
- Assert:
Type (targetFunction) is Object. - Let proto be ? targetFunction.[[GetPrototypeOf]]().
- Let obj be a newly created object.
- Set obj's essential internal methods to the default ordinary object definitions specified in
9.1 . - Set the [[Call]] internal method of obj as described in
9.4.1.1 . - If targetFunction has a [[Construct]] internal method, then
- Set the [[Construct]] internal method of obj as described in
9.4.1.2 .
- Set the [[Construct]] internal method of obj as described in
- Set the [[Prototype]] internal slot of obj to proto.
- Set the [[Extensible]] internal slot of obj to
true . - Set the [[BoundTargetFunction]] internal slot of obj to targetFunction.
- Set the [[BoundThis]] internal slot of obj to the value of boundThis.
- Set the [[BoundArguments]] internal slot of obj to boundArgs.
- 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 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.
Array exotic objects always have a non-configurable property named "length".
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.4.2.1 [[DefineOwnProperty]] ( P, Desc)
When the [[DefineOwnProperty]] internal method of an Array exotic object A is called with property key P, and
- Assert:
IsPropertyKey (P) istrue . - If P is
"length", then- Return ?
ArraySetLength (A, Desc).
- Return ?
- Else if P is an array index, then
- Let oldLenDesc be
OrdinaryGetOwnProperty (A,"length"). - 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. - Let oldLen be oldLenDesc.[[Value]].
- Let index be !
ToUint32 (P). - If index ≥ oldLen and oldLenDesc.[[Writable]] is
false , returnfalse . - Let succeeded be !
OrdinaryDefineOwnProperty (A, P, Desc). - If succeeded is
false , returnfalse . - If index ≥ oldLen, then
- Set oldLenDesc.[[Value]] to index + 1.
- Let succeeded be
OrdinaryDefineOwnProperty (A,"length", oldLenDesc). - Assert: succeeded is
true .
- Return
true .
- Let oldLenDesc be
- 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:
- Assert: length is an integer Number ≥ 0.
- If length is
-0 , let length be+0 . - If length>232-1, throw a
RangeError exception. - If the proto argument was not passed, let proto be the intrinsic object
%ArrayPrototype% . - Let A be a newly created Array exotic object.
- Set A's essential internal methods except for [[DefineOwnProperty]] to the default ordinary object definitions specified in
9.1 . - Set the [[DefineOwnProperty]] internal method of A as specified in
9.4.2.1 . - Set the [[Prototype]] internal slot of A to proto.
- Set the [[Extensible]] internal slot of A to
true . - Perform !
OrdinaryDefineOwnProperty (A,"length", PropertyDescriptor{[[Value]]: length, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - 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:
- Assert: length is an integer Number ≥ 0.
- If length is
-0 , let length be+0 . - Let C be
undefined . - Let isArray be ?
IsArray (originalArray). - If isArray is
true , then- Let C be ?
Get (originalArray,"constructor"). - If
IsConstructor (C) istrue , then- Let thisRealm be
the current Realm Record . - Let realmC be ?
GetFunctionRealm (C). - If thisRealm and realmC are not the same
Realm Record , then- If
SameValue (C, realmC.[[Intrinsics]].[[%Array% ]]) istrue , let C beundefined .
- If
- Let thisRealm be
- If
Type (C) is Object, then- Let C be ?
Get (C, @@species). - If C is
null , let C beundefined .
- Let C be ?
- Let C be ?
- If C is
undefined , return ?ArrayCreate (length). - If
IsConstructor (C) isfalse , throw aTypeError exception. - Return ?
Construct (C, « length »).
If originalArray was created using the standard built-in Array constructor for a
9.4.2.4 ArraySetLength (A, Desc)
When the abstract operation ArraySetLength is called with an Array exotic object A, and
- If the [[Value]] field of Desc is absent, then
- Return
OrdinaryDefineOwnProperty (A,"length", Desc).
- Return
- Let newLenDesc be a copy of Desc.
- Let newLen be ?
ToUint32 (Desc.[[Value]]). - Let numberLen be ?
ToNumber (Desc.[[Value]]). - If newLen ≠ numberLen, throw a
RangeError exception. - Set newLenDesc.[[Value]] to newLen.
- Let oldLenDesc be
OrdinaryGetOwnProperty (A,"length"). - 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. - Let oldLen be oldLenDesc.[[Value]].
- If newLen ≥ oldLen, then
- Return
OrdinaryDefineOwnProperty (A,"length", newLenDesc).
- Return
- If oldLenDesc.[[Writable]] is
false , returnfalse . - If newLenDesc.[[Writable]] is absent or has the value
true , let newWritable betrue . - Else,
- Need to defer setting the [[Writable]] attribute to
false in case any elements cannot be deleted. - Let newWritable be
false . - Set newLenDesc.[[Writable]] to
true .
- Need to defer setting the [[Writable]] attribute to
- Let succeeded be !
OrdinaryDefineOwnProperty (A,"length", newLenDesc). - If succeeded is
false , returnfalse . - While newLen < oldLen repeat,
- Set oldLen to oldLen - 1.
- Let deleteSucceeded be ! A.[[Delete]](!
ToString (oldLen)). - If deleteSucceeded is
false , then- Set newLenDesc.[[Value]] to oldLen + 1.
- If newWritable is
false , set newLenDesc.[[Writable]] tofalse . - Let succeeded be !
OrdinaryDefineOwnProperty (A,"length", newLenDesc). - Return
false .
- If newWritable is
false , then- Return
OrdinaryDefineOwnProperty (A,"length", PropertyDescriptor{[[Writable]]:false }). This call will always returntrue .
- Return
- Return
true .
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. Exotic String 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.
Exotic String objects have the same internal slots as ordinary objects. They also have a [[StringData]] internal slot.
Exotic String objects provide alternative definitions for the following internal methods. All of the other exotic String object essential internal methods that are not defined below are as specified in
9.4.3.1 [[GetOwnProperty]] ( P )
When the [[GetOwnProperty]] internal method of an exotic String object S is called with property key P, the following steps are taken:
- Assert:
IsPropertyKey (P) istrue . - Let desc be
OrdinaryGetOwnProperty (S, P). - If desc is not
undefined , return desc. - If
Type (P) is not String, returnundefined . - Let index be !
CanonicalNumericIndexString (P). - If index is
undefined , returnundefined . - If
IsInteger (index) isfalse , returnundefined . - If index =
-0 , returnundefined . - Let str be the String value of the [[StringData]] internal slot of S.
- Let len be the number of elements in str.
- If index < 0 or len ≤ index, return
undefined . - Let resultStr be a String value of length 1, containing one code unit from str, specifically the code unit at index index.
- Return a PropertyDescriptor{[[Value]]: resultStr, [[Writable]]:
false , [[Enumerable]]:true , [[Configurable]]:false }.
9.4.3.2 [[OwnPropertyKeys]] ( )
When the [[OwnPropertyKeys]] internal method of a String exotic object O is called, the following steps are taken:
- Let keys be a new empty
List . - Let str be the String value of the [[StringData]] internal slot of O.
- Let len be the number of elements in str.
- For each integer i starting with 0 such that i < len, in ascending order,
- Add !
ToString (i) as the last element of keys.
- Add !
- For each own property key P of O such that P is an integer index and
ToInteger (P) ≥ len, in ascending numeric index order,- Add P as the last element of keys.
- 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,- Add P as the last element of keys.
- For each own property key P of O such that
Type (P) is Symbol, in ascending chronological order of property creation,- Add P as the last element of keys.
- Return keys.
9.4.3.3 StringCreate ( value, prototype)
The abstract operation StringCreate with arguments value and prototype is used to specify the creation of new exotic String objects. It performs the following steps:
- Assert:
Type (value) is String. - Let S be a newly created String exotic object.
- Set the [[StringData]] internal slot of S to value.
- Set S's essential internal methods to the default ordinary object definitions specified in
9.1 . - Set the [[GetOwnProperty]] internal method of S as specified in
9.4.3.1 . - Set the [[OwnPropertyKeys]] internal method of S as specified in
9.4.3.2 . - Set the [[Prototype]] internal slot of S to prototype.
- Set the [[Extensible]] internal slot of S to
true . - Let length be the number of code unit elements in value.
- Perform !
DefinePropertyOrThrow (S,"length", PropertyDescriptor{[[Value]]: length, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:false }). - Return S.
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 (
Arguments exotic objects provide alternative definitions for the following internal methods. All of the other exotic arguments object essential internal methods that are not defined below are as specified in
For non-strict functions the integer indexed data properties of an arguments 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
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.
Arguments objects for strict mode functions define non-configurable accessor properties named "caller" and "callee" which throw a "callee" property has a more specific meaning for non-strict functions and a "caller" property has historically been provided as an implementation-defined extension by some ECMAScript implementations. The strict mode definition of these properties exists to ensure that neither of them is defined in any other manner by conforming ECMAScript implementations.
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:
- Let args be the arguments object.
- Let desc be
OrdinaryGetOwnProperty (args, P). - If desc is
undefined , return desc. - Let map be the value of the [[ParameterMap]] internal slot of the arguments object.
- Let isMapped be !
HasOwnProperty (map, P). - If the value of isMapped is
true , then- Set desc.[[Value]] to
Get (map, P).
- Set desc.[[Value]] to
- If
IsDataDescriptor (desc) istrue and P is"caller"and desc.[[Value]] is a strict mode Function object, throw aTypeError exception. - Return desc.
If an implementation does not provide a built-in caller property for argument exotic objects then step 7 of this algorithm must be skipped.
9.4.4.2 [[DefineOwnProperty]] (P, Desc)
The [[DefineOwnProperty]] internal method of an arguments exotic object when called with a property key P and
- Let args be the arguments object.
- Let map be the value of the [[ParameterMap]] internal slot of the arguments object.
- Let isMapped be
HasOwnProperty (map, P). - Let newArgDesc be Desc.
- If isMapped is
true andIsDataDescriptor (Desc) istrue , then- If Desc.[[Value]] is not present and Desc.[[Writable]] is present and its value is
false , then- Let newArgDesc be a copy of Desc.
- Set newArgDesc.[[Value]] to
Get (map, P).
- If Desc.[[Value]] is not present and Desc.[[Writable]] is present and its value is
- Let allowed be ?
OrdinaryDefineOwnProperty (args, P, newArgDesc). - If allowed is
false , returnfalse . - If the value of isMapped is
true , then- If
IsAccessorDescriptor (Desc) istrue , then- Call map.[[Delete]](P).
- Else,
- If Desc.[[Value]] is present, then
- Let setStatus be
Set (map, P, Desc.[[Value]],false ). - Assert: setStatus is
true because formal parameters mapped by argument objects are always writable.
- Let setStatus be
- If Desc.[[Writable]] is present and its value is
false , then- Call map.[[Delete]](P).
- If Desc.[[Value]] is present, then
- If
- 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
- Let args be the arguments object.
- Let map be the value of the [[ParameterMap]] internal slot of the arguments object.
- Let isMapped be !
HasOwnProperty (map, P). - If the value of isMapped is
false , then- Return ?
OrdinaryGet (args, P, Receiver).
- Return ?
- Else map contains a formal parameter mapping for P,
- Return
Get (map, P).
- Return
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
- Let args be the arguments object.
- If
SameValue (args, Receiver) isfalse , then- Let isMapped be
false .
- Let isMapped be
- Else,
- Let map be the value of the [[ParameterMap]] internal slot of the arguments object.
- Let isMapped be !
HasOwnProperty (map, P).
- If isMapped is
true , then- Let setStatus be
Set (map, P, V,false ). - Assert: setStatus is
true because formal parameters mapped by argument objects are always writable.
- Let setStatus be
- Return ?
OrdinarySet (args, P, V, Receiver).
9.4.4.5 [[HasProperty]] ( P )
The [[HasProperty]] internal method of an arguments exotic object when called with property key P, performs the following steps:
- Let args be the arguments object.
- If P is
"caller", then- Let desc be !
OrdinaryGetOwnProperty (args, P). - If
IsDataDescriptor (desc) istrue , returntrue .
- Let desc be !
- Return ?
OrdinaryHasProperty (args, P).
If an implementation does not provide a built-in caller property for argument exotic objects then step 2 of this algorithm must be skipped.
9.4.4.6 [[Delete]] (P)
The [[Delete]] internal method of an arguments exotic object when called with a property key P performs the following steps:
- Let args be the arguments object.
- Let map be the value of the [[ParameterMap]] internal slot of args.
- Let isMapped be !
HasOwnProperty (map, P). - Let result be ?
OrdinaryDelete (args, P). - If result is
true and the value of isMapped istrue , then- Call map.[[Delete]](P).
- Return result.
9.4.4.7 CreateUnmappedArgumentsObject (argumentsList)
The abstract operation CreateUnmappedArgumentsObject called with an argument argumentsList performs the following steps:
- Let len be the number of elements in argumentsList.
- Let obj be
ObjectCreate (%ObjectPrototype% , « [[ParameterMap]] »). - Set obj's [[ParameterMap]] internal slot to
undefined . - Perform
DefinePropertyOrThrow (obj,"length", PropertyDescriptor{[[Value]]: len, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Let index be 0.
- Repeat while index < len,
- Let val be argumentsList[index].
- Perform
CreateDataProperty (obj, !ToString (index), val). - Let index be index + 1.
- Perform !
DefinePropertyOrThrow (obj, @@iterator, PropertyDescriptor {[[Value]]: %ArrayProto_values%, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Perform !
DefinePropertyOrThrow (obj,"callee", PropertyDescriptor {[[Get]]:%ThrowTypeError% , [[Set]]:%ThrowTypeError% , [[Enumerable]]:false , [[Configurable]]:false }). - Perform !
DefinePropertyOrThrow (obj,"caller", PropertyDescriptor {[[Get]]:%ThrowTypeError% , [[Set]]:%ThrowTypeError% , [[Enumerable]]:false , [[Configurable]]:false }). - Return obj.
9.4.4.8 CreateMappedArgumentsObject ( func, formals, argumentsList, env )
The abstract operation CreateMappedArgumentsObject is called with object func, parsed grammar phrase formals,
- Assert: formals does not contain a rest parameter, any binding patterns, or any initializers. It may contain duplicate identifiers.
- Let len be the number of elements in argumentsList.
- Let obj be a newly created arguments exotic object with a [[ParameterMap]] internal slot.
- Set the [[GetOwnProperty]] internal method of obj as specified in
9.4.4.1 . - Set the [[DefineOwnProperty]] internal method of obj as specified in
9.4.4.2 . - Set the [[Get]] internal method of obj as specified in
9.4.4.3 . - Set the [[Set]] internal method of obj as specified in
9.4.4.4 . - Set the [[HasProperty]] internal method of obj as specified in
9.4.4.5 . - Set the [[Delete]] internal method of obj as specified in
9.4.4.6 . - Set the remainder of obj's essential internal methods to the default ordinary object definitions specified in
9.1 . - Set the [[Prototype]] internal slot of obj to
%ObjectPrototype% . - Set the [[Extensible]] internal slot of obj to
true . - Let map be
ObjectCreate (null ). - Set the [[ParameterMap]] internal slot of obj to map.
- Let parameterNames be the BoundNames of formals.
- Let numberOfParameters be the number of elements in parameterNames.
- Let index be 0.
- Repeat while index < len,
- Let val be argumentsList[index].
- Perform
CreateDataProperty (obj, !ToString (index), val). - Let index be index + 1.
- Perform
DefinePropertyOrThrow (obj,"length", PropertyDescriptor{[[Value]]: len, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Let mappedNames be a new empty
List . - Let index be numberOfParameters - 1.
- Repeat while index ≥ 0,
- Let name be parameterNames[index].
- If name is not an element of mappedNames, then
- Add name as an element of the list mappedNames.
- If index < len, then
- Let g be
MakeArgGetter (name, env). - Let p be
MakeArgSetter (name, env). - Perform map.[[DefineOwnProperty]](!
ToString (index), PropertyDescriptor{[[Set]]: p, [[Get]]: g, [[Enumerable]]:false , [[Configurable]]:true }).
- Let g be
- Let index be index - 1.
- Perform !
DefinePropertyOrThrow (obj, @@iterator, PropertyDescriptor {[[Value]]: %ArrayProto_values%, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Perform !
DefinePropertyOrThrow (obj,"callee", PropertyDescriptor {[[Value]]: func, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Return obj.
9.4.4.8.1 MakeArgGetter ( name, env)
The abstract operation MakeArgGetter called with String name and
- Let realm be
the current Realm Record . - Let steps be the steps of an ArgGetter function as specified below.
- Let getter be
CreateBuiltinFunction (realm, steps,%FunctionPrototype% , « [[Name]], [[Env]] »). - Set getter's [[Name]] internal slot to name.
- Set getter's [[Env]] internal slot to env.
- Return getter.
An ArgGetter function is an anonymous built-in function with [[Name]] and [[Env]] internal slots. When an ArgGetter function f that expects no arguments is called it performs the following steps:
- Let name be the value of f's [[Name]] internal slot.
- Let env be the value of f's [[Env]] internal slot.
- Return env.GetBindingValue(name,
false ).
ArgGetter functions are never directly accessible to ECMAScript code.
9.4.4.8.2 MakeArgSetter ( name, env)
The abstract operation MakeArgSetter called with String name and
- Let realm be
the current Realm Record . - Let steps be the steps of an ArgSetter function as specified below.
- Let setter be
CreateBuiltinFunction (realm, steps,%FunctionPrototype% , « [[Name]], [[Env]] »). - Set setter's [[Name]] internal slot to name.
- Set setter's [[Env]] internal slot to env.
- Return setter.
An ArgSetter function is an anonymous built-in function with [[Name]] and [[Env]] internal slots. When an ArgSetter function f is called with argument value it performs the following steps:
- Let name be the value of f's [[Name]] internal slot.
- Let env be the value of f's [[Env]] internal slot.
- Return env.SetMutableBinding(name, value,
false ).
ArgSetter functions are never directly accessible to ECMAScript code.
9.4.5 Integer Indexed Exotic Objects
An Integer Indexed 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.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:
- Assert:
IsPropertyKey (P) istrue . - Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot.
- If
Type (P) is String, then- Let numericIndex be !
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- Let value be ?
IntegerIndexedElementGet (O, numericIndex). - If value is
undefined , returnundefined . - Return a PropertyDescriptor{[[Value]]: value, [[Writable]]:
true , [[Enumerable]]:true , [[Configurable]]:false }.
- Let value be ?
- Let numericIndex be !
- 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:
- Assert:
IsPropertyKey (P) istrue . - Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot.
- If
Type (P) is String, then- Let numericIndex be !
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - If
IsInteger (numericIndex) isfalse , returnfalse . - If numericIndex =
-0 , returnfalse . - If numericIndex < 0, return
false . - If numericIndex ≥ the value of O's [[ArrayLength]] internal slot, return
false . - Return
true .
- Let numericIndex be !
- 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
- Assert:
IsPropertyKey (P) istrue . - Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot.
- If
Type (P) is String, then- Let numericIndex be !
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- If
IsInteger (numericIndex) isfalse , returnfalse . - Let intIndex be numericIndex.
- If intIndex =
-0 , returnfalse . - If intIndex < 0, return
false . - Let length be the value of O's [[ArrayLength]] internal slot.
- If intIndex ≥ length, return
false . - If
IsAccessorDescriptor (Desc) istrue , returnfalse . - If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is
true , returnfalse . - If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is
false , returnfalse . - If Desc has a [[Writable]] field and if Desc.[[Writable]] is
false , returnfalse . - If Desc has a [[Value]] field, then
- Let value be Desc.[[Value]].
- Return ?
IntegerIndexedElementSet (O, intIndex, value).
- Return
true .
- If
- Let numericIndex be !
- 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
- Assert:
IsPropertyKey (P) istrue . - If
Type (P) is String, then- Let numericIndex be !
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- Return ?
IntegerIndexedElementGet (O, numericIndex).
- Return ?
- Let numericIndex be !
- 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
- Assert:
IsPropertyKey (P) istrue . - If
Type (P) is String, then- Let numericIndex be !
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- Return ?
IntegerIndexedElementSet (O, numericIndex, V).
- Return ?
- Let numericIndex be !
- 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:
- Let keys be a new empty
List . - Assert: O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.
- Let len be the value of O's [[ArrayLength]] internal slot.
- For each integer i starting with 0 such that i < len, in ascending order,
- Add !
ToString (i) as the last element of keys.
- Add !
- 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- Add P as the last element of keys.
- For each own property key P of O such that
Type (P) is Symbol, in ascending chronological order of property creation- Add P as the last element of keys.
- 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
- Assert: internalSlotsList contains the names [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]].
- Let A be a newly created object with an internal slot for each name in internalSlotsList.
- Set A's essential internal methods to the default ordinary object definitions specified in
9.1 . - Set the [[GetOwnProperty]] internal method of A as specified in
9.4.5.1 . - Set the [[HasProperty]] internal method of A as specified in
9.4.5.2 . - Set the [[DefineOwnProperty]] internal method of A as specified in
9.4.5.3 . - Set the [[Get]] internal method of A as specified in
9.4.5.4 . - Set the [[Set]] internal method of A as specified in
9.4.5.5 . - Set the [[OwnPropertyKeys]] internal method of A as specified in
9.4.5.6 . - Set the [[Prototype]] internal slot of A to prototype.
- Set the [[Extensible]] internal slot of A to
true . - Return A.
9.4.5.8 IntegerIndexedElementGet ( O, index )
The abstract operation IntegerIndexedElementGet with arguments O and index performs the following steps:
- Assert:
Type (index) is Number. - Assert: O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.
- Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - If
IsInteger (index) isfalse , returnundefined . - If index =
-0 , returnundefined . - Let length be the value of O's [[ArrayLength]] internal slot.
- If index < 0 or index ≥ length, return
undefined . - Let offset be the value of O's [[ByteOffset]] internal slot.
- Let arrayTypeName be the String value of O's [[TypedArrayName]] internal slot.
- Let elementSize be the Number value of the Element Size value specified in
Table 50 for arrayTypeName. - Let indexedPosition be (index × elementSize) + offset.
- Let elementType be the String value of the Element
Type value inTable 50 for arrayTypeName. - Return
GetValueFromBuffer (buffer, indexedPosition, elementType).
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
The abstract operation IntegerIndexedElementSet with arguments O, index, and value performs the following steps:
- Assert:
Type (index) is Number. - Assert: O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.
- Let numValue be ?
ToNumber (value). - Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - If
IsInteger (index) isfalse , returnfalse . - If index =
-0 , returnfalse . - Let length be the value of O's [[ArrayLength]] internal slot.
- If index < 0 or index ≥ length, return
false . - Let offset be the value of O's [[ByteOffset]] internal slot.
- Let arrayTypeName be the String value of O's [[TypedArrayName]] internal slot.
- Let elementSize be the Number value of the Element Size value specified in
Table 50 for arrayTypeName. - Let indexedPosition be (index × elementSize) + offset.
- Let elementType be the String value of the Element
Type value inTable 50 for arrayTypeName. - Perform
SetValueInBuffer (buffer, indexedPosition, elementType, numValue). - 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 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]]:
Module namespace objects have the internal slots defined in
| Internal Slot |
|
Description |
|---|---|---|
| [[Module]] |
|
The |
| [[Exports]] |
|
A Array.prototype.sort using |
Module namespace exotic objects provide alternative definitions for all of the internal methods.
9.4.6.1 [[GetPrototypeOf]] ( )
When the [[GetPrototypeOf]] internal method of a module namespace exotic object O is called, the following steps are taken:
- Return
null .
9.4.6.2 [[SetPrototypeOf]] (V)
9.4.6.3 [[IsExtensible]] ( )
When the [[IsExtensible]] internal method of a module namespace exotic object O is called, the following steps are taken:
- Return
false .
9.4.6.4 [[PreventExtensions]] ( )
When the [[PreventExtensions]] internal method of a module namespace exotic object O is called, the following steps are taken:
- Return
true .
9.4.6.5 [[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:
- If
Type (P) is Symbol, returnOrdinaryGetOwnProperty (O, P). - Let exports be the value of O's [[Exports]] internal slot.
- If P is not an element of exports, return
undefined . - Let value be ? O.[[Get]](P, O).
- Return PropertyDescriptor{[[Value]]: value, [[Writable]]:
true , [[Enumerable]]:true , [[Configurable]]:false }.
9.4.6.6 [[DefineOwnProperty]] (P, Desc)
When the [[DefineOwnProperty]] internal method of a module namespace exotic object O is called with property key P and
- Return
false .
9.4.6.7 [[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:
- If
Type (P) is Symbol, returnOrdinaryHasProperty (O, P). - Let exports be the value of O's [[Exports]] internal slot.
- If P is an element of exports, return
true . - Return
false .
9.4.6.8 [[Get]] (P, Receiver)
When the [[Get]] internal method of a module namespace exotic object O is called with property key P and
- Assert:
IsPropertyKey (P) istrue . - If
Type (P) is Symbol, then- Return ?
OrdinaryGet (O, P, Receiver).
- Return ?
- Let exports be the value of O's [[Exports]] internal slot.
- If P is not an element of exports, return
undefined . - Let m be the value of O's [[Module]] internal slot.
- Let binding be ? m.ResolveExport(P, « », « »).
- Assert: binding is neither
null nor"ambiguous". - Let targetModule be binding.[[Module]].
- Assert: targetModule is not
undefined . - Let targetEnv be targetModule.[[Environment]].
- If targetEnv is
undefined , throw aReferenceError exception. - Let targetEnvRec be targetEnv's
EnvironmentRecord . - Return ? targetEnvRec.GetBindingValue(binding.[[BindingName]],
true ).
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.9 [[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
- Return
false .
9.4.6.10 [[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:
- Assert:
IsPropertyKey (P) istrue . - Let exports be the value of O's [[Exports]] internal slot.
- If P is an element of exports, return
false . - Return
true .
9.4.6.11 [[OwnPropertyKeys]] ( )
When the [[OwnPropertyKeys]] internal method of a module namespace exotic object O is called, the following steps are taken:
- Let exports be a copy of the value of O's [[Exports]] internal slot.
- Let symbolKeys be !
OrdinaryOwnPropertyKeys (O). - Append all the entries of symbolKeys to the end of exports.
- Return exports.
9.4.6.12 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:
- Assert: module is a
Module Record . - Assert: module.[[Namespace]] is
undefined . - Assert: exports is a
List of String values. - Let M be a newly created object.
- Set M's essential internal methods to the definitions specified in
9.4.6 . - Set M's [[Module]] internal slot to module.
- Set M's [[Exports]] internal slot to exports.
- Create own properties of M corresponding to the definitions in
26.3 . - Set module.[[Namespace]] to M.
- Return M.
9.4.7 Immutable Prototype Exotic Objects
An immutable prototype exotic object is an exotic object that has an immutable [[Prototype]] internal slot.
9.4.7.1 [[SetPrototypeOf]] (V)
When the [[SetPrototypeOf]] internal method of an
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 objects has an internal slot called [[ProxyHandler]]. The value of [[ProxyHandler]] is an object, called the proxy's handler object, or
| Internal Method | Handler Method |
|---|---|
| [[GetPrototypeOf]] |
getPrototypeOf
|
| [[SetPrototypeOf]] |
setPrototypeOf
|
| [[IsExtensible]] |
isExtensible
|
| [[PreventExtensions]] |
preventExtensions
|
| [[GetOwnProperty]] |
getOwnPropertyDescriptor
|
| [[HasProperty]] |
has
|
| [[Get]] |
get
|
| [[Set]] |
set
|
| [[Delete]] |
deleteProperty
|
| [[DefineOwnProperty]] |
defineProperty
|
| [[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
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
In the following algorithm descriptions, assume O is an ECMAScript proxy object, P is a property key value, V is any
9.5.1 [[GetPrototypeOf]] ( )
When the [[GetPrototypeOf]] internal method of a Proxy exotic object O is called, the following steps are taken:
- Let handler be the value of the [[ProxyHandler]] internal slot of O.
- If handler is
null , throw aTypeError exception. - Assert:
Type (handler) is Object. - Let target be the value of the [[ProxyTarget]] internal slot of O.
- Let trap be ?
GetMethod (handler,"getPrototypeOf"). - If trap is
undefined , then- Return ? target.[[GetPrototypeOf]]().
- Let handlerProto be ?
Call (trap, handler, « target »). - If
Type (handlerProto) is neither Object nor Null, throw aTypeError exception. - Let extensibleTarget be ?
IsExtensible (target). - If extensibleTarget is
true , return handlerProto. - Let targetProto be ? target.[[GetPrototypeOf]]().
- If
SameValue (handlerProto, targetProto) isfalse , throw aTypeError exception. - Return handlerProto.
[[GetPrototypeOf]] for proxy objects enforces the following invariant:
-
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:
- Assert: Either
Type (V) is Object orType (V) is Null. - Let handler be the value of the [[ProxyHandler]] internal slot of O.
- If handler is
null , throw aTypeError exception. - Assert:
Type (handler) is Object. - Let target be the value of the [[ProxyTarget]] internal slot of O.
- Let trap be ?
GetMethod (handler,"setPrototypeOf"). - If trap is
undefined , then- Return ? target.[[SetPrototypeOf]](V).
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target, V »)). - If booleanTrapResult is
false , returnfalse . - Let extensibleTarget be ?
IsExtensible (target). - If extensibleTarget is
true , returntrue . - Let targetProto be ? target.[[GetPrototypeOf]]().
- If
SameValue (V, targetProto) isfalse , throw aTypeError exception. - Return
true .
[[SetPrototypeOf]] for proxy objects enforces the following invariant:
- 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:
- Let handler be the value of the [[ProxyHandler]] internal slot of O.
- If handler is
null , throw aTypeError exception. - Assert:
Type (handler) is Object. - Let target be the value of the [[ProxyTarget]] internal slot of O.
- Let trap be ?
GetMethod (handler,"isExtensible"). - If trap is
undefined , then- Return ? target.[[IsExtensible]]().
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target »)). - Let targetResult be ? target.[[IsExtensible]]().
- If
SameValue (booleanTrapResult, targetResult) isfalse , throw aTypeError exception. - Return booleanTrapResult.
[[IsExtensible]] for proxy objects enforces the following invariant:
- 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:
- Let handler be the value of the [[ProxyHandler]] internal slot of O.
- If handler is
null , throw aTypeError exception. - Assert:
Type (handler) is Object. - Let target be the value of the [[ProxyTarget]] internal slot of O.
- Let trap be ?
GetMethod (handler,"preventExtensions"). - If trap is
undefined , then- Return ? target.[[PreventExtensions]]().
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target »)). - If booleanTrapResult is
true , then- Let targetIsExtensible be ? target.[[IsExtensible]]().
- If targetIsExtensible is
true , throw aTypeError exception.
- Return booleanTrapResult.
[[PreventExtensions]] for proxy objects enforces the following invariant:
- 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 isfalse .
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:
- Assert:
IsPropertyKey (P) istrue . - Let handler be the value of the [[ProxyHandler]] internal slot of O.
- If handler is
null , throw aTypeError exception. - Assert:
Type (handler) is Object. - Let target be the value of the [[ProxyTarget]] internal slot of O.
- Let trap be ?
GetMethod (handler,"getOwnPropertyDescriptor"). - If trap is
undefined , then- Return ? target.[[GetOwnProperty]](P).
- Let trapResultObj be ?
Call (trap, handler, « target, P »). - If
Type (trapResultObj) is neither Object nor Undefined, throw aTypeError exception. - Let targetDesc be ? target.[[GetOwnProperty]](P).
- If trapResultObj is
undefined , then- If targetDesc is
undefined , returnundefined . - If targetDesc.[[Configurable]] is
false , throw aTypeError exception. - Let extensibleTarget be ?
IsExtensible (target). - Assert:
Type (extensibleTarget) is Boolean. - If extensibleTarget is
false , throw aTypeError exception. - Return
undefined .
- If targetDesc is
- Let extensibleTarget be ?
IsExtensible (target). - Let resultDesc be ?
ToPropertyDescriptor (trapResultObj). - Call
CompletePropertyDescriptor (resultDesc). - Let valid be
IsCompatiblePropertyDescriptor (extensibleTarget, resultDesc, targetDesc). - If valid is
false , throw aTypeError exception. - If resultDesc.[[Configurable]] is
false , then- If targetDesc is
undefined or targetDesc.[[Configurable]] istrue , then- Throw a
TypeError exception.
- Throw a
- If targetDesc is
- Return resultDesc.
[[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 exists 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 exists 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
- Assert:
IsPropertyKey (P) istrue . - Let handler be the value of the [[ProxyHandler]] internal slot of O.
- If handler is
null , throw aTypeError exception. - Assert:
Type (handler) is Object. - Let target be the value of the [[ProxyTarget]] internal slot of O.
- Let trap be ?
GetMethod (handler,"defineProperty"). - If trap is
undefined , then- Return ? target.[[DefineOwnProperty]](P, Desc).
- Let descObj be
FromPropertyDescriptor (Desc). - Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target, P, descObj »)). - If booleanTrapResult is
false , returnfalse . - Let targetDesc be ? target.[[GetOwnProperty]](P).
- Let extensibleTarget be ?
IsExtensible (target). - If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is
false , then- Let settingConfigFalse be
true .
- Let settingConfigFalse be
- Else let settingConfigFalse be
false . - If targetDesc is
undefined , then- If extensibleTarget is
false , throw aTypeError exception. - If settingConfigFalse is
true , throw aTypeError exception.
- If extensibleTarget is
- Else targetDesc is not
undefined ,- If
IsCompatiblePropertyDescriptor (extensibleTarget, Desc, targetDesc) isfalse , throw aTypeError exception. - If settingConfigFalse is
true and targetDesc.[[Configurable]] istrue , throw aTypeError exception.
- If
- Return
true .
[[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:
- Assert:
IsPropertyKey (P) istrue . - Let handler be the value of the [[ProxyHandler]] internal slot of O.
- If handler is
null , throw aTypeError exception. - Assert:
Type (handler) is Object. - Let target be the value of the [[ProxyTarget]] internal slot of O.
- Let trap be ?
GetMethod (handler,"has"). - If trap is
undefined , then- Return ? target.[[HasProperty]](P).
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target, P »)). - If booleanTrapResult is
false , then- Let targetDesc be ? target.[[GetOwnProperty]](P).
- If targetDesc is not
undefined , then- If targetDesc.[[Configurable]] is
false , throw aTypeError exception. - Let extensibleTarget be ?
IsExtensible (target). - If extensibleTarget is
false , throw aTypeError exception.
- If targetDesc.[[Configurable]] is
- Return booleanTrapResult.
[[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
- Assert:
IsPropertyKey (P) istrue . - Let handler be the value of the [[ProxyHandler]] internal slot of O.
- If handler is
null , throw aTypeError exception. - Assert:
Type (handler) is Object. - Let target be the value of the [[ProxyTarget]] internal slot of O.
- Let trap be ?
GetMethod (handler,"get"). - If trap is
undefined , then- Return ? target.[[Get]](P, Receiver).
- Let trapResult be ?
Call (trap, handler, « target, P, Receiver »). - Let targetDesc be ? target.[[GetOwnProperty]](P).
- If targetDesc is not
undefined , then- If
IsDataDescriptor (targetDesc) istrue and targetDesc.[[Configurable]] isfalse and targetDesc.[[Writable]] isfalse , then- If
SameValue (trapResult, targetDesc.[[Value]]) isfalse , throw aTypeError exception.
- If
- If
IsAccessorDescriptor (targetDesc) istrue and targetDesc.[[Configurable]] isfalse and targetDesc.[[Get]] isundefined , then- If trapResult is not
undefined , throw aTypeError exception.
- If trapResult is not
- If
- Return trapResult.
[[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 hasundefined 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
- Assert:
IsPropertyKey (P) istrue . - Let handler be the value of the [[ProxyHandler]] internal slot of O.
- If handler is
null , throw aTypeError exception. - Assert:
Type (handler) is Object. - Let target be the value of the [[ProxyTarget]] internal slot of O.
- Let trap be ?
GetMethod (handler,"set"). - If trap is
undefined , then- Return ? target.[[Set]](P, V, Receiver).
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target, P, V, Receiver »)). - If booleanTrapResult is
false , returnfalse . - Let targetDesc be ? target.[[GetOwnProperty]](P).
- If targetDesc is not
undefined , then- If
IsDataDescriptor (targetDesc) istrue and targetDesc.[[Configurable]] isfalse and targetDesc.[[Writable]] isfalse , then- If
SameValue (V, targetDesc.[[Value]]) isfalse , throw aTypeError exception.
- If
- If
IsAccessorDescriptor (targetDesc) istrue and targetDesc.[[Configurable]] isfalse , then- If targetDesc.[[Set]] is
undefined , throw aTypeError exception.
- If targetDesc.[[Set]] is
- If
- Return
true .
[[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:
- Assert:
IsPropertyKey (P) istrue . - Let handler be the value of the [[ProxyHandler]] internal slot of O.
- If handler is
null , throw aTypeError exception. - Assert:
Type (handler) is Object. - Let target be the value of the [[ProxyTarget]] internal slot of O.
- Let trap be ?
GetMethod (handler,"deleteProperty"). - If trap is
undefined , then- Return ? target.[[Delete]](P).
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target, P »)). - If booleanTrapResult is
false , returnfalse . - Let targetDesc be ? target.[[GetOwnProperty]](P).
- If targetDesc is
undefined , returntrue . - If targetDesc.[[Configurable]] is
false , throw aTypeError exception. - Return
true .
[[Delete]] for proxy objects enforces the following invariant:
- 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:
- Let handler be the value of the [[ProxyHandler]] internal slot of O.
- If handler is
null , throw aTypeError exception. - Assert:
Type (handler) is Object. - Let target be the value of the [[ProxyTarget]] internal slot of O.
- Let trap be ?
GetMethod (handler,"ownKeys"). - If trap is
undefined , then- Return ? target.[[OwnPropertyKeys]]().
- Let trapResultArray be ?
Call (trap, handler, « target »). - Let trapResult be ?
CreateListFromArrayLike (trapResultArray, « String, Symbol »). - Let extensibleTarget be ?
IsExtensible (target). - Let targetKeys be ? target.[[OwnPropertyKeys]]().
- Assert: targetKeys is a
List containing only String and Symbol values. - Let targetConfigurableKeys be a new empty
List . - Let targetNonconfigurableKeys be a new empty
List . - Repeat, for each element key of targetKeys,
- Let desc be ? target.[[GetOwnProperty]](key).
- If desc is not
undefined and desc.[[Configurable]] isfalse , then- Append key as an element of targetNonconfigurableKeys.
- Else,
- Append key as an element of targetConfigurableKeys.
- If extensibleTarget is
true and targetNonconfigurableKeys is empty, then- Return trapResult.
- Let uncheckedResultKeys be a new
List which is a copy of trapResult. - Repeat, for each key that is an element of targetNonconfigurableKeys,
- If key is not an element of uncheckedResultKeys, throw a
TypeError exception. - Remove key from uncheckedResultKeys.
- If key is not an element of uncheckedResultKeys, throw a
- If extensibleTarget is
true , return trapResult. - Repeat, for each key that is an element of targetConfigurableKeys,
- If key is not an element of uncheckedResultKeys, throw a
TypeError exception. - Remove key from uncheckedResultKeys.
- If key is not an element of uncheckedResultKeys, throw a
- If uncheckedResultKeys is not empty, throw a
TypeError exception. - Return trapResult.
[[OwnPropertyKeys]] for proxy objects enforces the following invariants:
-
The result of [[OwnPropertyKeys]] is a
List . -
The
Type of each resultList 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
- Let handler be the value of the [[ProxyHandler]] internal slot of O.
- If handler is
null , throw aTypeError exception. - Assert:
Type (handler) is Object. - Let target be the value of the [[ProxyTarget]] internal slot of O.
- Let trap be ?
GetMethod (handler,"apply"). - If trap is
undefined , then- Return ?
Call (target, thisArgument, argumentsList).
- Return ?
- Let argArray be
CreateArrayFromList (argumentsList). - Return ?
Call (trap, handler, « target, thisArgument, argArray »).
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
- Let handler be the value of the [[ProxyHandler]] internal slot of O.
- If handler is
null , throw aTypeError exception. - Assert:
Type (handler) is Object. - Let target be the value of the [[ProxyTarget]] internal slot of O.
- Let trap be ?
GetMethod (handler,"construct"). - If trap is
undefined , then- Assert: target has a [[Construct]] internal method.
- Return ?
Construct (target, argumentsList, newTarget).
- Let argArray be
CreateArrayFromList (argumentsList). - Let newObj be ?
Call (trap, handler, « target, argArray, newTarget »). - If
Type (newObj) is not Object, throw aTypeError exception. - Return newObj.
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.
[[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:
- If
Type (target) is not Object, throw aTypeError exception. - If target is a Proxy exotic object and the value of the [[ProxyHandler]] internal slot of target is
null , throw aTypeError exception. - If
Type (handler) is not Object, throw aTypeError exception. - If handler is a Proxy exotic object and the value of the [[ProxyHandler]] internal slot of handler is
null , throw aTypeError exception. - Let P be a newly created object.
- Set P's essential internal methods (except for [[Call]] and [[Construct]]) to the definitions specified in
9.5 . - If
IsCallable (target) istrue , then - Set the [[ProxyTarget]] internal slot of P to target.
- Set the [[ProxyHandler]] internal slot of P to handler.
- Return P.