Stage 3 Draft / December 13, 2018

Private Methods and Accessors Proposal

Introduction

This document adds to the class fields proposal by introducing private methods and accessors. See the explainer for an overview.

This specification draft is phrased as a diff against the class fields proposal.

1Syntax

1.1Updated Productions

MethodDefinition[Yield, Await]:PropertyNameClassElementName[?Yield, ?Await](UniqueFormalParameters[~Yield, ~Await]){FunctionBody[~Yield, ~Await]} GeneratorMethod[?Yield, ?Await] AsyncMethod[?Yield, ?Await] AsyncGeneratorMethod[?Yield, ?Await] getPropertyNameClassElementName[?Yield, ?Await](){FunctionBody[~Yield, ~Await]} setPropertyNameClassElementName[?Yield, ?Await](PropertySetParameterList){FunctionBody[~Yield, ~Await]} GeneratorMethod[Yield, Await]:*PropertyNameClassElementName[?Yield, ?Await](UniqueFormalParameters[+Yield, ~Await]){GeneratorBody} AsyncMethod[Yield, Await]:async[no LineTerminator here]PropertyNameClassElementName[?Yield, ?Await](UniqueFormalParameters[~Yield, +Await]){AsyncFunctionBody} AsyncGeneratorMethod[Yield, Await]:async[no LineTerminator here]*PropertyNameClassElementName[?Yield, ?Await](UniqueFormalParameters[+Yield, +Await]){AsyncGeneratorBody}

1.2Static Semantics: Early Errors

ClassBody:ClassElementList
  • It is a Syntax Error if PrivateBoundNames of ClassBody contains any duplicate entries, unless the name is used once for a getter and once for a setter and in no other entries.
PropertyDefinition:MethodDefinition Editor's Note
In a follow-on proposal, object literals may be permitted to have private methods, fields and accessors.
ClassElement:staticMethodDefinition Editor's Note
In this specification, private static methods are not supported. This support may be provided by a follow-on proposal static class features.

2Modified algorithms

2.1Static Semantics: PropName

FieldDefinition:ClassElementNameInitializeropt
  1. Return PropName of ClassElementName.
ClassElementName[Yield, Await]:PropertyName[?Yield, ?Await]
  1. Return PropName of PropertyName.
ClassElementName[Yield, Await]:PrivateName
  1. Return empty.

2.2Runtime Semantics: Evaluation

ClassElementName[Yield, Await]:PropertyName[?Yield, ?Await]
  1. Return the result of evaluating PropertyName.
ClassElementName[Yield, Await]:PrivateName
  1. Let bindingName be StringValue of PrivateName.
  2. Let scope be the running execution context's PrivateNameEnvironment.
  3. Let scopeEnvRec be scope's EnvironmentRecord.
  4. Let field be NewPrivateName(bindingName).
  5. Perform ! scopeEnvRec.InitializeBinding(bindingName, field).
  6. Assert: scopeEnvRec has a binding for bindingName.
  7. If scopeEnvRec's binding for bindingName is uninitialized,
    1. Let field be NewPrivateName(bindingName).
    2. Perform ! scopeEnvRec.InitializeBinding(bindingName, field).
  8. Otherwise,
    1. Let field be scopeEnvRec.GetBindingValue(bindingName).
    2. NOTE: The only case where this may occur is in getter/setter pairs; other duplicates are prohibited as a Syntax Error.
  9. Assert: field.[[Description]] is bindingName.
  10. Return field.
Editor's Note
Each time a class declaration executes, distinct internal Private Names are created. This means, that they cannot directly access each other's private state if a method of one is called with the other as a receiver.

2.3InitializeInstanceFieldsElements ( O, constructor )

  1. Assert: Type ( O ) is Object.
  2. Assert: Assert constructor is an ECMAScript function object.
  3. If constructor.[[PrivateBrand]] is not undefined,
    1. Perform ? PrivateBrandAdd(O, constructor.[[PrivateBrand]]).
  4. Let fieldRecords be the value of constructor's [[Fields]] internal slot.
  5. For each item fieldRecord in order from fieldRecords,
    1. Perform ? DefineField(O, fieldRecord).
  6. Return.
