10 Ordinary and Exotic Objects Behaviours
10.1 Ordinary Object Internal Methods and Internal Slots
All
Every
In the following algorithm descriptions, assume O is an
Each
10.1.1 [[GetPrototypeOf]] ( )
The [[GetPrototypeOf]] internal method of an
- Return
OrdinaryGetPrototypeOf (O).
10.1.1.1 OrdinaryGetPrototypeOf ( O )
The abstract operation OrdinaryGetPrototypeOf takes argument O (an Object) and returns an Object or
- Return O.[[Prototype]].
10.1.2 [[SetPrototypeOf]] ( V )
The [[SetPrototypeOf]] internal method of an
- Return
OrdinarySetPrototypeOf (O, V).
10.1.2.1 OrdinarySetPrototypeOf ( O, V )
The abstract operation OrdinarySetPrototypeOf takes arguments O (an Object) and V (an Object or
- Let current be O.[[Prototype]].
- If
SameValue (V, current) istrue , returntrue . - Let extensible be O.[[Extensible]].
- If extensible is
false , returnfalse . - Let p be V.
- Let done be
false . - Repeat, while done is
false ,- If p is
null , set done totrue . - Else if
SameValue (p, O) istrue , returnfalse . - Else,
- If p.[[GetPrototypeOf]] is not the
ordinary object internal method defined in10.1.1 , set done totrue . - Else, set p to p.[[Prototype]].
- If p.[[GetPrototypeOf]] is not the
- If p is
- Set O.[[Prototype]] to V.
- Return
true .
The loop in step
10.1.3 [[IsExtensible]] ( )
The [[IsExtensible]] internal method of an
- Return
OrdinaryIsExtensible (O).
10.1.3.1 OrdinaryIsExtensible ( O )
The abstract operation OrdinaryIsExtensible takes argument O (an Object) and returns a Boolean. It performs the following steps when called:
- Return O.[[Extensible]].
10.1.4 [[PreventExtensions]] ( )
The [[PreventExtensions]] internal method of an
- Return
OrdinaryPreventExtensions (O).
10.1.4.1 OrdinaryPreventExtensions ( O )
The abstract operation OrdinaryPreventExtensions takes argument O (an Object) and returns
- Set O.[[Extensible]] to
false . - Return
true .
10.1.5 [[GetOwnProperty]] ( P )
The [[GetOwnProperty]] internal method of an
- Return
OrdinaryGetOwnProperty (O, P).
10.1.5.1 OrdinaryGetOwnProperty ( O, P )
The abstract operation OrdinaryGetOwnProperty takes arguments O (an Object) and P (a
- 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,
Assert : X is anaccessor property .- 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.
10.1.6 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of an
- Return ?
OrdinaryDefineOwnProperty (O, P, Desc).
10.1.6.1 OrdinaryDefineOwnProperty ( O, P, Desc )
The abstract operation OrdinaryDefineOwnProperty takes arguments O (an Object), P (a
- Let current be ?
O.[[GetOwnProperty]] (P). - Let extensible be ?
IsExtensible (O). - Return
ValidateAndApplyPropertyDescriptor (O, P, extensible, Desc, current).
10.1.6.2 IsCompatiblePropertyDescriptor ( Extensible, Desc, Current )
The abstract operation IsCompatiblePropertyDescriptor takes arguments Extensible (a Boolean), Desc (a
- Return
ValidateAndApplyPropertyDescriptor (undefined ,"" , Extensible, Desc, Current).
10.1.6.3 ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current )
The abstract operation ValidateAndApplyPropertyDescriptor takes arguments O (an Object or
Assert :IsPropertyKey (P) istrue .- If current is
undefined , then- If extensible is
false , returnfalse . - If O is
undefined , returntrue . - If
IsAccessorDescriptor (Desc) istrue , then- Create an own
accessor property named P of object O whose [[Get]], [[Set]], [[Enumerable]], and [[Configurable]] attributes are set to the value of the corresponding field in Desc if Desc has that field, or to the attribute'sdefault value otherwise.
- Create an own
- Else,
- Create an own
data property named P of object O whose [[Value]], [[Writable]], [[Enumerable]], and [[Configurable]] attributes are set to the value of the corresponding field in Desc if Desc has that field, or to the attribute'sdefault value otherwise.
- Create an own
- Return
true .
- If extensible is
Assert : current is afully populated Property Descriptor .- If Desc does not have any fields, return
true . - If current.[[Configurable]] is
false , then- If Desc has a [[Configurable]] field and Desc.[[Configurable]] is
true , returnfalse . - If Desc has an [[Enumerable]] field and
SameValue (Desc.[[Enumerable]], current.[[Enumerable]]) isfalse , returnfalse . - If
IsGenericDescriptor (Desc) isfalse andSameValue (IsAccessorDescriptor (Desc),IsAccessorDescriptor (current)) isfalse , returnfalse . - If
IsAccessorDescriptor (Desc) istrue , then - Else if current.[[Writable]] is
false , then- If Desc has a [[Writable]] field and Desc.[[Writable]] is
true , returnfalse . - If Desc has a [[Value]] field and
SameValue (Desc.[[Value]], current.[[Value]]) isfalse , returnfalse .
- If Desc has a [[Writable]] field and Desc.[[Writable]] is
- If Desc has a [[Configurable]] field and Desc.[[Configurable]] is
- If O is not
undefined , then- If
IsDataDescriptor (current) istrue andIsAccessorDescriptor (Desc) istrue , then- If Desc has a [[Configurable]] field, let configurable be Desc.[[Configurable]]; else let configurable be current.[[Configurable]].
- If Desc has a [[Enumerable]] field, let enumerable be Desc.[[Enumerable]]; else let enumerable be current.[[Enumerable]].
- Replace the property named P of object O with an
accessor property whose [[Configurable]] and [[Enumerable]] attributes are set to configurable and enumerable, respectively, and whose [[Get]] and [[Set]] attributes are set to the value of the corresponding field in Desc if Desc has that field, or to the attribute'sdefault value otherwise.
- Else if
IsAccessorDescriptor (current) istrue andIsDataDescriptor (Desc) istrue , then- If Desc has a [[Configurable]] field, let configurable be Desc.[[Configurable]]; else let configurable be current.[[Configurable]].
- If Desc has a [[Enumerable]] field, let enumerable be Desc.[[Enumerable]]; else let enumerable be current.[[Enumerable]].
- Replace the property named P of object O with a
data property whose [[Configurable]] and [[Enumerable]] attributes are set to configurable and enumerable, respectively, and whose [[Value]] and [[Writable]] attributes are set to the value of the corresponding field in Desc if Desc has that field, or to the attribute'sdefault value otherwise.
- Else,
- For each field of Desc, set the corresponding attribute of the property named P of object O to the value of the field.
- If
- Return
true .
10.1.7 [[HasProperty]] ( P )
The [[HasProperty]] internal method of an
- Return ?
OrdinaryHasProperty (O, P).
10.1.7.1 OrdinaryHasProperty ( O, P )
The abstract operation OrdinaryHasProperty takes arguments O (an Object) and P (a
- 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 ?
- Return
false .
10.1.8 [[Get]] ( P, Receiver )
The [[Get]] internal method of an
- Return ?
OrdinaryGet (O, P, Receiver).
10.1.8.1 OrdinaryGet ( O, P, Receiver )
The abstract operation OrdinaryGet takes arguments O (an Object), P (a
- 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).
- Let parent be ?
- 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).
10.1.9 [[Set]] ( P, V, Receiver )
The [[Set]] internal method of an
- Return ?
OrdinarySet (O, P, V, Receiver).
10.1.9.1 OrdinarySet ( O, P, V, Receiver )
The abstract operation OrdinarySet takes arguments O (an Object), P (a
- Let ownDesc be ?
O.[[GetOwnProperty]] (P). - Return ?
OrdinarySetWithOwnDescriptor (O, P, V, Receiver, ownDesc).
10.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc )
The abstract operation OrdinarySetWithOwnDescriptor takes arguments O (an Object), P (a
- If ownDesc is
undefined , then- Let parent be ?
O.[[GetPrototypeOf]] (). - If parent is not
null , then- Return ?
parent.[[Set]] (P, V, Receiver).
- Return ?
- Else,
- Set ownDesc to the PropertyDescriptor { [[Value]]:
undefined , [[Writable]]:true , [[Enumerable]]:true , [[Configurable]]:true }.
- Set ownDesc to the PropertyDescriptor { [[Value]]:
- Let parent be ?
- 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,
Assert : Receiver does not currently have a property P.- Return ?
CreateDataProperty (Receiver, P, V).
- 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 .
10.1.10 [[Delete]] ( P )
The [[Delete]] internal method of an
- Return ?
OrdinaryDelete (O, P).
10.1.10.1 OrdinaryDelete ( O, P )
The abstract operation OrdinaryDelete takes arguments O (an Object) and P (a
- 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 .
10.1.11 [[OwnPropertyKeys]] ( )
The [[OwnPropertyKeys]] internal method of an
- Return
OrdinaryOwnPropertyKeys (O).
10.1.11.1 OrdinaryOwnPropertyKeys ( O )
The abstract operation OrdinaryOwnPropertyKeys takes argument O (an Object) and returns a
- Let keys be a new empty
List . - For each own
property key P of O such that P is anarray index , in ascending numeric index order, do- Add P as the last element of keys.
- For each own
property key P of O such thatType (P) is String and P is not anarray index , in ascending chronological order of property creation, do- Add P as the last element of keys.
- For each own
property key P of O such thatType (P) is Symbol, in ascending chronological order of property creation, do- Add P as the last element of keys.
- Return keys.
10.1.12 OrdinaryObjectCreate ( proto [ , additionalInternalSlotsList ] )
The abstract operation OrdinaryObjectCreate takes argument proto (an Object or
- Let internalSlotsList be « [[Prototype]], [[Extensible]] ».
- If additionalInternalSlotsList is present, append each of its elements to internalSlotsList.
- Let O be
MakeBasicObject (internalSlotsList). - Set O.[[Prototype]] to proto.
- Return O.
Although OrdinaryObjectCreate does little more than call
10.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
The abstract operation OrdinaryCreateFromConstructor takes arguments constructor and intrinsicDefaultProto (a String) and optional argument internalSlotsList (a
Assert : intrinsicDefaultProto 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
OrdinaryObjectCreate (proto, internalSlotsList).
10.1.14 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
The abstract operation GetPrototypeFromConstructor takes arguments constructor (a
Assert : intrinsicDefaultProto 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 ?
Get (constructor,"prototype" ). - If
Type (proto) is not Object, then- Let realm be ?
GetFunctionRealm (constructor). - Set proto to 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
10.1.15 RequireInternalSlot ( O, internalSlot )
The abstract operation RequireInternalSlot takes arguments O and internalSlot and returns either a
- If
Type (O) is not Object, throw aTypeError exception. - If O does not have an internalSlot internal slot, throw a
TypeError exception. - Return
unused .
10.2 ECMAScript Function Objects
ECMAScript
In addition to [[Extensible]] and [[Prototype]], ECMAScript
| Internal Slot | Type | Description |
|---|---|---|
| [[Environment]] |
an |
The |
| [[PrivateEnvironment]] |
a |
The |
| [[FormalParameters]] |
a |
The root parse node of the source text that defines the function's formal parameter list. |
| [[ECMAScriptCode]] |
a |
The root parse node of the source text that defines the function's body. |
| [[ConstructorKind]] |
|
Whether or not the function is a derived class |
| [[Realm]] |
a |
The |
| [[ScriptOrModule]] |
a |
The script or module in which the function was created. |
| [[ThisMode]] |
|
Defines how this references are interpreted within the formal parameters and code body of the function. this refers to the |
| [[Strict]] | a Boolean |
|
| [[HomeObject]] | an Object |
If the function uses super, this is the object whose [[GetPrototypeOf]] provides the object where super property lookups begin.
|
| [[SourceText]] | a sequence of Unicode code points |
The |
| [[Fields]] |
a |
If the function is a class, this is a list of |
| [[PrivateMethods]] |
a |
If the function is a class, this is a list representing the non-static private methods and accessors of the class. |
| [[ClassFieldInitializerName]] |
a String, a Symbol, a |
If the function is created as the initializer of a class field, the name to use for |
| [[IsClassConstructor]] | a Boolean |
Indicates whether the function is a class |
All ECMAScript
10.2.1 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method of an ECMAScript
- Let callerContext be the
running execution context . - Let calleeContext be
PrepareForOrdinaryCall (F,undefined ). Assert : calleeContext is now therunning execution context .- If F.[[IsClassConstructor]] is
true , then- Let error be a newly created
TypeError object. - NOTE: error is created in calleeContext with F's associated
Realm Record . - Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - Return
ThrowCompletion (error).
- Let error be a newly created
- Perform
OrdinaryCallBindThis (F, calleeContext, thisArgument). - Let result be
Completion (OrdinaryCallEvaluateBody (F, argumentsList)). - Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - If result.[[Type]] is
return , return result.[[Value]]. ReturnIfAbrupt (result).- Return
undefined .
When calleeContext is removed from the
10.2.1.1 PrepareForOrdinaryCall ( F, newTarget )
The abstract operation PrepareForOrdinaryCall takes arguments F (a
- 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 F.[[Realm]].
- Set the
Realm of calleeContext to calleeRealm. - Set the ScriptOrModule of calleeContext to F.[[ScriptOrModule]].
- Let localEnv be
NewFunctionEnvironment (F, newTarget). - Set the LexicalEnvironment of calleeContext to localEnv.
- Set the VariableEnvironment of calleeContext to localEnv.
- Set the PrivateEnvironment of calleeContext to F.[[PrivateEnvironment]].
- 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.
10.2.1.2 OrdinaryCallBindThis ( F, calleeContext, thisArgument )
The abstract operation OrdinaryCallBindThis takes arguments F (a
- Let thisMode be F.[[ThisMode]].
- If thisMode is
lexical , returnunused . - Let calleeRealm be F.[[Realm]].
- Let localEnv be the LexicalEnvironment of calleeContext.
- If thisMode is
strict , let thisValue be thisArgument. - Else,
- If thisArgument is
undefined ornull , then- Let globalEnv be calleeRealm.[[GlobalEnv]].
Assert : globalEnv is aglobal Environment Record .- Let thisValue be globalEnv.[[GlobalThisValue]].
- Else,
- If thisArgument is
Assert : localEnv is afunction Environment Record .Assert : The next step never returns anabrupt completion because localEnv.[[ThisBindingStatus]] is notinitialized .- Perform ! localEnv.BindThisValue(thisValue).
- Return
unused .
10.2.1.3 Runtime Semantics: EvaluateBody
The
- Return ?
EvaluateFunctionBody ofFunctionBody with arguments functionObject and argumentsList.
- Return ?
EvaluateConciseBody ofConciseBody with arguments functionObject and argumentsList.
- Return ?
EvaluateGeneratorBody ofGeneratorBody with arguments functionObject and argumentsList.
- Return ?
EvaluateAsyncGeneratorBody ofAsyncGeneratorBody with arguments functionObject and argumentsList.
- Return ?
EvaluateAsyncFunctionBody ofAsyncFunctionBody with arguments functionObject and argumentsList.
- Return ?
EvaluateAsyncConciseBody ofAsyncConciseBody with arguments functionObject and argumentsList.
Assert : argumentsList is empty.Assert : functionObject.[[ClassFieldInitializerName]] is notempty .- If
IsAnonymousFunctionDefinition (AssignmentExpression ) istrue , then- Let value be ?
NamedEvaluation ofInitializer with argument functionObject.[[ClassFieldInitializerName]].
- Let value be ?
- Else,
- Let rhs be the result of evaluating
AssignmentExpression . - Let value be ?
GetValue (rhs).
- Let rhs be the result of evaluating
- Return
Completion Record { [[Type]]:return , [[Value]]: value, [[Target]]:empty }.
Even though field initializers constitute a function boundary, calling
Assert : argumentsList is empty.- Return ?
EvaluateClassStaticBlockBody ofClassStaticBlockBody with argument functionObject.
10.2.1.4 OrdinaryCallEvaluateBody ( F, argumentsList )
The abstract operation OrdinaryCallEvaluateBody takes arguments F (a
- Return ?
EvaluateBody of F.[[ECMAScriptCode]] with arguments F and argumentsList.
10.2.2 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method of an ECMAScript
- Let callerContext be the
running execution context . - Let kind be F.[[ConstructorKind]].
- If kind is
base , then- Let thisArgument be ?
OrdinaryCreateFromConstructor (newTarget," ).%Object.prototype% "
- Let thisArgument be ?
- Let calleeContext be
PrepareForOrdinaryCall (F, newTarget). Assert : calleeContext is now therunning execution context .- If kind is
base , then- Perform
OrdinaryCallBindThis (F, calleeContext, thisArgument). - Let initializeResult be
Completion (InitializeInstanceElements (thisArgument, F)). - If initializeResult is an
abrupt completion , then- Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - Return ? initializeResult.
- Remove calleeContext from the
- Perform
- Let constructorEnv be the LexicalEnvironment of calleeContext.
- Let result be
Completion (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, return result.[[Value]]. - If kind is
base , return thisArgument. - If result.[[Value]] is not
undefined , throw aTypeError exception.
- If
- Else,
ReturnIfAbrupt (result). - Let thisBinding be ? constructorEnv.GetThisBinding().
Assert :Type (thisBinding) is Object.- Return thisBinding.
10.2.3 OrdinaryFunctionCreate ( functionPrototype, sourceText, ParameterList, Body, thisMode, env, privateEnv )
The abstract operation OrdinaryFunctionCreate takes arguments functionPrototype (an Object), sourceText (a sequence of Unicode code points), ParameterList (a
- Let internalSlotsList be the internal slots listed in
Table 33 . - Let F be
OrdinaryObjectCreate (functionPrototype, internalSlotsList). - Set F.[[Call]] to the definition specified in
10.2.1 . - Set F.[[SourceText]] to sourceText.
- Set F.[[FormalParameters]] to ParameterList.
- Set F.[[ECMAScriptCode]] to Body.
- If the
source text matched by Body isstrict mode code , let Strict betrue ; else let Strict befalse . - Set F.[[Strict]] to Strict.
- If thisMode is
lexical-this , set F.[[ThisMode]] tolexical . - Else if Strict is
true , set F.[[ThisMode]] tostrict . - Else, set F.[[ThisMode]] to
global . - Set F.[[IsClassConstructor]] to
false . - Set F.[[Environment]] to env.
- Set F.[[PrivateEnvironment]] to privateEnv.
- Set F.[[ScriptOrModule]] to
GetActiveScriptOrModule (). - Set F.[[Realm]] to
the current Realm Record . - Set F.[[HomeObject]] to
undefined . - Set F.[[Fields]] to a new empty
List . - Set F.[[PrivateMethods]] to a new empty
List . - Set F.[[ClassFieldInitializerName]] to
empty . - Let len be the
ExpectedArgumentCount of ParameterList. - Perform
SetFunctionLength (F, len). - Return F.
10.2.4 AddRestrictedFunctionProperties ( F, realm )
The abstract operation AddRestrictedFunctionProperties takes arguments F (a
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 }). - Perform !
DefinePropertyOrThrow (F,"arguments" , PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]:false , [[Configurable]]:true }). - Return
unused .
10.2.4.1 %ThrowTypeError% ( )
The
- Throw a
TypeError exception.
The value of the [[Extensible]] internal slot of a
The
The
10.2.5 MakeConstructor ( F [ , writablePrototype [ , prototype ] ] )
The abstract operation MakeConstructor takes argument F (an ECMAScript
- If F is an ECMAScript
function object , thenAssert :IsConstructor (F) isfalse .Assert : F is an extensible object that does not have a"prototype" own property.- Set F.[[Construct]] to the definition specified in
10.2.2 .
- Else,
- Set F.[[Construct]] to the definition specified in
10.3.2 .
- Set F.[[Construct]] to the definition specified in
- Set F.[[ConstructorKind]] to
base . - If writablePrototype is not present, set writablePrototype to
true . - If prototype is not present, then
- Set prototype to
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
DefinePropertyOrThrow (prototype,"constructor" , PropertyDescriptor { [[Value]]: F, [[Writable]]: writablePrototype, [[Enumerable]]:false , [[Configurable]]:true }).
- Set prototype to
- Perform !
DefinePropertyOrThrow (F,"prototype" , PropertyDescriptor { [[Value]]: prototype, [[Writable]]: writablePrototype, [[Enumerable]]:false , [[Configurable]]:false }). - Return
unused .
10.2.6 MakeClassConstructor ( F )
The abstract operation MakeClassConstructor takes argument F (an ECMAScript
Assert : F.[[IsClassConstructor]] isfalse .- Set F.[[IsClassConstructor]] to
true . - Return
unused .
10.2.7 MakeMethod ( F, homeObject )
The abstract operation MakeMethod takes arguments F (an ECMAScript
- Set F.[[HomeObject]] to homeObject.
- Return
unused .
10.2.8 DefineMethodProperty ( homeObject, key, closure, enumerable )
The abstract operation DefineMethodProperty takes arguments homeObject (an Object), key (a
Assert : homeObject is an ordinary, extensible object with no non-configurable properties.- If key is a
Private Name , then- Return
PrivateElement { [[Key]]: key, [[Kind]]:method , [[Value]]: closure }.
- Return
- Else,
- Let desc be the PropertyDescriptor { [[Value]]: closure, [[Writable]]:
true , [[Enumerable]]: enumerable, [[Configurable]]:true }. - Perform !
DefinePropertyOrThrow (homeObject, key, desc). - Return
unused .
- Let desc be the PropertyDescriptor { [[Value]]: closure, [[Writable]]:
10.2.9 SetFunctionName ( F, name [ , prefix ] )
The abstract operation SetFunctionName takes arguments F (a
Assert : F is an extensible object that does not have a"name" own property.- If
Type (name) is Symbol, then- Let description be name's [[Description]] value.
- If description is
undefined , set name to the empty String. - Else, set name to the
string-concatenation of"[" , description, and"]" .
- Else if name is a
Private Name , then- Set name to name.[[Description]].
- If F has an [[InitialName]] internal slot, then
- Set F.[[InitialName]] to name.
- If prefix is present, then
- Set name to the
string-concatenation of prefix, the code unit 0x0020 (SPACE), and name. - If F has an [[InitialName]] internal slot, then
- Optionally, set F.[[InitialName]] to name.
- Set name to the
- Perform !
DefinePropertyOrThrow (F,"name" , PropertyDescriptor { [[Value]]: name, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:true }). - Return
unused .
10.2.10 SetFunctionLength ( F, length )
The abstract operation SetFunctionLength takes arguments F (a
Assert : F is an extensible object that does not have a"length" own property.- Perform !
DefinePropertyOrThrow (F,"length" , PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:true }). - Return
unused .
10.2.11 FunctionDeclarationInstantiation ( func, argumentsList )
The abstract operation FunctionDeclarationInstantiation takes arguments func (a
When an
It performs the following steps when called:
- Let calleeContext be the
running execution context . - Let code be func.[[ECMAScriptCode]].
- Let strict be func.[[Strict]].
- Let formals be func.[[FormalParameters]].
- 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 element d of varDeclarations, in reverse
List order, do- If d is neither a
VariableDeclaration nor aForBinding nor aBindingIdentifier , thenAssert : d is either aFunctionDeclaration , aGeneratorDeclaration , anAsyncFunctionDeclaration , or anAsyncGeneratorDeclaration .- 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 function declarations for the same name, the last declaration is used.
- Insert d as the first element of functionsToInitialize.
- If d is neither a
- Let argumentsObjectNeeded be
true . - If func.[[ThisMode]] is
lexical , then- NOTE: Arrow functions never have an arguments object.
- Set argumentsObjectNeeded to
false .
- Else if
"arguments" is an element of parameterNames, then- Set argumentsObjectNeeded to
false .
- Set argumentsObjectNeeded to
- Else if hasParameterExpressions is
false , then- If
"arguments" is an element of functionNames or if"arguments" is an element of lexicalNames, then- Set argumentsObjectNeeded to
false .
- Set argumentsObjectNeeded to
- If
- If strict is
true or if hasParameterExpressions isfalse , then- NOTE: Only a single
Environment Record is needed for the parameters, since calls toevalinstrict mode code cannot create new bindings which are visible outside of theeval. - Let env be the LexicalEnvironment of calleeContext.
- NOTE: Only a single
- Else,
- NOTE: A separate
Environment Record is needed to ensure that bindings created bydirect eval calls in the formal parameter list are outside the environment where parameters are declared. - Let calleeEnv be the LexicalEnvironment of calleeContext.
- Let env be
NewDeclarativeEnvironment (calleeEnv). Assert : The VariableEnvironment of calleeContext is calleeEnv.- Set the LexicalEnvironment of calleeContext to env.
- NOTE: A separate
- For each String paramName of parameterNames, do
- Let alreadyDeclared be ! env.HasBinding(paramName).
- NOTE:
Early errors ensure that duplicate parameter names can only occur innon-strict functions that do not have parameter default values or rest parameters. - If alreadyDeclared is
false , then- Perform ! env.CreateMutableBinding(paramName,
false ). - If hasDuplicates is
true , then- Perform ! env.InitializeBinding(paramName,
undefined ).
- Perform ! env.InitializeBinding(paramName,
- Perform ! env.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: A 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, env).
- NOTE: A mapped argument object is only provided for
- If strict is
true , then- Perform ! env.CreateImmutableBinding(
"arguments" ,false ).
- Perform ! env.CreateImmutableBinding(
- Else,
- Perform ! env.CreateMutableBinding(
"arguments" ,false ).
- Perform ! env.CreateMutableBinding(
- Perform ! env.InitializeBinding(
"arguments" , ao). - Let parameterBindings be the
list-concatenation of parameterNames and «"arguments" ».
- If strict is
- Else,
- Let parameterBindings be parameterNames.
- Let iteratorRecord be
CreateListIteratorRecord (argumentsList). - If hasDuplicates is
true , then- Perform ?
IteratorBindingInitialization of formals with arguments iteratorRecord andundefined .
- Perform ?
- Else,
- Perform ?
IteratorBindingInitialization of formals with arguments iteratorRecord and env.
- Perform ?
- If hasParameterExpressions is
false , then- NOTE: Only a single
Environment Record is needed for the parameters and top-level vars. - Let instantiatedVarNames be a copy of the
List parameterBindings. - For each element n of varNames, do
- If n is not an element of instantiatedVarNames, then
- Append n to instantiatedVarNames.
- Perform ! env.CreateMutableBinding(n,
false ). - Perform ! env.InitializeBinding(n,
undefined ).
- If n is not an element of instantiatedVarNames, then
- Let varEnv be env.
- NOTE: Only a single
- 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). - Set the VariableEnvironment of calleeContext to varEnv.
- Let instantiatedVarNames be a new empty
List . - For each element n of varNames, do
- If n is not an element of instantiatedVarNames, then
- Append n to instantiatedVarNames.
- Perform ! varEnv.CreateMutableBinding(n,
false ). - If n is not an element of parameterBindings or if n is an element of functionNames, let initialValue be
undefined . - Else,
- Let initialValue be ! env.GetBindingValue(n,
false ).
- Let initialValue be ! env.GetBindingValue(n,
- Perform ! varEnv.InitializeBinding(n, initialValue).
- NOTE: A var with the same name as a formal parameter initially has the same value as the corresponding initialized parameter.
- If n is not an element of instantiatedVarNames, then
- NOTE: A separate
- NOTE: Annex
B.3.2.1 adds additional steps at this point. - If strict is
false , then- Let lexEnv be
NewDeclarativeEnvironment (varEnv). - NOTE:
Non-strict functions use a separateEnvironment 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 forstrict functions because a strictdirect eval always places all declarations into a newEnvironment Record .
- Let lexEnv be
- Else, let lexEnv be varEnv.
- Set the LexicalEnvironment of calleeContext to lexEnv.
- Let lexDeclarations be the
LexicallyScopedDeclarations of code. - For each element d of 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 istrue , then- Perform ! lexEnv.CreateImmutableBinding(dn,
true ).
- Perform ! lexEnv.CreateImmutableBinding(dn,
- Else,
- Perform ! lexEnv.CreateMutableBinding(dn,
false ).
- Perform ! lexEnv.CreateMutableBinding(dn,
- If
- Let privateEnv be the PrivateEnvironment of calleeContext.
- For each
Parse Node f of functionsToInitialize, do- Let fn be the sole element of the
BoundNames of f. - Let fo be
InstantiateFunctionObject of f with arguments lexEnv and privateEnv. - Perform ! varEnv.SetMutableBinding(fn, fo,
false ).
- Let fn be the sole element of the
- Return
unused .
10.3 Built-in Function Objects
The built-in
If a built-in
If a built-in
Unless otherwise specified every built-in
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
Built-in new expression the argumentsList parameter of the invoked [[Construct]] internal method provides the values for the built-in
Built-in functions that are not
If a built-in
10.3.1 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method of a built-in
- Let callerContext be the
running execution context . - If callerContext is not already suspended, suspend callerContext.
- Let calleeContext be a new
execution context . - Set the Function of calleeContext to F.
- Let calleeRealm be F.[[Realm]].
- Set the
Realm of calleeContext to calleeRealm. - Set the ScriptOrModule of calleeContext to
null . - 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 a 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
10.3.2 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method of a built-in
- Let result be the
Completion Record that is the result of evaluating F in a manner that conforms to the specification of F. Thethis value is uninitialized, argumentsList provides the named parameters, and newTarget provides the NewTarget value.
10.3.3 CreateBuiltinFunction ( behaviour, length, name, additionalInternalSlotsList [ , realm [ , prototype [ , prefix ] ] ] )
The abstract operation CreateBuiltinFunction takes arguments behaviour (an
- If realm is not present, set realm to
the current Realm Record . - If prototype is not present, set prototype to realm.[[Intrinsics]].[[
%Function.prototype% ]]. - Let internalSlotsList be a
List containing the names of all the internal slots that10.3 requires for the built-infunction object that is about to be created. - Append to internalSlotsList the elements of additionalInternalSlotsList.
- Let func be a new built-in
function object that, when called, performs the action described by behaviour using the provided arguments as the values of the corresponding parameters specified by behaviour. The newfunction object has internal slots whose names are the elements of internalSlotsList, and an [[InitialName]] internal slot. - Set func.[[Prototype]] to prototype.
- Set func.[[Extensible]] to
true . - Set func.[[Realm]] to realm.
- Set func.[[InitialName]] to
null . - Perform
SetFunctionLength (func, length). - If prefix is not present, then
- Perform
SetFunctionName (func, name).
- Perform
- Else,
- Perform
SetFunctionName (func, name, prefix).
- Perform
- Return func.
Each built-in function defined in this specification is created by calling the CreateBuiltinFunction abstract operation.
10.4 Built-in Exotic Object Internal Methods and Slots
This specification defines several kinds of built-in
10.4.1 Bound Function Exotic Objects
A
An object is a bound function exotic object if its [[Call]] and (if applicable) [[Construct]] internal methods use the following implementations, and its other essential internal methods use the definitions found in
| Internal Slot | Type | Description |
|---|---|---|
| [[BoundTargetFunction]] | a callable Object |
The wrapped |
| [[BoundThis]] |
an |
The value that is always passed as the |
| [[BoundArguments]] |
a |
A list of values whose elements are used as the first arguments to any call to the wrapped function. |
10.4.1.1 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method of a
- Let target be F.[[BoundTargetFunction]].
- Let boundThis be F.[[BoundThis]].
- Let boundArgs be F.[[BoundArguments]].
- Let args be the
list-concatenation of boundArgs and argumentsList. - Return ?
Call (target, boundThis, args).
10.4.1.2 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method of a
- Let target be F.[[BoundTargetFunction]].
Assert :IsConstructor (target) istrue .- Let boundArgs be F.[[BoundArguments]].
- Let args be the
list-concatenation of boundArgs and argumentsList. - If
SameValue (F, newTarget) istrue , set newTarget to target. - Return ?
Construct (target, args, newTarget).
10.4.1.3 BoundFunctionCreate ( targetFunction, boundThis, boundArgs )
The abstract operation BoundFunctionCreate takes arguments targetFunction (a
- Let proto be ?
targetFunction.[[GetPrototypeOf]] (). - Let internalSlotsList be the
list-concatenation of « [[Prototype]], [[Extensible]] » and the internal slots listed inTable 34 . - Let obj be
MakeBasicObject (internalSlotsList). - Set obj.[[Prototype]] to proto.
- Set obj.[[Call]] as described in
10.4.1.1 . - If
IsConstructor (targetFunction) istrue , then- Set obj.[[Construct]] as described in
10.4.1.2 .
- Set obj.[[Construct]] as described in
- Set obj.[[BoundTargetFunction]] to targetFunction.
- Set obj.[[BoundThis]] to boundThis.
- Set obj.[[BoundArguments]] to boundArgs.
- Return obj.
10.4.2 Array Exotic Objects
An Array is an
A String
An object is an Array exotic object (or simply, an Array) if its [[DefineOwnProperty]] internal method uses the following implementation, and its other essential internal methods use the definitions found in
10.4.2.1 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of an
- 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 :IsDataDescriptor (oldLenDesc) istrue .Assert : oldLenDesc.[[Configurable]] isfalse .- Let oldLen be oldLenDesc.[[Value]].
Assert : oldLen is a non-negativeintegral Number .- 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 𝔽. - Set succeeded to !
OrdinaryDefineOwnProperty (A,"length" , oldLenDesc). Assert : succeeded istrue .
- Set oldLenDesc.[[Value]] to index +
- Return
true .
- Let oldLenDesc be
- Return ?
OrdinaryDefineOwnProperty (A, P, Desc).
10.4.2.2 ArrayCreate ( length [ , proto ] )
The abstract operation ArrayCreate takes argument length (a non-negative
- If length > 232 - 1, throw a
RangeError exception. - If proto is not present, set proto to
%Array.prototype% . - Let A be
MakeBasicObject (« [[Prototype]], [[Extensible]] »). - Set A.[[Prototype]] to proto.
- Set A.[[DefineOwnProperty]] as specified in
10.4.2.1 . - Perform !
OrdinaryDefineOwnProperty (A,"length" , PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Return A.
10.4.2.3 ArraySpeciesCreate ( originalArray, length )
The abstract operation ArraySpeciesCreate takes arguments originalArray and length (a non-negative
- Let isArray be ?
IsArray (originalArray). - If isArray is
false , return ?ArrayCreate (length). - 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 , set C toundefined .
- If
- Let thisRealm be
- If
Type (C) is Object, then- Set C to ?
Get (C, @@species). - If C is
null , set C toundefined .
- Set C to ?
- 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 Array.prototype methods that now are defined using ArraySpeciesCreate.
10.4.2.4 ArraySetLength ( A, Desc )
The abstract operation ArraySetLength takes arguments A (an Array) and Desc (a
- If Desc does not have a [[Value]] field, 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
SameValueZero (newLen, numberLen) isfalse , throw aRangeError exception. - Set newLenDesc.[[Value]] to newLen.
- Let oldLenDesc be
OrdinaryGetOwnProperty (A,"length" ). Assert :IsDataDescriptor (oldLenDesc) istrue .Assert : oldLenDesc.[[Configurable]] isfalse .- Let oldLen be oldLenDesc.[[Value]].
- If newLen ≥ oldLen, then
- Return !
OrdinaryDefineOwnProperty (A,"length" , newLenDesc).
- Return !
- If oldLenDesc.[[Writable]] is
false , returnfalse . - If newLenDesc does not have a [[Writable]] field or newLenDesc.[[Writable]] is
true , let newWritable betrue . - Else,
- NOTE: Setting the [[Writable]] attribute to
false is deferred in case any elements cannot be deleted. - Let newWritable be
false . - Set newLenDesc.[[Writable]] to
true .
- NOTE: Setting the [[Writable]] attribute to
- Let succeeded be !
OrdinaryDefineOwnProperty (A,"length" , newLenDesc). - If succeeded is
false , returnfalse . - For each own
property key P of A that is anarray index , whose numeric value is greater than or equal to newLen, in descending numeric index order, do- Let deleteSucceeded be ! A.[[Delete]](P).
- If deleteSucceeded is
false , then- Set newLenDesc.[[Value]] to !
ToUint32 (P) +1 𝔽. - If newWritable is
false , set newLenDesc.[[Writable]] tofalse . - Perform !
OrdinaryDefineOwnProperty (A,"length" , newLenDesc). - Return
false .
- Set newLenDesc.[[Value]] to !
- If newWritable is
false , then- Set succeeded to !
OrdinaryDefineOwnProperty (A,"length" , PropertyDescriptor { [[Writable]]:false }). Assert : succeeded istrue .
- Set succeeded to !
- Return
true .
10.4.3 String Exotic Objects
A String object is an
An object is a String exotic object (or simply, a String object) if its [[GetOwnProperty]], [[DefineOwnProperty]], and [[OwnPropertyKeys]] internal methods use the following implementations, and its other essential internal methods use the definitions found in
10.4.3.1 [[GetOwnProperty]] ( P )
The [[GetOwnProperty]] internal method of a
- Let desc be
OrdinaryGetOwnProperty (S, P). - If desc is not
undefined , return desc. - Return
StringGetOwnProperty (S, P).
10.4.3.2 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of a
- Let stringDesc be
StringGetOwnProperty (S, P). - If stringDesc is not
undefined , then- Let extensible be S.[[Extensible]].
- Return
IsCompatiblePropertyDescriptor (extensible, Desc, stringDesc).
- Return !
OrdinaryDefineOwnProperty (S, P, Desc).
10.4.3.3 [[OwnPropertyKeys]] ( )
The [[OwnPropertyKeys]] internal method of a
- Let keys be a new empty
List . - Let str be O.[[StringData]].
Assert :Type (str) is String.- Let len be the length of str.
- For each
integer i starting with 0 such that i < len, in ascending order, do- Add !
ToString (𝔽(i)) as the last element of keys.
- Add !
- For each own
property key P of O such that P is anarray index and !ToIntegerOrInfinity (P) ≥ len, in ascending numeric index order, do- Add P as the last element of keys.
- For each own
property key P of O such thatType (P) is String and P is not anarray index , in ascending chronological order of property creation, do- Add P as the last element of keys.
- For each own
property key P of O such thatType (P) is Symbol, in ascending chronological order of property creation, do- Add P as the last element of keys.
- Return keys.
10.4.3.4 StringCreate ( value, prototype )
The abstract operation StringCreate takes arguments value (a String) and prototype and returns a
- Let S be
MakeBasicObject (« [[Prototype]], [[Extensible]], [[StringData]] »). - Set S.[[Prototype]] to prototype.
- Set S.[[StringData]] to value.
- Set S.[[GetOwnProperty]] as specified in
10.4.3.1 . - Set S.[[DefineOwnProperty]] as specified in
10.4.3.2 . - Set S.[[OwnPropertyKeys]] as specified in
10.4.3.3 . - 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.
10.4.3.5 StringGetOwnProperty ( S, P )
The abstract operation StringGetOwnProperty takes arguments S (an Object that has a [[StringData]] internal slot) and P (a
- If
Type (P) is not String, returnundefined . - Let index be
CanonicalNumericIndexString (P). - If index is
undefined , returnundefined . - If
IsIntegralNumber (index) isfalse , returnundefined . - If index is
-0 𝔽, returnundefined . - Let str be S.[[StringData]].
Assert :Type (str) is String.- Let len be the length of str.
- If ℝ(index) < 0 or len ≤ ℝ(index), return
undefined . - Let resultStr be the
substring of str from ℝ(index) to ℝ(index) + 1. - Return the PropertyDescriptor { [[Value]]: resultStr, [[Writable]]:
false , [[Enumerable]]:true , [[Configurable]]:false }.
10.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
An object is an arguments exotic object if its internal methods use the following implementations, with the ones not specified here using those found in
While
Object.prototype.toString (
The
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.
Ordinary arguments objects define a non-configurable
ECMAScript implementations of
10.4.4.1 [[GetOwnProperty]] ( P )
The [[GetOwnProperty]] internal method of an
- Let desc be
OrdinaryGetOwnProperty (args, P). - If desc is
undefined , return desc. - Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P). - If isMapped is
true , then- Set desc.[[Value]] to !
Get (map, P).
- Set desc.[[Value]] to !
- Return desc.
10.4.4.2 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of an
- Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P). - Let newArgDesc be Desc.
- If isMapped is
true andIsDataDescriptor (Desc) istrue , then- If Desc does not have a [[Value]] field, and Desc has a [[Writable]] field, and Desc.[[Writable]] is
false , then- Set newArgDesc to a copy of Desc.
- Set newArgDesc.[[Value]] to !
Get (map, P).
- If Desc does not have a [[Value]] field, and Desc has a [[Writable]] field, and Desc.[[Writable]] is
- Let allowed be !
OrdinaryDefineOwnProperty (args, P, newArgDesc). - If allowed is
false , returnfalse . - If isMapped is
true , then- If
IsAccessorDescriptor (Desc) istrue , then- Perform ! map.[[Delete]](P).
- Else,
- If
- Return
true .
10.4.4.3 [[Get]] ( P, Receiver )
The [[Get]] internal method of an
- Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P). - If isMapped is
false , then- Return ?
OrdinaryGet (args, P, Receiver).
- Return ?
- Else,
10.4.4.4 [[Set]] ( P, V, Receiver )
The [[Set]] internal method of an
- If
SameValue (args, Receiver) isfalse , then- Let isMapped be
false .
- Let isMapped be
- Else,
- Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P).
- If isMapped is
true , then - Return ?
OrdinarySet (args, P, V, Receiver).
10.4.4.5 [[Delete]] ( P )
The [[Delete]] internal method of an
- Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P). - Let result be ?
OrdinaryDelete (args, P). - If result is
true and isMapped istrue , then- Perform ! map.[[Delete]](P).
- Return result.
10.4.4.6 CreateUnmappedArgumentsObject ( argumentsList )
The abstract operation CreateUnmappedArgumentsObject takes argument argumentsList and returns an
- Let len be the number of elements in argumentsList.
- Let obj be
OrdinaryObjectCreate (%Object.prototype% , « [[ParameterMap]] »). - Set obj.[[ParameterMap]] 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 !
CreateDataPropertyOrThrow (obj, !ToString (𝔽(index)), val). - Set index to index + 1.
- Perform !
DefinePropertyOrThrow (obj, @@iterator, PropertyDescriptor { [[Value]]:%Array.prototype.values% , [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Perform !
DefinePropertyOrThrow (obj,"callee" , PropertyDescriptor { [[Get]]:%ThrowTypeError% , [[Set]]:%ThrowTypeError% , [[Enumerable]]:false , [[Configurable]]:false }). - Return obj.
10.4.4.7 CreateMappedArgumentsObject ( func, formals, argumentsList, env )
The abstract operation CreateMappedArgumentsObject takes arguments func (an Object), formals (a
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
MakeBasicObject (« [[Prototype]], [[Extensible]], [[ParameterMap]] »). - Set obj.[[GetOwnProperty]] as specified in
10.4.4.1 . - Set obj.[[DefineOwnProperty]] as specified in
10.4.4.2 . - Set obj.[[Get]] as specified in
10.4.4.3 . - Set obj.[[Set]] as specified in
10.4.4.4 . - Set obj.[[Delete]] as specified in
10.4.4.5 . - Set obj.[[Prototype]] to
%Object.prototype% . - Let map be
OrdinaryObjectCreate (null ). - Set obj.[[ParameterMap]] 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 !
CreateDataPropertyOrThrow (obj, !ToString (𝔽(index)), val). - Set index to index + 1.
- Perform !
DefinePropertyOrThrow (obj,"length" , PropertyDescriptor { [[Value]]: 𝔽(len), [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Let mappedNames be a new empty
List . - Set index to 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
- Set index to index - 1.
- Perform !
DefinePropertyOrThrow (obj, @@iterator, PropertyDescriptor { [[Value]]:%Array.prototype.values% , [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Perform !
DefinePropertyOrThrow (obj,"callee" , PropertyDescriptor { [[Value]]: func, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Return obj.
10.4.4.7.1 MakeArgGetter ( name, env )
The abstract operation MakeArgGetter takes arguments name (a String) and env (an
- Let getterClosure be a new
Abstract Closure with no parameters that captures name and env and performs the following steps when called:- Return env.GetBindingValue(name,
false ).
- Return env.GetBindingValue(name,
- Let getter be
CreateBuiltinFunction (getterClosure, 0,"" , « »). - NOTE: getter is never directly accessible to ECMAScript code.
- Return getter.
10.4.4.7.2 MakeArgSetter ( name, env )
The abstract operation MakeArgSetter takes arguments name (a String) and env (an
- Let setterClosure be a new
Abstract Closure with parameters (value) that captures name and env and performs the following steps when called:- Return ! env.SetMutableBinding(name, value,
false ).
- Return ! env.SetMutableBinding(name, value,
- Let setter be
CreateBuiltinFunction (setterClosure, 1,"" , « »). - NOTE: setter is never directly accessible to ECMAScript code.
- Return setter.
10.4.5 Integer-Indexed Exotic Objects
An
An object is an Integer-Indexed exotic object if its [[GetOwnProperty]], [[HasProperty]], [[DefineOwnProperty]], [[Get]], [[Set]], [[Delete]], and [[OwnPropertyKeys]] internal methods use the definitions in this section, and its other essential internal methods use the definitions found in
10.4.5.1 [[GetOwnProperty]] ( P )
The [[GetOwnProperty]] internal method of an
- 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 the PropertyDescriptor { [[Value]]: value, [[Writable]]:
true , [[Enumerable]]:true , [[Configurable]]:true }.
- Let value be
- Let numericIndex be
- Return
OrdinaryGetOwnProperty (O, P).
10.4.5.2 [[HasProperty]] ( P )
The [[HasProperty]] internal method of an
- If
Type (P) is String, then- Let numericIndex be
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , returnIsValidIntegerIndex (O, numericIndex).
- Let numericIndex be
- Return ?
OrdinaryHasProperty (O, P).
10.4.5.3 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of an
- If
Type (P) is String, then- Let numericIndex be
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- If
IsValidIntegerIndex (O, numericIndex) isfalse , returnfalse . - If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is
false , returnfalse . - If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is
false , returnfalse . - If
IsAccessorDescriptor (Desc) istrue , returnfalse . - If Desc has a [[Writable]] field and if Desc.[[Writable]] is
false , returnfalse . - If Desc has a [[Value]] field, perform ?
IntegerIndexedElementSet (O, numericIndex, Desc.[[Value]]). - Return
true .
- If
- Let numericIndex be
- Return !
OrdinaryDefineOwnProperty (O, P, Desc).
10.4.5.4 [[Get]] ( P, Receiver )
The [[Get]] internal method of an
- 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).
10.4.5.5 [[Set]] ( P, V, Receiver )
The [[Set]] internal method of an
- If
Type (P) is String, then- Let numericIndex be
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- Perform ?
IntegerIndexedElementSet (O, numericIndex, V). - Return
true .
- Perform ?
- Let numericIndex be
- Return ?
OrdinarySet (O, P, V, Receiver).
10.4.5.6 [[Delete]] ( P )
The [[Delete]] internal method of an
- If
Type (P) is String, then- Let numericIndex be
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- If
IsValidIntegerIndex (O, numericIndex) isfalse , returntrue ; else returnfalse .
- If
- Let numericIndex be
- Return !
OrdinaryDelete (O, P).
10.4.5.7 [[OwnPropertyKeys]] ( )
The [[OwnPropertyKeys]] internal method of an
- Let keys be a new empty
List . - If
IsDetachedBuffer (O.[[ViewedArrayBuffer]]) isfalse , then - For each own
property key P of O such thatType (P) is String and P is not aninteger index , in ascending chronological order of property creation, do- Add P as the last element of keys.
- For each own
property key P of O such thatType (P) is Symbol, in ascending chronological order of property creation, do- Add P as the last element of keys.
- Return keys.
10.4.5.8 IntegerIndexedObjectCreate ( prototype )
The abstract operation IntegerIndexedObjectCreate takes argument prototype and returns an
- Let internalSlotsList be « [[Prototype]], [[Extensible]], [[ViewedArrayBuffer]], [[TypedArrayName]], [[ContentType]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] ».
- Let A be
MakeBasicObject (internalSlotsList). - Set A.[[GetOwnProperty]] as specified in
10.4.5.1 . - Set A.[[HasProperty]] as specified in
10.4.5.2 . - Set A.[[DefineOwnProperty]] as specified in
10.4.5.3 . - Set A.[[Get]] as specified in
10.4.5.4 . - Set A.[[Set]] as specified in
10.4.5.5 . - Set A.[[Delete]] as specified in
10.4.5.6 . - Set A.[[OwnPropertyKeys]] as specified in
10.4.5.7 . - Set A.[[Prototype]] to prototype.
- Return A.
10.4.5.9 IsValidIntegerIndex ( O, index )
The abstract operation IsValidIntegerIndex takes arguments O (an
- If
IsDetachedBuffer (O.[[ViewedArrayBuffer]]) istrue , returnfalse . - If
IsIntegralNumber (index) isfalse , returnfalse . - If index is
-0 𝔽, returnfalse . - If ℝ(index) < 0 or ℝ(index) ≥ O.[[ArrayLength]], return
false . - Return
true .
10.4.5.10 IntegerIndexedElementGet ( O, index )
The abstract operation IntegerIndexedElementGet takes arguments O (an
- If
IsValidIntegerIndex (O, index) isfalse , returnundefined . - Let offset be O.[[ByteOffset]].
- Let elementSize be
TypedArrayElementSize (O). - Let indexedPosition be (ℝ(index) × elementSize) + offset.
- Let elementType be
TypedArrayElementType (O). - Return
GetValueFromBuffer (O.[[ViewedArrayBuffer]], indexedPosition, elementType,true ,Unordered ).
10.4.5.11 IntegerIndexedElementSet ( O, index, value )
The abstract operation IntegerIndexedElementSet takes arguments O (an
- If O.[[ContentType]] is
BigInt , let numValue be ?ToBigInt (value). - Otherwise, let numValue be ?
ToNumber (value). - If
IsValidIntegerIndex (O, index) istrue , then- Let offset be O.[[ByteOffset]].
- Let elementSize be
TypedArrayElementSize (O). - Let indexedPosition be (ℝ(index) × elementSize) + offset.
- Let elementType be
TypedArrayElementType (O). - Perform
SetValueInBuffer (O.[[ViewedArrayBuffer]], indexedPosition, elementType, numValue,true ,Unordered ).
- Return
unused .
This operation always appears to succeed, but it has no effect when attempting to write past the end of a TypedArray or to a TypedArray which is backed by a detached ArrayBuffer.
10.4.6 Module Namespace Exotic Objects
A export * export items. Each String-valued own
An object is a module namespace exotic object if its [[GetPrototypeOf]], [[SetPrototypeOf]], [[IsExtensible]], [[PreventExtensions]], [[GetOwnProperty]], [[DefineOwnProperty]], [[HasProperty]], [[Get]], [[Set]], [[Delete]], and [[OwnPropertyKeys]] internal methods use the definitions in this section, and its other essential internal methods use the definitions found in
| Internal Slot | Type | Description |
|---|---|---|
| [[Module]] |
a |
The |
| [[Exports]] |
a |
A |
10.4.6.1 [[GetPrototypeOf]] ( )
The [[GetPrototypeOf]] internal method of a
- Return
null .
10.4.6.2 [[SetPrototypeOf]] ( V )
The [[SetPrototypeOf]] internal method of a
- Return !
SetImmutablePrototype (O, V).
10.4.6.3 [[IsExtensible]] ( )
The [[IsExtensible]] internal method of a
- Return
false .
10.4.6.4 [[PreventExtensions]] ( )
The [[PreventExtensions]] internal method of a
- Return
true .
10.4.6.5 [[GetOwnProperty]] ( P )
The [[GetOwnProperty]] internal method of a
- If
Type (P) is Symbol, returnOrdinaryGetOwnProperty (O, P). - Let exports be O.[[Exports]].
- 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 }.
10.4.6.6 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of a
- If
Type (P) is Symbol, return !OrdinaryDefineOwnProperty (O, P, Desc). - Let current be ? O.[[GetOwnProperty]](P).
- If current is
undefined , returnfalse . - If Desc has a [[Configurable]] field and Desc.[[Configurable]] is
true , returnfalse . - If Desc has an [[Enumerable]] field and Desc.[[Enumerable]] is
false , returnfalse . - If
IsAccessorDescriptor (Desc) istrue , returnfalse . - If Desc has a [[Writable]] field and Desc.[[Writable]] is
false , returnfalse . - If Desc has a [[Value]] field, return
SameValue (Desc.[[Value]], current.[[Value]]). - Return
true .
10.4.6.7 [[HasProperty]] ( P )
The [[HasProperty]] internal method of a
- If
Type (P) is Symbol, return !OrdinaryHasProperty (O, P). - Let exports be O.[[Exports]].
- If P is an element of exports, return
true . - Return
false .
10.4.6.8 [[Get]] ( P, Receiver )
The [[Get]] internal method of a
- If
Type (P) is Symbol, then- Return !
OrdinaryGet (O, P, Receiver).
- Return !
- Let exports be O.[[Exports]].
- If P is not an element of exports, return
undefined . - Let m be O.[[Module]].
- Let binding be ! m.ResolveExport(P).
Assert : binding is aResolvedBinding Record .- Let targetModule be binding.[[Module]].
Assert : targetModule is notundefined .- If binding.[[BindingName]] is
namespace , then- Return ?
GetModuleNamespace (targetModule).
- Return ?
- Let targetEnv be targetModule.[[Environment]].
- If targetEnv is
empty , throw aReferenceError exception. - Return ? targetEnv.GetBindingValue(binding.[[BindingName]],
true ).
ResolveExport is side-effect free. Each time this operation is called with a specific exportName, resolveSet pair as arguments it must return the same result. An implementation might choose to pre-compute or cache the ResolveExport results for the [[Exports]] of each
10.4.6.9 [[Set]] ( P, V, Receiver )
The [[Set]] internal method of a
- Return
false .
10.4.6.10 [[Delete]] ( P )
The [[Delete]] internal method of a
- If
Type (P) is Symbol, then- Return !
OrdinaryDelete (O, P).
- Return !
- Let exports be O.[[Exports]].
- If P is an element of exports, return
false . - Return
true .
10.4.6.11 [[OwnPropertyKeys]] ( )
The [[OwnPropertyKeys]] internal method of a
- Let exports be O.[[Exports]].
- Let symbolKeys be
OrdinaryOwnPropertyKeys (O). - Return the
list-concatenation of exports and symbolKeys.
10.4.6.12 ModuleNamespaceCreate ( module, exports )
The abstract operation ModuleNamespaceCreate takes arguments module (a
Assert : module.[[Namespace]] isempty .- Let internalSlotsList be the internal slots listed in
Table 35 . - Let M be
MakeBasicObject (internalSlotsList). - Set M's essential internal methods to the definitions specified in
10.4.6 . - Set M.[[Module]] to module.
- Let sortedExports be a
List whose elements are the elements of exports ordered as if an Array of the same values had been sorted using%Array.prototype.sort% usingundefined as comparefn. - Set M.[[Exports]] to sortedExports.
- Create own properties of M corresponding to the definitions in
28.3 . - Set module.[[Namespace]] to M.
- Return M.
10.4.7 Immutable Prototype Exotic Objects
An
An object is an immutable prototype exotic object if its [[SetPrototypeOf]] internal method uses the following implementation. (Its other essential internal methods may use any implementation, depending on the specific
Unlike other
10.4.7.1 [[SetPrototypeOf]] ( V )
The [[SetPrototypeOf]] internal method of an
- Return ?
SetImmutablePrototype (O, V).
10.4.7.2 SetImmutablePrototype ( O, V )
The abstract operation SetImmutablePrototype takes arguments O and V (an Object or
- Let current be ?
O.[[GetPrototypeOf]] (). - If
SameValue (V, current) istrue , returntrue . - Return
false .
10.5 Proxy Object Internal Methods and Internal Slots
A Proxy object is an
An object is a Proxy exotic object if its essential internal methods (including [[Call]] and [[Construct]], if applicable) use the definitions in this section. These internal methods are installed in
| Internal Method | Handler Method |
|---|---|
| [[GetPrototypeOf]] |
getPrototypeOf
|
| [[SetPrototypeOf]] |
setPrototypeOf
|
| [[IsExtensible]] |
isExtensible
|
| [[PreventExtensions]] |
preventExtensions
|
| [[GetOwnProperty]] |
getOwnPropertyDescriptor
|
| [[DefineOwnProperty]] |
defineProperty
|
| [[HasProperty]] |
has
|
| [[Get]] |
get
|
| [[Set]] |
set
|
| [[Delete]] |
deleteProperty
|
| [[OwnPropertyKeys]] |
ownKeys
|
| [[Call]] |
apply
|
| [[Construct]] |
construct
|
When a handler method is called to provide the implementation of a Proxy object internal method, the handler method is passed the proxy's target object as a parameter. A proxy's handler object does not necessarily have a method corresponding to every essential internal method. Invoking an internal method on the proxy results in the invocation of the corresponding internal method on the proxy's target object if the handler object does not have a method corresponding to the internal trap.
The [[ProxyHandler]] and [[ProxyTarget]] internal slots of a Proxy object are always initialized when the object is created and typically may not be modified. Some Proxy objects are created in a manner that permits them to be subsequently revoked. When a proxy is revoked, its [[ProxyHandler]] and [[ProxyTarget]] internal slots are set to
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
10.5.1 [[GetPrototypeOf]] ( )
The [[GetPrototypeOf]] internal method of a
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"getPrototypeOf" ). - If trap is
undefined , then- Return ?
target.[[GetPrototypeOf]] ().
- Return ?
- 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 invariants:
-
The result of [[GetPrototypeOf]] must be either an Object or
null . - If the target object is not extensible, [[GetPrototypeOf]] applied to the Proxy object must return the same value as [[GetPrototypeOf]] applied to the Proxy object's target object.
10.5.2 [[SetPrototypeOf]] ( V )
The [[SetPrototypeOf]] internal method of a
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"setPrototypeOf" ). - If trap is
undefined , then- Return ?
target.[[SetPrototypeOf]] (V).
- Return ?
- 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 invariants:
- The result of [[SetPrototypeOf]] is a Boolean value.
- If the target object is not extensible, the argument value must be the same as the result of [[GetPrototypeOf]] applied to target object.
10.5.3 [[IsExtensible]] ( )
The [[IsExtensible]] internal method of a
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"isExtensible" ). - If trap is
undefined , then- Return ?
IsExtensible (target).
- Return ?
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target »)). - Let targetResult be ?
IsExtensible (target). - If
SameValue (booleanTrapResult, targetResult) isfalse , throw aTypeError exception. - Return booleanTrapResult.
[[IsExtensible]] for Proxy objects enforces the following invariants:
- The result of [[IsExtensible]] is a Boolean value.
- [[IsExtensible]] applied to the Proxy object must return the same value as [[IsExtensible]] applied to the Proxy object's target object with the same argument.
10.5.4 [[PreventExtensions]] ( )
The [[PreventExtensions]] internal method of a
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"preventExtensions" ). - If trap is
undefined , then- Return ?
target.[[PreventExtensions]]() .
- Return ?
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target »)). - If booleanTrapResult is
true , then- Let extensibleTarget be ?
IsExtensible (target). - If extensibleTarget is
true , throw aTypeError exception.
- Let extensibleTarget be ?
- Return booleanTrapResult.
[[PreventExtensions]] for Proxy objects enforces the following invariants:
- The result of [[PreventExtensions]] is a Boolean value.
-
[[PreventExtensions]] applied to the Proxy object only returns
true if [[IsExtensible]] applied to the Proxy object's target object isfalse .
10.5.5 [[GetOwnProperty]] ( P )
The [[GetOwnProperty]] internal method of a
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"getOwnPropertyDescriptor" ). - If trap is
undefined , then- Return ?
target.[[GetOwnProperty]] (P).
- Return ?
- 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). - If extensibleTarget is
false , throw aTypeError exception. - Return
undefined .
- If targetDesc is
- Let extensibleTarget be ?
IsExtensible (target). - Let resultDesc be ?
ToPropertyDescriptor (trapResultObj). - Perform
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 resultDesc has a [[Writable]] field and resultDesc.[[Writable]] is
false , thenAssert : targetDesc has a [[Writable]] field.- If targetDesc.[[Writable]] is
true , throw aTypeError exception.
- 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 a non-extensible target object.
- A property cannot be reported as existent, if it does not exist as an own property of the target object and the target object is not extensible.
- A property cannot be reported as non-configurable, unless it exists as a non-configurable own property of the target object.
- A property cannot be reported as both non-configurable and non-writable, unless it exists as a non-configurable, non-writable own property of the target object.
10.5.6 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of a
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"defineProperty" ). - If trap is
undefined , then- Return ?
target.[[DefineOwnProperty]] (P, Desc).
- Return ?
- 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,
- If
IsCompatiblePropertyDescriptor (extensibleTarget, Desc, targetDesc) isfalse , throw aTypeError exception. - If settingConfigFalse is
true and targetDesc.[[Configurable]] istrue , throw aTypeError exception. - If
IsDataDescriptor (targetDesc) istrue , targetDesc.[[Configurable]] isfalse , and targetDesc.[[Writable]] istrue , then- If Desc has a [[Writable]] field and Desc.[[Writable]] is
false , throw aTypeError exception.
- If Desc has a [[Writable]] field and Desc.[[Writable]] is
- 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.
- A non-configurable property cannot be non-writable, unless there exists a corresponding non-configurable, non-writable 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.
10.5.7 [[HasProperty]] ( P )
The [[HasProperty]] internal method of a
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"has" ). - If trap is
undefined , then- Return ?
target.[[HasProperty]] (P).
- Return ?
- 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
- Let targetDesc be ?
- 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.
10.5.8 [[Get]] ( P, Receiver )
The [[Get]] internal method of a
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"get" ). - If trap is
undefined , then- Return ?
target.[[Get]] (P, Receiver).
- Return ?
- Let trapResult be ?
Call (trap, handler, « target, P, Receiver »). - Let targetDesc be ?
target.[[GetOwnProperty]] (P). - If targetDesc is not
undefined and targetDesc.[[Configurable]] isfalse , then- If
IsDataDescriptor (targetDesc) istrue and targetDesc.[[Writable]] isfalse , then- If
SameValue (trapResult, targetDesc.[[Value]]) isfalse , throw aTypeError exception.
- If
- If
IsAccessorDescriptor (targetDesc) istrue 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 ownaccessor property that hasundefined as its [[Get]] attribute.
10.5.9 [[Set]] ( P, V, Receiver )
The [[Set]] internal method of a
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"set" ). - If trap is
undefined , then- Return ?
target.[[Set]] (P, V, Receiver).
- Return ?
- 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 and targetDesc.[[Configurable]] isfalse , then- If
IsDataDescriptor (targetDesc) istrue and targetDesc.[[Writable]] isfalse , then- If
SameValue (V, targetDesc.[[Value]]) isfalse , throw aTypeError exception.
- If
- If
IsAccessorDescriptor (targetDesc) istrue , 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 hasundefined as its [[Set]] attribute.
10.5.10 [[Delete]] ( P )
The [[Delete]] internal method of a
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"deleteProperty" ). - If trap is
undefined , then- Return ?
target.[[Delete]] (P).
- Return ?
- 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. - Let extensibleTarget be ?
IsExtensible (target). - If extensibleTarget is
false , throw aTypeError exception. - Return
true .
[[Delete]] for Proxy objects enforces the following invariants:
- The result of [[Delete]] is a Boolean value.
- A property cannot be reported as deleted, if it exists as a non-configurable own property of the target object.
- A property cannot be reported as deleted, if it exists as an own property of the target object and the target object is non-extensible.
10.5.11 [[OwnPropertyKeys]] ( )
The [[OwnPropertyKeys]] internal method of a
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"ownKeys" ). - If trap is
undefined , then- Return ?
target.[[OwnPropertyKeys]]() .
- Return ?
- Let trapResultArray be ?
Call (trap, handler, « target »). - Let trapResult be ?
CreateListFromArrayLike (trapResultArray, « String, Symbol »). - If trapResult contains any duplicate entries, throw a
TypeError exception. - Let extensibleTarget be ?
IsExtensible (target). - Let targetKeys be ?
target.[[OwnPropertyKeys]]() . Assert : targetKeys is aList ofproperty keys .Assert : targetKeys contains no duplicate entries.- Let targetConfigurableKeys be a new empty
List . - Let targetNonconfigurableKeys be a new empty
List . - For each element key of targetKeys, do
- 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.
- Let desc be ?
- If extensibleTarget is
true and targetNonconfigurableKeys is empty, then- Return trapResult.
- Let uncheckedResultKeys be a
List whose elements are the elements of trapResult. - For each element key of targetNonconfigurableKeys, do
- 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. - For each element key of targetConfigurableKeys, do
- 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 returned
List contains no duplicate entries. -
The Type of each result
List element is either String or Symbol. -
The result
List must contain the keys of all non-configurable own properties of the target object. -
If the target object is not extensible, then the result
List must contain all the keys of the own properties of the target object and no other values.
10.5.12 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method of a
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- 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
10.5.13 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method of a
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
Assert :IsConstructor (target) istrue .- Let trap be ?
GetMethod (handler,"construct" ). - If trap is
undefined , then- Return ?
Construct (target, argumentsList, newTarget).
- Return ?
- 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
[[Construct]] for Proxy objects enforces the following invariants:
- The result of [[Construct]] must be an Object.
10.5.14 ProxyCreate ( target, handler )
The abstract operation ProxyCreate takes arguments target and handler and returns either a
- If
Type (target) is not Object, throw aTypeError exception. - If
Type (handler) is not Object, throw aTypeError exception. - Let P be
MakeBasicObject (« [[ProxyHandler]], [[ProxyTarget]] »). - Set P's essential internal methods, except for [[Call]] and [[Construct]], to the definitions specified in
10.5 . - If
IsCallable (target) istrue , then- Set P.[[Call]] as specified in
10.5.12 . - If
IsConstructor (target) istrue , then- Set P.[[Construct]] as specified in
10.5.13 .
- Set P.[[Construct]] as specified in
- Set P.[[Call]] as specified in
- Set P.[[ProxyTarget]] to target.
- Set P.[[ProxyHandler]] to handler.
- Return P.