티스토리 수익 글 보기
- Toggle shortcuts help
? - Toggle “can call user code” annotations
u - Navigate to/from multipage
m - Jump to search box
/ - Toggle pinning of the current clause
p - Jump to the nth pin
1-9 - Jump to the 10th pin
0 - Jump to the most recent link target
`
10 Ordinary and Exotic Objects Behaviours
10.1 Ordinary Object Internal Methods and Internal Slots
All
Every
In the following algorithm descriptions, assume O is an
Each
10.1.1 [[GetPrototypeOf]] ( )
The [[GetPrototypeOf]] internal method of an
- Return
OrdinaryGetPrototypeOf (O).
10.1.1.1 OrdinaryGetPrototypeOf ( O )
The abstract operation OrdinaryGetPrototypeOf takes argument O (an Object) and returns an Object or
- Return O.[[Prototype]].
10.1.2 [[SetPrototypeOf]] ( V )
The [[SetPrototypeOf]] internal method of an
- Return
OrdinarySetPrototypeOf (O, V).
10.1.2.1 OrdinarySetPrototypeOf ( O, V )
The abstract operation OrdinarySetPrototypeOf takes arguments O (an Object) and V (an Object or
- Let current be O.[[Prototype]].
- If
SameValue (V, current) istrue , returntrue . - Let extensible be O.[[Extensible]].
- If extensible is
false , returnfalse . - Let p be V.
- Let done be
false . - Repeat, while done is
false ,- If p is
null , then- Set done to
true .
- Set done to
- Else if
SameValue (p, O) istrue , then- Return
false .
- Return
- Else,
- If p.[[GetPrototypeOf]] is not the
ordinary object internal method defined in10.1.1 , set done totrue . - Else, set p to p.[[Prototype]].
- If p.[[GetPrototypeOf]] is not the
- If p is
- Set O.[[Prototype]] to V.
- Return
true .
The loop in step
10.1.3 [[IsExtensible]] ( )
The [[IsExtensible]] internal method of an
- Return
OrdinaryIsExtensible (O).
10.1.3.1 OrdinaryIsExtensible ( O )
The abstract operation OrdinaryIsExtensible takes argument O (an Object) and returns a Boolean. It performs the following steps when called:
- Return O.[[Extensible]].
10.1.4 [[PreventExtensions]] ( )
The [[PreventExtensions]] internal method of an
- Return
OrdinaryPreventExtensions (O).
10.1.4.1 OrdinaryPreventExtensions ( O )
The abstract operation OrdinaryPreventExtensions takes argument O (an Object) and returns
- Set O.[[Extensible]] to
false . - Return
true .
10.1.5 [[GetOwnProperty]] ( P )
The [[GetOwnProperty]] internal method of an
- Return
OrdinaryGetOwnProperty (O, P).
10.1.5.1 OrdinaryGetOwnProperty ( O, P )
The abstract operation OrdinaryGetOwnProperty takes arguments O (an Object) and P (a
- If O does not have an own property with key P, return
undefined . - Let D be a newly created
Property Descriptor with no fields. - Let X be O‘s own property whose key is P.
- If X is a
data property , then- Set D.[[Value]] to the value of X‘s [[Value]] attribute.
- Set D.[[Writable]] to the value of X‘s [[Writable]] attribute.
- Else,
Assert : X is anaccessor property .- Set D.[[Get]] to the value of X‘s [[Get]] attribute.
- Set D.[[Set]] to the value of X‘s [[Set]] attribute.
- Set D.[[Enumerable]] to the value of X‘s [[Enumerable]] attribute.
- Set D.[[Configurable]] to the value of X‘s [[Configurable]] attribute.
- Return D.
10.1.6 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of an
- Return ?
OrdinaryDefineOwnProperty (O, P, Desc).
10.1.6.1 OrdinaryDefineOwnProperty ( O, P, Desc )
The abstract operation OrdinaryDefineOwnProperty takes arguments O (an Object), P (a
- Let current be ? O.[[GetOwnProperty]](P).
- Let extensible be ?
IsExtensible (O). - Return
ValidateAndApplyPropertyDescriptor (O, P, extensible, Desc, current).
10.1.6.2 IsCompatiblePropertyDescriptor ( Extensible, Desc, Current )
The abstract operation IsCompatiblePropertyDescriptor takes arguments Extensible (a Boolean), Desc (a
- Return
ValidateAndApplyPropertyDescriptor (undefined ,“” , Extensible, Desc, Current).
10.1.6.3 ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current )
The abstract operation ValidateAndApplyPropertyDescriptor takes arguments O (an Object or
Assert : P is aproperty key .- If current is
undefined , then- If extensible is
false , returnfalse . - If O is
undefined , returntrue . - If
IsAccessorDescriptor (Desc) istrue , then- Create an own
accessor property named P of object O whose [[Get]], [[Set]], [[Enumerable]], and [[Configurable]] attributes are set to the value of the corresponding field in Desc if Desc has that field, or to the attribute’sdefault value otherwise.
- Create an own
- Else,
- Create an own
data property named P of object O whose [[Value]], [[Writable]], [[Enumerable]], and [[Configurable]] attributes are set to the value of the corresponding field in Desc if Desc has that field, or to the attribute’sdefault value otherwise.
- Create an own
- Return
true .
- If extensible is
Assert : current is afully populated Property Descriptor .- If Desc does not have any fields, return
true . - If current.[[Configurable]] is
false , then- If Desc has a [[Configurable]] field and Desc.[[Configurable]] is
true , returnfalse . - If Desc has an [[Enumerable]] field and Desc.[[Enumerable]] is not current.[[Enumerable]], return
false . - If
IsGenericDescriptor (Desc) isfalse andIsAccessorDescriptor (Desc) is notIsAccessorDescriptor (current), returnfalse . - If
IsAccessorDescriptor (current) istrue , then - Else if current.[[Writable]] is
false , then- If Desc has a [[Writable]] field and Desc.[[Writable]] is
true , returnfalse . - NOTE:
SameValue returnstrue forNaN values which may be distinguishable by other means. Returning here ensures that any existing property of O remains unmodified. - If Desc has a [[Value]] field, return
SameValue (Desc.[[Value]], current.[[Value]]).
- If Desc has a [[Writable]] field and Desc.[[Writable]] is
- If Desc has a [[Configurable]] field and Desc.[[Configurable]] is
- If O is not
undefined , then- If
IsDataDescriptor (current) istrue andIsAccessorDescriptor (Desc) istrue , then- If Desc has a [[Configurable]] field, let configurable be Desc.[[Configurable]]; else let configurable be current.[[Configurable]].
- If Desc has an [[Enumerable]] field, let enumerable be Desc.[[Enumerable]]; else let enumerable be current.[[Enumerable]].
- Replace the property named P of object O with an
accessor property whose [[Configurable]] and [[Enumerable]] attributes are set to configurable and enumerable, respectively, and whose [[Get]] and [[Set]] attributes are set to the value of the corresponding field in Desc if Desc has that field, or to the attribute’sdefault value otherwise.
- Else if
IsAccessorDescriptor (current) istrue andIsDataDescriptor (Desc) istrue , then- If Desc has a [[Configurable]] field, let configurable be Desc.[[Configurable]]; else let configurable be current.[[Configurable]].
- If Desc has an [[Enumerable]] field, let enumerable be Desc.[[Enumerable]]; else let enumerable be current.[[Enumerable]].
- Replace the property named P of object O with a
data property whose [[Configurable]] and [[Enumerable]] attributes are set to configurable and enumerable, respectively, and whose [[Value]] and [[Writable]] attributes are set to the value of the corresponding field in Desc if Desc has that field, or to the attribute’sdefault value otherwise.
- Else,
- For each field of Desc, set the corresponding attribute of the property named P of object O to the value of the field.
- If
- Return
true .
10.1.7 [[HasProperty]] ( P )
The [[HasProperty]] internal method of an
- Return ?
OrdinaryHasProperty (O, P).
10.1.7.1 OrdinaryHasProperty ( O, P )
The abstract operation OrdinaryHasProperty takes arguments O (an Object) and P (a
- Let hasOwn be ? O.[[GetOwnProperty]](P).
- If hasOwn is not
undefined , returntrue . - Let parent be ? O.[[GetPrototypeOf]]().
- If parent is not
null , then- Return ? parent.[[HasProperty]](P).
- Return
false .
10.1.8 [[Get]] ( P, Receiver )
The [[Get]] internal method of an
- Return ?
OrdinaryGet (O, P, Receiver).
10.1.8.1 OrdinaryGet ( O, P, Receiver )
The abstract operation OrdinaryGet takes arguments O (an Object), P (a
- Let desc be ? O.[[GetOwnProperty]](P).
- If desc is
undefined , then- Let parent be ? O.[[GetPrototypeOf]]().
- If parent is
null , returnundefined . - Return ? parent.[[Get]](P, Receiver).
- If
IsDataDescriptor (desc) istrue , return desc.[[Value]]. Assert :IsAccessorDescriptor (desc) istrue .- Let getter be desc.[[Get]].
- If getter is
undefined , returnundefined . - Return ?
Call (getter, Receiver).
10.1.9 [[Set]] ( P, V, Receiver )
The [[Set]] internal method of an
- Return ?
OrdinarySet (O, P, V, Receiver).
10.1.9.1 OrdinarySet ( O, P, V, Receiver )
The abstract operation OrdinarySet takes arguments O (an Object), P (a
- Let ownDesc be ? O.[[GetOwnProperty]](P).
- Return ?
OrdinarySetWithOwnDescriptor (O, P, V, Receiver, ownDesc).
10.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc )
The abstract operation OrdinarySetWithOwnDescriptor takes arguments O (an Object), P (a
- If ownDesc is
undefined , then- Let parent be ? O.[[GetPrototypeOf]]().
- If parent is not
null , then- Return ? parent.[[Set]](P, V, Receiver).
- Else,
- Set ownDesc to the PropertyDescriptor { [[Value]]:
undefined , [[Writable]]:true , [[Enumerable]]:true , [[Configurable]]:true }.
- Set ownDesc to the PropertyDescriptor { [[Value]]:
- If
IsDataDescriptor (ownDesc) istrue , then- If ownDesc.[[Writable]] is
false , returnfalse . - If Receiver
is not an Object , returnfalse . - Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P).
- If existingDescriptor is not
undefined , then- If
IsAccessorDescriptor (existingDescriptor) istrue , returnfalse . - If existingDescriptor.[[Writable]] is
false , returnfalse . - Let valueDesc be the PropertyDescriptor { [[Value]]: V }.
- Return ? Receiver.[[DefineOwnProperty]](P, valueDesc).
- If
- Else,
Assert : Receiver does not currently have a property P.- Return ?
CreateDataProperty (Receiver, P, V).
- If ownDesc.[[Writable]] is
Assert :IsAccessorDescriptor (ownDesc) istrue .- Let setter be ownDesc.[[Set]].
- If setter is
undefined , returnfalse . - Perform ?
Call (setter, Receiver, « V »). - Return
true .
10.1.10 [[Delete]] ( P )
The [[Delete]] internal method of an
- Return ?
OrdinaryDelete (O, P).
10.1.10.1 OrdinaryDelete ( O, P )
The abstract operation OrdinaryDelete takes arguments O (an Object) and P (a
- Let desc be ? O.[[GetOwnProperty]](P).
- If desc is
undefined , returntrue . - If desc.[[Configurable]] is
true , then- Remove the own property with name P from O.
- Return
true .
- Return
false .
10.1.11 [[OwnPropertyKeys]] ( )
The [[OwnPropertyKeys]] internal method of an
- Return
OrdinaryOwnPropertyKeys (O).
10.1.11.1 OrdinaryOwnPropertyKeys ( O )
The abstract operation OrdinaryOwnPropertyKeys takes argument O (an Object) and returns a
- Let keys be a new empty
List . - For each own
property key P of O such that P is anarray index , in ascending numeric index order, do- Append P to keys.
- For each own
property key P of O such that Pis a String and P is not anarray index , in ascending chronological order of property creation, do- Append P to keys.
- For each own
property key P of O such that Pis a Symbol , in ascending chronological order of property creation, do- Append P to 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, set internalSlotsList to the
list-concatenation of internalSlotsList and additionalInternalSlotsList. - 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 (a
Assert : intrinsicDefaultProto is this specification’s name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object.- Let proto be ?
GetPrototypeFromConstructor (constructor, intrinsicDefaultProto). - If internalSlotsList is present, let slotsList be internalSlotsList.
- Else, let slotsList be a new empty
List . - Return
OrdinaryObjectCreate (proto, slotsList).
10.1.14 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
The abstract operation GetPrototypeFromConstructor takes arguments constructor (a
Assert : intrinsicDefaultProto is this specification’s name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object.- Let proto be ?
Get (constructor,“prototype” ). - If proto
is not an 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 (an
- If O
is not an Object , throw aTypeError exception. - If O does not have an internalSlot internal slot, throw a
TypeError exception. - Return
unused .
10.2 ECMAScript Function Objects
ECMAScript
In addition to [[Extensible]] and [[Prototype]], ECMAScript
| Internal Slot | Type | Description |
|---|---|---|
| [[Environment]] |
an |
The |
| [[PrivateEnvironment]] |
a |
The |
| [[FormalParameters]] |
a |
The root parse node of the source text that defines the function’s formal parameter list. |
| [[ECMAScriptCode]] |
a |
The root parse node of the source text that defines the function’s body. |
| [[ConstructorKind]] |
|
Whether or not the function is a derived class |
| [[Realm]] |
a |
The |
| [[ScriptOrModule]] |
a |
The script or module in which the function was created. |
| [[ThisMode]] |
|
Defines how this references are interpreted within the formal parameters and code body of the function. this refers to the |
| [[Strict]] | a Boolean |
|
| [[HomeObject]] | an Object |
If the function uses super, this is the object whose [[GetPrototypeOf]] provides the object where super property lookups begin.
|
| [[SourceText]] | a sequence of Unicode code points |
The |
| [[Fields]] |
a |
If the function is a class, this is a list of |
| [[PrivateMethods]] |
a |
If the function is a class, this is a list representing the non-static private methods and accessors of the class. |
| [[ClassFieldInitializerName]] |
a String, a Symbol, a |
If the function is created as the initializer of a class field, the name to use for |
| [[IsClassConstructor]] | a Boolean |
Indicates whether the function is a class |
All ECMAScript
10.2.1 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method of an ECMAScript
- Let callerContext be the
running execution context . - Let calleeContext be
PrepareForOrdinaryCall (F,undefined ). Assert : calleeContext is now therunning execution context .- If F.[[IsClassConstructor]] is
true , then- Let error be a newly created
TypeError object. - NOTE: error is created in calleeContext with F‘s associated
Realm Record . - Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - Return
ThrowCompletion (error).
- Let error be a newly created
- Perform
OrdinaryCallBindThis (F, calleeContext, thisArgument). - Let result be
Completion (OrdinaryCallEvaluateBody (F, argumentsList)). - Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - If result is a
return completion , return result.[[Value]]. Assert : result is athrow completion .- Return ? result.
When calleeContext is removed from the
10.2.1.1 PrepareForOrdinaryCall ( F, newTarget )
The abstract operation PrepareForOrdinaryCall takes arguments F (an ECMAScript
- Let callerContext be the
running execution context . - Let calleeContext be a new
ECMAScript code execution context . - Set the Function of calleeContext to F.
- Let calleeRealm be F.[[Realm]].
- Set the
Realm of calleeContext to calleeRealm. - Set the ScriptOrModule of calleeContext to F.[[ScriptOrModule]].
- Let localEnv be
NewFunctionEnvironment (F, newTarget). - Set the LexicalEnvironment of calleeContext to localEnv.
- Set the VariableEnvironment of calleeContext to localEnv.
- Set the PrivateEnvironment of calleeContext to F.[[PrivateEnvironment]].
- If callerContext is not already suspended, suspend callerContext.
- Push calleeContext onto the
execution context stack ; calleeContext is now therunning execution context . - NOTE: Any exception objects produced after this point are associated with calleeRealm.
- Return calleeContext.
10.2.1.2 OrdinaryCallBindThis ( F, calleeContext, thisArgument )
The abstract operation OrdinaryCallBindThis takes arguments F (an ECMAScript
- Let thisMode be F.[[ThisMode]].
- If thisMode is
lexical , returnunused . - Let calleeRealm be F.[[Realm]].
- Let localEnv be the LexicalEnvironment of calleeContext.
- If thisMode is
strict , then- Let thisValue be thisArgument.
- Else,
- If thisArgument is either
undefined ornull , then- Let globalEnv be calleeRealm.[[GlobalEnv]].
Assert : globalEnv is aGlobal Environment Record .- Let thisValue be globalEnv.[[GlobalThisValue]].
- Else,
- If thisArgument is either
Assert : localEnv is aFunction Environment Record .Assert : The next step never returns anabrupt completion because localEnv.[[ThisBindingStatus]] is notinitialized .- Perform !
BindThisValue (localEnv, thisValue). - Return
unused .
10.2.1.3 Runtime Semantics: EvaluateBody
The
- Return ?
EvaluateFunctionBody ofFunctionBody with arguments functionObject and argumentsList.
- Return ?
EvaluateConciseBody ofConciseBody with arguments functionObject and argumentsList.
- Return ?
EvaluateGeneratorBody ofGeneratorBody with arguments functionObject and argumentsList.
- Return ?
EvaluateAsyncGeneratorBody ofAsyncGeneratorBody with arguments functionObject and argumentsList.
- Return ?
EvaluateAsyncFunctionBody ofAsyncFunctionBody with arguments functionObject and argumentsList.
- Return ?
EvaluateAsyncConciseBody ofAsyncConciseBody with arguments functionObject and argumentsList.
Assert : argumentsList is empty.Assert : functionObject.[[ClassFieldInitializerName]] is notempty .- If
IsAnonymousFunctionDefinition (AssignmentExpression ) istrue , then- Let value be ?
NamedEvaluation ofInitializer with argument functionObject.[[ClassFieldInitializerName]].
- Let value be ?
- Else,
- Let rhs be ?
Evaluation ofAssignmentExpression . - Let value be ?
GetValue (rhs).
- Let rhs be ?
- Return
ReturnCompletion (value).
Even though field initializers constitute a function boundary, calling
Assert : argumentsList is empty.- Return ?
EvaluateClassStaticBlockBody ofClassStaticBlockBody with argument functionObject.
10.2.1.4 OrdinaryCallEvaluateBody ( F, argumentsList )
The abstract operation OrdinaryCallEvaluateBody takes arguments F (an ECMAScript
- Return ?
EvaluateBody of F.[[ECMAScriptCode]] with arguments F and argumentsList.
10.2.2 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method of an ECMAScript
- Let callerContext be the
running execution context . - Let kind be F.[[ConstructorKind]].
- If kind is
base , then- Let thisArgument be ?
OrdinaryCreateFromConstructor (newTarget,“%Object.prototype%” ).
- Let thisArgument be ?
- Let calleeContext be
PrepareForOrdinaryCall (F, newTarget). Assert : calleeContext is now therunning execution context .- If kind is
base , then- Perform
OrdinaryCallBindThis (F, calleeContext, thisArgument). - Let initializeResult be
Completion (InitializeInstanceElements (thisArgument, F)). - If initializeResult is an
abrupt completion , then- Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - Return ? initializeResult.
- Remove calleeContext from the
- Perform
- Let constructorEnv be the LexicalEnvironment of calleeContext.
- Let result be
Completion (OrdinaryCallEvaluateBody (F, argumentsList)). - Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - If result is a
throw completion , then- Return ? result.
Assert : result is areturn completion .- If result.[[Value]]
is an Object , return result.[[Value]]. - If kind is
base , return thisArgument. - If result.[[Value]] is not
undefined , throw aTypeError exception. - Let thisBinding be ? constructorEnv.GetThisBinding().
Assert : thisBindingis an Object .- Return thisBinding.
10.2.3 OrdinaryFunctionCreate ( functionPrototype, sourceText, ParameterList, Body, thisMode, env, privateEnv )
The abstract operation OrdinaryFunctionCreate takes arguments functionPrototype (an Object), sourceText (a sequence of Unicode code points), ParameterList (a
- Let internalSlotsList be the internal slots listed in
Table 28 . - Let F be
OrdinaryObjectCreate (functionPrototype, internalSlotsList). - Set F.[[Call]] to the definition specified in
10.2.1 . - Set F.[[SourceText]] to sourceText.
- Set F.[[FormalParameters]] to ParameterList.
- Set F.[[ECMAScriptCode]] to Body.
- Let Strict be
IsStrict (Body). - Set F.[[Strict]] to Strict.
- If thisMode is
lexical-this , set F.[[ThisMode]] tolexical . - Else if Strict is
true , set F.[[ThisMode]] tostrict . - Else, set F.[[ThisMode]] to
global . - Set F.[[IsClassConstructor]] to
false . - Set F.[[Environment]] to env.
- Set F.[[PrivateEnvironment]] to privateEnv.
- Set F.[[ScriptOrModule]] to
GetActiveScriptOrModule (). - Set F.[[Realm]] to
the current Realm Record . - Set F.[[HomeObject]] to
undefined . - Set F.[[Fields]] to a new empty
List . - Set F.[[PrivateMethods]] to a new empty
List . - Set F.[[ClassFieldInitializerName]] to
empty . - Let len be the
ExpectedArgumentCount of ParameterList. - Perform
SetFunctionLength (F, len). - Return F.
10.2.4 AddRestrictedFunctionProperties ( F, realm )
The abstract operation AddRestrictedFunctionProperties takes arguments F (a
Assert : realm.[[Intrinsics]].[[%ThrowTypeError% ]] exists and has been initialized.- Let thrower be realm.[[Intrinsics]].[[
%ThrowTypeError% ]]. - Perform !
DefinePropertyOrThrow (F,“caller” , PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]:false , [[Configurable]]:true }). - Perform !
DefinePropertyOrThrow (F,“arguments” , PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]:false , [[Configurable]]:true }). - Return
unused .
10.2.4.1 %ThrowTypeError% ( )
This function is the %ThrowTypeError% intrinsic object.
It is an anonymous built-in
It performs the following steps when called:
- Throw a
TypeError exception.
The value of the [[Extensible]] internal slot of this function is
The
The
10.2.5 MakeConstructor ( F [ , writablePrototype [ , prototype ] ] )
The abstract operation MakeConstructor takes argument F (an ECMAScript
- If F is an ECMAScript
function object , thenAssert :IsConstructor (F) isfalse .Assert : F is an extensible object that does not have a“prototype” own property.- Set F.[[Construct]] to the definition specified in
10.2.2 .
- Else,
- Set F.[[Construct]] to the definition specified in
10.3.2 .
- Set F.[[Construct]] to the definition specified in
- Set F.[[ConstructorKind]] to
base . - If writablePrototype is not present, set writablePrototype to
true . - If prototype is not present, then
- Set prototype to
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
DefinePropertyOrThrow (prototype,“constructor” , PropertyDescriptor { [[Value]]: F, [[Writable]]: writablePrototype, [[Enumerable]]:false , [[Configurable]]:true }).
- Set prototype to
- Perform !
DefinePropertyOrThrow (F,“prototype” , PropertyDescriptor { [[Value]]: prototype, [[Writable]]: writablePrototype, [[Enumerable]]:false , [[Configurable]]:false }). - Return
unused .
10.2.6 MakeClassConstructor ( F )
The abstract operation MakeClassConstructor takes argument F (an ECMAScript
Assert : F.[[IsClassConstructor]] isfalse .- Set F.[[IsClassConstructor]] to
true . - Return
unused .
10.2.7 MakeMethod ( F, homeObject )
The abstract operation MakeMethod takes arguments F (an ECMAScript
Assert : homeObject is anordinary object .- Set F.[[HomeObject]] to homeObject.
- Return
unused .
10.2.8 DefineMethodProperty ( homeObject, key, closure, enumerable )
The abstract operation DefineMethodProperty takes arguments homeObject (an Object), key (a
Assert : homeObject is an ordinary, extensible object.- If key is a
Private Name , then- Return
PrivateElement { [[Key]]: key, [[Kind]]:method , [[Value]]: closure }.
- Return
- Else,
- Let desc be the PropertyDescriptor { [[Value]]: closure, [[Writable]]:
true , [[Enumerable]]: enumerable, [[Configurable]]:true }. - Perform ?
DefinePropertyOrThrow (homeObject, key, desc). - NOTE:
DefinePropertyOrThrow only returns anabrupt completion when attempting to define a class static method whose key is“prototype” . - Return
unused .
- Let desc be the PropertyDescriptor { [[Value]]: closure, [[Writable]]:
10.2.9 SetFunctionName ( F, name [ , prefix ] )
The abstract operation SetFunctionName takes arguments F (a
Assert : F is an extensible object that does not have a“name” own property.- If name
is a Symbol , then- Let description be name.[[Description]].
- If description is
undefined , set name to the empty String. - Else, set name to the
string-concatenation of“[“ , description, and“]” .
- Else if name is a
Private Name , then- Set name to name.[[Description]].
- If F has an [[InitialName]] internal slot, then
- Set F.[[InitialName]] to name.
- If prefix is present, then
- Set name to the
string-concatenation of prefix, the code unit 0x0020 (SPACE), and name. - If F has an [[InitialName]] internal slot, then
- NOTE: The choice in the following step is made independently each time this Abstract Operation is invoked.
- Optionally, set F.[[InitialName]] to name.
- Set name to the
- Perform !
DefinePropertyOrThrow (F,“name” , PropertyDescriptor { [[Value]]: name, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:true }). - Return
unused .
10.2.10 SetFunctionLength ( F, length )
The abstract operation SetFunctionLength takes arguments F (a
Assert : F is an extensible object that does not have a“length” own property.- Perform !
DefinePropertyOrThrow (F,“length” , PropertyDescriptor { [[Value]]:𝔽 (length), [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:true }). - Return
unused .
10.2.11 FunctionDeclarationInstantiation ( func, argumentsList )
The abstract operation FunctionDeclarationInstantiation takes arguments func (an ECMAScript
When an
It performs the following steps when called:
- Let calleeContext be the
running execution context . - Let code be func.[[ECMAScriptCode]].
- Let strict be func.[[Strict]].
- Let formals be func.[[FormalParameters]].
- Let parameterNames be the
BoundNames of formals. - If parameterNames has any duplicate entries, let hasDuplicates be
true ; otherwise let hasDuplicates befalse . - Let simpleParameterList be
IsSimpleParameterList of formals. - Let hasParameterExpressions be
ContainsExpression of formals. - Let varNames be the
VarDeclaredNames of code. - Let varDeclarations be the
VarScopedDeclarations of code. - Let lexicalNames be the
LexicallyDeclaredNames of code. - Let functionNames be a new empty
List . - Let functionsToInitialize be a new empty
List . - For each element d of varDeclarations, in reverse
List order, do- If d is neither a
VariableDeclaration nor aForBinding nor aBindingIdentifier , thenAssert : d is either aFunctionDeclaration , aGeneratorDeclaration , anAsyncFunctionDeclaration , or anAsyncGeneratorDeclaration .- Let fn be the sole element of the
BoundNames of d. - If functionNames does not contain fn, then
- Insert fn as the first element of functionNames.
- NOTE: If there are multiple function declarations for the same name, the last declaration is used.
- Insert d as the first element of functionsToInitialize.
- If d is neither a
- Let argumentsObjectNeeded be
true . - If func.[[ThisMode]] is
lexical , then- NOTE: Arrow functions never have an arguments object.
- Set argumentsObjectNeeded to
false .
- Else if parameterNames contains
“arguments” , then- Set argumentsObjectNeeded to
false .
- Set argumentsObjectNeeded to
- Else if hasParameterExpressions is
false , then- If functionNames contains
“arguments” or lexicalNames contains“arguments” , then- Set argumentsObjectNeeded to
false .
- Set argumentsObjectNeeded to
- If functionNames contains
- If strict is
true or hasParameterExpressions isfalse , then- NOTE: Only a single
Environment Record is needed for the parameters, since calls toevalinstrict mode code cannot create new bindings which are visible outside of theeval. - Let env be the LexicalEnvironment of calleeContext.
- NOTE: Only a single
- Else,
- NOTE: A separate
Environment Record is needed to ensure that bindings created bydirect eval calls in the formal parameter list are outside the environment where parameters are declared. - Let calleeEnv be the LexicalEnvironment of calleeContext.
- Let env be
NewDeclarativeEnvironment (calleeEnv). Assert : The VariableEnvironment of calleeContext and calleeEnv are the sameEnvironment Record .- Set the LexicalEnvironment of calleeContext to env.
- NOTE: A separate
- For each String paramName of parameterNames, do
- Let alreadyDeclared be ! env.HasBinding(paramName).
- NOTE:
Early errors ensure that duplicate parameter names can only occur innon-strict functions that do not have parameter default values or rest parameters. - If alreadyDeclared is
false , then- Perform ! env.CreateMutableBinding(paramName,
false ). - If hasDuplicates is
true , then- Perform ! env.InitializeBinding(paramName,
undefined ).
- Perform ! env.InitializeBinding(paramName,
- Perform ! env.CreateMutableBinding(paramName,
- If argumentsObjectNeeded is
true , then- If strict is
true or simpleParameterList isfalse , then- Let ao be
CreateUnmappedArgumentsObject (argumentsList).
- Let ao be
- Else,
- NOTE: A mapped argument object is only provided for
non-strict functions that don’t have a rest parameter, any parameter default value initializers, or any destructured parameters. - Let ao be
CreateMappedArgumentsObject (func, formals, argumentsList, env).
- NOTE: A mapped argument object is only provided for
- If strict is
true , then- Perform ! env.CreateImmutableBinding(
“arguments” ,false ). - NOTE: In
strict mode code early errors prevent attempting to assign to this binding, so its mutability is not observable.
- Perform ! env.CreateImmutableBinding(
- Else,
- Perform ! env.CreateMutableBinding(
“arguments” ,false ).
- Perform ! env.CreateMutableBinding(
- Perform ! env.InitializeBinding(
“arguments” , ao). - Let parameterBindings be the
list-concatenation of parameterNames and «“arguments” ».
- If strict is
- Else,
- Let parameterBindings be parameterNames.
- Let iteratorRecord be
CreateListIteratorRecord (argumentsList). - If hasDuplicates is
true , then- Let usedEnv be
undefined .
- Let usedEnv be
- Else,
- Let usedEnv be env.
- NOTE: The following step cannot return a
ReturnCompletion because the only way such a completion can arise in expression position is by use ofYieldExpression , which is forbidden in parameter lists by Early Error rules in15.5.1 and15.6.1 . - Perform ?
IteratorBindingInitialization of formals with arguments iteratorRecord and usedEnv. - 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 instantiatedVarNames does not contain n, then
- Append n to instantiatedVarNames.
- Perform ! env.CreateMutableBinding(n,
false ). - Perform ! env.InitializeBinding(n,
undefined ).
- If instantiatedVarNames does not contain n, 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 instantiatedVarNames does not contain n, then
- Append n to instantiatedVarNames.
- Perform ! varEnv.CreateMutableBinding(n,
false ). - If parameterBindings does not contain n, or if functionNames contains n, then
- Let initialValue be
undefined .
- Let initialValue be
- Else,
- Let initialValue be ! env.GetBindingValue(n,
false ).
- Let initialValue be ! env.GetBindingValue(n,
- Perform ! varEnv.InitializeBinding(n, initialValue).
- NOTE: A var with the same name as a formal parameter initially has the same value as the corresponding initialized parameter.
- If instantiatedVarNames does not contain n, then
- NOTE: A separate
- If strict is
true , then- Let lexEnv be varEnv.
- Else,
- If the
host is a web browser or otherwise supportsBlock-Level Function Declarations Web Legacy Compatibility Semantics , then- For each
FunctionDeclaration f that is directly contained in theStatementList of anyBlock ,CaseClause , orDefaultClause x such that codeContains x istrue , do- Let F be the
StringValue of theBindingIdentifier of f. - If replacing the
FunctionDeclaration f with aVariableStatement that has F as aBindingIdentifier would not produce any Early Errors for func and parameterNames does not contain F, then- NOTE: A var binding for F is only instantiated here if it is neither a VarDeclaredName, the name of a formal parameter, or another
FunctionDeclaration . - If instantiatedVarNames does not contain F and F is not
“arguments” , then- Perform ! varEnv.CreateMutableBinding(F,
false ). - Perform ! varEnv.InitializeBinding(F,
undefined ). - Append F to instantiatedVarNames.
- Perform ! varEnv.CreateMutableBinding(F,
- When the
FunctionDeclaration f is evaluated, perform the following steps in place of theFunctionDeclaration Evaluation algorithm provided in15.2.6 :- Let fEnv be the
running execution context ‘s VariableEnvironment. - Let bEnv be the
running execution context ‘s LexicalEnvironment. - Let fObj be ! bEnv.GetBindingValue(F,
false ). - Perform ! fEnv.SetMutableBinding(F, fObj,
false ). - Return
unused .
- Let fEnv be the
- NOTE: A var binding for F is only instantiated here if it is neither a VarDeclaredName, the name of a formal parameter, or another
- Let F be the
- For each
- Let lexEnv be
NewDeclarativeEnvironment (varEnv). - NOTE:
Non-strict functions use a separateEnvironment Record for top-level lexical declarations so that adirect eval can determine whether any var scoped declarations introduced by the eval code conflict with pre-existing top-level lexically scoped declarations. This is not needed forstrict functions because a strictdirect eval always places all declarations into a newEnvironment Record .
- If the
- Set the LexicalEnvironment of calleeContext to lexEnv.
- Let lexDeclarations be the
LexicallyScopedDeclarations of code. - For each element d of lexDeclarations, do
- NOTE: A lexically declared name cannot be the same as a function/generator declaration, formal parameter, or a var name. Lexically declared names are only instantiated here but not initialized.
- For each element dn of the
BoundNames of d, do- If
IsConstantDeclaration of d istrue , then- Perform ! lexEnv.CreateImmutableBinding(dn,
true ).
- Perform ! lexEnv.CreateImmutableBinding(dn,
- Else,
- Perform ! lexEnv.CreateMutableBinding(dn,
false ).
- Perform ! lexEnv.CreateMutableBinding(dn,
- If
- Let privateEnv be the PrivateEnvironment of calleeContext.
- For each
Parse Node f of functionsToInitialize, do- Let fn be the sole element of the
BoundNames of f. - Let fo be
InstantiateFunctionObject of f with arguments lexEnv and privateEnv. - Perform ! varEnv.SetMutableBinding(fn, fo,
false ).
- Let fn be the sole element of the
- Return
unused .
10.3 Built-in Function Objects
A built-in
In addition to the internal slots required of every
- [[Realm]], a
Realm Record that represents therealm in which the function was created. - [[InitialName]], a String that is the initial name of the function. It is used by
20.2.3.5 . - [[Async]], a Boolean that indicates whether the function has async function call and construct behaviour in
BuiltinCallOrConstruct .
The initial value of a built-in
A built-in
A built-in
An implementation may provide additional built-in
10.3.1 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method of a built-in
- Return ?
BuiltinCallOrConstruct (F, thisArgument, argumentsList,undefined ).
10.3.2 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method of a built-in
- Let result be ?
BuiltinCallOrConstruct (F,uninitialized , argumentsList, newTarget). Assert : resultis an Object .- Return result.
10.3.3 BuiltinCallOrConstruct ( F, thisArgument, argumentsList, newTarget )
The abstract operation BuiltinCallOrConstruct takes arguments F (a built-in
- Let callerContext be the
running execution context . - If callerContext is not already suspended, suspend callerContext.
- Let calleeContext be a new
execution context . - Set the Function of calleeContext to F.
- Let calleeRealm be F.[[Realm]].
- Set the
Realm of calleeContext to calleeRealm. - Set the ScriptOrModule of calleeContext to
null . - Perform any necessary
implementation-defined initialization of calleeContext. - Push calleeContext onto the
execution context stack ; calleeContext is now therunning execution context . - If F.[[Async]] is
true , then- Let promiseCapability be !
NewPromiseCapability (%Promise% ). - Let resultsClosure be a new
Abstract Closure with no parameters that captures F, thisArgument, argumentsList, and newTarget and performs the following steps when called:- Let result be the
Completion Record that is the result of evaluating F in a manner that conforms to the specification of F. If thisArgument isuninitialized , thethis value is uninitialized; otherwise thisArgument provides thethis value. argumentsList provides the named parameters. newTarget provides the NewTarget value. - NOTE: If F is defined in this document, “the specification of F” is the behaviour specified for it via algorithm steps or other means.
- Return
Completion (result).
- Let result be the
- Perform
AsyncFunctionStart (promiseCapability, resultsClosure). - Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - Return promiseCapability.[[Promise]].
- Let promiseCapability be !
- Else,
- Let result be the
Completion Record that is the result of evaluating F in a manner that conforms to the specification of F. If thisArgument isuninitialized , thethis value is uninitialized; otherwise thisArgument provides thethis value. argumentsList provides the named parameters. newTarget provides the NewTarget value. - NOTE: If F is defined in this document, “the specification of F” is the behaviour specified for it via algorithm steps or other means.
- Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - Return ? result.
- Let result be the
When calleeContext is removed from the
10.3.4 CreateBuiltinFunction ( behaviour, length, name, additionalInternalSlotsList [ , realm [ , prototype [ , prefix [ , async ] ] ] ] )
The abstract operation CreateBuiltinFunction takes arguments behaviour (an
- If realm is not present, set realm to
the current Realm Record . - If prototype is not present, set prototype to realm.[[Intrinsics]].[[
%Function.prototype% ]]. - If async is not present, set async to
false . - Let internalSlotsList be a
List containing the names of all the internal slots that10.3 requires for the built-infunction object that is about to be created. - Append to internalSlotsList the elements of additionalInternalSlotsList.
- Let func be a new built-in
function object that, when called, performs the action described by behaviour using the provided arguments as the values of the corresponding parameters specified by behaviour. The newfunction object has internal slots whose names are the elements of internalSlotsList, and an [[InitialName]] internal slot. - Set func.[[Async]] to async.
- Set func.[[Prototype]] to prototype.
- Set func.[[Extensible]] to
true . - Set func.[[Realm]] to realm.
- Set func.[[InitialName]] to
null . - Perform
SetFunctionLength (func, length). - If prefix is not present, then
- Perform
SetFunctionName (func, name).
- Perform
- Else,
- Perform
SetFunctionName (func, name, prefix).
- Perform
- Return func.
Each built-in function defined in this specification is created by calling the CreateBuiltinFunction abstract operation.
10.4 Built-in Exotic Object Internal Methods and Slots
This specification defines several kinds of built-in
10.4.1 Bound Function Exotic Objects
A
An object is a bound function exotic object if its [[Call]] and (if applicable) [[Construct]] internal methods use the following implementations, and its other essential internal methods use the definitions found in
| Internal Slot | Type | Description |
|---|---|---|
| [[BoundTargetFunction]] | a callable Object |
The wrapped |
| [[BoundThis]] |
an |
The value that is always passed as the |
| [[BoundArguments]] |
a |
A list of values whose elements are used as the first arguments to any call to the wrapped function. |
10.4.1.1 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method of a
- Let target be F.[[BoundTargetFunction]].
- Let boundThis be F.[[BoundThis]].
- Let boundArgs be F.[[BoundArguments]].
- Let args be the
list-concatenation of boundArgs and argumentsList. - Return ?
Call (target, boundThis, args).
10.4.1.2 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method of a
- Let target be F.[[BoundTargetFunction]].
Assert :IsConstructor (target) istrue .- Let boundArgs be F.[[BoundArguments]].
- Let args be the
list-concatenation of boundArgs and argumentsList. - If
SameValue (F, newTarget) istrue , set newTarget to target. - Return ?
Construct (target, args, newTarget).
10.4.1.3 BoundFunctionCreate ( targetFunction, boundThis, boundArgs )
The abstract operation BoundFunctionCreate takes arguments targetFunction (a
- Let proto be ? targetFunction.[[GetPrototypeOf]]().
- Let internalSlotsList be the
list-concatenation of « [[Prototype]], [[Extensible]] » and the internal slots listed inTable 29 . - Let obj be
MakeBasicObject (internalSlotsList). - Set obj.[[Prototype]] to proto.
- Set obj.[[Call]] as specified in
10.4.1.1 . - If
IsConstructor (targetFunction) istrue , then- Set obj.[[Construct]] as specified in
10.4.1.2 .
- Set obj.[[Construct]] as specified in
- Set obj.[[BoundTargetFunction]] to targetFunction.
- Set obj.[[BoundThis]] to boundThis.
- Set obj.[[BoundArguments]] to boundArgs.
- Return obj.
10.4.2 Array Exotic Objects
An Array is an
An object is an Array exotic object (or simply, an Array) if its [[DefineOwnProperty]] internal method uses the following implementation, and its other essential internal methods use the definitions found in
10.4.2.1 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of an
- If P is
“length” , then- Return ?
ArraySetLength (A, Desc).
- Return ?
- Else if P is an
array index , then- Let lengthDesc be
OrdinaryGetOwnProperty (A,“length” ). Assert : lengthDesc is notundefined .Assert :IsDataDescriptor (lengthDesc) istrue .Assert : lengthDesc.[[Configurable]] isfalse .- Let length be lengthDesc.[[Value]].
Assert : length is a non-negativeintegral Number .- Let index be !
ToUint32 (P). - If index ≥ length and lengthDesc.[[Writable]] is
false , returnfalse . - Let succeeded be !
OrdinaryDefineOwnProperty (A, P, Desc). - If succeeded is
false , returnfalse . - If index ≥ length, then
- Set lengthDesc.[[Value]] to index +
1 𝔽. - Set succeeded to !
OrdinaryDefineOwnProperty (A,“length” , lengthDesc). Assert : succeeded istrue .
- Set lengthDesc.[[Value]] to index +
- Return
true .
- Let lengthDesc be
- Return ?
OrdinaryDefineOwnProperty (A, P, Desc).
10.4.2.2 ArrayCreate ( length [ , proto ] )
The abstract operation ArrayCreate takes argument length (a non-negative
- If length > 232 – 1, throw a
RangeError exception. - If proto is not present, set proto to
%Array.prototype% . - Let A be
MakeBasicObject (« [[Prototype]], [[Extensible]] »). - Set A.[[Prototype]] to proto.
- Set A.[[DefineOwnProperty]] as specified in
10.4.2.1 . - Perform !
OrdinaryDefineOwnProperty (A,“length” , PropertyDescriptor { [[Value]]:𝔽 (length), [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Return A.
10.4.2.3 ArraySpeciesCreate ( originalArray, length )
The abstract operation ArraySpeciesCreate takes arguments originalArray (an Object) 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
- Let thisRealm be
- If C
is an Object , then- Set C to ?
Get (C,%Symbol.species% ). - If C is
null , set C toundefined .
- Set C to ?
- If C is
undefined , return ?ArrayCreate (length). - If
IsConstructor (C) isfalse , throw aTypeError exception. - Return ?
Construct (C, «𝔽 (length) »).
If originalArray was created using the standard built-in Array Array.prototype methods that now are defined using ArraySpeciesCreate.
10.4.2.4 ArraySetLength ( A, Desc )
The abstract operation ArraySetLength takes arguments A (an Array) and Desc (a
- If Desc does not have a [[Value]] field, then
- Return !
OrdinaryDefineOwnProperty (A,“length” , Desc).
- Return !
- Let newLenDesc be a copy of Desc.
- Let newLen be ?
ToUint32 (Desc.[[Value]]). - Let numberLen be ?
ToNumber (Desc.[[Value]]). - If
SameValueZero (newLen, numberLen) isfalse , throw aRangeError exception. - Set newLenDesc.[[Value]] to newLen.
- Let oldLenDesc be
OrdinaryGetOwnProperty (A,“length” ). Assert : oldLenDesc is notundefined .Assert :IsDataDescriptor (oldLenDesc) istrue .Assert : oldLenDesc.[[Configurable]] isfalse .- Let oldLen be oldLenDesc.[[Value]].
- If newLen ≥ oldLen, then
- Return !
OrdinaryDefineOwnProperty (A,“length” , newLenDesc).
- Return !
- If oldLenDesc.[[Writable]] is
false , returnfalse . - If newLenDesc does not have a [[Writable]] field or newLenDesc.[[Writable]] is
true , then- Let newWritable be
true .
- Let newWritable be
- Else,
- NOTE: Setting the [[Writable]] attribute to
false is deferred in case any elements cannot be deleted. - Let newWritable be
false . - Set newLenDesc.[[Writable]] to
true .
- NOTE: Setting the [[Writable]] attribute to
- Let succeeded be !
OrdinaryDefineOwnProperty (A,“length” , newLenDesc). - If succeeded is
false , returnfalse . - For each own
property key P of A such that P is anarray index and !ToUint32 (P) ≥ newLen, in descending numeric index order, do- Let deleteSucceeded be ! A.[[Delete]](P).
- If deleteSucceeded is
false , then- Set newLenDesc.[[Value]] to !
ToUint32 (P) +1 𝔽. - If newWritable is
false , set newLenDesc.[[Writable]] tofalse . - Perform !
OrdinaryDefineOwnProperty (A,“length” , newLenDesc). - Return
false .
- Set newLenDesc.[[Value]] to !
- If newWritable is
false , then- Set succeeded to !
OrdinaryDefineOwnProperty (A,“length” , PropertyDescriptor { [[Writable]]:false }). Assert : succeeded istrue .
- Set succeeded to !
- Return
true .
10.4.3 String Exotic Objects
A String object is an
An object is a String exotic object (or simply, a String object) if its [[GetOwnProperty]], [[DefineOwnProperty]], and [[OwnPropertyKeys]] internal methods use the following implementations, and its other essential internal methods use the definitions found in
10.4.3.1 [[GetOwnProperty]] ( P )
The [[GetOwnProperty]] internal method of a
- Let desc be
OrdinaryGetOwnProperty (S, P). - If desc is not
undefined , return desc. - Return
StringGetOwnProperty (S, P).
10.4.3.2 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of a
- Let stringDesc be
StringGetOwnProperty (S, P). - If stringDesc is not
undefined , then- Let extensible be S.[[Extensible]].
- Return
IsCompatiblePropertyDescriptor (extensible, Desc, stringDesc).
- Return !
OrdinaryDefineOwnProperty (S, P, Desc).
10.4.3.3 [[OwnPropertyKeys]] ( )
The [[OwnPropertyKeys]] internal method of a
- Let keys be a new empty
List . - Let str be O.[[StringData]].
Assert : stris a String .- Let len be the length of str.
- For each
integer i such that 0 ≤ i < len, in ascending order, do - For each own
property key P of O such that P is anarray index and !ToIntegerOrInfinity (P) ≥ len, in ascending numeric index order, do- Append P to keys.
- For each own
property key P of O such that Pis a String and P is not anarray index , in ascending chronological order of property creation, do- Append P to keys.
- For each own
property key P of O such that Pis a Symbol , in ascending chronological order of property creation, do- Append P to keys.
- Return keys.
10.4.3.4 StringCreate ( value, prototype )
The abstract operation StringCreate takes arguments value (a String) and prototype (an Object) and returns a
- Let S be
MakeBasicObject (« [[Prototype]], [[Extensible]], [[StringData]] »). - Set S.[[Prototype]] to prototype.
- Set S.[[StringData]] to value.
- Set S.[[GetOwnProperty]] as specified in
10.4.3.1 . - Set S.[[DefineOwnProperty]] as specified in
10.4.3.2 . - Set S.[[OwnPropertyKeys]] as specified in
10.4.3.3 . - Let length be the length of value.
- Perform !
DefinePropertyOrThrow (S,“length” , PropertyDescriptor { [[Value]]:𝔽 (length), [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:false }). - Return S.
10.4.3.5 StringGetOwnProperty ( S, P )
The abstract operation StringGetOwnProperty takes arguments S (an Object that has a [[StringData]] internal slot) and P (a
- If P
is not a String , returnundefined . - Let index be
CanonicalNumericIndexString (P). - If index is not an
integral Number , returnundefined . - If index is
-0 𝔽 or index <-0 𝔽, returnundefined . - Let str be S.[[StringData]].
Assert : stris a String .- Let len be the length of str.
- If
ℝ (index) ≥ len, returnundefined . - Let resultStr be the
substring of str fromℝ (index) toℝ (index) + 1. - Return the PropertyDescriptor { [[Value]]: resultStr, [[Writable]]:
false , [[Enumerable]]:true , [[Configurable]]:false }.
10.4.4 Arguments Exotic Objects
Most ECMAScript functions make an arguments object available to their code. Depending upon the characteristics of the function definition, its arguments object is either an
An object is an arguments exotic object if its internal methods use the following implementations, with the ones not specified here using those found in
While
Object.prototype.toString (
The
The ParameterMap object and its property values are used as a device for specifying the arguments object correspondence to argument bindings. The ParameterMap object and the objects that are the values of its properties are not directly observable from ECMAScript code. An ECMAScript implementation does not need to actually create or use such objects to implement the specified semantics.
Ordinary arguments objects define a non-configurable
ECMAScript implementations of
10.4.4.1 [[GetOwnProperty]] ( P )
The [[GetOwnProperty]] internal method of an
- Let desc be
OrdinaryGetOwnProperty (args, P). - If desc is
undefined , returnundefined . - Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P). - If isMapped is
true , then- Set desc.[[Value]] to !
Get (map, P).
- Set desc.[[Value]] to !
- Return desc.
10.4.4.2 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of an
- Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P). - Let newArgDesc be Desc.
- If isMapped is
true andIsDataDescriptor (Desc) istrue , then- If Desc does not have a [[Value]] field, Desc has a [[Writable]] field, and Desc.[[Writable]] is
false , then- Set newArgDesc to a copy of Desc.
- Set newArgDesc.[[Value]] to !
Get (map, P).
- If Desc does not have a [[Value]] field, Desc has a [[Writable]] field, and Desc.[[Writable]] is
- Let allowed be !
OrdinaryDefineOwnProperty (args, P, newArgDesc). - If allowed is
false , returnfalse . - If isMapped is
true , then- If
IsAccessorDescriptor (Desc) istrue , then- Perform ! map.[[Delete]](P).
- Else,
- If
- Return
true .
10.4.4.3 [[Get]] ( P, Receiver )
The [[Get]] internal method of an
- Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P). - If isMapped is
false , then- Return ?
OrdinaryGet (args, P, Receiver).
- Return ?
- Else,
10.4.4.4 [[Set]] ( P, V, Receiver )
The [[Set]] internal method of an
- If
SameValue (args, Receiver) isfalse , then- Let isMapped be
false .
- Let isMapped be
- Else,
- Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P).
- If isMapped is
true , then - Return ?
OrdinarySet (args, P, V, Receiver).
10.4.4.5 [[Delete]] ( P )
The [[Delete]] internal method of an
- Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P). - Let result be ?
OrdinaryDelete (args, P). - If result is
true and isMapped istrue , then- Perform ! map.[[Delete]](P).
- Return result.
10.4.4.6 CreateUnmappedArgumentsObject ( argumentsList )
The abstract operation CreateUnmappedArgumentsObject takes argument argumentsList (a
- Let len be the number of elements in argumentsList.
- Let obj be
OrdinaryObjectCreate (%Object.prototype% , « [[ParameterMap]] »). - Set obj.[[ParameterMap]] to
undefined . - Perform !
DefinePropertyOrThrow (obj,“length” , PropertyDescriptor { [[Value]]:𝔽 (len), [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Let index be 0.
- Repeat, while index < len,
- Let val be argumentsList[index].
- Perform !
CreateDataPropertyOrThrow (obj, !ToString (𝔽 (index)), val). - Set index to index + 1.
- Perform !
DefinePropertyOrThrow (obj,%Symbol.iterator% , PropertyDescriptor { [[Value]]: %Array.prototype.values%, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Perform !
DefinePropertyOrThrow (obj,“callee” , PropertyDescriptor { [[Get]]:%ThrowTypeError% , [[Set]]:%ThrowTypeError% , [[Enumerable]]:false , [[Configurable]]:false }). - Return obj.
10.4.4.7 CreateMappedArgumentsObject ( func, formals, argumentsList, env )
The abstract operation CreateMappedArgumentsObject takes arguments func (an Object), formals (a
Assert : formals does not contain a rest parameter, any binding patterns, or any initializers. It may contain duplicate identifiers.- Let len be the number of elements in argumentsList.
- Let obj be
MakeBasicObject (« [[Prototype]], [[Extensible]], [[ParameterMap]] »). - Set obj.[[GetOwnProperty]] as specified in
10.4.4.1 . - Set obj.[[DefineOwnProperty]] as specified in
10.4.4.2 . - Set obj.[[Get]] as specified in
10.4.4.3 . - Set obj.[[Set]] as specified in
10.4.4.4 . - Set obj.[[Delete]] as specified in
10.4.4.5 . - Set obj.[[Prototype]] to
%Object.prototype% . - Let map be
OrdinaryObjectCreate (null ). - Set obj.[[ParameterMap]] to map.
- Let parameterNames be the
BoundNames of formals. - Let numberOfParameters be the number of elements in parameterNames.
- Let index be 0.
- Repeat, while index < len,
- Let val be argumentsList[index].
- Perform !
CreateDataPropertyOrThrow (obj, !ToString (𝔽 (index)), val). - Set index to index + 1.
- Perform !
DefinePropertyOrThrow (obj,“length” , PropertyDescriptor { [[Value]]:𝔽 (len), [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Let mappedNames be a new empty
List . - Set index to numberOfParameters – 1.
- Repeat, while index ≥ 0,
- Let name be parameterNames[index].
- If mappedNames does not contain name, then
- Append name to 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,%Symbol.iterator% , PropertyDescriptor { [[Value]]: %Array.prototype.values%, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Perform !
DefinePropertyOrThrow (obj,“callee” , PropertyDescriptor { [[Value]]: func, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Return obj.
10.4.4.7.1 MakeArgGetter ( name, env )
The abstract operation MakeArgGetter takes arguments name (a String) and env (an
- Let getterClosure be a new
Abstract Closure with no parameters that captures name and env and performs the following steps when called:- Return
NormalCompletion (! env.GetBindingValue(name,false )).
- Return
- Let getter be
CreateBuiltinFunction (getterClosure, 0,“” , « »). - NOTE: getter is never directly accessible to ECMAScript code.
- Return getter.
10.4.4.7.2 MakeArgSetter ( name, env )
The abstract operation MakeArgSetter takes arguments name (a String) and env (an
- Let setterClosure be a new
Abstract Closure with parameters (value) that captures name and env and performs the following steps when called:- Return
NormalCompletion (! env.SetMutableBinding(name, value,false )).
- Return
- Let setter be
CreateBuiltinFunction (setterClosure, 1,“” , « »). - NOTE: setter is never directly accessible to ECMAScript code.
- Return setter.
10.4.5 TypedArray Exotic Objects
A
Because
An object is a TypedArray if its [[PreventExtensions]], [[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 [[PreventExtensions]] ( )
The [[PreventExtensions]] internal method of a
- NOTE: The extensibility-related invariants specified in
6.1.7.3 do not allow this method to returntrue when O can gain (or lose and then regain) properties, which might occur for properties withinteger index names when its underlying buffer is resized. - If
IsTypedArrayFixedLength (O) isfalse , returnfalse . - Return
OrdinaryPreventExtensions (O).
10.4.5.2 [[GetOwnProperty]] ( P )
The [[GetOwnProperty]] internal method of a
- If P
is a String , then- Let numericIndex be
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- Let value be
TypedArrayGetElement (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.3 [[HasProperty]] ( P )
The [[HasProperty]] internal method of a
- If P
is a String , then- Let numericIndex be
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , returnIsValidIntegerIndex (O, numericIndex).
- Let numericIndex be
- Return ?
OrdinaryHasProperty (O, P).
10.4.5.4 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of a
- If P
is a 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 Desc.[[Configurable]] is
false , returnfalse . - If Desc has an [[Enumerable]] field and Desc.[[Enumerable]] is
false , returnfalse . - If
IsAccessorDescriptor (Desc) istrue , returnfalse . - If Desc has a [[Writable]] field and Desc.[[Writable]] is
false , returnfalse . - If Desc has a [[Value]] field, perform ?
TypedArraySetElement (O, numericIndex, Desc.[[Value]]). - Return
true .
- If
- Let numericIndex be
- Return !
OrdinaryDefineOwnProperty (O, P, Desc).
10.4.5.5 [[Get]] ( P, Receiver )
The [[Get]] internal method of a
- If P
is a String , then- Let numericIndex be
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- Return
TypedArrayGetElement (O, numericIndex).
- Return
- Let numericIndex be
- Return ?
OrdinaryGet (O, P, Receiver).
10.4.5.6 [[Set]] ( P, V, Receiver )
The [[Set]] internal method of a
- If P
is a String , then- Let numericIndex be
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- If
SameValue (O, Receiver) istrue , then- Perform ?
TypedArraySetElement (O, numericIndex, V). - Return
true .
- Perform ?
- If
IsValidIntegerIndex (O, numericIndex) isfalse , returntrue .
- If
- Let numericIndex be
- Return ?
OrdinarySet (O, P, V, Receiver).
10.4.5.7 [[Delete]] ( P )
The [[Delete]] internal method of a
- If P
is a 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.8 [[OwnPropertyKeys]] ( )
The [[OwnPropertyKeys]] internal method of a
- Let taRecord be
MakeTypedArrayWithBufferWitnessRecord (O,seq-cst ). - Let keys be a new empty
List . - If
IsTypedArrayOutOfBounds (taRecord) isfalse , then- Let length be
TypedArrayLength (taRecord). - For each
integer i such that 0 ≤ i < length, in ascending order, do
- Let length be
- For each own
property key P of O such that Pis a String and P is not aninteger index , in ascending chronological order of property creation, do- Append P to keys.
- For each own
property key P of O such that Pis a Symbol , in ascending chronological order of property creation, do- Append P to keys.
- Return keys.
10.4.5.9 TypedArray With Buffer Witness Records
An TypedArray With Buffer Witness Record is a
TypedArray With Buffer Witness Records have the fields listed in
| Field Name | Value | Meaning |
|---|---|---|
| [[Object]] |
a |
The |
| [[CachedBufferByteLength]] |
a non-negative |
The byte length of the object’s [[ViewedArrayBuffer]] when the |
10.4.5.10 MakeTypedArrayWithBufferWitnessRecord ( obj, order )
The abstract operation MakeTypedArrayWithBufferWitnessRecord takes arguments obj (a
- Let buffer be obj.[[ViewedArrayBuffer]].
- If
IsDetachedBuffer (buffer) istrue , then- Let byteLength be
detached .
- Let byteLength be
- Else,
- Let byteLength be
ArrayBufferByteLength (buffer, order).
- Let byteLength be
- Return the
TypedArray With Buffer Witness Record { [[Object]]: obj, [[CachedBufferByteLength]]: byteLength }.
10.4.5.11 TypedArrayCreate ( prototype )
The abstract operation TypedArrayCreate takes argument prototype (an Object) and returns a
- Let internalSlotsList be « [[Prototype]], [[Extensible]], [[ViewedArrayBuffer]], [[TypedArrayName]], [[ContentType]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] ».
- Let A be
MakeBasicObject (internalSlotsList). - Set A.[[PreventExtensions]] as specified in
10.4.5.1 . - Set A.[[GetOwnProperty]] as specified in
10.4.5.2 . - Set A.[[HasProperty]] as specified in
10.4.5.3 . - Set A.[[DefineOwnProperty]] as specified in
10.4.5.4 . - Set A.[[Get]] as specified in
10.4.5.5 . - Set A.[[Set]] as specified in
10.4.5.6 . - Set A.[[Delete]] as specified in
10.4.5.7 . - Set A.[[OwnPropertyKeys]] as specified in
10.4.5.8 . - Set A.[[Prototype]] to prototype.
- Return A.
10.4.5.12 TypedArrayByteLength ( taRecord )
The abstract operation TypedArrayByteLength takes argument taRecord (a
Assert :IsTypedArrayOutOfBounds (taRecord) isfalse .- Let O be taRecord.[[Object]].
- If O.[[ByteLength]] is not
auto , return O.[[ByteLength]]. - Let length be
TypedArrayLength (taRecord). - Let elementSize be
TypedArrayElementSize (O). - NOTE: The returned byte length is always an
integer multiple of elementSize, even when the underlying buffer has been resized to a non-integer multiple. - Return length × elementSize.
10.4.5.13 TypedArrayLength ( taRecord )
The abstract operation TypedArrayLength takes argument taRecord (a
Assert :IsTypedArrayOutOfBounds (taRecord) isfalse .- Let O be taRecord.[[Object]].
- If O.[[ArrayLength]] is not
auto , return O.[[ArrayLength]]. Assert :IsFixedLengthArrayBuffer (O.[[ViewedArrayBuffer]]) isfalse .- Let byteOffset be O.[[ByteOffset]].
- Let elementSize be
TypedArrayElementSize (O). - Let byteLength be taRecord.[[CachedBufferByteLength]].
Assert : byteLength is notdetached .- Return
floor ((byteLength – byteOffset) / elementSize).
10.4.5.14 IsTypedArrayOutOfBounds ( taRecord )
The abstract operation IsTypedArrayOutOfBounds takes argument taRecord (a
- Let O be taRecord.[[Object]].
- Let bufferByteLength be taRecord.[[CachedBufferByteLength]].
- If
IsDetachedBuffer (O.[[ViewedArrayBuffer]]) istrue , thenAssert : bufferByteLength isdetached .- Return
true .
Assert : bufferByteLength is a non-negativeinteger .- Let byteOffsetStart be O.[[ByteOffset]].
- If O.[[ArrayLength]] is
auto , then- Let byteOffsetEnd be bufferByteLength.
- Else,
- Let elementSize be
TypedArrayElementSize (O). - Let arrayByteLength be O.[[ArrayLength]] × elementSize.
- Let byteOffsetEnd be byteOffsetStart + arrayByteLength.
- Let elementSize be
- NOTE: A 0-length
TypedArray whose [[ByteOffset]] is bufferByteLength is not considered out-of-bounds. - If byteOffsetStart > bufferByteLength or byteOffsetEnd > bufferByteLength, return
true . - Return
false .
10.4.5.15 IsTypedArrayFixedLength ( O )
The abstract operation IsTypedArrayFixedLength takes argument O (a
- If O.[[ArrayLength]] is
auto , returnfalse . - Let buffer be O.[[ViewedArrayBuffer]].
- If
IsFixedLengthArrayBuffer (buffer) isfalse andIsSharedArrayBuffer (buffer) isfalse , returnfalse . - Return
true .
10.4.5.16 IsValidIntegerIndex ( O, index )
The abstract operation IsValidIntegerIndex takes arguments O (a
- If
IsDetachedBuffer (O.[[ViewedArrayBuffer]]) istrue , returnfalse . - If index is not an
integral Number , returnfalse . - If index is
-0 𝔽 or index <-0 𝔽, returnfalse . - Let taRecord be
MakeTypedArrayWithBufferWitnessRecord (O,unordered ). - NOTE: Bounds checking is not a synchronizing operation when O‘s backing buffer is a
growable SharedArrayBuffer . - If
IsTypedArrayOutOfBounds (taRecord) istrue , returnfalse . - Let length be
TypedArrayLength (taRecord). - If
ℝ (index) ≥ length, returnfalse . - Return
true .
10.4.5.17 TypedArrayGetElement ( O, index )
The abstract operation TypedArrayGetElement takes arguments O (a
- If
IsValidIntegerIndex (O, index) isfalse , returnundefined . - Let offset be O.[[ByteOffset]].
- Let elementSize be
TypedArrayElementSize (O). - Let byteIndexInBuffer be (
ℝ (index) × elementSize) + offset. - Let elementType be
TypedArrayElementType (O). - Return
GetValueFromBuffer (O.[[ViewedArrayBuffer]], byteIndexInBuffer, elementType,true ,unordered ).
10.4.5.18 TypedArraySetElement ( O, index, value )
The abstract operation TypedArraySetElement takes arguments O (a
- If O.[[ContentType]] is
bigint , let numValue be ?ToBigInt (value). - Otherwise, let numValue be ?
ToNumber (value). - If
IsValidIntegerIndex (O, index) istrue , then- Let offset be O.[[ByteOffset]].
- Let elementSize be
TypedArrayElementSize (O). - Let byteIndexInBuffer be (
ℝ (index) × elementSize) + offset. - Let elementType be
TypedArrayElementType (O). - Perform
SetValueInBuffer (O.[[ViewedArrayBuffer]], byteIndexInBuffer, elementType, numValue,true ,unordered ).
- Return
unused .
This operation always appears to succeed, but it has no effect when attempting to write past the end of a
10.4.5.19 IsArrayBufferViewOutOfBounds ( O )
The abstract operation IsArrayBufferViewOutOfBounds takes argument O (a
- If O has a [[DataView]] internal slot, then
- Let viewRecord be
MakeDataViewWithBufferWitnessRecord (O,seq-cst ). - Return
IsViewOutOfBounds (viewRecord).
- Let viewRecord be
- Let taRecord be
MakeTypedArrayWithBufferWitnessRecord (O,seq-cst ). - Return
IsTypedArrayOutOfBounds (taRecord).
10.4.6 Module Namespace Exotic Objects
A export * export items. Each String-valued own
An object is a module namespace exotic object if its [[GetPrototypeOf]], [[SetPrototypeOf]], [[IsExtensible]], [[PreventExtensions]], [[GetOwnProperty]], [[DefineOwnProperty]], [[HasProperty]], [[Get]], [[Set]], [[Delete]], and [[OwnPropertyKeys]] internal methods use the definitions in this section, and its other essential internal methods use the definitions found in
| Internal Slot | Type | Description |
|---|---|---|
| [[Module]] |
a |
The |
| [[Exports]] |
a |
A |
10.4.6.1 [[GetPrototypeOf]] ( )
The [[GetPrototypeOf]] internal method of a
- Return
null .
10.4.6.2 [[SetPrototypeOf]] ( V )
The [[SetPrototypeOf]] internal method of a
- Return !
SetImmutablePrototype (O, V).
10.4.6.3 [[IsExtensible]] ( )
The [[IsExtensible]] internal method of a
- Return
false .
10.4.6.4 [[PreventExtensions]] ( )
The [[PreventExtensions]] internal method of a
- Return
true .
10.4.6.5 [[GetOwnProperty]] ( P )
The [[GetOwnProperty]] internal method of a
- If P
is a Symbol , returnOrdinaryGetOwnProperty (O, P). - Let exports be O.[[Exports]].
- If exports does not contain P, return
undefined . - Let value be ? O.[[Get]](P, O).
- Return PropertyDescriptor { [[Value]]: value, [[Writable]]:
true , [[Enumerable]]:true , [[Configurable]]:false }.
10.4.6.6 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of a
- If P
is a Symbol , return !OrdinaryDefineOwnProperty (O, P, Desc). - Let current be ? O.[[GetOwnProperty]](P).
- If current is
undefined , returnfalse . - If Desc has a [[Configurable]] field and Desc.[[Configurable]] is
true , returnfalse . - If Desc has an [[Enumerable]] field and Desc.[[Enumerable]] is
false , returnfalse . - If
IsAccessorDescriptor (Desc) istrue , returnfalse . - If Desc has a [[Writable]] field and Desc.[[Writable]] is
false , returnfalse . - If Desc has a [[Value]] field, return
SameValue (Desc.[[Value]], current.[[Value]]). - Return
true .
10.4.6.7 [[HasProperty]] ( P )
The [[HasProperty]] internal method of a
- If P
is a Symbol , return !OrdinaryHasProperty (O, P). - Let exports be O.[[Exports]].
- If exports contains P, return
true . - Return
false .
10.4.6.8 [[Get]] ( P, Receiver )
The [[Get]] internal method of a
- If P
is a Symbol , then- Return !
OrdinaryGet (O, P, Receiver).
- Return !
- Let exports be O.[[Exports]].
- If exports does not contain P, return
undefined . - Let m be O.[[Module]].
- Let binding be m.ResolveExport(P).
Assert : binding is aResolvedBinding Record .- Let targetModule be binding.[[Module]].
Assert : targetModule is notundefined .- If binding.[[BindingName]] is
namespace , then- Return
GetModuleNamespace (targetModule).
- Return
- Let targetEnv be targetModule.[[Environment]].
- If targetEnv is
empty , throw aReferenceError exception. - Return ? targetEnv.GetBindingValue(binding.[[BindingName]],
true ).
ResolveExport is side-effect free. Each time this operation is called with a specific exportName, resolveSet pair as arguments it must return the same result. An implementation might choose to pre-compute or cache the ResolveExport results for the [[Exports]] of each
10.4.6.9 [[Set]] ( P, V, Receiver )
The [[Set]] internal method of a
- Return
false .
10.4.6.10 [[Delete]] ( P )
The [[Delete]] internal method of a
- If P
is a Symbol , then- Return !
OrdinaryDelete (O, P).
- Return !
- Let exports be O.[[Exports]].
- If exports contains P, return
false . - Return
true .
10.4.6.11 [[OwnPropertyKeys]] ( )
The [[OwnPropertyKeys]] internal method of a
- Let exports be O.[[Exports]].
- Let symbolKeys be
OrdinaryOwnPropertyKeys (O). - Return the
list-concatenation of exports and symbolKeys.
10.4.6.12 ModuleNamespaceCreate ( module, exports )
The abstract operation ModuleNamespaceCreate takes arguments module (a
Assert : module.[[Namespace]] isempty .- Let internalSlotsList be the internal slots listed in
Table 31 . - Let M be
MakeBasicObject (internalSlotsList). - Set M‘s essential internal methods to the definitions specified in
10.4.6 . - Set M.[[Module]] to module.
- Let sortedExports be a
List whose elements are the elements of exports, sorted according tolexicographic code unit order . - Set M.[[Exports]] to sortedExports.
- Create own properties of M corresponding to the definitions in
28.3 . - Set module.[[Namespace]] to M.
- Return M.
10.4.7 Immutable Prototype Exotic Objects
An
An object is an immutable prototype exotic object if its [[SetPrototypeOf]] internal method uses the following implementation. (Its other essential internal methods may use any implementation, depending on the specific
Unlike other
10.4.7.1 [[SetPrototypeOf]] ( V )
The [[SetPrototypeOf]] internal method of an
- Return ?
SetImmutablePrototype (O, V).
10.4.7.2 SetImmutablePrototype ( O, V )
The abstract operation SetImmutablePrototype takes arguments O (an Object) and V (an Object or
- Let current be ? O.[[GetPrototypeOf]]().
- If
SameValue (V, current) istrue , returntrue . - Return
false .
10.5 Proxy Object Internal Methods and Internal Slots
A Proxy object is an
An object is a Proxy exotic object if its essential internal methods (including [[Call]] and [[Construct]], if applicable) use the definitions in this section. These internal methods are installed in
| Internal Method | Handler Method |
|---|---|
| [[GetPrototypeOf]] |
getPrototypeOf
|
| [[SetPrototypeOf]] |
setPrototypeOf
|
| [[IsExtensible]] |
isExtensible
|
| [[PreventExtensions]] |
preventExtensions
|
| [[GetOwnProperty]] |
getOwnPropertyDescriptor
|
| [[DefineOwnProperty]] |
defineProperty
|
| [[HasProperty]] |
has
|
| [[Get]] |
get
|
| [[Set]] |
set
|
| [[Delete]] |
deleteProperty
|
| [[OwnPropertyKeys]] |
ownKeys
|
| [[Call]] |
apply
|
| [[Construct]] |
construct
|
When a handler method is called to provide the implementation of a Proxy object internal method, the handler method is passed the proxy’s target object as a parameter. A proxy’s handler object does not necessarily have a method corresponding to every essential internal method. Invoking an internal method on the proxy results in the invocation of the corresponding internal method on the proxy’s target object if the handler object does not have a method corresponding to the internal trap.
The [[ProxyHandler]] and [[ProxyTarget]] internal slots of a Proxy object are always initialized when the object is created and typically may not be modified. Some Proxy objects are created in a manner that permits them to be subsequently revoked. When a proxy is revoked, its [[ProxyHandler]] and [[ProxyTarget]] internal slots are set to
Because Proxy objects permit the implementation of internal methods to be provided by arbitrary ECMAScript code, it is possible to define a Proxy object whose handler methods violates the invariants defined in
In the following algorithm descriptions, assume O is an ECMAScript Proxy object, P is a
10.5.1 [[GetPrototypeOf]] ( )
The [[GetPrototypeOf]] internal method of a
- Perform ?
ValidateNonRevokedProxy (O). - Let target be O.[[ProxyTarget]].
- Let handler be O.[[ProxyHandler]].
Assert : handleris an Object .- Let trap be ?
GetMethod (handler,“getPrototypeOf” ). - If trap is
undefined , then- Return ? target.[[GetPrototypeOf]]().
- Let handlerProto be ?
Call (trap, handler, « target »). - If handlerProto
is not an Object and handlerProto is notnull , 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
- Perform ?
ValidateNonRevokedProxy (O). - Let target be O.[[ProxyTarget]].
- Let handler be O.[[ProxyHandler]].
Assert : handleris an Object .- 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
- Perform ?
ValidateNonRevokedProxy (O). - Let target be O.[[ProxyTarget]].
- Let handler be O.[[ProxyHandler]].
Assert : handleris an Object .- 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 booleanTrapResult is not targetResult, throw a
TypeError 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
- Perform ?
ValidateNonRevokedProxy (O). - Let target be O.[[ProxyTarget]].
- Let handler be O.[[ProxyHandler]].
Assert : handleris an Object .- 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
- Perform ?
ValidateNonRevokedProxy (O). - Let target be O.[[ProxyTarget]].
- Let handler be O.[[ProxyHandler]].
Assert : handleris an Object .- Let trap be ?
GetMethod (handler,“getOwnPropertyDescriptor” ). - If trap is
undefined , then- Return ? target.[[GetOwnProperty]](P).
- Let trapResultObj be ?
Call (trap, handler, « target, P »). - If trapResultObj
is not an Object and trapResultObj is notundefined , throw aTypeError exception. - Let targetDesc be ? target.[[GetOwnProperty]](P).
- If trapResultObj is
undefined , then- If targetDesc is
undefined , returnundefined . - If targetDesc.[[Configurable]] is
false , throw aTypeError exception. - Let extensibleTarget be ?
IsExtensible (target). - If extensibleTarget is
false , throw aTypeError exception. - Return
undefined .
- If targetDesc is
- Let extensibleTarget be ?
IsExtensible (target). - Let resultDesc be ?
ToPropertyDescriptor (trapResultObj). - Perform
CompletePropertyDescriptor (resultDesc). - Let valid be
IsCompatiblePropertyDescriptor (extensibleTarget, resultDesc, targetDesc). - If valid is
false , throw aTypeError exception. - If resultDesc.[[Configurable]] is
false , then- If targetDesc is
undefined or targetDesc.[[Configurable]] istrue , then- Throw a
TypeError exception.
- Throw a
- If resultDesc has a [[Writable]] field and resultDesc.[[Writable]] is
false , thenAssert : targetDesc has a [[Writable]] field.- If targetDesc.[[Writable]] is
true , throw aTypeError exception.
- If targetDesc is
- Return resultDesc.
[[GetOwnProperty]] for Proxy objects enforces the following invariants:
-
The result of [[GetOwnProperty]] must be either an Object or
undefined . - A property cannot be reported as non-existent, if it exists as a non-configurable own property of the target object.
- A property cannot be reported as non-existent, if it exists as an own property of a non-extensible target object.
- A property cannot be reported as existent, if it does not exist as an own property of the target object and the target object is not extensible.
- A property cannot be reported as non-configurable, unless it exists as a non-configurable own property of the target object.
- A property cannot be reported as both non-configurable and non-writable, unless it exists as a non-configurable, non-writable own property of the target object.
10.5.6 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of a
- Perform ?
ValidateNonRevokedProxy (O). - Let target be O.[[ProxyTarget]].
- Let handler be O.[[ProxyHandler]].
Assert : handleris an Object .- 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 Desc.[[Configurable]] is
false , then- Let settingConfigFalse be
true .
- Let settingConfigFalse be
- Else,
- Let settingConfigFalse be
false .
- Let settingConfigFalse be
- 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
- Perform ?
ValidateNonRevokedProxy (O). - Let target be O.[[ProxyTarget]].
- Let handler be O.[[ProxyHandler]].
Assert : handleris an Object .- 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
- Perform ?
ValidateNonRevokedProxy (O). - Let target be O.[[ProxyTarget]].
- Let handler be O.[[ProxyHandler]].
Assert : handleris an Object .- 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
- Perform ?
ValidateNonRevokedProxy (O). - Let target be O.[[ProxyTarget]].
- Let handler be O.[[ProxyHandler]].
Assert : handleris an Object .- 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
- Perform ?
ValidateNonRevokedProxy (O). - Let target be O.[[ProxyTarget]].
- Let handler be O.[[ProxyHandler]].
Assert : handleris an Object .- 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
- Perform ?
ValidateNonRevokedProxy (O). - Let target be O.[[ProxyTarget]].
- Let handler be O.[[ProxyHandler]].
Assert : handleris an Object .- 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,property-key ). - If trapResult contains any duplicate entries, throw a
TypeError exception. - Let extensibleTarget be ?
IsExtensible (target). - Let targetKeys be ? target.[[OwnPropertyKeys]]().
Assert : targetKeys is aList ofproperty keys .Assert : targetKeys contains no duplicate entries.- Let targetConfigurableKeys be a new empty
List . - Let targetNonconfigurableKeys be a new empty
List . - For each element key of targetKeys, do
- Let desc be ? target.[[GetOwnProperty]](key).
- If desc is not
undefined and desc.[[Configurable]] isfalse , then- Append key to targetNonconfigurableKeys.
- Else,
- Append key to 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 uncheckedResultKeys does not contain key, throw a
TypeError exception. - Remove key from uncheckedResultKeys.
- If uncheckedResultKeys does not contain key, throw a
- If extensibleTarget is
true , return trapResult. - For each element key of targetConfigurableKeys, do
- If uncheckedResultKeys does not contain key, throw a
TypeError exception. - Remove key from uncheckedResultKeys.
- If uncheckedResultKeys does not contain key, 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. -
Each element of the returned
List is aproperty key . -
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
- Perform ?
ValidateNonRevokedProxy (O). - Let target be O.[[ProxyTarget]].
- Let handler be O.[[ProxyHandler]].
Assert : handleris an Object .- 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
- Perform ?
ValidateNonRevokedProxy (O). - Let target be O.[[ProxyTarget]].
Assert :IsConstructor (target) istrue .- Let handler be O.[[ProxyHandler]].
Assert : handleris an Object .- 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 newObj
is not an 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 ValidateNonRevokedProxy ( proxy )
The abstract operation ValidateNonRevokedProxy takes argument proxy (a
- If proxy.[[ProxyTarget]] is
null , throw aTypeError exception. Assert : proxy.[[ProxyHandler]] is notnull .- Return
unused .
10.5.15 ProxyCreate ( target, handler )
The abstract operation ProxyCreate takes arguments target (an
- If target
is not an Object , throw aTypeError exception. - If handler
is not an Object , throw aTypeError exception. - Let P be
MakeBasicObject (« [[ProxyHandler]], [[ProxyTarget]] »). - Set P‘s essential internal methods, except for [[Call]] and [[Construct]], to the definitions specified in
10.5 . - If
IsCallable (target) istrue , then- Set P.[[Call]] as specified in
10.5.12 . - If
IsConstructor (target) istrue , then- Set P.[[Construct]] as specified in
10.5.13 .
- Set P.[[Construct]] as specified in
- Set P.[[Call]] as specified in
- Set P.[[ProxyTarget]] to target.
- Set P.[[ProxyHandler]] to handler.
- Return P.