Editor's Note
The PrivateBrand enables the use of private methods on the instance. It is added before the fields so that the private methods may be called from field initializers.
Editor's Note
Private fields are added to the object one by one, interspersed with evaluation of the initializers, following the construction of the receiver. These semantics allow for a later initializer to refer to a previously private field.

2.4Static Semantics: PrivateBoundNames

ClassElement:MethodDefinition ClassElement:staticMethodDefinition
  1. Return PrivateBoundNames of MethodDefinition.
MethodDefinition[Yield, Await]:ClassElementName[?Yield, ?Await](UniqueFormalParameters[~Yield, ~Await]){FunctionBody[~Yield, ~Await]} getClassElementName[?Yield, ?Await](){FunctionBody[~Yield, ~Await]} setClassElementName[?Yield, ?Await](PropertySetParameterList){FunctionBody[~Yield, ~Await]} GeneratorMethod[Yield, Await]:*ClassElementName[?Yield, ?Await](UniqueFormalParameters[+Yield, ~Await]){GeneratorBody} AsyncMethod[Yield, Await]:async[no LineTerminator here]ClassElementName[?Yield, ?Await](UniqueFormalParameters[~Yield, +Await]){AsyncFunctionBody} AsyncGeneratorMethod[Yield, Await]:async[no LineTerminator here]*ClassElementName[?Yield, ?Await](UniqueFormalParameters[~Yield, +Await]){AsyncFunctionBody}
  1. Return PrivateBoundNames of ClassElementName.
MethodDefinition[Yield, Await]:GeneratorMethod[?Yield, ?Await]
  1. Return PrivateBoundNames of GeneratorMethod.
MethodDefinition[Yield, Await]:AsyncMethod[?Yield, ?Await]
  1. Return PrivateBoundNames of AsyncMethod.
MethodDefinition[Yield, Await]:AsyncGeneratorMethod[?Yield, ?Await]
  1. Return PrivateBoundNames of AsyncGeneratorMethod.

2.5Runtime Semantics: ClassDefinitionEvaluation

With parameter className.

