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
In the following algorithm descriptions, assume O is an
Each
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 O.[[Prototype]].
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 : EitherType (V) is Object orType (V) is Null.- 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 in9.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 8 guarantees that there will be no circularities in any prototype chain that only includes objects that use the
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 O.[[Extensible]].
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 O.[[Extensible]] tofalse .- 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 - 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.
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 ?
IsExtensible (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:
If
Assert : If O is notundefined , thenIsPropertyKey (P) istrue .- If current is
undefined , then- If extensible is
false , returnfalse . Assert : extensible istrue .- If
IsGenericDescriptor (Desc) istrue orIsDataDescriptor (Desc) istrue , then- If O is not
undefined , create an owndata 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 itsdefault value .
- If O is not
- Else,
Assert : !IsAccessorDescriptor (Desc) istrue .- If O is not
undefined , create an ownaccessor 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 itsdefault value .
- Return
true .
- If extensible is
- If every field in Desc is absent, return
true . - If current.[[Configurable]] is
false , then- If Desc.[[Configurable]] is present and its value is
true , returnfalse . - If Desc.[[Enumerable]] is present and !
SameValue (Desc.[[Enumerable]], current.[[Enumerable]]) isfalse , returnfalse .
- If Desc.[[Configurable]] is present and its value is
- If !
IsGenericDescriptor (Desc) istrue , then- NOTE: No further validation is required.
- Else if !
SameValue (!IsDataDescriptor (current), !IsDataDescriptor (Desc)) isfalse , then- If current.[[Configurable]] is
false , returnfalse . - If
IsDataDescriptor (current) istrue , then- If O is not
undefined , convert the property named P of object O from adata property to anaccessor property . Preserve the existing values of the converted property's [[Configurable]] and [[Enumerable]] attributes and set the rest of the property's attributes to theirdefault values .
- If O is not
- Else,
- If O is not
undefined , convert the property named P of object O from anaccessor property to adata property . Preserve the existing values of the converted property's [[Configurable]] and [[Enumerable]] attributes and set the rest of the property's attributes to theirdefault values .
- If O is not
- If current.[[Configurable]] is
- Else if
IsDataDescriptor (current) andIsDataDescriptor (Desc) are bothtrue , then- If current.[[Configurable]] is
false and current.[[Writable]] isfalse , then- If Desc.[[Writable]] is present and Desc.[[Writable]] is
true , returnfalse . - If Desc.[[Value]] is present and
SameValue (Desc.[[Value]], current.[[Value]]) isfalse , returnfalse . - Return
true .
- If Desc.[[Writable]] is present and Desc.[[Writable]] is
- If current.[[Configurable]] is
- Else,
Assert : !IsAccessorDescriptor (current) and !IsAccessorDescriptor (Desc) are bothtrue .- If current.[[Configurable]] is
false , then
- 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 .
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).
- Return
OrdinarySetWithOwnDescriptor (O, P, V, Receiver, ownDesc).
9.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc )
When the abstract operation OrdinarySetWithOwnDescriptor is called with Object O, property key P, value V,
Assert :IsPropertyKey (P) istrue .- If ownDesc is
undefined , then- Let parent be ? O.[[GetPrototypeOf]]().
- If parent is not
null , then- Return ? parent.[[Set]](P, V, Receiver).
- Else,
Set ownDesc to the PropertyDescriptor { [[Value]]:undefined , [[Writable]]:true , [[Enumerable]]:true , [[Configurable]]:true }.
- 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 .
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 such that P is an
array index , in ascending numeric index order, do- 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 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 that
Type (P) is Symbol, in ascending chronological order of property creation, do- Add P as the last element of keys.
- Return keys.
9.1.12 OrdinaryObjectCreate ( proto [ , additionalInternalSlotsList ] )
The abstract operation OrdinaryObjectCreate with 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
9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
The abstract operation OrdinaryCreateFromConstructor creates an
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
OrdinaryObjectCreate (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
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). 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
9.1.15 RequireInternalSlot ( O, internalSlot )
The abstract operation RequireInternalSlot throws an exception unless O is an Object and has the given internal slot.
- If
Type (O) is not Object, throw aTypeError exception. - If O does not have an internalSlot internal slot, throw a
TypeError exception.
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
In addition to [[Extensible]] and [[Prototype]], ECMAScript function objects also have the internal slots listed in
| Internal Slot |
|
Description |
|---|---|---|
| [[Environment]] |
|
The |
| [[FormalParameters]] |
|
The root parse node of the source text that defines the function's formal parameter list. |
| [[ECMAScriptCode]] |
|
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]] |
|
The |
| [[ScriptOrModule]] |
|
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]] | Boolean |
|
| [[HomeObject]] | Object |
If the function uses super, this is the object whose [[GetPrototypeOf]] provides the object where super property lookups begin.
|
| [[SourceText]] | sequence of Unicode code points |
The |
| [[IsClassConstructor]] | Boolean |
Indicates whether the function is a class |
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
Assert : F is an ECMAScriptfunction object .- If F.[[IsClassConstructor]] is
true , throw aTypeError exception. - Let callerContext be the
running execution context . - Let calleeContext be
PrepareForOrdinaryCall (F,undefined ). Assert : calleeContext is now therunning 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
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 F.[[Realm]].
Set theRealm 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.- 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
- Let thisMode be F.[[ThisMode]].
- If thisMode is
lexical , returnNormalCompletion (undefined ). - 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]].
- Let globalEnvRec be globalEnv's
EnvironmentRecord . Assert : globalEnvRec is a globalEnvironment Record .- Let thisValue be globalEnvRec.[[GlobalThisValue]].
- Else,
- If thisArgument is
- Let envRec be localEnv's
EnvironmentRecord . Assert : envRec is afunction Environment Record .Assert : The next step never returns anabrupt completion because envRec.[[ThisBindingStatus]] is notinitialized .- Return envRec.BindThisValue(thisValue).
9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList )
When the abstract operation OrdinaryCallEvaluateBody is called with
- Return the result of EvaluateBody of the parsed code that is F.[[ECMAScriptCode]] passing F and argumentsList as the arguments.
9.2.2 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method for an ECMAScript
Assert : F is an ECMAScriptfunction object .Assert :Type (newTarget) is Object.- 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 , 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 OrdinaryFunctionCreate ( functionPrototype, ParameterList, Body, thisMode, Scope )
The abstract operation OrdinaryFunctionCreate requires the arguments: an object functionPrototype, a parameter list
Assert :Type (functionPrototype) is Object.- Let internalSlotsList be the internal slots listed in
Table 27 . - Let F be !
OrdinaryObjectCreate (functionPrototype, internalSlotsList). Set F.[[Call]] to the definition specified in9.2.1 .Set F.[[FormalParameters]] to ParameterList.Set F.[[ECMAScriptCode]] to Body.- If the source text matching Body is
strict 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]] tofalse .Set F.[[Environment]] to Scope.Set F.[[ScriptOrModule]] toGetActiveScriptOrModule ().Set F.[[Realm]] tothe current Realm Record .Set F.[[HomeObject]] toundefined .- Let len be the ExpectedArgumentCount of ParameterList.
- Perform !
SetFunctionLength (F, len). - Return F.
9.2.4 AddRestrictedFunctionProperties ( F, realm )
The abstract operation AddRestrictedFunctionProperties is called with 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 }). - Return !
DefinePropertyOrThrow (F,"arguments" , PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]:false , [[Configurable]]:true }).
9.2.4.1 %ThrowTypeError% ( )
The
- Throw a
TypeError exception.
The value of the [[Extensible]] internal slot of a
The
9.2.5 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
Assert : F is an ECMAScriptfunction object .Assert :IsConstructor (F) isfalse .Assert : F is an extensible object that does not have a"prototype" own property.Set F.[[Construct]] to the definition specified in9.2.2 .Set F.[[ConstructorKind]] tobase .- If writablePrototype is not present, set writablePrototype to
true . - If prototype is not present, then
Set prototype toOrdinaryObjectCreate (%Object.prototype% ).- Perform !
DefinePropertyOrThrow (prototype,"constructor" , PropertyDescriptor { [[Value]]: F, [[Writable]]: writablePrototype, [[Enumerable]]:false , [[Configurable]]:true }).
- Perform !
DefinePropertyOrThrow (F,"prototype" , PropertyDescriptor { [[Value]]: prototype, [[Writable]]: writablePrototype, [[Enumerable]]:false , [[Configurable]]:false }). - Return
NormalCompletion (undefined ).
9.2.6 MakeClassConstructor ( F )
The abstract operation MakeClassConstructor with argument F performs the following steps:
Assert : F is an ECMAScriptfunction object .Assert : F.[[IsClassConstructor]] isfalse .Set F.[[IsClassConstructor]] totrue .- Return
NormalCompletion (undefined ).
9.2.7 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 ECMAScriptfunction object .Assert :Type (homeObject) is Object.Set F.[[HomeObject]] to homeObject.- Return
NormalCompletion (undefined ).
9.2.8 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
Assert : F is an extensible object that does not have a"name" own property.Assert :Type (name) is either Symbol or String.Assert : If prefix is present, thenType (prefix) is String.- 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"]" .
- If prefix is present, then
Set name to thestring-concatenation of prefix, the code unit 0x0020 (SPACE), and name.
- Return !
DefinePropertyOrThrow (F,"name" , PropertyDescriptor { [[Value]]: name, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:true }).
9.2.9 SetFunctionLength ( F, length )
The abstract operation SetFunctionLength requires a Function argument F and a Number argument length. This operation adds a
Assert : F is an extensible object that does not have a"length" own property.Assert :Type (length) is Number.Assert : !IsNonNegativeInteger (length) istrue .- Return !
DefinePropertyOrThrow (F,"length" , PropertyDescriptor { [[Value]]: length, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:true }).
9.2.10 FunctionDeclarationInstantiation ( func, argumentsList )
When an
FunctionDeclarationInstantiation is performed as follows using arguments func and argumentsList. func is the
- 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 d in 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 objects.
Set argumentsObjectNeeded tofalse .
- Else if
"arguments" is an element of parameterNames, thenSet argumentsObjectNeeded tofalse .
- Else if hasParameterExpressions is
false , then- If
"arguments" is an element of functionNames or if"arguments" is an element of lexicalNames, thenSet argumentsObjectNeeded tofalse .
- If
- If strict is
true or if hasParameterExpressions isfalse , then- NOTE: Only a single lexical environment is needed for the parameters and top-level vars.
- Let env be the LexicalEnvironment of calleeContext.
- Let envRec be env's
EnvironmentRecord .
- 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). - Let envRec be env's
EnvironmentRecord . Assert : The VariableEnvironment of calleeContext is calleeEnv.Set the LexicalEnvironment of calleeContext to env.
- NOTE: A separate
- 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: 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, 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). - Let parameterBindings be a new
List of parameterNames with"arguments" appended.
- If strict is
- Else,
- Let parameterBindings be parameterNames.
- Let iteratorRecord be
CreateListIteratorRecord (argumentsList). - 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 parameterBindings. - 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 parameterBindings 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: 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.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
Parse Node f in functionsToInitialize, do- Let fn be the sole element of the BoundNames of f.
- Let fo be InstantiateFunctionObject of 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
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 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 new expression the argumentsList parameter of the invoked [[Construct]] internal method provides the values for the built-in
Built-in functions that are not constructors do not have a
If a built-in
9.3.1 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method for 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 theRealm of calleeContext to calleeRealm.Set the ScriptOrModule of calleeContext to F.[[ScriptOrModule]].- 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
9.3.2 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method for built-in
9.3.3 CreateBuiltinFunction ( steps, internalSlotsList [ , realm [ , prototype ] ] )
The abstract operation CreateBuiltinFunction takes arguments steps, internalSlotsList, realm, and prototype. The argument internalSlotsList is a
Assert : steps is either a set of algorithm steps or other definition of a function's behaviour provided in this specification.- If realm is not present, set realm to
the current Realm Record . Assert : realm is aRealm Record .- If prototype is not present, set prototype to realm.[[Intrinsics]].[[
%Function.prototype% ]]. - Let func be a new built-in
function object that when called performs the action described by steps. The newfunction object has internal slots whose names are the elements of internalSlotsList. Set func.[[Realm]] to realm.Set func.[[Prototype]] to prototype.Set func.[[Extensible]] totrue .Set func.[[ScriptOrModule]] tonull .- Return func.
Each built-in function defined in this specification is created by calling the CreateBuiltinFunction abstract operation.
9.4 Built-in Exotic Object Internal Methods and Slots
This specification defines several kinds of built-in exotic objects. These objects generally behave similar to ordinary objects except for a few specific situations. The following exotic objects use the
9.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
Bound function exotic objects do not have the internal slots of ECMAScript function objects listed in
| Internal Slot |
|
Description |
|---|---|---|
| [[BoundTargetFunction]] | Callable Object |
The wrapped |
| [[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. |
9.4.1.1 [[Call]] ( thisArgument, argumentsList )
When the [[Call]] internal method of a
- Let target be F.[[BoundTargetFunction]].
- Let boundThis be F.[[BoundThis]].
- Let boundArgs be F.[[BoundArguments]].
- 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 a
- Let target be F.[[BoundTargetFunction]].
Assert :IsConstructor (target) istrue .- Let boundArgs be F.[[BoundArguments]].
- 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 , set newTarget to 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 internalSlotsList be the internal slots listed in
Table 28 , plus [[Prototype]] and [[Extensible]]. - Let obj be !
MakeBasicObject (internalSlotsList). Set obj.[[Prototype]] to proto.Set obj.[[Call]] as described in9.4.1.1 .- If
IsConstructor (targetFunction) istrue , then Set obj.[[BoundTargetFunction]] to targetFunction.Set obj.[[BoundThis]] to boundThis.Set obj.[[BoundArguments]] to boundArgs.- Return obj.
9.4.2 Array Exotic Objects
An Array object is an
A String
An object is an Array exotic object (or simply, an Array object) if its [[DefineOwnProperty]] internal method uses the following implementation, and its other essential internal methods use the definitions found in
9.4.2.1 [[DefineOwnProperty]] ( P, Desc )
When the [[DefineOwnProperty]] internal method of an
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 beundefined or an accessor descriptor because Array objects are created with a lengthdata property that cannot be deleted or reconfigured.- Let oldLen be oldLenDesc.[[Value]].
Assert :IsNonNegativeInteger (oldLen) istrue .- 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 istrue .
- 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
Assert : !IsNonNegativeInteger (length) istrue .- If length is
-0 , set length to+0 . - 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 in9.4.2.1 .- 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
Assert : !IsNonNegativeInteger (length) istrue .- If length is
-0 , set length to+0 . - 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 - 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.
9.4.2.4 ArraySetLength ( A, Desc )
When the abstract operation ArraySetLength is called with an
- If Desc.[[Value]] 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 beundefined or an accessor descriptor because Array objects are created with a lengthdata 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]] totrue .
- Need to defer 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 an
array 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 , thenSet newLenDesc.[[Value]] to !ToUint32 (P) + 1.- If newWritable is
false , set newLenDesc.[[Writable]] tofalse . - Perform !
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
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
String exotic objects have the same internal slots as ordinary objects. They also have a [[StringData]] internal slot.
9.4.3.1 [[GetOwnProperty]] ( P )
When the [[GetOwnProperty]] internal method of a
Assert :IsPropertyKey (P) istrue .- Let desc be
OrdinaryGetOwnProperty (S, P). - If desc is not
undefined , return desc. - Return !
StringGetOwnProperty (S, P).
9.4.3.2 [[DefineOwnProperty]] ( P, Desc )
When the [[DefineOwnProperty]] internal method of a
Assert :IsPropertyKey (P) istrue .- 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).
9.4.3.3 [[OwnPropertyKeys]] ( )
When 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 an
array index andToInteger (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 that
Type (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 that
Type (P) is Symbol, in ascending chronological order of property creation, do- Add P as the last element of keys.
- Return keys.
9.4.3.4 StringCreate ( value, prototype )
The abstract operation StringCreate with arguments value and prototype is used to specify the creation of new String exotic objects. It performs the following steps:
Assert :Type (value) is String.- Let S be !
MakeBasicObject (« [[Prototype]], [[Extensible]], [[StringData]] »). Set S.[[Prototype]] to prototype.Set S.[[StringData]] to value.Set S.[[GetOwnProperty]] as specified in9.4.3.1 .Set S.[[DefineOwnProperty]] as specified in9.4.3.2 .Set S.[[OwnPropertyKeys]] as specified in9.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.
9.4.3.5 StringGetOwnProperty ( S, P )
The abstract operation StringGetOwnProperty called with arguments S and P performs the following steps:
Assert : S is an Object that has a [[StringData]] internal slot.Assert :IsPropertyKey (P) istrue .- 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 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 String value of length 1, containing one code unit from str, specifically the code unit at index index.
- Return the PropertyDescriptor { [[Value]]: resultStr, [[Writable]]:
false , [[Enumerable]]:true , [[Configurable]]:false }.
9.4.4 Arguments Exotic Objects
Most ECMAScript functions make an arguments object available to their code. Depending upon the characteristics of the function definition, its arguments object is either an
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
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 (
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 arguments exotic objects have historically contained an
9.4.4.1 [[GetOwnProperty]] ( P )
The [[GetOwnProperty]] internal method of an
- Let args be the arguments object.
- 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 - Return desc.
9.4.4.2 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of an
- Let args be the arguments object.
- Let map be args.[[ParameterMap]].
- Let isMapped be
HasOwnProperty (map, P). - Let newArgDesc be Desc.
- If isMapped is
true andIsDataDescriptor (Desc) istrue , then - Let allowed be ?
OrdinaryDefineOwnProperty (args, P, newArgDesc). - If allowed is
false , returnfalse . - If isMapped is
true , then- If
IsAccessorDescriptor (Desc) istrue , then- Call map.[[Delete]](P).
- Else,
- If
- Return
true .
9.4.4.3 [[Get]] ( P, Receiver )
The [[Get]] internal method of an
- Let args be the arguments object.
- Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P). - If isMapped is
false , then- Return ?
OrdinaryGet (args, P, Receiver).
- Return ?
- Else,
9.4.4.4 [[Set]] ( P, V, Receiver )
The [[Set]] internal method of an
- Let args be the arguments object.
- 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).
9.4.4.5 [[Delete]] ( P )
The [[Delete]] internal method of an
- Let args be the arguments object.
- 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- Call map.[[Delete]](P).
- Return result.
9.4.4.6 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
OrdinaryObjectCreate (%Object.prototype% , « [[ParameterMap]] »). Set obj.[[ParameterMap]] toundefined .- 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.
9.4.4.7 CreateMappedArgumentsObject ( func, formals, argumentsList, env )
The abstract operation CreateMappedArgumentsObject is called with object func,
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 in9.4.4.1 .Set obj.[[DefineOwnProperty]] as specified in9.4.4.2 .Set obj.[[Get]] as specified in9.4.4.3 .Set obj.[[Set]] as specified in9.4.4.4 .Set obj.[[Delete]] as specified in9.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 . - 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
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.
9.4.4.7.1 MakeArgGetter ( name, env )
The abstract operation MakeArgGetter called with String name and
- Let steps be the steps of an ArgGetter function as specified below.
- Let getter be !
CreateBuiltinFunction (steps, « [[Name]], [[Env]] »). Set getter.[[Name]] to name.Set getter.[[Env]] to env.- Return getter.
An ArgGetter function is an anonymous built-in function with [[Name]] and [[Env]] internal slots. When an ArgGetter function that expects no arguments is called it performs the following steps:
- Let f be the
active function object . - Let name be f.[[Name]].
- Let env be f.[[Env]].
- Return env.GetBindingValue(name,
false ).
ArgGetter functions are never directly accessible to ECMAScript code.
9.4.4.7.2 MakeArgSetter ( name, env )
The abstract operation MakeArgSetter called with String name and
- Let steps be the steps of an ArgSetter function as specified below.
- Let setter be !
CreateBuiltinFunction (steps, « [[Name]], [[Env]] »). Set setter.[[Name]] to name.Set setter.[[Env]] to env.- Return setter.
An ArgSetter function is an anonymous built-in function with [[Name]] and [[Env]] internal slots. When an ArgSetter function is called with argument value it performs the following steps:
- Let f be the
active function object . - Let name be f.[[Name]].
- Let env be f.[[Env]].
- Return env.SetMutableBinding(name, value,
false ).
ArgSetter functions are never directly accessible to ECMAScript code.
9.4.5 Integer-Indexed Exotic Objects
An
An object is an Integer-Indexed exotic object if its [[GetOwnProperty]], [[HasProperty]], [[DefineOwnProperty]], [[Get]], [[Set]], and [[OwnPropertyKeys]] internal methods use the definitions in this section, and its other essential internal methods use the definitions found in
9.4.5.1 [[GetOwnProperty]] ( P )
When the [[GetOwnProperty]] internal method of an
Assert :IsPropertyKey (P) istrue .Assert : O is anInteger-Indexed exotic object .- 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]]:false }.
- Let value be ?
- Let numericIndex be !
- Return
OrdinaryGetOwnProperty (O, P).
9.4.5.2 [[HasProperty]] ( P )
When the [[HasProperty]] internal method of an
Assert :IsPropertyKey (P) istrue .Assert : O is anInteger-Indexed exotic object .- If
Type (P) is String, then- Let numericIndex be !
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- Let buffer be O.[[ViewedArrayBuffer]].
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - If !
IsValidIntegerIndex (O, numericIndex) isfalse , returnfalse . - Return
true .
- Let numericIndex be !
- Return ?
OrdinaryHasProperty (O, P).
9.4.5.3 [[DefineOwnProperty]] ( P, Desc )
When the [[DefineOwnProperty]] internal method of an
Assert :IsPropertyKey (P) istrue .Assert : O is anInteger-Indexed exotic object .- If
Type (P) is String, then- Let numericIndex be !
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- If !
IsValidIntegerIndex (O, numericIndex) isfalse , returnfalse . - 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, numericIndex, 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
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
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
- Let keys be a new empty
List . Assert : O is anInteger-Indexed exotic object .- Let len be O.[[ArrayLength]].
- 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
Type (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 that
Type (P) is Symbol, in ascending chronological order of property creation, do- Add P as the last element of keys.
- Return keys.
9.4.5.7 IntegerIndexedObjectCreate ( prototype )
The abstract operation IntegerIndexedObjectCreate is used to specify the creation of new
- Let internalSlotsList be « [[Prototype]], [[Extensible]], [[ViewedArrayBuffer]], [[TypedArrayName]], [[ContentType]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] ».
- Let A be !
MakeBasicObject (internalSlotsList). Set A.[[GetOwnProperty]] as specified in9.4.5.1 .Set A.[[HasProperty]] as specified in9.4.5.2 .Set A.[[DefineOwnProperty]] as specified in9.4.5.3 .Set A.[[Get]] as specified in9.4.5.4 .Set A.[[Set]] as specified in9.4.5.5 .Set A.[[OwnPropertyKeys]] as specified in9.4.5.6 .Set A.[[Prototype]] to prototype.- Return A.
9.4.5.8 IsValidIntegerIndex ( O, index )
The abstract operation IsValidIntegerIndex with arguments O and index performs the following steps:
Assert : O is anInteger-Indexed exotic object .Assert :Type (index) is Number.- If !
IsInteger (index) isfalse , returnfalse . - If index is
-0 , returnfalse . - If index < 0 or index ≥ O.[[ArrayLength]], return
false . - Return
true .
9.4.5.9 IntegerIndexedElementGet ( O, index )
The abstract operation IntegerIndexedElementGet with arguments O and index performs the following steps:
Assert : O is anInteger-Indexed exotic object .Assert :Type (index) is Number.- Let buffer be O.[[ViewedArrayBuffer]].
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - If !
IsValidIntegerIndex (O, index) isfalse , returnundefined . - Let offset be O.[[ByteOffset]].
- Let arrayTypeName be the String value of O.[[TypedArrayName]].
- Let elementSize be the Element Size value specified in
Table 61 for arrayTypeName. - Let indexedPosition be (index × elementSize) + offset.
- Let elementType be the Element
Type value inTable 61 for arrayTypeName. - Return
GetValueFromBuffer (buffer, indexedPosition, elementType,true ,Unordered ).
9.4.5.10 IntegerIndexedElementSet ( O, index, value )
The abstract operation IntegerIndexedElementSet with arguments O, index, and value performs the following steps:
Assert : O is anInteger-Indexed exotic object .Assert :Type (index) is Number.- If O.[[ContentType]] is
BigInt , let numValue be ?ToBigInt (value). - Otherwise, let numValue be ?
ToNumber (value). - Let buffer be O.[[ViewedArrayBuffer]].
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - If !
IsValidIntegerIndex (O, index) isfalse , returnfalse . - Let offset be O.[[ByteOffset]].
- Let arrayTypeName be the String value of O.[[TypedArrayName]].
- Let elementSize be the Element Size value specified in
Table 61 for arrayTypeName. - Let indexedPosition be (index × elementSize) + offset.
- Let elementType be the Element
Type value inTable 61 for arrayTypeName. - Perform
SetValueInBuffer (buffer, indexedPosition, elementType, numValue,true ,Unordered ). - Return
true .
9.4.6 Module Namespace Exotic Objects
A 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
An object is a module namespace exotic object if its [[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
Module namespace exotic objects have the internal slots defined in
| Internal Slot |
|
Description |
|---|---|---|
| [[Module]] |
|
The |
| [[Exports]] |
|
A Array.prototype.sort using |
| [[Prototype]] | Null |
This slot always contains the value |
Module namespace exotic objects provide alternative definitions for all of the internal methods except [[GetPrototypeOf]], which behaves as defined in
9.4.6.1 [[SetPrototypeOf]] ( V )
When the [[SetPrototypeOf]] internal method of a
- Return ?
SetImmutablePrototype (O, V).
9.4.6.2 [[IsExtensible]] ( )
When the [[IsExtensible]] internal method of a
- Return
false .
9.4.6.3 [[PreventExtensions]] ( )
When the [[PreventExtensions]] internal method of a
- Return
true .
9.4.6.4 [[GetOwnProperty]] ( P )
When 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 }.
9.4.6.5 [[DefineOwnProperty]] ( P, Desc )
When the [[DefineOwnProperty]] internal method of a
- If
Type (P) is Symbol, returnOrdinaryDefineOwnProperty (O, P, Desc). - Let current be ? O.[[GetOwnProperty]](P).
- If current is
undefined , returnfalse . - If
IsAccessorDescriptor (Desc) istrue , returnfalse . - If Desc.[[Writable]] is present and has value
false , returnfalse . - If Desc.[[Enumerable]] is present and has value
false , returnfalse . - If Desc.[[Configurable]] is present and has value
true , returnfalse . - If Desc.[[Value]] is present, return
SameValue (Desc.[[Value]], current.[[Value]]). - Return
true .
9.4.6.6 [[HasProperty]] ( P )
When the [[HasProperty]] internal method of a
- If
Type (P) is Symbol, returnOrdinaryHasProperty (O, P). - Let exports be O.[[Exports]].
- If P is an element of exports, return
true . - Return
false .
9.4.6.7 [[Get]] ( P, Receiver )
When the [[Get]] internal method of a
Assert :IsPropertyKey (P) istrue .- 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
undefined , throw aReferenceError exception. - Let targetEnvRec be targetEnv's
EnvironmentRecord . - Return ? targetEnvRec.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
9.4.6.8 [[Set]] ( P, V, Receiver )
When the [[Set]] internal method of a
- Return
false .
9.4.6.9 [[Delete]] ( P )
When the [[Delete]] internal method of a
Assert :IsPropertyKey (P) istrue .- 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 .
9.4.6.10 [[OwnPropertyKeys]] ( )
When the [[OwnPropertyKeys]] internal method of a
- Let exports be a copy of O.[[Exports]].
- Let symbolKeys be !
OrdinaryOwnPropertyKeys (O). - Append all the entries of symbolKeys to the end of exports.
- Return exports.
9.4.6.11 ModuleNamespaceCreate ( module, exports )
The abstract operation ModuleNamespaceCreate with arguments module, and exports is used to specify the creation of new module namespace exotic objects. It performs the following steps:
Assert : module is aModule Record .Assert : module.[[Namespace]] isundefined .Assert : exports is aList of String values.- Let internalSlotsList be the internal slots listed in
Table 29 . - Let M be !
MakeBasicObject (internalSlotsList). Set M's essential internal methods to the definitions specified in9.4.6 .Set M.[[Prototype]] tonull .Set M.[[Module]] to module.- Let sortedExports be a new
List containing the same values as the list exports where the values are ordered as if an Array of the same values had been sorted usingArray.prototype.sortusingundefined as comparefn. Set M.[[Exports]] to sortedExports.- 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
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 exotic objects, there is not a dedicated creation abstract operation provided for immutable prototype exotic objects. This is because they are only used by
9.4.7.1 [[SetPrototypeOf]] ( V )
When the [[SetPrototypeOf]] internal method of an
- Return ?
SetImmutablePrototype (O, V).
9.4.7.2 SetImmutablePrototype ( O, V )
9.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 property key value, V is any
9.5.1 [[GetPrototypeOf]] ( )
When 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]]().
- 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.
9.5.2 [[SetPrototypeOf]] ( V )
When the [[SetPrototypeOf]] internal method of a
Assert : EitherType (V) is Object orType (V) is Null.- 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).
- 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.
9.5.3 [[IsExtensible]] ( )
When 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.
9.5.4 [[PreventExtensions]] ( )
When 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]]().
- 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 .
9.5.5 [[GetOwnProperty]] ( P )
When the [[GetOwnProperty]] internal method of a
Assert :IsPropertyKey (P) istrue .- 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).
- 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). - 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 resultDesc has a [[Writable]] field and resultDesc.[[Writable]] is
false , then- If targetDesc.[[Writable]] is
true , throw aTypeError exception.
- If targetDesc.[[Writable]] is
- 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 the target object is not extensible, unless it does not exist as an own property of the target object.
- A property cannot be reported as existent, if the target object is not extensible, unless it exists as an own property of the target object.
- 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.
9.5.6 [[DefineOwnProperty]] ( P, Desc )
When the [[DefineOwnProperty]] internal method of a
Assert :IsPropertyKey (P) istrue .- 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).
- 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.
9.5.7 [[HasProperty]] ( P )
When the [[HasProperty]] internal method of a
Assert :IsPropertyKey (P) istrue .- 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).
- 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
Assert :IsPropertyKey (P) istrue .- 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).
- 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.
9.5.9 [[Set]] ( P, V, Receiver )
When the [[Set]] internal method of a
Assert :IsPropertyKey (P) istrue .- 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).
- 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.
9.5.10 [[Delete]] ( P )
When the [[Delete]] internal method of a
Assert :IsPropertyKey (P) istrue .- 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).
- 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.
9.5.11 [[OwnPropertyKeys]] ( )
When 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]]().
- 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 containing only String and Symbol values.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.
- If extensibleTarget is
true and targetNonconfigurableKeys is empty, then- Return trapResult.
- Let uncheckedResultKeys be a new
List which is a copy of trapResult. - For each key that is an element 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 key that is an element 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 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
- 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
9.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.
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 target.[[ProxyHandler]] isnull , throw aTypeError exception. - If
Type (handler) is not Object, throw aTypeError exception. - If handler is a
Proxy exotic object and handler.[[ProxyHandler]] isnull , throw aTypeError exception. - Let P be !
MakeBasicObject (« [[ProxyHandler]], [[ProxyTarget]] »). Set P's essential internal methods, except for [[Call]] and [[Construct]], to the definitions specified in9.5 .- If
IsCallable (target) istrue , thenSet P.[[Call]] as specified in9.5.12 .- If
IsConstructor (target) istrue , then
Set P.[[ProxyTarget]] to target.Set P.[[ProxyHandler]] to handler.- Return P.