10 Ordinary and Exotic Objects Behaviours
10.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
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). It performs the following steps when called:
- 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
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 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). 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). It performs the following steps when called:
Set O.[[Extensible]] tofalse .- 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 property key). It performs the following steps when called:
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.
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 property key), and Desc (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 ,undefined , Extensible, Desc, Current).
10.1.6.3 ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current )
The abstract operation ValidateAndApplyPropertyDescriptor takes arguments O (an Object or
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 .
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 property key). It performs the following steps when called:
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 .
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 property key), and Receiver (an
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).
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 property key), V (an
Assert :IsPropertyKey (P) istrue .- 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 property key), V (an
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 .
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 property key). It performs the following steps when called:
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 .
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). It performs the following steps when called:
- 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.
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 and optional argument internalSlotsList (a
Assert : intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object.- Let proto be ?
GetPrototypeFromConstructor (constructor, intrinsicDefaultProto). - Return !
OrdinaryObjectCreate (proto, internalSlotsList).
10.1.14 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
The abstract operation GetPrototypeFromConstructor takes arguments constructor and intrinsicDefaultProto. It 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
10.1.15 RequireInternalSlot ( O, internalSlot )
The abstract operation RequireInternalSlot takes arguments O and internalSlot. It throws an exception unless O is an Object and has the given internal slot. It performs the following steps when called:
- If
Type (O) is not Object, throw aTypeError exception. - If O does not have an internalSlot internal slot, throw a
TypeError exception.
10.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.
10.2.1 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method of an ECMAScript
Assert : F is an ECMAScriptfunction object .- 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
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
10.2.1.1 PrepareForOrdinaryCall ( F, newTarget )
The abstract operation PrepareForOrdinaryCall takes arguments F (a
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.
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 , 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]].
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 .- Return localEnv.BindThisValue(thisValue).
10.2.1.3 Runtime Semantics: EvaluateBody
With parameters functionObject and argumentsList (a
- 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.
10.2.1.4 OrdinaryCallEvaluateBody ( F, argumentsList )
The abstract operation OrdinaryCallEvaluateBody takes arguments F (a
- Return the result of
EvaluateBody of the parsed code that is F.[[ECMAScriptCode]] passing F and argumentsList as the arguments.
10.2.2 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method of 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 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 ? constructorEnv.GetThisBinding().
10.2.3 OrdinaryFunctionCreate ( functionPrototype, sourceText, ParameterList, Body, thisMode, Scope )
The abstract operation OrdinaryFunctionCreate takes arguments functionPrototype (an Object), sourceText (a sequence of Unicode code points), ParameterList (a
Assert :Type (functionPrototype) is Object.- Let internalSlotsList be the internal slots listed in
Table 29 . - Let F be !
OrdinaryObjectCreate (functionPrototype, internalSlotsList). Set F.[[Call]] to the definition specified in10.2.1 .Set F.[[SourceText]] to sourceText.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.
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 }). - Return !
DefinePropertyOrThrow (F,"arguments" , PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]:false , [[Configurable]]:true }).
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 (a
Assert : F is an ECMAScriptfunction object or a built-infunction object .- 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 in10.2.2 .
Set F.[[ConstructorKind]] tobase .- 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 }).
- Perform !
DefinePropertyOrThrow (F,"prototype" , PropertyDescriptor { [[Value]]: prototype, [[Writable]]: writablePrototype, [[Enumerable]]:false , [[Configurable]]:false }). - Return
NormalCompletion (undefined ).
10.2.6 MakeClassConstructor ( F )
The abstract operation MakeClassConstructor takes argument F. It performs the following steps when called:
Assert : F is an ECMAScriptfunction object .Assert : F.[[IsClassConstructor]] isfalse .Set F.[[IsClassConstructor]] totrue .- Return
NormalCompletion (undefined ).
10.2.7 MakeMethod ( F, homeObject )
The abstract operation MakeMethod takes arguments F and homeObject. It configures F as a method. It performs the following steps when called:
Assert : F is an ECMAScriptfunction object .Assert :Type (homeObject) is Object.Set F.[[HomeObject]] to homeObject.- Return
NormalCompletion (undefined ).
10.2.8 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.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 F has an [[InitialName]] internal slot, then
Set F.[[InitialName]] to name.
- If prefix is present, then
Set name to thestring-concatenation of prefix, the code unit 0x0020 (SPACE), and name.- If F has an [[InitialName]] internal slot, then
- Optionally, set F.[[InitialName]] to name.
- Return !
DefinePropertyOrThrow (F,"name" , PropertyDescriptor { [[Value]]: name, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:true }).
10.2.9 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.- Return !
DefinePropertyOrThrow (F,"length" , PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:true }).
10.2.10 FunctionDeclarationInstantiation ( func, argumentsList )
When an
The abstract operation FunctionDeclarationInstantiation takes arguments func (a
- 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 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
Environment Record is needed for the parameters and top-level vars. - 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 in non-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).
- If strict is
true , then- Perform ! env.CreateImmutableBinding(
"arguments" ,false ).
- Perform ! env.CreateImmutableBinding(
- Else,
- Perform ! env.CreateMutableBinding(
"arguments" ,false ).
- Perform ! env.CreateMutableBinding(
- Call env.InitializeBinding(
"arguments" , ao). - Let parameterBindings be a
List whose elements are the elements of parameterNames, followed by"arguments" .
- If strict is
- Else,
- Let parameterBindings be parameterNames.
- Let iteratorRecord be
CreateListIteratorRecord (argumentsList). - If hasDuplicates is
true , then- Perform ?
IteratorBindingInitialization for formals with iteratorRecord andundefined as arguments.
- Perform ?
- Else,
- Perform ?
IteratorBindingInitialization for formals with iteratorRecord and env as arguments.
- 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 ). - Call 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,
- Call 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.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
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.
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
- 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 argument lexEnv. - Perform ! varEnv.SetMutableBinding(fn, fo,
false ).
- Let fn be the sole element of the
- Return
NormalCompletion (empty ).
Parameter
10.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
Built-in functions have an [[InitialName]] internal slot.
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 theRealm of calleeContext to calleeRealm.Set the ScriptOrModule of calleeContext tonull .- 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 ( steps, length, name, internalSlotsList [ , realm [ , prototype [ , prefix ] ] ] )
The abstract operation CreateBuiltinFunction takes arguments steps, length, name, and internalSlotsList (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 or realm is
empty , set realm tothe 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, and an [[InitialName]] internal slot. Set func.[[Realm]] to realm.Set func.[[Prototype]] to prototype.Set func.[[Extensible]] totrue .Set func.[[InitialName]] tonull .- 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 exotic objects. These objects generally behave similar to ordinary objects except for a few specific situations. The following exotic objects use the
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
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. |
10.4.1.1 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method of a
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 a
List whose elements are the elements of boundArgs, followed by the elements of 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, boundThis, and boundArgs. It is used to specify the creation of new bound function exotic objects. It performs the following steps when called:
Assert :Type (targetFunction) is Object.- Let proto be ? targetFunction.[[GetPrototypeOf]]().
- Let internalSlotsList be the internal slots listed in
Table 30 , plus [[Prototype]] and [[Extensible]]. - Let obj be !
MakeBasicObject (internalSlotsList). Set obj.[[Prototype]] to proto.Set obj.[[Call]] as described in10.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.
10.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
10.4.2.1 [[DefineOwnProperty]] ( P, Desc )
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 : !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 𝔽.- Let succeeded be
OrdinaryDefineOwnProperty (A,"length" , oldLenDesc). Assert : succeeded istrue .
- 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 in10.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 - 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 object) and Desc (a
- 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 is not the same value as numberLen, throw a
RangeError 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.[[Writable]] is absent or has the value
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]] totrue .
- 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 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- Let succeeded be !
OrdinaryDefineOwnProperty (A,"length" , PropertyDescriptor { [[Writable]]:false }). Assert : succeeded istrue .
- Let succeeded be !
- 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
String exotic objects have the same internal slots as ordinary objects. They also have a [[StringData]] internal slot.
10.4.3.1 [[GetOwnProperty]] ( P )
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).
10.4.3.2 [[DefineOwnProperty]] ( P, Desc )
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).
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 an
array 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 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.
10.4.3.4 StringCreate ( value, prototype )
The abstract operation StringCreate takes arguments value (a String) and prototype. It is used to specify the creation of new String exotic objects. It performs the following steps when called:
- Let S be !
MakeBasicObject (« [[Prototype]], [[Extensible]], [[StringData]] »). Set S.[[Prototype]] to prototype.Set S.[[StringData]] to value.Set S.[[GetOwnProperty]] as specified in10.4.3.1 .Set S.[[DefineOwnProperty]] as specified in10.4.3.2 .Set S.[[OwnPropertyKeys]] as specified in10.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 and P. It performs the following steps when called:
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
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 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 }.
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
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
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 - 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 - 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 .
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- Call map.[[Delete]](P).
- Return result.
10.4.4.6 CreateUnmappedArgumentsObject ( argumentsList )
The abstract operation CreateUnmappedArgumentsObject takes argument argumentsList. It performs the following steps when called:
- 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.
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 in10.4.4.1 .Set obj.[[DefineOwnProperty]] as specified in10.4.4.2 .Set obj.[[Get]] as specified in10.4.4.3 .Set obj.[[Set]] as specified in10.4.4.4 .Set obj.[[Delete]] as specified in10.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.
10.4.4.7.1 MakeArgGetter ( name, env )
The abstract operation MakeArgGetter takes arguments name (a String) and env (an
- Let steps be the steps of an ArgGetter function as specified below.
- Let length be the number of non-optional parameters of an ArgGetter function as specified below.
- Let getter be !
CreateBuiltinFunction (steps, length,"" , « [[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.
10.4.4.7.2 MakeArgSetter ( name, env )
The abstract operation MakeArgSetter takes arguments name (a String) and env (an
- Let steps be the steps of an ArgSetter function as specified below.
- Let length be the number of non-optional parameters of an ArgSetter function as specified below.
- Let setter be !
CreateBuiltinFunction (steps, length,"" , « [[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.
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
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]]:true }.
- Let value be !
- Let numericIndex be !
- Return
OrdinaryGetOwnProperty (O, P).
10.4.5.2 [[HasProperty]] ( P )
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 , return !IsValidIntegerIndex (O, numericIndex).
- Let numericIndex be !
- Return ?
OrdinaryHasProperty (O, P).
10.4.5.3 [[DefineOwnProperty]] ( P, Desc )
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 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
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).
10.4.5.5 [[Set]] ( P, V, Receiver )
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- 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
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 , 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 . Assert : O is anInteger-Indexed exotic object .- If
IsDetachedBuffer (O.[[ViewedArrayBuffer]]) isfalse , then - 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.
10.4.5.8 IntegerIndexedObjectCreate ( prototype )
The abstract operation IntegerIndexedObjectCreate takes argument prototype. It 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 in10.4.5.1 .Set A.[[HasProperty]] as specified in10.4.5.2 .Set A.[[DefineOwnProperty]] as specified in10.4.5.3 .Set A.[[Get]] as specified in10.4.5.4 .Set A.[[Set]] as specified in10.4.5.5 .Set A.[[Delete]] as specified in10.4.5.6 .Set A.[[OwnPropertyKeys]] as specified in10.4.5.7 .Set A.[[Prototype]] to prototype.- Return A.
10.4.5.9 IsValidIntegerIndex ( O, index )
The abstract operation IsValidIntegerIndex takes arguments O and index (a Number). It performs the following steps when called:
Assert : O is anInteger-Indexed exotic object .- 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 and index (a Number). It performs the following steps when called:
Assert : O is anInteger-Indexed exotic object .- 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 60 for arrayTypeName. - Let indexedPosition be (ℝ(index) × elementSize) + offset.
- Let elementType be the Element
Type value inTable 60 for arrayTypeName. - Return
GetValueFromBuffer (O.[[ViewedArrayBuffer]], indexedPosition, elementType,true ,Unordered ).
10.4.5.11 IntegerIndexedElementSet ( O, index, value )
The abstract operation IntegerIndexedElementSet takes arguments O, index (a Number), and value. It performs the following steps when called:
Assert : O is anInteger-Indexed exotic object .- 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 arrayTypeName be the String value of O.[[TypedArrayName]].
- Let elementSize be the Element Size value specified in
Table 60 for arrayTypeName. - Let indexedPosition be (ℝ(index) × elementSize) + offset.
- Let elementType be the Element
Type value inTable 60 for arrayTypeName. - Perform
SetValueInBuffer (O.[[ViewedArrayBuffer]], indexedPosition, elementType, numValue,true ,Unordered ).
- Return
NormalCompletion (undefined ).
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 property key is the
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 |
| [[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
10.4.6.1 [[SetPrototypeOf]] ( V )
The [[SetPrototypeOf]] internal method of a
- Return ?
SetImmutablePrototype (O, V).
10.4.6.2 [[IsExtensible]] ( )
The [[IsExtensible]] internal method of a
- Return
false .
10.4.6.3 [[PreventExtensions]] ( )
The [[PreventExtensions]] internal method of a
- Return
true .
10.4.6.4 [[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.5 [[DefineOwnProperty]] ( P, Desc )
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 Desc.[[Configurable]] is present and has value
true , returnfalse . - If Desc.[[Enumerable]] is present and has value
false , returnfalse . - If !
IsAccessorDescriptor (Desc) istrue , returnfalse . - If Desc.[[Writable]] is present and has value
false , returnfalse . - If Desc.[[Value]] is present, return
SameValue (Desc.[[Value]], current.[[Value]]). - Return
true .
10.4.6.6 [[HasProperty]] ( P )
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 .
10.4.6.7 [[Get]] ( P, Receiver )
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. - 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.8 [[Set]] ( P, V, Receiver )
The [[Set]] internal method of a
- Return
false .
10.4.6.9 [[Delete]] ( P )
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 .
10.4.6.10 [[OwnPropertyKeys]] ( )
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.
10.4.6.11 ModuleNamespaceCreate ( module, exports )
The abstract operation ModuleNamespaceCreate takes arguments module and exports. It is used to specify the creation of new module namespace exotic objects. It performs the following steps when called:
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 31 . - Let M be !
MakeBasicObject (internalSlotsList). Set M's essential internal methods to the definitions specified in10.4.6 .Set M.[[Prototype]] tonull .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 exotic objects, there is not a dedicated creation abstract operation provided for immutable prototype exotic objects. This is because they are only used by
10.4.7.1 [[SetPrototypeOf]] ( V )
The [[SetPrototypeOf]] internal method of an
- Return ?
SetImmutablePrototype (O, V).
10.4.7.2 SetImmutablePrototype ( O, V )
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 property key value, V is any
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]]().
- 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
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.
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]]().
- 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
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.
10.5.6 [[DefineOwnProperty]] ( P, Desc )
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.
10.5.7 [[HasProperty]] ( P )
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.
10.5.8 [[Get]] ( P, Receiver )
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.
10.5.9 [[Set]] ( P, V, Receiver )
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.
10.5.10 [[Delete]] ( P )
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.
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]]().
- 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 whose elements are 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
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 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.
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. It is used to specify the creation of new Proxy exotic objects. It performs the following steps when called:
- 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 in10.5 .- If
IsCallable (target) istrue , thenSet P.[[Call]] as specified in10.5.12 .- If
IsConstructor (target) istrue , then
Set P.[[ProxyTarget]] to target.Set P.[[ProxyHandler]] to handler.- Return P.