ClassTail:ClassHeritageopt{ClassBodyopt}
  1. Let lex be the LexicalEnvironment of the running execution context.
  2. Let classScope be NewDeclarativeEnvironment(lex).
  3. Let classScopeEnvRec be classScope's EnvironmentRecord.
  4. If className is not undefined, then
    1. Perform classScopeEnvRec.CreateImmutableBinding(className, true).
  5. Let outerPrivateEnvironment be the PrivateNameEnvironment of the running execution context.
  6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
  7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
  8. If ClassBodyopt is present, then
    1. For each element dn of the PrivateBoundNames of ClassBodyopt,
      1. Perform classPrivateEnvRec.CreateImmutableBinding(dn, true).
  9. If ClassHeritageopt is not present, then
    1. Let protoParent be the intrinsic object %ObjectPrototype%.
    2. Let constructorParent be the intrinsic object %FunctionPrototype%.
  10. Else,
    1. Set the running execution context's LexicalEnvironment to classScope.
    2. NOTE: The running execution context's PrivateNameEnvironment is outerPrivateEnvironment when evaluating ClassHeritage.
    3. Let superclass be the result of evaluating ClassHeritage.
    4. Set the running execution context's LexicalEnvironment to lex.
    5. ReturnIfAbrupt(superclass).
    6. If superclass is null, then
      1. Let protoParent be null.
      2. Let constructorParent be the intrinsic object %FunctionPrototype%.
    7. Else if IsConstructor(superclass) is false, throw a TypeError exception.
    8. Else,
      1. Let protoParent be ? Get(superclass, "prototype").
      2. If Type(protoParent) is neither Object nor Null, throw a TypeError exception.
      3. Let constructorParent be superclass.
  11. Let proto be ObjectCreate(protoParent).
  12. If ClassBodyopt is not present, let constructor be empty.
  13. Else, let constructor be ConstructorMethod of ClassBody.
  14. If constructor is empty, then
    1. If ClassHeritageopt is present and protoParent is not null, then
      1. Let constructor be the result of parsing the source text
        constructor(... args){ super (...args);}
        using the syntactic grammar with the goal symbol MethodDefinition[~Yield].
    2. Else,
      1. Let constructor be the result of parsing the source text
        constructor( ){ }
        using the syntactic grammar with the goal symbol MethodDefinition[~Yield].
  15. Set the running execution context's LexicalEnvironment to classScope.
  16. Set the running execution context's PrivateNameEnvironment to classPrivateEnvironment.
  17. Let constructorInfo be the result of performing DefineMethod for constructor with arguments proto and constructorParent as the optional functionPrototype argument.
  18. Assert: constructorInfo is not an abrupt completion.
  19. Let F be constructorInfo.[[Closure]].
  20. If ClassHeritageopt is present and protoParent is not null, then set F.[[ConstructorKind]] to "derived".
  21. Perform MakeConstructor(F, false, proto).
  22. Perform MakeClassConstructor(F).
  23. Perform CreateMethodProperty(proto, "constructor", F).
  24. If ClassBodyopt is not present, let methods be a new empty List.
  25. Else, let elements be NonConstructorMethodDefinitions of ClassBody.
  26. Let instanceFields be a new empty List.
  27. For each ClassElement e in order from elements,
    1. If IsStatic of e is false, then
      1. Let field be the result of performing ClassElementEvaluation for e with arguments proto and false.
    2. Else,
      1. Let field be the result of performing PropertyDefinitionEvaluation for mClassElementEvaluation for e with arguments F and false.
    3. If field is an abrupt completion, then
      1. Set the running execution context's LexicalEnvironment to lex.
      2. Set the running execution context's PrivateNameEnvironment to outerPrivateEnvironment.
      3. Return Completion(field).
    4. If field is not empty, append field to instanceFields.
  28. Set the running execution context's LexicalEnvironment to lex.
  29. If className is not undefined, then
    1. Perform classScopeEnvRec.InitializeBinding(className, F).
  30. Set F.[[Fields]] to instanceFields.
  31. If PrivateBoundNames of ClassBody contains a Private Name P such that the [[Type]] field of P's [[Descriptor]] is either method or accessor,
    1. Set F.[[PrivateBrand]] to proto.
  32. Set the running execution context's PrivateNameEnvironment to outerPrivateEnvironment.
  33. Return F.

