9 Ordinary and Exotic Objects Behaviours
9.1 Ordinary Object Internal Methods and Internal Slots
All ordinary objects have an internal slot called [[Prototype]]. The value of this internal slot is either
Every ordinary object has a Boolean-valued [[Extensible]] internal slot which is used to fulfill the extensibility-related internal method invariants specified in
In the following algorithm descriptions, assume O is an ordinary object, P is a property key value, V is any
Each ordinary object internal method delegates to a similarly-named abstract operation. If such an abstract operation depends on another internal method, then the internal method is invoked on O rather than calling the similarly-named abstract operation directly. These semantics ensure that exotic objects have their overridden internal methods invoked when ordinary object internal methods are applied to them.
9.1.1 [[GetPrototypeOf]] ( )
When the [[GetPrototypeOf]] internal method of O is called, the following steps are taken:
- Return !
OrdinaryGetPrototypeOf (O).
9.1.1.1 OrdinaryGetPrototypeOf ( O )
When the abstract operation OrdinaryGetPrototypeOf is called with Object O, the following steps are taken:
- Return O.[[Prototype]].
9.1.2 [[SetPrototypeOf]] ( V )
When the [[SetPrototypeOf]] internal method of O is called with argument V, the following steps are taken:
- Return !
OrdinarySetPrototypeOf (O, V).
9.1.2.1 OrdinarySetPrototypeOf ( O, V )
When the abstract operation OrdinarySetPrototypeOf is called with Object O and value V, the following steps are taken:
The loop in step 8 guarantees that there will be no circularities in any prototype chain that only includes objects that use the ordinary object definitions for [[GetPrototypeOf]] and [[SetPrototypeOf]].
9.1.3 [[IsExtensible]] ( )
When the [[IsExtensible]] internal method of O is called, the following steps are taken:
- Return !
OrdinaryIsExtensible (O).
9.1.3.1 OrdinaryIsExtensible ( O )
When the abstract operation OrdinaryIsExtensible is called with Object O, the following steps are taken:
- Return O.[[Extensible]].
9.1.4 [[PreventExtensions]] ( )
When the [[PreventExtensions]] internal method of O is called, the following steps are taken:
- Return !
OrdinaryPreventExtensions (O).
9.1.4.1 OrdinaryPreventExtensions ( O )
When the abstract operation OrdinaryPreventExtensions is called with Object O, the following steps are taken:
Set O.[[Extensible]] tofalse .- Return
true .
9.1.5 [[GetOwnProperty]] ( P )
When the [[GetOwnProperty]] internal method of O is called with property key P, the following steps are taken:
- Return !
OrdinaryGetOwnProperty (O, P).
9.1.5.1 OrdinaryGetOwnProperty ( O, P )
When the abstract operation OrdinaryGetOwnProperty is called with Object O and with property key P, the following steps are taken:
Assert :IsPropertyKey (P) istrue .- If O does not have an own property with key P, return
undefined . - Let D be a newly created
Property Descriptor with no fields. - Let X be O's own property whose key is P.
- If X is a
data property , then - Else X is an
accessor property , Set D.[[Enumerable]] to the value of X's [[Enumerable]] attribute.Set D.[[Configurable]] to the value of X's [[Configurable]] attribute.- Return D.
9.1.6 [[DefineOwnProperty]] ( P, Desc )
When the [[DefineOwnProperty]] internal method of O is called with property key P and
- Return ?
OrdinaryDefineOwnProperty (O, P, Desc).
9.1.6.1 OrdinaryDefineOwnProperty ( O, P, Desc )
When the abstract operation OrdinaryDefineOwnProperty is called with Object O, property key P, and
- Let current be ? O.[[GetOwnProperty]](P).
- Let extensible be ?
IsExtensible (O). - Return
ValidateAndApplyPropertyDescriptor (O, P, extensible, Desc, current).
9.1.6.2 IsCompatiblePropertyDescriptor ( Extensible, Desc, Current )
When the abstract operation IsCompatiblePropertyDescriptor is called with Boolean value Extensible, and Property Descriptors Desc, and Current, the following steps are taken:
- Return
ValidateAndApplyPropertyDescriptor (undefined ,undefined , Extensible, Desc, Current).
9.1.6.3 ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current )
When the abstract operation ValidateAndApplyPropertyDescriptor is called with Object O, property key P, Boolean value extensible, and Property Descriptors Desc, and current, the following steps are taken:
If
Assert : If O is notundefined , thenIsPropertyKey (P) istrue .- If current is
undefined , then- If extensible is
false , returnfalse . Assert : extensible istrue .- If
IsGenericDescriptor (Desc) istrue orIsDataDescriptor (Desc) istrue , then- If O is not
undefined , create an owndata property named P of object O whose [[Value]], [[Writable]], [[Enumerable]] and [[Configurable]] attribute values are described by Desc. If the value of an attribute field of Desc is absent, the attribute of the newly created property is set to its default value.
- If O is not
- Else Desc must be an accessor
Property Descriptor ,- If O is not
undefined , create an ownaccessor property named P of object O whose [[Get]], [[Set]], [[Enumerable]] and [[Configurable]] attribute values are described by Desc. If the value of an attribute field of Desc is absent, the attribute of the newly created property is set to its default value.
- If O is not
- Return
true .
- If extensible is
- If every field in Desc is absent, return
true . - If current.[[Configurable]] is
false , then- If Desc.[[Configurable]] is present and its value is
true , returnfalse . - If Desc.[[Enumerable]] is present and the [[Enumerable]] fields of current and Desc are the Boolean negation of each other, return
false .
- If Desc.[[Configurable]] is present and its value is
- If
IsGenericDescriptor (Desc) istrue , no further validation is required. - Else if
IsDataDescriptor (current) andIsDataDescriptor (Desc) have different results, then- If current.[[Configurable]] is
false , returnfalse . - If
IsDataDescriptor (current) istrue , then- If O is not
undefined , convert the property named P of object O from adata property to anaccessor property . Preserve the existing values of the converted property's [[Configurable]] and [[Enumerable]] attributes and set the rest of the property's attributes to their default values.
- If O is not
- Else,
- If O is not
undefined , convert the property named P of object O from anaccessor property to adata property . Preserve the existing values of the converted property's [[Configurable]] and [[Enumerable]] attributes and set the rest of the property's attributes to their default values.
- If O is not
- If current.[[Configurable]] is
- Else if
IsDataDescriptor (current) andIsDataDescriptor (Desc) are bothtrue , then- If current.[[Configurable]] is
false and current.[[Writable]] isfalse , then- If Desc.[[Writable]] is present and Desc.[[Writable]] is
true , returnfalse . - If Desc.[[Value]] is present and
SameValue (Desc.[[Value]], current.[[Value]]) isfalse , returnfalse . - Return
true .
- If Desc.[[Writable]] is present and Desc.[[Writable]] is
- If current.[[Configurable]] is
- Else
IsAccessorDescriptor (current) andIsAccessorDescriptor (Desc) are bothtrue , - If O is not
undefined , then- For each field of Desc that is present, set the corresponding attribute of the property named P of object O to the value of the field.
- Return
true .
9.1.7 [[HasProperty]] ( P )
When the [[HasProperty]] internal method of O is called with property key P, the following steps are taken:
- Return ?
OrdinaryHasProperty (O, P).
9.1.7.1 OrdinaryHasProperty ( O, P )
When the abstract operation OrdinaryHasProperty is called with Object O and with property key P, the following steps are taken:
Assert :IsPropertyKey (P) istrue .- Let hasOwn be ? O.[[GetOwnProperty]](P).
- If hasOwn is not
undefined , returntrue . - Let parent be ? O.[[GetPrototypeOf]]().
- If parent is not
null , then- Return ? parent.[[HasProperty]](P).
- Return
false .
9.1.8 [[Get]] ( P, Receiver )
When the [[Get]] internal method of O is called with property key P and
- Return ?
OrdinaryGet (O, P, Receiver).
9.1.8.1 OrdinaryGet ( O, P, Receiver )
When the abstract operation OrdinaryGet is called with Object O, property key P, and
Assert :IsPropertyKey (P) istrue .- Let desc be ? O.[[GetOwnProperty]](P).
- If desc is
undefined , then- Let parent be ? O.[[GetPrototypeOf]]().
- If parent is
null , returnundefined . - Return ? parent.[[Get]](P, Receiver).
- If
IsDataDescriptor (desc) istrue , return desc.[[Value]]. Assert :IsAccessorDescriptor (desc) istrue .- Let getter be desc.[[Get]].
- If getter is
undefined , returnundefined . - Return ?
Call (getter, Receiver).
9.1.9 [[Set]] ( P, V, Receiver )
When the [[Set]] internal method of O is called with property key P, value V, and
- Return ?
OrdinarySet (O, P, V, Receiver).
9.1.9.1 OrdinarySet ( O, P, V, Receiver )
When the abstract operation OrdinarySet is called with Object O, property key P, value V, and
Assert :IsPropertyKey (P) istrue .- Let ownDesc be ? O.[[GetOwnProperty]](P).
- Return
OrdinarySetWithOwnDescriptor (O, P, V, Receiver, ownDesc).
9.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc )
When the abstract operation OrdinarySetWithOwnDescriptor is called with Object O, property key P, value V,
Assert :IsPropertyKey (P) istrue .- If ownDesc is
undefined , then- Let parent be ? O.[[GetPrototypeOf]]().
- If parent is not
null , then- Return ? parent.[[Set]](P, V, Receiver).
- Else,
Set ownDesc to the PropertyDescriptor { [[Value]]:undefined , [[Writable]]:true , [[Enumerable]]:true , [[Configurable]]:true }.
- If
IsDataDescriptor (ownDesc) istrue , then- If ownDesc.[[Writable]] is
false , returnfalse . - If
Type (Receiver) is not Object, returnfalse . - Let existingDescriptor be ? Receiver.[[GetOwnProperty]](P).
- If existingDescriptor is not
undefined , then- If
IsAccessorDescriptor (existingDescriptor) istrue , returnfalse . - If existingDescriptor.[[Writable]] is
false , returnfalse . - Let valueDesc be the PropertyDescriptor { [[Value]]: V }.
- Return ? Receiver.[[DefineOwnProperty]](P, valueDesc).
- If
- Else Receiver does not currently have a property P,
- Return ?
CreateDataProperty (Receiver, P, V).
- Return ?
- If ownDesc.[[Writable]] is
Assert :IsAccessorDescriptor (ownDesc) istrue .- Let setter be ownDesc.[[Set]].
- If setter is
undefined , returnfalse . - Perform ?
Call (setter, Receiver, « V »). - Return
true .
9.1.10 [[Delete]] ( P )
When the [[Delete]] internal method of O is called with property key P, the following steps are taken:
- Return ?
OrdinaryDelete (O, P).
9.1.10.1 OrdinaryDelete ( O, P )
When the abstract operation OrdinaryDelete is called with Object O and property key P, the following steps are taken:
Assert :IsPropertyKey (P) istrue .- Let desc be ? O.[[GetOwnProperty]](P).
- If desc is
undefined , returntrue . - If desc.[[Configurable]] is
true , then- Remove the own property with name P from O.
- Return
true .
- Return
false .
9.1.11 [[OwnPropertyKeys]] ( )
When the [[OwnPropertyKeys]] internal method of O is called, the following steps are taken:
- Return !
OrdinaryOwnPropertyKeys (O).
9.1.11.1 OrdinaryOwnPropertyKeys ( O )
When the abstract operation OrdinaryOwnPropertyKeys is called with Object O, the following steps are taken:
- Let keys be a new empty
List . - For each own property key P of O that is an
array index , in ascending numeric index order, do- Add P as the last element of keys.
- For each own property key P of O that is a String but is not an
array index , in ascending chronological order of property creation, do- Add P as the last element of keys.
- For each own property key P of O that is a Symbol, in ascending chronological order of property creation, do
- Add P as the last element of keys.
- Return keys.
9.1.12 ObjectCreate ( proto [ , internalSlotsList ] )
The abstract operation ObjectCreate with argument proto (an object or null) is used to specify the runtime creation of new ordinary objects. The optional argument internalSlotsList is a
- If internalSlotsList is not present, set internalSlotsList to a new empty
List . - Let obj be a newly created object with an internal slot for each name in internalSlotsList.
Set obj's essential internal methods to the default ordinary object definitions specified in9.1 .Set obj.[[Prototype]] to proto.Set obj.[[Extensible]] totrue .- Return obj.
9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
The abstract operation OrdinaryCreateFromConstructor creates an ordinary object whose [[Prototype]] value is retrieved from a prototype property, if it exists. Otherwise the intrinsic named by intrinsicDefaultProto is used for [[Prototype]]. The optional internalSlotsList is a
Assert : intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object.- Let proto be ?
GetPrototypeFromConstructor (constructor, intrinsicDefaultProto). - Return
ObjectCreate (proto, internalSlotsList).
9.1.14 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
The abstract operation GetPrototypeFromConstructor determines the [[Prototype]] value that should be used to create an object corresponding to a specific prototype property, if it exists. Otherwise the intrinsic named by intrinsicDefaultProto is used for [[Prototype]]. This abstract operation performs the following steps:
Assert : intrinsicDefaultProto is a String value that is this specification's name of an intrinsic object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]] value of an object.Assert :IsCallable (constructor) istrue .- Let proto be ?
Get (constructor,"prototype"). - If
Type (proto) is not Object, then- Let realm be ?
GetFunctionRealm (constructor). Set proto to realm's intrinsic object named intrinsicDefaultProto.
- Let realm be ?
- Return proto.
If constructor does not supply a [[Prototype]] value, the default value that is used is obtained from the
9.2 ECMAScript Function Objects
ECMAScript function objects encapsulate parameterized ECMAScript code closed over a lexical environment and support the dynamic evaluation of that code. An ECMAScript
ECMAScript function objects have the additional internal slots listed in
| Internal Slot |
|
Description |
|---|---|---|
| [[Environment]] |
|
The |
| [[FormalParameters]] |
|
The root parse node of the source text that defines the function's formal parameter list. |
| [[FunctionKind]] | String |
Either "normal", "classConstructor", "generator", "async", or "async generator".
|
| [[ECMAScriptCode]] |
|
The root parse node of the source text that defines the function's body. |
| [[ConstructorKind]] | String |
Either "base" or "derived".
|
| [[Realm]] |
|
The |
| [[ScriptOrModule]] |
|
The script or module in which the function was created. |
| [[ThisMode]] | (lexical, strict, global) |
Defines how this references are interpreted within the formal parameters and code body of the function. this refers to the |
| [[Strict]] | Boolean |
|
| [[HomeObject]] | Object |
If the function uses super, this is the object whose [[GetPrototypeOf]] provides the object where super property lookups begin.
|
| [[SourceText]] | String |
The |
All ECMAScript function objects have the [[Call]] internal method defined here. ECMAScript functions that are also constructors in addition have the [[Construct]] internal method.
9.2.1 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method for an ECMAScript
Assert : F is an ECMAScriptfunction object .- If F.[[FunctionKind]] is
"classConstructor", throw aTypeError exception. - Let callerContext be the
running execution context . - Let calleeContext be
PrepareForOrdinaryCall (F,undefined ). Assert : calleeContext is now therunning execution context .- Perform
OrdinaryCallBindThis (F, calleeContext, thisArgument). - Let result be
OrdinaryCallEvaluateBody (F, argumentsList). - Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - If result.[[Type]] is
return , returnNormalCompletion (result.[[Value]]). ReturnIfAbrupt (result).- Return
NormalCompletion (undefined ).
When calleeContext is removed from the
9.2.1.1 PrepareForOrdinaryCall ( F, newTarget )
When the abstract operation PrepareForOrdinaryCall is called with
Assert :Type (newTarget) is Undefined or Object.- Let callerContext be the
running execution context . - Let calleeContext be a new ECMAScript code
execution context . Set the Function of calleeContext to F.- Let calleeRealm be F.[[Realm]].
Set theRealm of calleeContext to calleeRealm.Set the ScriptOrModule of calleeContext to F.[[ScriptOrModule]].- Let localEnv be
NewFunctionEnvironment (F, newTarget). Set the LexicalEnvironment of calleeContext to localEnv.Set the VariableEnvironment of calleeContext to localEnv.- If callerContext is not already suspended, suspend callerContext.
- Push calleeContext onto the
execution context stack ; calleeContext is now therunning execution context . - NOTE: Any exception objects produced after this point are associated with calleeRealm.
- Return calleeContext.
9.2.1.2 OrdinaryCallBindThis ( F, calleeContext, thisArgument )
When the abstract operation OrdinaryCallBindThis is called with
- Let thisMode be F.[[ThisMode]].
- If thisMode is
lexical , returnNormalCompletion (undefined ). - Let calleeRealm be F.[[Realm]].
- Let localEnv be the LexicalEnvironment of calleeContext.
- If thisMode is
strict , let thisValue be thisArgument. - Else,
- If thisArgument is
undefined ornull , then- Let globalEnv be calleeRealm.[[GlobalEnv]].
- Let globalEnvRec be globalEnv's
EnvironmentRecord . Assert : globalEnvRec is a globalEnvironment Record .- Let thisValue be globalEnvRec.[[GlobalThisValue]].
- Else,
- If thisArgument is
- Let envRec be localEnv's
EnvironmentRecord . Assert : envRec is afunction Environment Record .Assert : The next step never returns anabrupt completion because envRec.[[ThisBindingStatus]] is not"initialized".- Return envRec.BindThisValue(thisValue).
9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList )
When the abstract operation OrdinaryCallEvaluateBody is called with
- Return the result of EvaluateBody of the parsed code that is F.[[ECMAScriptCode]] passing F and argumentsList as the arguments.
9.2.2 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method for an ECMAScript
Assert : F is an ECMAScriptfunction object .Assert :Type (newTarget) is Object.- Let callerContext be the
running execution context . - Let kind be F.[[ConstructorKind]].
- If kind is
"base", then- Let thisArgument be ?
OrdinaryCreateFromConstructor (newTarget,"%ObjectPrototype%").
- Let thisArgument be ?
- Let calleeContext be
PrepareForOrdinaryCall (F, newTarget). Assert : calleeContext is now therunning execution context .- If kind is
"base", performOrdinaryCallBindThis (F, calleeContext, thisArgument). - Let constructorEnv be the LexicalEnvironment of calleeContext.
- Let envRec be constructorEnv's
EnvironmentRecord . - Let result be
OrdinaryCallEvaluateBody (F, argumentsList). - Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - If result.[[Type]] is
return , then- If
Type (result.[[Value]]) is Object, returnNormalCompletion (result.[[Value]]). - If kind is
"base", returnNormalCompletion (thisArgument). - If result.[[Value]] is not
undefined , throw aTypeError exception.
- If
- Else,
ReturnIfAbrupt (result). - Return ? envRec.GetThisBinding().
9.2.3 FunctionAllocate ( functionPrototype, strict, functionKind )
The abstract operation FunctionAllocate requires the three arguments functionPrototype, strict and functionKind. FunctionAllocate performs the following steps:
Assert :Type (functionPrototype) is Object.Assert : functionKind is either"normal","non-constructor","generator","async", or"async generator".- If functionKind is
"normal", let needsConstruct betrue . - Else, let needsConstruct be
false . - If functionKind is
"non-constructor", set functionKind to"normal". - Let F be a newly created ECMAScript
function object with the internal slots listed inTable 27 . All of those internal slots are initialized toundefined . Set F's essential internal methods to the default ordinary object definitions specified in9.1 .Set F.[[Call]] to the definition specified in9.2.1 .- If needsConstruct is
true , then Set F.[[Strict]] to strict.Set F.[[FunctionKind]] to functionKind.Set F.[[Prototype]] to functionPrototype.Set F.[[Extensible]] totrue .Set F.[[Realm]] tothe current Realm Record .- Return F.
9.2.4 FunctionInitialize ( F, kind, ParameterList, Body, Scope )
The abstract operation FunctionInitialize requires the arguments: a
- Let len be the ExpectedArgumentCount of ParameterList.
- Perform !
SetFunctionLength (F, len). - Let Strict be F.[[Strict]].
Set F.[[Environment]] to Scope.Set F.[[FormalParameters]] to ParameterList.Set F.[[ECMAScriptCode]] to Body.Set F.[[ScriptOrModule]] toGetActiveScriptOrModule ().- If kind is
Arrow , set F.[[ThisMode]] tolexical . - Else if Strict is
true , set F.[[ThisMode]] tostrict . - Else, set F.[[ThisMode]] to
global . - Return F.
9.2.5 FunctionCreate ( kind, ParameterList, Body, Scope, Strict [ , prototype ] )
The abstract operation FunctionCreate requires the arguments: kind which is one of (Normal, Method, Arrow), a parameter list
- If prototype is not present, then
Set prototype to the intrinsic object%FunctionPrototype% .
- If kind is not
Normal , let allocKind be"non-constructor". - Else, let allocKind be
"normal". - Let F be
FunctionAllocate (prototype, Strict, allocKind). - Return
FunctionInitialize (F, kind, ParameterList, Body, Scope).
9.2.6 GeneratorFunctionCreate ( kind, ParameterList, Body, Scope, Strict )
The abstract operation GeneratorFunctionCreate requires the arguments: kind which is one of (Normal, Method), a parameter list
- Let functionPrototype be the intrinsic object
%Generator% . - Let F be
FunctionAllocate (functionPrototype, Strict,"generator"). - Return
FunctionInitialize (F, kind, ParameterList, Body, Scope).
9.2.7 AsyncGeneratorFunctionCreate ( kind, ParameterList, Body, Scope, Strict )
The abstract operation AsyncGeneratorFunctionCreate requires the arguments: kind which is one of (
- Let functionPrototype be the intrinsic object
%AsyncGenerator% . - Let F be !
FunctionAllocate (functionPrototype, Strict,"generator"). - Return !
FunctionInitialize (F, kind, ParameterList, Body, Scope).
9.2.8 AsyncFunctionCreate ( kind, parameters, body, Scope, Strict )
The abstract operation AsyncFunctionCreate requires the arguments: kind which is one of (
- Let functionPrototype be the intrinsic object
%AsyncFunctionPrototype% .
9.2.9 AddRestrictedFunctionProperties ( F, realm )
The abstract operation AddRestrictedFunctionProperties is called with a
Assert : realm.[[Intrinsics]].[[%ThrowTypeError% ]] exists and has been initialized.- Let thrower be realm.[[Intrinsics]].[[
%ThrowTypeError% ]]. - Perform !
DefinePropertyOrThrow (F,"caller", PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]:false , [[Configurable]]:true }). - Return !
DefinePropertyOrThrow (F,"arguments", PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]:false , [[Configurable]]:true }).
9.2.9.1 %ThrowTypeError% ( )
The
- Throw a
TypeError exception.
The value of the [[Extensible]] internal slot of a
The "length" property of a
9.2.10 MakeConstructor ( F [ , writablePrototype [ , prototype ] ] )
The abstract operation MakeConstructor requires a Function argument F and optionally, a Boolean writablePrototype and an object prototype. If prototype is provided it is assumed to already contain, if needed, a "constructor" property whose value is F. This operation converts F into a
Assert : F is an ECMAScriptfunction object .Assert :IsConstructor (F) istrue .Assert : F is an extensible object that does not have aprototypeown property.- If writablePrototype is not present, set writablePrototype to
true . - If prototype is not present, then
Set prototype toObjectCreate (%ObjectPrototype% ).- Perform !
DefinePropertyOrThrow (prototype,"constructor", PropertyDescriptor { [[Value]]: F, [[Writable]]: writablePrototype, [[Enumerable]]:false , [[Configurable]]:true }).
- Perform !
DefinePropertyOrThrow (F,"prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: writablePrototype, [[Enumerable]]:false , [[Configurable]]:false }). - Return
NormalCompletion (undefined ).
9.2.11 MakeClassConstructor ( F )
The abstract operation MakeClassConstructor with argument F performs the following steps:
Assert : F is an ECMAScriptfunction object .Assert : F.[[FunctionKind]] is"normal".Set F.[[FunctionKind]] to"classConstructor".- Return
NormalCompletion (undefined ).
9.2.12 MakeMethod ( F, homeObject )
The abstract operation MakeMethod with arguments F and homeObject configures F as a method by performing the following steps:
Assert : F is an ECMAScriptfunction object .Assert :Type (homeObject) is Object.Set F.[[HomeObject]] to homeObject.- Return
NormalCompletion (undefined ).
9.2.13 SetFunctionName ( F, name [ , prefix ] )
The abstract operation SetFunctionName requires a Function argument F, a String or Symbol argument name and optionally a String argument prefix. This operation adds a name property to F by performing the following steps:
Assert : F is an extensible object that does not have anameown property.Assert :Type (name) is either Symbol or String.Assert : If prefix is present, thenType (prefix) is String.- If
Type (name) is Symbol, then- Let description be name's [[Description]] value.
- If description is
undefined , set name to the empty String. - Else, set name to the
string-concatenation of"[", description, and"]".
- If prefix is present, then
Set name to thestring-concatenation of prefix, the code unit 0x0020 (SPACE), and name.
- Return !
DefinePropertyOrThrow (F,"name", PropertyDescriptor { [[Value]]: name, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:true }).
9.2.14 SetFunctionLength ( F, length )
The abstract operation SetFunctionLength requires a Function argument F and a Number argument length. This operation adds a "length" property to F by performing the following steps:
Assert : F is an extensible object that does not have a"length"own property.Assert :Type (length) is Number.Assert : length ≥ 0 and !ToInteger (length) is equal to length.- Return !
DefinePropertyOrThrow (F,"length", PropertyDescriptor { [[Value]]: length, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:true }).
9.2.15 FunctionDeclarationInstantiation ( func, argumentsList )
When an
FunctionDeclarationInstantiation is performed as follows using arguments func and argumentsList. func is the
- Let calleeContext be the
running execution context . - Let env be the LexicalEnvironment of calleeContext.
- Let envRec be env's
EnvironmentRecord . - Let code be func.[[ECMAScriptCode]].
- Let strict be func.[[Strict]].
- Let formals be func.[[FormalParameters]].
- Let parameterNames be the BoundNames of formals.
- If parameterNames has any duplicate entries, let hasDuplicates be
true . Otherwise, let hasDuplicates befalse . - Let simpleParameterList be IsSimpleParameterList of formals.
- Let hasParameterExpressions be ContainsExpression of formals.
- Let varNames be the VarDeclaredNames of code.
- Let varDeclarations be the VarScopedDeclarations of code.
- Let lexicalNames be the LexicallyDeclaredNames of code.
- Let functionNames be a new empty
List . - Let functionsToInitialize be a new empty
List . - For each d in varDeclarations, in reverse list order, do
- If d is neither a
VariableDeclaration nor aForBinding nor aBindingIdentifier , thenAssert : d is either aFunctionDeclaration , aGeneratorDeclaration , anAsyncFunctionDeclaration , or anAsyncGeneratorDeclaration .- Let fn be the sole element of the BoundNames of d.
- If fn is not an element of functionNames, then
- Insert fn as the first element of functionNames.
- NOTE: If there are multiple function declarations for the same name, the last declaration is used.
- Insert d as the first element of functionsToInitialize.
- If d is neither a
- Let argumentsObjectNeeded be
true . - If func.[[ThisMode]] is
lexical , then- NOTE: Arrow functions never have an arguments objects.
Set argumentsObjectNeeded tofalse .
- Else if
"arguments"is an element of parameterNames, thenSet argumentsObjectNeeded tofalse .
- Else if hasParameterExpressions is
false , then- If
"arguments"is an element of functionNames or if"arguments"is an element of lexicalNames, thenSet argumentsObjectNeeded tofalse .
- If
- For each String paramName in parameterNames, do
- Let alreadyDeclared be envRec.HasBinding(paramName).
- NOTE: Early errors ensure that duplicate parameter names can only occur in non-strict functions that do not have parameter default values or rest parameters.
- If alreadyDeclared is
false , then- Perform ! envRec.CreateMutableBinding(paramName,
false ). - If hasDuplicates is
true , then- Perform ! envRec.InitializeBinding(paramName,
undefined ).
- Perform ! envRec.InitializeBinding(paramName,
- Perform ! envRec.CreateMutableBinding(paramName,
- If argumentsObjectNeeded is
true , then- If strict is
true or if simpleParameterList isfalse , then- Let ao be
CreateUnmappedArgumentsObject (argumentsList).
- Let ao be
- Else,
- NOTE: mapped argument object is only provided for non-strict functions that don't have a rest parameter, any parameter default value initializers, or any destructured parameters.
- Let ao be
CreateMappedArgumentsObject (func, formals, argumentsList, envRec).
- If strict is
true , then- Perform ! envRec.CreateImmutableBinding(
"arguments",false ).
- Perform ! envRec.CreateImmutableBinding(
- Else,
- Perform ! envRec.CreateMutableBinding(
"arguments",false ).
- Perform ! envRec.CreateMutableBinding(
- Call envRec.InitializeBinding(
"arguments", ao). - Let parameterBindings be a new
List of parameterNames with"arguments"appended.
- If strict is
- Else,
- Let parameterBindings be parameterNames.
- Let iteratorRecord be
CreateListIteratorRecord (argumentsList). - If hasDuplicates is
true , then- Perform ? IteratorBindingInitialization for formals with iteratorRecord and
undefined as arguments.
- Perform ? IteratorBindingInitialization for formals with iteratorRecord and
- Else,
- Perform ? IteratorBindingInitialization for formals with iteratorRecord and env as arguments.
- If hasParameterExpressions is
false , then- NOTE: Only a single lexical environment is needed for the parameters and top-level vars.
- Let instantiatedVarNames be a copy of the
List parameterBindings. - For each n in varNames, do
- If n is not an element of instantiatedVarNames, then
- Append n to instantiatedVarNames.
- Perform ! envRec.CreateMutableBinding(n,
false ). - Call envRec.InitializeBinding(n,
undefined ).
- If n is not an element of instantiatedVarNames, then
- Let varEnv be env.
- Let varEnvRec be envRec.
- Else,
- NOTE: A separate
Environment Record is needed to ensure that closures created by expressions in the formal parameter list do not have visibility of declarations in the function body. - Let varEnv be
NewDeclarativeEnvironment (env). - Let varEnvRec be varEnv's
EnvironmentRecord . Set the VariableEnvironment of calleeContext to varEnv.- Let instantiatedVarNames be a new empty
List . - For each n in varNames, do
- If n is not an element of instantiatedVarNames, then
- Append n to instantiatedVarNames.
- Perform ! varEnvRec.CreateMutableBinding(n,
false ). - If n is not an element of parameterBindings or if n is an element of functionNames, let initialValue be
undefined . - Else,
- Let initialValue be ! envRec.GetBindingValue(n,
false ).
- Let initialValue be ! envRec.GetBindingValue(n,
- Call varEnvRec.InitializeBinding(n, initialValue).
- NOTE: vars whose names are the same as a formal parameter, initially have the same value as the corresponding initialized parameter.
- If n is not an element of instantiatedVarNames, then
- NOTE: A separate
- NOTE: Annex
B.3.3.1 adds additional steps at this point. - If strict is
false , then- Let lexEnv be
NewDeclarativeEnvironment (varEnv). - NOTE: Non-strict functions use a separate lexical
Environment Record for top-level lexical declarations so that adirect eval can determine whether any var scoped declarations introduced by the eval code conflict with pre-existing top-level lexically scoped declarations. This is not needed for strict functions because a strictdirect eval always places all declarations into a newEnvironment Record .
- Let lexEnv be
- Else, let lexEnv be varEnv.
- Let lexEnvRec be lexEnv's
EnvironmentRecord . Set the LexicalEnvironment of calleeContext to lexEnv.- Let lexDeclarations be the LexicallyScopedDeclarations of code.
- For each element d in lexDeclarations, do
- NOTE: A lexically declared name cannot be the same as a function/generator declaration, formal parameter, or a var name. Lexically declared names are only instantiated here but not initialized.
- For each element dn of the BoundNames of d, do
- If IsConstantDeclaration of d is
true , then- Perform ! lexEnvRec.CreateImmutableBinding(dn,
true ).
- Perform ! lexEnvRec.CreateImmutableBinding(dn,
- Else,
- Perform ! lexEnvRec.CreateMutableBinding(dn,
false ).
- Perform ! lexEnvRec.CreateMutableBinding(dn,
- If IsConstantDeclaration of d is
- For each
Parse Node f in functionsToInitialize, do- Let fn be the sole element of the BoundNames of f.
- Let fo be the result of performing InstantiateFunctionObject for f with argument lexEnv.
- Perform ! varEnvRec.SetMutableBinding(fn, fo,
false ).
- Return
NormalCompletion (empty ).
Parameter
9.3 Built-in Function Objects
The built-in function objects defined in this specification may be implemented as either ECMAScript function objects (
If a built-in
Unless otherwise specified every built-in
The behaviour specified for each built-in function via algorithm steps or other means is the specification of the function body behaviour for both [[Call]] and [[Construct]] invocations of the function. However, [[Construct]] invocation is not supported by all built-in functions. For each built-in function, when invoked with [[Call]], the [[Call]] thisArgument provides the "classConstructor".
Built-in function objects that are not identified as constructors do not implement the [[Construct]] internal method unless otherwise specified in the description of a particular function. When a built-in new expression the argumentsList parameter of the invoked [[Construct]] internal method provides the values for the built-in
Built-in functions that are not constructors do not have a prototype property unless otherwise specified in the description of a particular function.
If a built-in
9.3.1 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method for a built-in
- Let callerContext be the
running execution context . - If callerContext is not already suspended, suspend callerContext.
- Let calleeContext be a new ECMAScript code
execution context . Set the Function of calleeContext to F.- Let calleeRealm be F.[[Realm]].
Set theRealm of calleeContext to calleeRealm.Set the ScriptOrModule of calleeContext to F.[[ScriptOrModule]].- Perform any necessary implementation-defined initialization of calleeContext.
- Push calleeContext onto the
execution context stack ; calleeContext is now therunning execution context . - Let result be the
Completion Record that is the result of evaluating F in an implementation-defined manner that conforms to the specification of F. thisArgument is thethis value, argumentsList provides the named parameters, and the NewTarget value isundefined . - Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - Return result.
When calleeContext is removed from the
9.3.2 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method for built-in
9.3.3 CreateBuiltinFunction ( steps, internalSlotsList [ , realm [ , prototype ] ] )
The abstract operation CreateBuiltinFunction takes arguments steps, internalSlotsList, realm, and prototype. The argument internalSlotsList is a
Assert : steps is either a set of algorithm steps or other definition of a function's behaviour provided in this specification.- If realm is not present, set realm to
the current Realm Record . Assert : realm is aRealm Record .- If prototype is not present, set prototype to realm.[[Intrinsics]].[[
%FunctionPrototype% ]]. - Let func be a new built-in
function object that when called performs the action described by steps. The newfunction object has internal slots whose names are the elements of internalSlotsList. The initial value of each of those internal slots isundefined . Set func.[[Realm]] to realm.Set func.[[Prototype]] to prototype.Set func.[[Extensible]] totrue .Set func.[[ScriptOrModule]] tonull .- Return func.
Each built-in function defined in this specification is created by calling the CreateBuiltinFunction abstract operation.
9.4 Built-in Exotic Object Internal Methods and Slots
This specification defines several kinds of built-in exotic objects. These objects generally behave similar to ordinary objects except for a few specific situations. The following exotic objects use the ordinary object internal methods except where it is explicitly specified otherwise below:
9.4.1 Bound Function Exotic Objects
A bound function is an
Bound function objects do not have the internal slots of ECMAScript function objects defined in
| Internal Slot |
|
Description |
|---|---|---|
| [[BoundTargetFunction]] | Callable Object |
The wrapped |
| [[BoundThis]] | Any |
The value that is always passed as the |
| [[BoundArguments]] |
|
A list of values whose elements are used as the first arguments to any call to the wrapped function. |
Bound function objects provide all of the essential internal methods as specified in
9.4.1.1 [[Call]] ( thisArgument, argumentsList )
When the [[Call]] internal method of a
- Let target be F.[[BoundTargetFunction]].
- Let boundThis be F.[[BoundThis]].
- Let boundArgs be F.[[BoundArguments]].
- Let args be a new list containing the same values as the list boundArgs in the same order followed by the same values as the list argumentsList in the same order.
- Return ?
Call (target, boundThis, args).
9.4.1.2 [[Construct]] ( argumentsList, newTarget )
When the [[Construct]] internal method of a
- Let target be F.[[BoundTargetFunction]].
Assert :IsConstructor (target) istrue .- Let boundArgs be F.[[BoundArguments]].
- Let args be a new list containing the same values as the list boundArgs in the same order followed by the same values as the list argumentsList in the same order.
- If
SameValue (F, newTarget) istrue , set newTarget to target. - Return ?
Construct (target, args, newTarget).
9.4.1.3 BoundFunctionCreate ( targetFunction, boundThis, boundArgs )
The abstract operation BoundFunctionCreate with arguments targetFunction, boundThis and boundArgs is used to specify the creation of new Bound Function exotic objects. It performs the following steps:
Assert :Type (targetFunction) is Object.- Let proto be ? targetFunction.[[GetPrototypeOf]]().
- Let obj be a newly created object.
Set obj's essential internal methods to the default ordinary object definitions specified in9.1 .Set obj.[[Call]] as described in9.4.1.1 .- If
IsConstructor (targetFunction) istrue , then Set obj.[[Prototype]] to proto.Set obj.[[Extensible]] totrue .Set obj.[[BoundTargetFunction]] to targetFunction.Set obj.[[BoundThis]] to boundThis.Set obj.[[BoundArguments]] to boundArgs.- Return obj.
9.4.2 Array Exotic Objects
An Array object is an "length" property whose value is always a nonnegative integer less than 232. The value of the "length" property is numerically greater than the name of every own property whose name is an "length" property is changed, if necessary, to be one more than the numeric value of that "length" property is changed, every own property whose name is an "length" or
A String
Array exotic objects provide an alternative definition for the [[DefineOwnProperty]] internal method. Except for that internal method, Array exotic objects provide all of the other essential internal methods as specified in
9.4.2.1 [[DefineOwnProperty]] ( P, Desc )
When the [[DefineOwnProperty]] internal method of an Array
Assert :IsPropertyKey (P) istrue .- If P is
"length", then- Return ?
ArraySetLength (A, Desc).
- Return ?
- Else if P is an
array index , then- Let oldLenDesc be
OrdinaryGetOwnProperty (A,"length"). Assert : oldLenDesc will never beundefined or an accessor descriptor because Array objects are created with a lengthdata property that cannot be deleted or reconfigured.- Let oldLen be oldLenDesc.[[Value]].
- Let index be !
ToUint32 (P). - If index ≥ oldLen and oldLenDesc.[[Writable]] is
false , returnfalse . - Let succeeded be !
OrdinaryDefineOwnProperty (A, P, Desc). - If succeeded is
false , returnfalse . - If index ≥ oldLen, then
Set oldLenDesc.[[Value]] to index + 1.- Let succeeded be
OrdinaryDefineOwnProperty (A,"length", oldLenDesc). Assert : succeeded istrue .
- Return
true .
- Let oldLenDesc be
- Return
OrdinaryDefineOwnProperty (A, P, Desc).
9.4.2.2 ArrayCreate ( length [ , proto ] )
The abstract operation ArrayCreate with argument length (either 0 or a positive integer) and optional argument proto is used to specify the creation of new Array exotic objects. It performs the following steps:
Assert : length is an integer Number ≥ 0.- If length is
-0 , set length to+0 . - If length > 232 - 1, throw a
RangeError exception. - If proto is not present, set proto to the intrinsic object
%ArrayPrototype% . - Let A be a newly created Array
exotic object . Set A's essential internal methods except for [[DefineOwnProperty]] to the default ordinary object definitions specified in9.1 .Set A.[[DefineOwnProperty]] as specified in9.4.2.1 .Set A.[[Prototype]] to proto.Set A.[[Extensible]] totrue .- Perform !
OrdinaryDefineOwnProperty (A,"length", PropertyDescriptor { [[Value]]: length, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Return A.
9.4.2.3 ArraySpeciesCreate ( originalArray, length )
The abstract operation ArraySpeciesCreate with arguments originalArray and length is used to specify the creation of a new Array object using a
Assert : length is an integer Number ≥ 0.- If length is
-0 , set length to+0 . - Let isArray be ?
IsArray (originalArray). - If isArray is
false , return ?ArrayCreate (length). - Let C be ?
Get (originalArray,"constructor"). - If
IsConstructor (C) istrue , then- Let thisRealm be
the current Realm Record . - Let realmC be ?
GetFunctionRealm (C). - If thisRealm and realmC are not the same
Realm Record , then- If
SameValue (C, realmC.[[Intrinsics]].[[%Array% ]]) istrue , set C toundefined .
- If
- Let thisRealm be
- If
Type (C) is Object, then - If C is
undefined , return ?ArrayCreate (length). - If
IsConstructor (C) isfalse , throw aTypeError exception. - Return ?
Construct (C, « length »).
If originalArray was created using the standard built-in Array
9.4.2.4 ArraySetLength ( A, Desc )
When the abstract operation ArraySetLength is called with an Array
- If Desc.[[Value]] is absent, then
- Return
OrdinaryDefineOwnProperty (A,"length", Desc).
- Return
- Let newLenDesc be a copy of Desc.
- Let newLen be ?
ToUint32 (Desc.[[Value]]). - Let numberLen be ?
ToNumber (Desc.[[Value]]). - If newLen ≠ numberLen, throw a
RangeError exception. Set newLenDesc.[[Value]] to newLen.- Let oldLenDesc be
OrdinaryGetOwnProperty (A,"length"). Assert : oldLenDesc will never beundefined or an accessor descriptor because Array objects are created with a lengthdata property that cannot be deleted or reconfigured.- Let oldLen be oldLenDesc.[[Value]].
- If newLen ≥ oldLen, then
- Return
OrdinaryDefineOwnProperty (A,"length", newLenDesc).
- Return
- If oldLenDesc.[[Writable]] is
false , returnfalse . - If newLenDesc.[[Writable]] is absent or has the value
true , let newWritable betrue . - Else,
- Need to defer setting the [[Writable]] attribute to
false in case any elements cannot be deleted. - Let newWritable be
false . Set newLenDesc.[[Writable]] totrue .
- Need to defer setting the [[Writable]] attribute to
- Let succeeded be !
OrdinaryDefineOwnProperty (A,"length", newLenDesc). - If succeeded is
false , returnfalse . - Repeat, while newLen < oldLen,
- Decrease oldLen by 1.
- Let deleteSucceeded be ! A.[[Delete]](!
ToString (oldLen)). - If deleteSucceeded is
false , thenSet newLenDesc.[[Value]] to oldLen + 1.- If newWritable is
false , set newLenDesc.[[Writable]] tofalse . - Perform !
OrdinaryDefineOwnProperty (A,"length", newLenDesc). - Return
false .
- If newWritable is
false , then- Return
OrdinaryDefineOwnProperty (A,"length", PropertyDescriptor { [[Writable]]:false }). This call will always returntrue .
- Return
- Return
true .
In steps 3 and 4, if Desc.[[Value]] is an object then its valueOf method is called twice. This is legacy behaviour that was specified with this effect starting with the 2nd Edition of this specification.
9.4.3 String Exotic Objects
A String object is an "length" whose value is the number of code unit elements in the encapsulated String value. Both the code unit data properties and the "length" property are non-writable and non-configurable.
String exotic objects have the same internal slots as ordinary objects. They also have a [[StringData]] internal slot.
String exotic objects provide alternative definitions for the following internal methods. All of the other String
9.4.3.1 [[GetOwnProperty]] ( P )
When the [[GetOwnProperty]] internal method of a String
Assert :IsPropertyKey (P) istrue .- Let desc be
OrdinaryGetOwnProperty (S, P). - If desc is not
undefined , return desc. - Return !
StringGetOwnProperty (S, P).
9.4.3.2 [[DefineOwnProperty]] ( P, Desc )
When the [[DefineOwnProperty]] internal method of a String
Assert :IsPropertyKey (P) istrue .- Let stringDesc be !
StringGetOwnProperty (S, P). - If stringDesc is not
undefined , then- Let extensible be S.[[Extensible]].
- Return !
IsCompatiblePropertyDescriptor (extensible, Desc, stringDesc).
- Return !
OrdinaryDefineOwnProperty (S, P, Desc).
9.4.3.3 [[OwnPropertyKeys]] ( )
When the [[OwnPropertyKeys]] internal method of a String
- Let keys be a new empty
List . - Let str be O.[[StringData]].
Assert :Type (str) is String.- Let len be the length of str.
- For each integer i starting with 0 such that i < len, in ascending order, do
- Add !
ToString (i) as the last element of keys.
- Add !
- For each own property key P of O such that P is an
array index andToInteger (P) ≥ len, in ascending numeric index order, do- Add P as the last element of keys.
- For each own property key P of O such that
Type (P) is String and P is not anarray index , in ascending chronological order of property creation, do- Add P as the last element of keys.
- For each own property key P of O such that
Type (P) is Symbol, in ascending chronological order of property creation, do- Add P as the last element of keys.
- Return keys.
9.4.3.4 StringCreate ( value, prototype )
The abstract operation StringCreate with arguments value and prototype is used to specify the creation of new String exotic objects. It performs the following steps:
Assert :Type (value) is String.- Let S be a newly created String
exotic object . Set S.[[StringData]] to value.Set S's essential internal methods to the default ordinary object definitions specified in9.1 .Set S.[[GetOwnProperty]] as specified in9.4.3.1 .Set S.[[DefineOwnProperty]] as specified in9.4.3.2 .Set S.[[OwnPropertyKeys]] as specified in9.4.3.3 .Set S.[[Prototype]] to prototype.Set S.[[Extensible]] totrue .- Let length be the number of code unit elements in value.
- Perform !
DefinePropertyOrThrow (S,"length", PropertyDescriptor { [[Value]]: length, [[Writable]]:false , [[Enumerable]]:false , [[Configurable]]:false }). - Return S.
9.4.3.5 StringGetOwnProperty ( S, P )
The abstract operation StringGetOwnProperty called with arguments S and P performs the following steps:
Assert : S is an Object that has a [[StringData]] internal slot.Assert :IsPropertyKey (P) istrue .- If
Type (P) is not String, returnundefined . - Let index be !
CanonicalNumericIndexString (P). - If index is
undefined , returnundefined . - If
IsInteger (index) isfalse , returnundefined . - If index =
-0 , returnundefined . - Let str be S.[[StringData]].
Assert :Type (str) is String.- Let len be the length of str.
- If index < 0 or len ≤ index, return
undefined . - Let resultStr be the String value of length 1, containing one code unit from str, specifically the code unit at index index.
- Return a PropertyDescriptor { [[Value]]: resultStr, [[Writable]]:
false , [[Enumerable]]:true , [[Configurable]]:false }.
9.4.4 Arguments Exotic Objects
Most ECMAScript functions make an arguments object available to their code. Depending upon the characteristics of the function definition, its arguments object is either an ordinary object or an arguments
Arguments exotic objects have the same internal slots as ordinary objects. They also have a [[ParameterMap]] internal slot. Ordinary arguments objects also have a [[ParameterMap]] internal slot whose value is always undefined. For ordinary argument objects the [[ParameterMap]] internal slot is only used by Object.prototype.toString (
Arguments exotic objects provide alternative definitions for the following internal methods. All of the other arguments
The integer-indexed data properties of an arguments
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 "callee" which throws a "callee" property has a more specific meaning for arguments exotic objects, which are created only for some class of non-strict functions. The definition of this property in the ordinary variant exists to ensure that it is not defined in any other manner by conforming ECMAScript implementations.
ECMAScript implementations of arguments exotic objects have historically contained an "caller". Prior to ECMAScript 2017, this specification included the definition of a throwing "caller" property on ordinary arguments objects. Since implementations do not contain this extension any longer, ECMAScript 2017 dropped the requirement for a throwing "caller" accessor.
9.4.4.1 [[GetOwnProperty]] ( P )
The [[GetOwnProperty]] internal method of an arguments
- Let args be the arguments object.
- Let desc be
OrdinaryGetOwnProperty (args, P). - If desc is
undefined , return desc. - Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P). - If isMapped is
true , then - Return desc.
9.4.4.2 [[DefineOwnProperty]] ( P, Desc )
The [[DefineOwnProperty]] internal method of an arguments
- Let args be the arguments object.
- Let map be args.[[ParameterMap]].
- Let isMapped be
HasOwnProperty (map, P). - Let newArgDesc be Desc.
- If isMapped is
true andIsDataDescriptor (Desc) istrue , then - Let allowed be ?
OrdinaryDefineOwnProperty (args, P, newArgDesc). - If allowed is
false , returnfalse . - If isMapped is
true , then- If
IsAccessorDescriptor (Desc) istrue , then- Call map.[[Delete]](P).
- Else,
- If
- Return
true .
9.4.4.3 [[Get]] ( P, Receiver )
The [[Get]] internal method of an arguments
- Let args be the arguments object.
- Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P). - If isMapped is
false , then- Return ?
OrdinaryGet (args, P, Receiver).
- Return ?
- Else map contains a formal parameter mapping for P,
- Return
Get (map, P).
- Return
9.4.4.4 [[Set]] ( P, V, Receiver )
The [[Set]] internal method of an arguments
- Let args be the arguments object.
- If
SameValue (args, Receiver) isfalse , then- Let isMapped be
false .
- Let isMapped be
- Else,
- Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P).
- If isMapped is
true , then - Return ?
OrdinarySet (args, P, V, Receiver).
9.4.4.5 [[Delete]] ( P )
The [[Delete]] internal method of an arguments
- Let args be the arguments object.
- Let map be args.[[ParameterMap]].
- Let isMapped be !
HasOwnProperty (map, P). - Let result be ?
OrdinaryDelete (args, P). - If result is
true and isMapped istrue , then- Call map.[[Delete]](P).
- Return result.
9.4.4.6 CreateUnmappedArgumentsObject ( argumentsList )
The abstract operation CreateUnmappedArgumentsObject called with an argument argumentsList performs the following steps:
- Let len be the number of elements in argumentsList.
- Let obj be
ObjectCreate (%ObjectPrototype% , « [[ParameterMap]] »). Set obj.[[ParameterMap]] toundefined .- Perform
DefinePropertyOrThrow (obj,"length", PropertyDescriptor { [[Value]]: len, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Let index be 0.
- Repeat, while index < len,
- Let val be argumentsList[index].
- Perform
CreateDataProperty (obj, !ToString (index), val). - Increase index by 1.
- Perform !
DefinePropertyOrThrow (obj, @@iterator, PropertyDescriptor { [[Value]]: %ArrayProto_values%, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Perform !
DefinePropertyOrThrow (obj,"callee", PropertyDescriptor { [[Get]]:%ThrowTypeError% , [[Set]]:%ThrowTypeError% , [[Enumerable]]:false , [[Configurable]]:false }). - Return obj.
9.4.4.7 CreateMappedArgumentsObject ( func, formals, argumentsList, env )
The abstract operation CreateMappedArgumentsObject is called with object func,
Assert : formals does not contain a rest parameter, any binding patterns, or any initializers. It may contain duplicate identifiers.- Let len be the number of elements in argumentsList.
- Let obj be a newly created arguments
exotic object with a [[ParameterMap]] internal slot. Set obj.[[GetOwnProperty]] as specified in9.4.4.1 .Set obj.[[DefineOwnProperty]] as specified in9.4.4.2 .Set obj.[[Get]] as specified in9.4.4.3 .Set obj.[[Set]] as specified in9.4.4.4 .Set obj.[[Delete]] as specified in9.4.4.5 .Set the remainder of obj's essential internal methods to the default ordinary object definitions specified in9.1 .Set obj.[[Prototype]] to%ObjectPrototype% .Set obj.[[Extensible]] totrue .- Let map be
ObjectCreate (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
CreateDataProperty (obj, !ToString (index), val). - Increase index by 1.
- Perform
DefinePropertyOrThrow (obj,"length", PropertyDescriptor { [[Value]]: len, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Let mappedNames be a new empty
List . - Let index be numberOfParameters - 1.
- Repeat, while index ≥ 0,
- Let name be parameterNames[index].
- If name is not an element of mappedNames, then
- Add name as an element of the list mappedNames.
- If index < len, then
- Let g be
MakeArgGetter (name, env). - Let p be
MakeArgSetter (name, env). - Perform map.[[DefineOwnProperty]](!
ToString (index), PropertyDescriptor { [[Set]]: p, [[Get]]: g, [[Enumerable]]:false , [[Configurable]]:true }).
- Let g be
- Decrease index by 1.
- Perform !
DefinePropertyOrThrow (obj, @@iterator, PropertyDescriptor { [[Value]]: %ArrayProto_values%, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Perform !
DefinePropertyOrThrow (obj,"callee", PropertyDescriptor { [[Value]]: func, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:true }). - Return obj.
9.4.4.7.1 MakeArgGetter ( name, env )
The abstract operation MakeArgGetter called with String name and
- Let steps be the steps of an ArgGetter function as specified below.
- Let getter be
CreateBuiltinFunction (steps, « [[Name]], [[Env]] »). Set getter.[[Name]] to name.Set getter.[[Env]] to env.- Return getter.
An ArgGetter function is an anonymous built-in function with [[Name]] and [[Env]] internal slots. When an ArgGetter function that expects no arguments is called it performs the following steps:
- Let f be the
active function object . - Let name be f.[[Name]].
- Let env be f.[[Env]].
- Return env.GetBindingValue(name,
false ).
ArgGetter functions are never directly accessible to ECMAScript code.
9.4.4.7.2 MakeArgSetter ( name, env )
The abstract operation MakeArgSetter called with String name and
- Let steps be the steps of an ArgSetter function as specified below.
- Let setter be
CreateBuiltinFunction (steps, « [[Name]], [[Env]] »). Set setter.[[Name]] to name.Set setter.[[Env]] to env.- Return setter.
An ArgSetter function is an anonymous built-in function with [[Name]] and [[Env]] internal slots. When an ArgSetter function is called with argument value it performs the following steps:
- Let f be the
active function object . - Let name be f.[[Name]].
- Let env be f.[[Env]].
- Return env.SetMutableBinding(name, value,
false ).
ArgSetter functions are never directly accessible to ECMAScript code.
9.4.5 Integer-Indexed Exotic Objects
An Integer-Indexed exotic object is an
9.4.5.1 [[GetOwnProperty]] ( P )
When the [[GetOwnProperty]] internal method of an
Assert :IsPropertyKey (P) istrue .Assert : O is an Object that has a [[ViewedArrayBuffer]] internal slot.- If
Type (P) is String, then- Let numericIndex be !
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- Let value be ?
IntegerIndexedElementGet (O, numericIndex). - If value is
undefined , returnundefined . - Return a PropertyDescriptor { [[Value]]: value, [[Writable]]:
true , [[Enumerable]]:true , [[Configurable]]:false }.
- Let value be ?
- Let numericIndex be !
- Return
OrdinaryGetOwnProperty (O, P).
9.4.5.2 [[HasProperty]] ( P )
When the [[HasProperty]] internal method of an
Assert :IsPropertyKey (P) istrue .Assert : O is an Object that has a [[ViewedArrayBuffer]] internal slot.- If
Type (P) is String, then- Let numericIndex be !
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- Let buffer be O.[[ViewedArrayBuffer]].
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - If
IsInteger (numericIndex) isfalse , returnfalse . - If numericIndex =
-0 , returnfalse . - If numericIndex < 0, return
false . - If numericIndex ≥ O.[[ArrayLength]], return
false . - Return
true .
- Let numericIndex be !
- Return ?
OrdinaryHasProperty (O, P).
9.4.5.3 [[DefineOwnProperty]] ( P, Desc )
When the [[DefineOwnProperty]] internal method of an
Assert :IsPropertyKey (P) istrue .Assert : O is an Object that has a [[ViewedArrayBuffer]] internal slot.- If
Type (P) is String, then- Let numericIndex be !
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- If
IsInteger (numericIndex) isfalse , returnfalse . - If numericIndex =
-0 , returnfalse . - If numericIndex < 0, return
false . - Let length be O.[[ArrayLength]].
- If numericIndex ≥ length, return
false . - If
IsAccessorDescriptor (Desc) istrue , returnfalse . - If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is
true , returnfalse . - If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is
false , returnfalse . - If Desc has a [[Writable]] field and if Desc.[[Writable]] is
false , returnfalse . - If Desc has a [[Value]] field, then
- Let value be Desc.[[Value]].
- Return ?
IntegerIndexedElementSet (O, numericIndex, value).
- Return
true .
- If
- Let numericIndex be !
- Return !
OrdinaryDefineOwnProperty (O, P, Desc).
9.4.5.4 [[Get]] ( P, Receiver )
When the [[Get]] internal method of an
Assert :IsPropertyKey (P) istrue .- If
Type (P) is String, then- Let numericIndex be !
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- Return ?
IntegerIndexedElementGet (O, numericIndex).
- Return ?
- Let numericIndex be !
- Return ?
OrdinaryGet (O, P, Receiver).
9.4.5.5 [[Set]] ( P, V, Receiver )
When the [[Set]] internal method of an
Assert :IsPropertyKey (P) istrue .- If
Type (P) is String, then- Let numericIndex be !
CanonicalNumericIndexString (P). - If numericIndex is not
undefined , then- Return ?
IntegerIndexedElementSet (O, numericIndex, V).
- Return ?
- Let numericIndex be !
- Return ?
OrdinarySet (O, P, V, Receiver).
9.4.5.6 [[OwnPropertyKeys]] ( )
When the [[OwnPropertyKeys]] internal method of an
- Let keys be a new empty
List . Assert : O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.- Let len be O.[[ArrayLength]].
- For each integer i starting with 0 such that i < len, in ascending order, do
- Add !
ToString (i) as the last element of keys.
- Add !
- For each own property key P of O such that
Type (P) is String and P is not aninteger index , in ascending chronological order of property creation, do- Add P as the last element of keys.
- For each own property key P of O such that
Type (P) is Symbol, in ascending chronological order of property creation, do- Add P as the last element of keys.
- Return keys.
9.4.5.7 IntegerIndexedObjectCreate ( prototype, internalSlotsList )
The abstract operation IntegerIndexedObjectCreate with arguments prototype and internalSlotsList is used to specify the creation of new
Assert : internalSlotsList contains the names [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]].- Let A be a newly created object with an internal slot for each name in internalSlotsList.
Set A's essential internal methods to the default ordinary object definitions specified in9.1 .Set A.[[GetOwnProperty]] as specified in9.4.5.1 .Set A.[[HasProperty]] as specified in9.4.5.2 .Set A.[[DefineOwnProperty]] as specified in9.4.5.3 .Set A.[[Get]] as specified in9.4.5.4 .Set A.[[Set]] as specified in9.4.5.5 .Set A.[[OwnPropertyKeys]] as specified in9.4.5.6 .Set A.[[Prototype]] to prototype.Set A.[[Extensible]] totrue .- Return A.
9.4.5.8 IntegerIndexedElementGet ( O, index )
The abstract operation IntegerIndexedElementGet with arguments O and index performs the following steps:
Assert :Type (index) is Number.Assert : O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.- Let buffer be O.[[ViewedArrayBuffer]].
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - If
IsInteger (index) isfalse , returnundefined . - If index =
-0 , returnundefined . - Let length be O.[[ArrayLength]].
- If index < 0 or index ≥ length, return
undefined . - Let offset be O.[[ByteOffset]].
- Let arrayTypeName be the String value of O.[[TypedArrayName]].
- Let elementSize be the Number value of the Element Size value specified in
Table 59 for arrayTypeName. - Let indexedPosition be (index × elementSize) + offset.
- Let elementType be the String value of the Element
Type value inTable 59 for arrayTypeName. - Return
GetValueFromBuffer (buffer, indexedPosition, elementType,true ,"Unordered").
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
The abstract operation IntegerIndexedElementSet with arguments O, index, and value performs the following steps:
Assert :Type (index) is Number.Assert : O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.- Let numValue be ?
ToNumber (value). - Let buffer be O.[[ViewedArrayBuffer]].
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - If
IsInteger (index) isfalse , returnfalse . - If index =
-0 , returnfalse . - Let length be O.[[ArrayLength]].
- If index < 0 or index ≥ length, return
false . - Let offset be O.[[ByteOffset]].
- Let arrayTypeName be the String value of O.[[TypedArrayName]].
- Let elementSize be the Number value of the Element Size value specified in
Table 59 for arrayTypeName. - Let indexedPosition be (index × elementSize) + offset.
- Let elementType be the String value of the Element
Type value inTable 59 for arrayTypeName. - Perform
SetValueInBuffer (buffer, indexedPosition, elementType, numValue,true ,"Unordered"). - Return
true .
9.4.6 Module Namespace Exotic Objects
A module namespace object is an export * export items. Each String-valued own property key is the StringValue of the corresponding exported binding name. These are the only String-keyed properties of a module namespace
Module namespace objects have the internal slots defined in
| Internal Slot |
|
Description |
|---|---|---|
| [[Module]] |
|
The |
| [[Exports]] |
|
A Array.prototype.sort using |
| [[Prototype]] | Null |
This slot always contains the value |
Module namespace exotic objects provide alternative definitions for all of the internal methods except [[GetPrototypeOf]], which behaves as defined in
9.4.6.1 [[SetPrototypeOf]] ( V )
When the [[SetPrototypeOf]] internal method of a module namespace
- Return ?
SetImmutablePrototype (O, V).
9.4.6.2 [[IsExtensible]] ( )
When the [[IsExtensible]] internal method of a module namespace
- Return
false .
9.4.6.3 [[PreventExtensions]] ( )
When the [[PreventExtensions]] internal method of a module namespace
- Return
true .
9.4.6.4 [[GetOwnProperty]] ( P )
When the [[GetOwnProperty]] internal method of a module namespace
- If
Type (P) is Symbol, returnOrdinaryGetOwnProperty (O, P). - Let exports be O.[[Exports]].
- If P is not an element of exports, return
undefined . - Let value be ? O.[[Get]](P, O).
- Return PropertyDescriptor { [[Value]]: value, [[Writable]]:
true , [[Enumerable]]:true , [[Configurable]]:false }.
9.4.6.5 [[DefineOwnProperty]] ( P, Desc )
When the [[DefineOwnProperty]] internal method of a module namespace
- If
Type (P) is Symbol, returnOrdinaryDefineOwnProperty (O, P, Desc). - Let current be ? O.[[GetOwnProperty]](P).
- If current is
undefined , returnfalse . - If
IsAccessorDescriptor (Desc) istrue , returnfalse . - If Desc.[[Writable]] is present and has value
false , returnfalse . - If Desc.[[Enumerable]] is present and has value
false , returnfalse . - If Desc.[[Configurable]] is present and has value
true , returnfalse . - If Desc.[[Value]] is present, return
SameValue (Desc.[[Value]], current.[[Value]]). - Return
true .
9.4.6.6 [[HasProperty]] ( P )
When the [[HasProperty]] internal method of a module namespace
- If
Type (P) is Symbol, returnOrdinaryHasProperty (O, P). - Let exports be O.[[Exports]].
- If P is an element of exports, return
true . - Return
false .
9.4.6.7 [[Get]] ( P, Receiver )
When the [[Get]] internal method of a module namespace
Assert :IsPropertyKey (P) istrue .- If
Type (P) is Symbol, then- Return ?
OrdinaryGet (O, P, Receiver).
- Return ?
- Let exports be O.[[Exports]].
- If P is not an element of exports, return
undefined . - Let m be O.[[Module]].
- Let binding be ! m.ResolveExport(P, « »).
Assert : binding is aResolvedBinding Record .- Let targetModule be binding.[[Module]].
Assert : targetModule is notundefined .- Let targetEnv be targetModule.[[Environment]].
- If targetEnv is
undefined , throw aReferenceError exception. - Let targetEnvRec be targetEnv's
EnvironmentRecord . - Return ? targetEnvRec.GetBindingValue(binding.[[BindingName]],
true ).
ResolveExport is idempotent and side-effect free. An implementation might choose to pre-compute or cache the ResolveExport results for the [[Exports]] of each module namespace
9.4.6.8 [[Set]] ( P, V, Receiver )
When the [[Set]] internal method of a module namespace
- Return
false .
9.4.6.9 [[Delete]] ( P )
When the [[Delete]] internal method of a module namespace
Assert :IsPropertyKey (P) istrue .- If
Type (P) is Symbol, then- Return ?
OrdinaryDelete (O, P).
- Return ?
- Let exports be O.[[Exports]].
- If P is an element of exports, return
false . - Return
true .
9.4.6.10 [[OwnPropertyKeys]] ( )
When the [[OwnPropertyKeys]] internal method of a module namespace
- Let exports be a copy of O.[[Exports]].
- Let symbolKeys be !
OrdinaryOwnPropertyKeys (O). - Append all the entries of symbolKeys to the end of exports.
- Return exports.
9.4.6.11 ModuleNamespaceCreate ( module, exports )
The abstract operation ModuleNamespaceCreate with arguments module, and exports is used to specify the creation of new module namespace exotic objects. It performs the following steps:
Assert : module is aModule Record .Assert : module.[[Namespace]] isundefined .Assert : exports is aList of String values.- Let M be a newly created object.
Set M's essential internal methods to the definitions specified in9.4.6 .Set M.[[Module]] to module.- Let sortedExports be a new
List containing the same values as the list exports where the values are ordered as if an Array of the same values had been sorted usingArray.prototype.sortusingundefined as comparefn. Set M.[[Exports]] to sortedExports.- Create own properties of M corresponding to the definitions in
26.3 . Set module.[[Namespace]] to M.- Return M.
9.4.7 Immutable Prototype Exotic Objects
An immutable prototype exotic object is an
Immutable prototype exotic objects have the same internal slots as ordinary objects. They are exotic only in the following internal methods. All other internal methods of immutable prototype exotic objects that are not explicitly defined below are instead defined as in ordinary objects.
9.4.7.1 [[SetPrototypeOf]] ( V )
When the [[SetPrototypeOf]] internal method of an
- Return ?
SetImmutablePrototype (O, V).
9.4.7.2 SetImmutablePrototype ( O, V )
9.5 Proxy Object Internal Methods and Internal Slots
A proxy object is an
| Internal Method | Handler Method |
|---|---|
| [[GetPrototypeOf]] |
getPrototypeOf
|
| [[SetPrototypeOf]] |
setPrototypeOf
|
| [[IsExtensible]] |
isExtensible
|
| [[PreventExtensions]] |
preventExtensions
|
| [[GetOwnProperty]] |
getOwnPropertyDescriptor
|
| [[DefineOwnProperty]] |
defineProperty
|
| [[HasProperty]] |
has
|
| [[Get]] |
get
|
| [[Set]] |
set
|
| [[Delete]] |
deleteProperty
|
| [[OwnPropertyKeys]] |
ownKeys
|
| [[Call]] |
apply
|
| [[Construct]] |
construct
|
When a handler method is called to provide the implementation of a proxy object internal method, the handler method is passed the proxy's target object as a parameter. A proxy's handler object does not necessarily have a method corresponding to every essential internal method. Invoking an internal method on the proxy results in the invocation of the corresponding internal method on the proxy's target object if the handler object does not have a method corresponding to the internal trap.
The [[ProxyHandler]] and [[ProxyTarget]] internal slots of a proxy object are always initialized when the object is created and typically may not be modified. Some proxy objects are created in a manner that permits them to be subsequently revoked. When a proxy is revoked, its [[ProxyHandler]] and [[ProxyTarget]] internal slots are set to
Because proxy objects permit the implementation of internal methods to be provided by arbitrary ECMAScript code, it is possible to define a proxy object whose handler methods violates the invariants defined in
In the following algorithm descriptions, assume O is an ECMAScript proxy object, P is a property key value, V is any
9.5.1 [[GetPrototypeOf]] ( )
When the [[GetPrototypeOf]] internal method of a Proxy
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"getPrototypeOf"). - If trap is
undefined , then- Return ? target.[[GetPrototypeOf]]().
- Let handlerProto be ?
Call (trap, handler, « target »). - If
Type (handlerProto) is neither Object nor Null, throw aTypeError exception. - Let extensibleTarget be ?
IsExtensible (target). - If extensibleTarget is
true , return handlerProto. - Let targetProto be ? target.[[GetPrototypeOf]]().
- If
SameValue (handlerProto, targetProto) isfalse , throw aTypeError exception. - Return handlerProto.
[[GetPrototypeOf]] for proxy objects enforces the following invariants:
-
The result of [[GetPrototypeOf]] must be either an Object or
null . - If the target object is not extensible, [[GetPrototypeOf]] applied to the proxy object must return the same value as [[GetPrototypeOf]] applied to the proxy object's target object.
9.5.2 [[SetPrototypeOf]] ( V )
When the [[SetPrototypeOf]] internal method of a Proxy
Assert : EitherType (V) is Object orType (V) is Null.- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"setPrototypeOf"). - If trap is
undefined , then- Return ? target.[[SetPrototypeOf]](V).
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target, V »)). - If booleanTrapResult is
false , returnfalse . - Let extensibleTarget be ?
IsExtensible (target). - If extensibleTarget is
true , returntrue . - Let targetProto be ? target.[[GetPrototypeOf]]().
- If
SameValue (V, targetProto) isfalse , throw aTypeError exception. - Return
true .
[[SetPrototypeOf]] for proxy objects enforces the following invariants:
- The result of [[SetPrototypeOf]] is a Boolean value.
- If the target object is not extensible, the argument value must be the same as the result of [[GetPrototypeOf]] applied to target object.
9.5.3 [[IsExtensible]] ( )
When the [[IsExtensible]] internal method of a Proxy
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"isExtensible"). - If trap is
undefined , then- Return ? target.[[IsExtensible]]().
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target »)). - Let targetResult be ? target.[[IsExtensible]]().
- If
SameValue (booleanTrapResult, targetResult) isfalse , throw aTypeError exception. - Return booleanTrapResult.
[[IsExtensible]] for proxy objects enforces the following invariants:
- The result of [[IsExtensible]] is a Boolean value.
- [[IsExtensible]] applied to the proxy object must return the same value as [[IsExtensible]] applied to the proxy object's target object with the same argument.
9.5.4 [[PreventExtensions]] ( )
When the [[PreventExtensions]] internal method of a Proxy
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"preventExtensions"). - If trap is
undefined , then- Return ? target.[[PreventExtensions]]().
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target »)). - If booleanTrapResult is
true , then- Let targetIsExtensible be ? target.[[IsExtensible]]().
- If targetIsExtensible is
true , throw aTypeError exception.
- Return booleanTrapResult.
[[PreventExtensions]] for proxy objects enforces the following invariants:
- The result of [[PreventExtensions]] is a Boolean value.
-
[[PreventExtensions]] applied to the proxy object only returns
true if [[IsExtensible]] applied to the proxy object's target object isfalse .
9.5.5 [[GetOwnProperty]] ( P )
When the [[GetOwnProperty]] internal method of a Proxy
Assert :IsPropertyKey (P) istrue .- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"getOwnPropertyDescriptor"). - If trap is
undefined , then- Return ? target.[[GetOwnProperty]](P).
- Let trapResultObj be ?
Call (trap, handler, « target, P »). - If
Type (trapResultObj) is neither Object nor Undefined, throw aTypeError exception. - Let targetDesc be ? target.[[GetOwnProperty]](P).
- If trapResultObj is
undefined , then- If targetDesc is
undefined , returnundefined . - If targetDesc.[[Configurable]] is
false , throw aTypeError exception. - Let extensibleTarget be ?
IsExtensible (target). - If extensibleTarget is
false , throw aTypeError exception. - Return
undefined .
- If targetDesc is
- Let extensibleTarget be ?
IsExtensible (target). - Let resultDesc be ?
ToPropertyDescriptor (trapResultObj). - Call
CompletePropertyDescriptor (resultDesc). - Let valid be
IsCompatiblePropertyDescriptor (extensibleTarget, resultDesc, targetDesc). - If valid is
false , throw aTypeError exception. - If resultDesc.[[Configurable]] is
false , then- If targetDesc is
undefined or targetDesc.[[Configurable]] istrue , then- Throw a
TypeError exception.
- Throw a
- If targetDesc is
- Return resultDesc.
[[GetOwnProperty]] for proxy objects enforces the following invariants:
-
The result of [[GetOwnProperty]] must be either an Object or
undefined . - A property cannot be reported as non-existent, if it exists as a non-configurable own property of the target object.
- A property cannot be reported as non-existent, if it exists as an own property of the target object and the target object is not extensible.
- A property cannot be reported as existent, if it does not exist as an own property of the target object and the target object is not extensible.
- A property cannot be reported as non-configurable, if it does not exist as an own property of the target object or if it exists as a configurable own property of the target object.
9.5.6 [[DefineOwnProperty]] ( P, Desc )
When the [[DefineOwnProperty]] internal method of a Proxy
Assert :IsPropertyKey (P) istrue .- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"defineProperty"). - If trap is
undefined , then- Return ? target.[[DefineOwnProperty]](P, Desc).
- Let descObj be
FromPropertyDescriptor (Desc). - Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target, P, descObj »)). - If booleanTrapResult is
false , returnfalse . - Let targetDesc be ? target.[[GetOwnProperty]](P).
- Let extensibleTarget be ?
IsExtensible (target). - If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is
false , then- Let settingConfigFalse be
true .
- Let settingConfigFalse be
- Else, let settingConfigFalse be
false . - If targetDesc is
undefined , then- If extensibleTarget is
false , throw aTypeError exception. - If settingConfigFalse is
true , throw aTypeError exception.
- If extensibleTarget is
- Else targetDesc is not
undefined ,- If
IsCompatiblePropertyDescriptor (extensibleTarget, Desc, targetDesc) isfalse , throw aTypeError exception. - If settingConfigFalse is
true and targetDesc.[[Configurable]] istrue , throw aTypeError exception.
- If
- Return
true .
[[DefineOwnProperty]] for proxy objects enforces the following invariants:
- The result of [[DefineOwnProperty]] is a Boolean value.
- A property cannot be added, if the target object is not extensible.
- A property cannot be non-configurable, unless there exists a corresponding non-configurable own property of the target object.
-
If a property has a corresponding target object property then applying the
Property Descriptor of the property to the target object using [[DefineOwnProperty]] will not throw an exception.
9.5.7 [[HasProperty]] ( P )
When the [[HasProperty]] internal method of a Proxy
Assert :IsPropertyKey (P) istrue .- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"has"). - If trap is
undefined , then- Return ? target.[[HasProperty]](P).
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target, P »)). - If booleanTrapResult is
false , then- Let targetDesc be ? target.[[GetOwnProperty]](P).
- If targetDesc is not
undefined , then- If targetDesc.[[Configurable]] is
false , throw aTypeError exception. - Let extensibleTarget be ?
IsExtensible (target). - If extensibleTarget is
false , throw aTypeError exception.
- If targetDesc.[[Configurable]] is
- Return booleanTrapResult.
[[HasProperty]] for proxy objects enforces the following invariants:
- The result of [[HasProperty]] is a Boolean value.
- A property cannot be reported as non-existent, if it exists as a non-configurable own property of the target object.
- A property cannot be reported as non-existent, if it exists as an own property of the target object and the target object is not extensible.
9.5.8 [[Get]] ( P, Receiver )
When the [[Get]] internal method of a Proxy
Assert :IsPropertyKey (P) istrue .- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"get"). - If trap is
undefined , then- Return ? target.[[Get]](P, Receiver).
- Let trapResult be ?
Call (trap, handler, « target, P, Receiver »). - Let targetDesc be ? target.[[GetOwnProperty]](P).
- If targetDesc is not
undefined and targetDesc.[[Configurable]] isfalse , then- If
IsDataDescriptor (targetDesc) istrue and targetDesc.[[Writable]] isfalse , then- If
SameValue (trapResult, targetDesc.[[Value]]) isfalse , throw aTypeError exception.
- If
- If
IsAccessorDescriptor (targetDesc) istrue and targetDesc.[[Get]] isundefined , then- If trapResult is not
undefined , throw aTypeError exception.
- If trapResult is not
- If
- Return trapResult.
[[Get]] for proxy objects enforces the following invariants:
-
The value reported for a property must be the same as the value of the corresponding target object property if the target object property is a non-writable, non-configurable own
data property . -
The value reported for a property must be
undefined if the corresponding target object property is a non-configurable ownaccessor property that hasundefined as its [[Get]] attribute.
9.5.9 [[Set]] ( P, V, Receiver )
When the [[Set]] internal method of a Proxy
Assert :IsPropertyKey (P) istrue .- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"set"). - If trap is
undefined , then- Return ? target.[[Set]](P, V, Receiver).
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target, P, V, Receiver »)). - If booleanTrapResult is
false , returnfalse . - Let targetDesc be ? target.[[GetOwnProperty]](P).
- If targetDesc is not
undefined and targetDesc.[[Configurable]] isfalse , then- If
IsDataDescriptor (targetDesc) istrue and targetDesc.[[Writable]] isfalse , then- If
SameValue (V, targetDesc.[[Value]]) isfalse , throw aTypeError exception.
- If
- If
IsAccessorDescriptor (targetDesc) istrue , then- If targetDesc.[[Set]] is
undefined , throw aTypeError exception.
- If targetDesc.[[Set]] is
- If
- Return
true .
[[Set]] for proxy objects enforces the following invariants:
- The result of [[Set]] is a Boolean value.
-
Cannot change the value of a property to be different from the value of the corresponding target object property if the corresponding target object property is a non-writable, non-configurable own
data property . -
Cannot set the value of a property if the corresponding target object property is a non-configurable own
accessor property that hasundefined as its [[Set]] attribute.
9.5.10 [[Delete]] ( P )
When the [[Delete]] internal method of a Proxy
Assert :IsPropertyKey (P) istrue .- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"deleteProperty"). - If trap is
undefined , then- Return ? target.[[Delete]](P).
- Let booleanTrapResult be
ToBoolean (?Call (trap, handler, « target, P »)). - If booleanTrapResult is
false , returnfalse . - Let targetDesc be ? target.[[GetOwnProperty]](P).
- If targetDesc is
undefined , returntrue . - If targetDesc.[[Configurable]] is
false , throw aTypeError exception. - 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.
9.5.11 [[OwnPropertyKeys]] ( )
When the [[OwnPropertyKeys]] internal method of a Proxy
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"ownKeys"). - If trap is
undefined , then- Return ? target.[[OwnPropertyKeys]]().
- Let trapResultArray be ?
Call (trap, handler, « target »). - Let trapResult be ?
CreateListFromArrayLike (trapResultArray, « String, Symbol »). - If trapResult contains any duplicate entries, throw a
TypeError exception. - Let extensibleTarget be ?
IsExtensible (target). - Let targetKeys be ? target.[[OwnPropertyKeys]]().
Assert : targetKeys is aList containing only String and Symbol values.Assert : targetKeys contains no duplicate entries.- Let targetConfigurableKeys be a new empty
List . - Let targetNonconfigurableKeys be a new empty
List . - For each element key of targetKeys, do
- Let desc be ? target.[[GetOwnProperty]](key).
- If desc is not
undefined and desc.[[Configurable]] isfalse , then- Append key as an element of targetNonconfigurableKeys.
- Else,
- Append key as an element of targetConfigurableKeys.
- If extensibleTarget is
true and targetNonconfigurableKeys is empty, then- Return trapResult.
- Let uncheckedResultKeys be a new
List which is a copy of trapResult. - For each key that is an element of targetNonconfigurableKeys, do
- If key is not an element of uncheckedResultKeys, throw a
TypeError exception. - Remove key from uncheckedResultKeys.
- If key is not an element of uncheckedResultKeys, throw a
- If extensibleTarget is
true , return trapResult. - For each key that is an element of targetConfigurableKeys, do
- If key is not an element of uncheckedResultKeys, throw a
TypeError exception. - Remove key from uncheckedResultKeys.
- If key is not an element of uncheckedResultKeys, throw a
- If uncheckedResultKeys is not empty, throw a
TypeError exception. - Return trapResult.
[[OwnPropertyKeys]] for proxy objects enforces the following invariants:
-
The result of [[OwnPropertyKeys]] is a
List . -
The returned
List contains no duplicate entries. -
The
Type of each resultList element is either String or Symbol. -
The result
List must contain the keys of all non-configurable own properties of the target object. -
If the target object is not extensible, then the result
List must contain all the keys of the own properties of the target object and no other values.
9.5.12 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method of a Proxy
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
- Let trap be ?
GetMethod (handler,"apply"). - If trap is
undefined , then- Return ?
Call (target, thisArgument, argumentsList).
- Return ?
- Let argArray be
CreateArrayFromList (argumentsList). - Return ?
Call (trap, handler, « target, thisArgument, argArray »).
A Proxy
9.5.13 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method of a Proxy
- Let handler be O.[[ProxyHandler]].
- If handler is
null , throw aTypeError exception. Assert :Type (handler) is Object.- Let target be O.[[ProxyTarget]].
Assert :IsConstructor (target) istrue .- Let trap be ?
GetMethod (handler,"construct"). - If trap is
undefined , then- Return ?
Construct (target, argumentsList, newTarget).
- Return ?
- Let argArray be
CreateArrayFromList (argumentsList). - Let newObj be ?
Call (trap, handler, « target, argArray, newTarget »). - If
Type (newObj) is not Object, throw aTypeError exception. - Return newObj.
A Proxy
[[Construct]] for proxy objects enforces the following invariants:
- The result of [[Construct]] must be an Object.
9.5.14 ProxyCreate ( target, handler )
The abstract operation ProxyCreate with arguments target and handler is used to specify the creation of new Proxy exotic objects. It performs the following steps:
- If
Type (target) is not Object, throw aTypeError exception. - If target is a Proxy
exotic object and target.[[ProxyHandler]] isnull , throw aTypeError exception. - If
Type (handler) is not Object, throw aTypeError exception. - If handler is a Proxy
exotic object and handler.[[ProxyHandler]] isnull , throw aTypeError exception. - Let P be a newly created object.
Set P's essential internal methods (except for [[Call]] and [[Construct]]) to the definitions specified in9.5 .- If
IsCallable (target) istrue , thenSet P.[[Call]] as specified in9.5.12 .- If
IsConstructor (target) istrue , then
Set P.[[ProxyTarget]] to target.Set P.[[ProxyHandler]] to handler.- Return P.