From 853832751aab570ac22ab83f58d838d567e599b8 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Fri, 13 Sep 2019 14:06:23 +0200 Subject: [PATCH] Normative: Define private names at the beginning of the class Rebase of this repository on https://github.com/tc39/proposal-class-fields/pull/269 --- spec.html | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/spec.html b/spec.html index c40bd46..3ce2194 100644 --- a/spec.html +++ b/spec.html @@ -180,20 +180,12 @@

Runtime Semantics: Evaluation

ClassElementName[Yield, Await] : PrivateIdentifier - 1. Let _bindingName_ be StringValue of |PrivateIdentifier|. + 1. Let _privateIdentifier_ be StringValue of |PrivateIdentifier|. 1. Let _scope_ be the running execution context's PrivateEnvironment. 1. Let _scopeEnvRec_ be _scope_'s EnvironmentRecord. - 1. Let _field_ be NewPrivateName(_bindingName_). - 1. Perform ! _scopeEnvRec_.InitializeBinding(_bindingName_, _field_). - 1. Assert: _scopeEnvRec_ has a binding for _bindingName_. - 1. If _scopeEnvRec_'s binding for _bindingName_ is uninitialized, - 1. Let _field_ be NewPrivateName(_bindingName_). - 1. Perform ! _scopeEnvRec_.InitializeBinding(_bindingName_, _field_). - 1. Else, - 1. Let _field_ be _scopeEnvRec_.GetBindingValue(_bindingName_). - 1. NOTE: The only case where this may occur is in getter/setter pairs; other duplicates are prohibited as a Syntax Error. - 1. Assert: _field_.[[Description]] is _bindingName_. - 1. Return _field_. + 1. Let _name_ be _scopeEnvRec_.GetBindingValue(_bindingName_). + 1. Assert: _name_.[[Description]] is _privateIdentifier_. + 1. Return _name_. 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. @@ -284,6 +276,8 @@

Runtime Semantics: ClassDefinitionEvaluation

1. If |ClassBody_opt| is present, then 1. For each element _dn_ of the PrivateBoundIdentifiers of |ClassBody_opt|, 1. Perform _classPrivateEnvRec_.CreateImmutableBinding(_dn_, *true*). + 1. Let _privateName_ be NewPrivateName(_dn_). + 1. Perform ! _classPrivateEnvRec_.InitializeBinding(_dn_, _dn_). 1. If |ClassHeritage_opt| is not present, then 1. Let _protoParent_ be the intrinsic object %ObjectPrototype%. 1. Let _constructorParent_ be the intrinsic object %FunctionPrototype%.