2.6DefineOrdinaryMethod ( key, homeObject, closure, enumerable )

  1. Perform SetFunctionName(closure, key).
  2. If key is a Private Name,
    1. Let descriptor be key's associated [[Descriptor]]
    2. Assert: descriptor does not have a [[Type]] field.
    3. Set descriptor.[[Type]] to method.
    4. Set descriptor.[[Value]] to _closure.
    5. Set descriptor.[[Brand]] to homeObject.
  3. Else,
    1. Let desc be the PropertyDescriptor{[[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true}.
    2. Perform ? DefinePropertyOrThrow(homeObject, key, desc).

2.7Runtime Semantics: ClassElementEvaluation

With parameters homeObject and enumerable.

ClassElementEvaluation returns a List of Records of the form { [[Kind]]: "method" or "field", [[Key]]: Property Key or Private Name, [[Descriptor]]: a Property Descriptor, [[Placement]]: "static", "prototype" or "own", [[Initializer]]: optional function for initial value which exists only for fields }.

ClassElement:MethodDefinition
  1. Return ClassElementEvaluation of MethodDefinition with arguments ! Get(homeObject, "prototype"),enumerable, and "prototype".
ClassElement:staticMethodDefinition
  1. Return ClassElementEvaluation of MethodDefinition with arguments homeObject, enumerable and "static".
MethodDefinition:ClassElementName(UniqueFormalParameters){FunctionBody}
  1. Let methodDef be DefineMethod of MethodDefinition with argument homeObject.
  2. ReturnIfAbrupt(methodDef).
  3. Perform SetFunctionName(methodDef.[[Closure]], methodDef.[[Key]]).
  4. Let desc be the PropertyDescriptor{[[Value]]: methodDef.[[Closure]], [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true}.
  5. Return ? DefinePropertyOrThrow(homeObject, methodDef.[[Key]], desc).
  6. Perform ? DefineOrdinaryMethod(methodDef.[[Key]], homeObject, methodDef.[[Closure]], _enumerable).
MethodDefinition:getClassElementName(){FunctionBody}
  1. Let key be the result of evaluating ClassElementName.
  2. ReturnIfAbrupt(key).
  3. If the function code for this MethodDefinition is strict mode code, let strict be true. Otherwise let strict be false.
  4. Let scope be the running execution context's LexicalEnvironment.
  5. Let formalParameterList be an instance of the production FormalParameters:[empty] .
  6. Let closure be FunctionCreate(Method, formalParameterList, FunctionBody, scope, strict).
  7. Perform MakeMethod(closure, homeObject).
  8. Perform SetFunctionName(closure, key, "get").
  9. If key is a Private Name,
    1. Let descriptor be key's associated [[Descriptor]]
    2. If descriptor has a [[Type]] field,
      1. Assert: descriptor.[[Type]] is accessor.
      2. Assert: descriptor.[[Brand]] is homeObject.
      3. Assert: descriptor does not have a [[Get]] field.
      4. Set descriptor.[[Get]] to closure.
    3. Otherwise,
      1. Set descriptor.[[Type]] to accessor.
      2. Set descriptor.[[Brand]] to homeObject.
      3. Set descriptor.[[Get]] to closure.
  10. Else,
    1. Let desc be the PropertyDescriptor{[[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true}.
    2. Perform ? DefinePropertyOrThrow(homeObject, key, desc).
MethodDefinition:setClassElementName(PropertySetParameterList){FunctionBody}
  1. Let key be the result of evaluating ClassElementName.
  2. ReturnIfAbrupt(key).
  3. If the function code for this MethodDefinition is strict mode code, let strict be true. Otherwise let strict be false.
  4. Let scope be the running execution context's LexicalEnvironment.
  5. Let closure be FunctionCreate(Method, PropertySetParameterList, FunctionBody, scope, strict).
  6. Perform MakeMethod(closure, homeObject).
  7. Perform SetFunctionName(closure, key, "set").
  8. If key is a Private Name,
    1. Let descriptor be key's associated [[Descriptor]]
    2. If descriptor has a [[Type]] field,
      1. Assert: descriptor.[[Type]] is accessor.
      2. Assert: descriptor.[[Brand]] is homeObject.
      3. Assert: descriptor does not have a [[Set]] field.
      4. Set descriptor.[[Set]] to closure.
    3. Otherwise,
      1. Set descriptor.[[Type]] to accessor.
      2. Set descriptor.[[Brand]] to homeObject.
      3. Set descriptor.[[Set]] to closure.
  9. Else,
    1. Let desc be the PropertyDescriptor{[[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true}.
    2. Perform ? DefinePropertyOrThrow(homeObject, key, desc).
GeneratorMethod:*ClassElementName(UniqueFormalParameters){GeneratorBody}
  1. Let key be the result of evaluating ClassElementName.
  2. ReturnIfAbrupt(key).
  3. If the function code for this GeneratorMethod is strict mode code, let strict be true. Otherwise let strict be false.
  4. Let scope be the running execution context's LexicalEnvironment.
  5. Let closure be GeneratorFunctionCreate(Method, UniqueFormalParameters, GeneratorBody, scope, strict).
  6. Perform MakeMethod(closure, homeObject).
  7. Let prototype be ObjectCreate(%GeneratorPrototype%).
  8. Perform DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor{[[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}).
  9. Perform SetFunctionName(closure, propKey).
  10. Let desc be the PropertyDescriptor{[[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true}.
  11. Return ? DefinePropertyOrThrow(homeObject, propKey, desc).
  12. Return DefineOrdinaryMethod(key, homeObject, closure, enumerable).
AsyncMethod:async[no LineTerminator here]ClassElementName(UniqueFormalParameters){AsyncFunctionBody}
  1. Let key be the result of evaluating ClassElementName.
  2. ReturnIfAbrupt(key).
  3. If the function code for this AsyncMethod is strict mode code, let strict be true. Otherwise let strict be false.
  4. Let scope be the LexicalEnvironment of the running execution context.
  5. Let closure be ! AsyncFunctionCreate(Method, UniqueFormalParameters, AsyncFunctionBody, scope, strict).
  6. Perform ! MakeMethod(closure, homeObject).
  7. Perform ! SetFunctionName(closure, key).
  8. Let desc be the PropertyDescriptor{[[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true}.
  9. Return ? DefinePropertyOrThrow(homeObject, propKey, desc).
  10. Perform ? DefineOrdinaryMethod(key, homeObject, closure, _enumerable).
AsyncGeneratorMethod:async[no LineTerminator here]*ClassElementName(UniqueFormalParameters){AsyncGeneratorBody}
  1. Let key be the result of evaluating ClassElementName.
  2. ReturnIfAbrupt(key).
  3. If the function code for this AsyncGeneratorMethod is strict mode code, let strict be true. Otherwise let strict be false.
  4. Let scope be the running execution context's LexicalEnvironment.
  5. Let closure be ! AsyncGeneratorFunctionCreate(Method, UniqueFormalParameters, AsyncGeneratorBody, scope, strict).
  6. Perform ! MakeMethod(closure, object).
  7. Let prototype be ! ObjectCreate(%AsyncGeneratorPrototype%).
  8. Perform ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
  9. Perform ! SetFunctionName(closure, propKey).
  10. Let desc be PropertyDescriptor { [[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true }.
  11. Return ? DefinePropertyOrThrow(object, propKey, desc).
  12. Perform ? DefineOrdinaryMethod(key, homeObject, closure, _enumerable).

2.8The super Keyword

2.8.1Runtime Semantics: Evaluation

SuperCall:superArguments
  1. Let newTarget be GetNewTarget().
  2. If newTarget is undefined, throw a ReferenceError exception.
  3. Let func be ? GetSuperConstructor().
  4. Let argList be ArgumentListEvaluation of Arguments.
  5. ReturnIfAbrupt(argList).
  6. Let result be ? Construct(func, argList, newTarget).
  7. Let thisER be GetThisEnvironment( ).
  8. Let F be thisER.[[FunctionObject]].
  9. Assert: F is an ECMAScript function object.
  10. Perform ? InitializeInstanceFieldsElements(result, F).
  11. Return ? thisER.BindThisValue(result).

2.9[[Construct]] ( argumentsList, newTarget)

The [[Construct]] internal method for an ECMAScript Function object F is called with parameters argumentsList and newTarget. argumentsList is a possibly empty List of ECMAScript language values. The following steps are taken:

  1. Assert: F is an ECMAScript function object.
  2. Assert: Type(newTarget) is Object.
  3. Let callerContext be the running execution context.
  4. Let kind be F.[[ConstructorKind]].
  5. If kind is "base", then
    1. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget, "%ObjectPrototype%").
  6. Let calleeContext be PrepareForOrdinaryCall(F, newTarget).
  7. Assert: calleeContext is now the running execution context.
  8. If kind is "base", then
    1. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument).
    2. Let result be InitializeInstanceFieldsElements(thisArgument, F).
    3. If result is an abrupt completion, then
      1. Remove calleeContext from execution context stack and restore callerContext as the running execution context.
      2. Return Completion(result).
  9. Let constructorEnv be the LexicalEnvironment of calleeContext.
  10. Let envRec be constructorEnv's EnvironmentRecord.
  11. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
  12. Remove calleeContext from the execution context stack and restore callerContext as the running execution context.
  13. If result.[[Type]] is return, then
    1. If Type(result.[[Value]]) is Object, return NormalCompletion(result.[[Value]]).
    2. If kind is "base", return NormalCompletion(thisArgument).
    3. If result.[[Value]] is not undefined, throw a TypeError exception.
  14. Else, ReturnIfAbrupt(result).
  15. Return ? envRec.GetThisBinding().
Editor's Note
Fields are added by the base class constructor when the super chain reaches up to that, rather than by the subclass constructor when creating the object, in order to be analogous to ES2015 subclassable builtins. See this GitHub thread for more discussion.

3Private Names and references

Each PrivateName value immutably holds a mutable record called [[Descriptor]], initially empty, which may have the following fields added to it:

Table 1: Fields of the [[Descriptor]] record
Field Type For which types is it present Description
[[Type]] field, method or accessor All Indicates what the private name is used for.
[[Brand]] an ECMAScript value method or accessor The "original" class of the private method or accessor; checked for in the [[PrivateBrands]] internal slot of instances before access is provided.
[[Value]] Function method The value of the private method.
[[Get]] Function accessor The getter for a private accessor.
[[Set]] Function accessor The setter for a private accessor.

In addition to [[PrivateFieldValues]], all ECMAScript objects have a new additional internal slot, [[PrivateBrands]], which is an initially empty List of ECMAScript values which are used for checking to see if an object supports a private method or accessor. The entries in the list correspond to the "original prototype" (or, in the case of static methods, the "original constructor") which contained the private method or accessor.

Editor's Note

Although this specification uses logic of a [[PrivateBrand]] List which is held per-instance, the use of this list obeys certain invariants:

  • Nothing is removed from the list; things are only added to the end.
  • There is no way to distinguish different copies of the list.
  • The list is mutable, but there are never any references to it outside of the particular object which holds it, so additions can be thought of as replacing the internal slot with another list which contains the new element.

There are multiple possible implementation strategies which take advantage of these invariants for better runtime performance and lower space overhead, e.g., the following successive optimizations:

  • The set of lists can be represented as a tree, where nodes represent a brand list, and the path to the root is the set of brands included. This tree will only have nodes added to it over time, and never needs to be mutated in any other way. In typical code, nodes only need to be allocated and added the first time a class is instantiated.
  • If deep inheritance hierarchies with private methods are common in practice, each node can have an array representing the set of brands, which can be traversed with better cache locality.
  • If a brand comes from a base class, only the first element of the array needs to be examined, rather than traversing up the tree.
  • If a brand comes from a subclass, the search can speculatively first check the entry at the depth in the class hierarchy (of classes with private methods) where the brand was at the time the class was created, and fall back to checking the whole array only on failure, along the lines of the classic Java O(1) instanceof check algorithm.

3.1PrivateBrandCheck(O, P)

  1. Let descriptor be P's associated [[Descriptor]].
  2. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, descriptor.[[Brand]]) is true,
    1. Throw a TypeError exception.

3.2PrivateBrandAdd(O, brand)

  1. If O.[[PrivateBrands]] contains an entry e such that SameValue(e, brand) is true,
    1. Throw a TypeError exception.
  2. Append brand to O.[[PrivateBrands]].

3.3PrivateFieldGet (P, O )

  1. Assert: P is a Private Name value.
  2. If O is not an object, throw a TypeError exception.
  3. Let descriptor be P's associated [[Descriptor]].
  4. If descriptor.[[Type]] is field,
    1. Let entry be PrivateFieldFind(P, O).
    2. If entry is empty, throw a TypeError exception.
    3. Return entry.[[PrivateFieldValue]].
  5. Perform ? PrivateBrandCheck(O, P).
  6. If descriptor.[[Type]] is method,
    1. Return descriptor.[[Value]].
  7. Otherwise, descriptor.[[Type]] is accessor,
    1. If descriptor does not have a [[Get]] field, throw a TypeError exception.
    2. Let getter be descriptor.[[Get]].
    3. Return ? Call(getter, O).

3.4PrivateFieldSet (P, O, value )

  1. Assert: P is a Private Name value.
  2. If O is not an object, throw a TypeError exception.
  3. Let descriptor be P's associated [[Descriptor]].
  4. If descriptor.[[Type]] is field,
    1. Let entry be PrivateFieldFind(P, O).
    2. If entry is empty, throw a TypeError exception.
    3. Set entry.[[PrivateFieldValue]] to value.
    4. Return.
  5. If descriptor.[[Type]] is method, throw a TypeError exception.
  6. Otherwise, descriptor.[[Type]] is accessor,
    1. If O.[[PrivateFieldBrands]] does not contain descriptor.[[Brand]], throw a TypeError exception.
    2. If descriptor does not have a [[Set]] field, throw a TypeError exception.
    3. Let setter be descriptor.[[Set]].
    4. Perform ? Call(setter, O, value).
    5. Return.

ACopyright & Software License

Copyright Notice

© 2018 Daniel Ehrenberg, Jeff Morrison, Kevin Smith, Kevin Gibbons

Software License

All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.