This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathspec.html
729 lines (671 loc) · 33.9 KB
/
spec.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
<meta charset="utf8">
<pre class=metadata>
title: Private Methods and Accessors Proposal
stage: 4
contributors: Daniel Ehrenberg, Jeff Morrison, Kevin Smith, Kevin Gibbons
</pre>
<style>
emu-example figure {
align-items: initial;
width: 100%;
}
emu-note {
display: block;
border-left-color: #474747;
}
emu-note span.note {
display: inline-block;
color: #fff;
background-color: #474747;
width: initial;
padding-right: 50px;
}
emu-note div.note-contents {
padding-left: 5px;
}
emu-note[type=editor] {
border-left-color: #900;
}
emu-note[type=editor] span.note {
background-color: #900;
}
emu-example {
border-left: 5px solid #006387;
margin: 1em 0;
}
emu-example figure figcaption:first-child {
display: inline-block;
color: #fff;
background-color: #006387;
margin: 0;
padding: 0 50px 0 5px;
font-weight: normal;
text-transform: uppercase;
margin-left: -5px;
}
emu-example figure figcaption:nth-child(2) {
margin: 0;
padding: 0;
padding-left: 5px;
margin-left: -5px;
font-size: 20px;
font-weight: bold;
margin-bottom: 10px;
}
emu-example p:nth-of-type(1) {
margin-top: 0;
}
emu-example figure {
padding-left: 5px;
display: block;
margin: 0;
}
emu-example pre {
margin: 0;
}
</style>
<emu-intro id=sec-intro>
<emu-note>
<p>This is a deprecated document. The document with all updated changes for this proposal has been merged and available as an unified document <a href="https://tc39.es/proposal-class-fields/unified.html">here</a>.</p>
</emu-note>
<h1>Introduction</h1>
<p>This document adds to the <a href="https://tc39.github.io/proposal-class-fields">class fields</a> proposal by introducing private methods and accessors. See <a href="https://github.com/tc39/proposal-private-methods">the explainer</a> for an overview.</p>
<p>This specification draft is phrased as a diff against the class fields proposal.</p>
</emu-intro>
<emu-clause id=sec-syntax>
<h1>Syntax</h1>
<emu-clause id=sec-updated-syntax>
<h1>Updated Productions</h1>
<emu-grammar>
MethodDefinition[Yield, Await] :
<del>PropertyName[?Yield, ?Await] `(` UniqueFormalParameters[~Yield, ~Await] `)` `{` FunctionBody[~Yield, ~Await] `}`</del>
<ins>ClassElementName[?Yield, ?Await] `(` UniqueFormalParameters[~Yield, ~Await] `)` `{` FunctionBody[~Yield, ~Await] `}`</ins>
GeneratorMethod[?Yield, ?Await]
AsyncMethod[?Yield, ?Await]
AsyncGeneratorMethod[?Yield, ?Await]
<del>`get` PropertyName[?Yield, ?Await] `(` `)` `{` FunctionBody[~Yield, ~Await] `}`</del>
<ins>`get` ClassElementName[?Yield, ?Await] `(` `)` `{` FunctionBody[~Yield, ~Await] `}`</ins>
<del>`set` PropertyName[?Yield, ?Await] `(` PropertySetParameterList `)` `{` FunctionBody[~Yield, ~Await] `}`</del>
<ins>`set` ClassElementName[?Yield, ?Await] `(` PropertySetParameterList `)` `{` FunctionBody[~Yield, ~Await] `}`</ins>
GeneratorMethod[Yield, Await] :
<del>`*` PropertyName[?Yield, ?Await] `(` UniqueFormalParameters[+Yield, ~Await] `)` `{` GeneratorBody `}`</del>
<ins>`*` ClassElementName[?Yield, ?Await] `(` UniqueFormalParameters[+Yield, ~Await] `)` `{` GeneratorBody `}`</ins>
AsyncMethod[Yield, Await] :
<del>`async` [no LineTerminator here] PropertyName[?Yield, ?Await] `(` UniqueFormalParameters[~Yield, +Await] `)` `{` AsyncFunctionBody `}`</del>
<ins>`async` [no LineTerminator here] ClassElementName[?Yield, ?Await] `(` UniqueFormalParameters[~Yield, +Await] `)` `{` AsyncFunctionBody `}`</ins>
AsyncGeneratorMethod[Yield, Await] :
<del>`async` [no LineTerminator here] `*` PropertyName[?Yield, ?Await] `(` UniqueFormalParameters[+Yield, +Await] `)` `{` AsyncGeneratorBody `}`</del>
<ins>`async` [no LineTerminator here] `*` ClassElementName[?Yield, ?Await] `(` UniqueFormalParameters[+Yield, +Await] `)` `{` AsyncGeneratorBody `}`</ins>
</emu-grammar>
</emu-clause>
<emu-clause id="sec-static-semantics-early-errors">
<h1>Static Semantics: Early Errors</h1>
<emu-grammar>
ClassBody : ClassElementList
</emu-grammar>
<ul>
<li>It is a Syntax Error if PrivateBoundIdentifiers of |ClassBody| contains any duplicate entries, <ins>unless the name is used once for a getter and once for a setter and in no other entries</ins>.</li>
</ul>
<emu-grammar>PropertyDefinition : MethodDefinition</emu-grammar>
<ul>
<li>It is a Syntax Error if PrivateBoundIdentifiers of |MethodDefinition| is non-empty.</li>
</ul>
<emu-note type=editor>In a follow-on proposal, object literals may be permitted to have private methods, fields and accessors.</emu-note>
<emu-grammar>
ClassElement : `static` MethodDefinition
</emu-grammar>
<ul>
<li>It is a Syntax Error if PrivateBoundIdentifiers of |MethodDefinition| is non-empty.</li>
</ul>
<emu-note type=editor>In this specification, private static methods are not supported. This support may be provided by a follow-on proposal <a href="https://github.com/tc39/proposal-static-class-features/">static class features</a>.</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-internal-algorithms">
<h1>Modified algorithms</h1>
<emu-clause id="static-semantics-propname">
<h1>Static Semantics: PropName</h1>
<emu-grammar>
FieldDefinition : ClassElementName Initializer?
</emu-grammar>
<emu-alg>
1. Return PropName of |ClassElementName|.
</emu-alg>
<emu-grammar>
ClassElementName[Yield, Await] : PropertyName[?Yield, ?Await]
</emu-grammar>
<emu-alg>
1. Return PropName of |PropertyName|.
</emu-alg>
<emu-grammar>
ClassElementName[Yield, Await] : PrivateIdentifier
</emu-grammar>
<emu-alg>
1. Return ~empty~.
</emu-alg>
</emu-clause>
<emu-clause id="sec-runtime-semantics-evaluate-name">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>
ClassElementName[Yield, Await] : PropertyIdentifier[?Yield, ?Await]
</emu-grammar>
<emu-alg>
1. Return the result of evaluating |PropertyIdentifier|.
</emu-alg>
<emu-grammar>
ClassElementName[Yield, Await] : PrivateIdentifier
</emu-grammar>
<emu-alg>
1. Let _bindingName_ be StringValue of |PrivateIdentifier|.
1. Let _scope_ be the running execution context's PrivateEnvironment.
1. Let _scopeEnvRec_ be _scope_'s EnvironmentRecord.
1. <del>Let _field_ be NewPrivateName(_bindingName_).</del>
1. <del>Perform ! _scopeEnvRec_.InitializeBinding(_bindingName_, _field_).</del>
1. <ins>Assert: _scopeEnvRec_ has a binding for _bindingName_.</ins>
1. <ins>If _scopeEnvRec_'s binding for _bindingName_ is uninitialized,</ins>
1. <ins>Let _field_ be NewPrivateName(_bindingName_).</ins>
1. <ins>Perform ! _scopeEnvRec_.InitializeBinding(_bindingName_, _field_).</ins>
1. <ins>Else,</ins>
1. <ins>Let _field_ be _scopeEnvRec_.GetBindingValue(_bindingName_).</ins>
1. <ins>NOTE: The only case where this may occur is in getter/setter pairs; other duplicates are prohibited as a Syntax Error.</ins>
1. <ins>Assert: _field_.[[Description]] is _bindingName_.</ins>
1. Return _field_.
</emu-alg>
<emu-note type=editor>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.</emu-note>
</emu-clause>
<emu-clause id="initialize-instance-elements">
<h1>InitializeInstance<del>Fields</del><ins>Elements</ins> ( _O_, _constructor_ )</h1>
<emu-alg>
1. Assert: Type ( _O_ ) is Object.
1. Assert: Assert _constructor_ is an ECMAScript function object.
1. <ins>If _constructor_.[[PrivateBrand]] is not *undefined*,</ins>
1. <ins>Perform ? PrivateBrandAdd(_O_, _constructor_.[[PrivateBrand]]).</ins>
1. Let _fieldRecords_ be the value of _constructor_'s [[Fields]] internal slot.
1. For each item _fieldRecord_ in order from _fieldRecords_,
1. Perform ? DefineField(_O_, _fieldRecord_).
1. Return.
</emu-alg>
<emu-note type=editor>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.</emu-note>
<emu-note type=editor>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 previous private field.</emu-note>
</emu-clause>
<emu-clause id="sec-private-bound-identifiers" aoid="PrivateBoundIdentifiers" id="sec-private-bound-names">
<h1>Static Semantics: PrivateBoundIdentifiers</h1>
<emu-grammar>
ClassElement : MethodDefinition
ClassElement : `static` MethodDefinition
</emu-grammar>
<emu-alg>
1. Return PrivateBoundIdentifiers of |MethodDefinition|.
</emu-alg>
<emu-grammar>
MethodDefinition[Yield, Await] :
ClassElementName[?Yield, ?Await] `(` UniqueFormalParameters[~Yield, ~Await] `)` `{` FunctionBody[~Yield, ~Await] `}`
`get` ClassElementName[?Yield, ?Await] `(` `)` `{` FunctionBody[~Yield, ~Await] `}`
`set` ClassElementName[?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 `}`
</emu-grammar>
<emu-alg>
1. Return PrivateBoundIdentifiers of |ClassElementName|.
</emu-alg>
<emu-grammar>
MethodDefinition[Yield, Await] : GeneratorMethod[?Yield, ?Await]
</emu-grammar>
<emu-alg>
1. Return PrivateBoundIdentifiers of |GeneratorMethod|.
</emu-alg>
<emu-grammar>
MethodDefinition[Yield, Await] : AsyncMethod[?Yield, ?Await]
</emu-grammar>
<emu-alg>
1. Return PrivateBoundIdentifiers of |AsyncMethod|.
</emu-alg>
<emu-grammar>
MethodDefinition[Yield, Await] : AsyncGeneratorMethod[?Yield, ?Await]
</emu-grammar>
<emu-alg>
1. Return PrivateBoundIdentifiers of |AsyncGeneratorMethod|.
</emu-alg>
</emu-clause>
<emu-clause id="runtime-semantics-class-definition-evaluation">
<h1>Runtime Semantics: ClassDefinitionEvaluation</h1>
<p>With parameter _className_.</p>
<emu-grammar>ClassTail : ClassHeritage? `{` ClassBody? `}`</emu-grammar>
<emu-alg>
1. Let _lex_ be the LexicalEnvironment of the running execution context.
1. Let _classScope_ be NewDeclarativeEnvironment(_lex_).
1. Let _classScopeEnvRec_ be _classScope_'s EnvironmentRecord.
1. If _className_ is not *undefined*, then
1. Perform _classScopeEnvRec_.CreateImmutableBinding(_className_, *true*).
1. Let _outerPrivateEnvironment_ be the PrivateEnvironment of the running execution context.
1. Let _classPrivateEnvironment_ be NewDeclarativeEnvironment(_outerPrivateEnvironment_).
1. Let _classPrivateEnvRec_ be _classPrivateEnvironment_'s EnvironmentRecord.
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. If |ClassHeritage_opt| is not present, then
1. Let _protoParent_ be the intrinsic object %ObjectPrototype%.
1. Let _constructorParent_ be the intrinsic object %FunctionPrototype%.
1. Else,
1. Set the running execution context's LexicalEnvironment to _classScope_.
1. NOTE: The running execution context's PrivateEnvironment is _outerPrivateEnvironment_ when evaluating |ClassHeritage|.
1. Let _superclass_ be the result of evaluating |ClassHeritage|.
1. Set the running execution context's LexicalEnvironment to _lex_.
1. ReturnIfAbrupt(_superclass_).
1. If _superclass_ is *null*, then
1. Let _protoParent_ be *null*.
1. Let _constructorParent_ be the intrinsic object %FunctionPrototype%.
1. Else if IsConstructor(_superclass_) is *false*, throw a *TypeError* exception.
1. Else,
1. Let _protoParent_ be ? Get(_superclass_, `"prototype"`).
1. If Type(_protoParent_) is neither Object nor Null, throw a *TypeError* exception.
1. Let _constructorParent_ be _superclass_.
1. Let _proto_ be ObjectCreate(_protoParent_).
1. If |ClassBody_opt| is not present, let _constructor_ be ~empty~.
1. Else, let _constructor_ be ConstructorMethod of |ClassBody|.
1. If _constructor_ is ~empty~, then
1. If |ClassHeritage_opt| is present and _protoParent_ is not *null*, then
1. Let _constructor_ be the result of parsing the source text
<pre><code class="javascript">constructor(... args){ super (...args);}</code></pre>
using the syntactic grammar with the goal symbol |MethodDefinition[~Yield]|.
1. Else,
1. Let _constructor_ be the result of parsing the source text
<pre><code class="javascript">constructor( ){ }</code></pre>
using the syntactic grammar with the goal symbol |MethodDefinition[~Yield]|.
1. Set the running execution context's LexicalEnvironment to _classScope_.
1. Set the running execution context's PrivateEnvironment to _classPrivateEnvironment_.
1. Let _constructorInfo_ be the result of performing DefineMethod for _constructor_ with arguments _proto_ and _constructorParent_ as the optional _functionPrototype_ argument.
1. Assert: _constructorInfo_ is not an abrupt completion.
1. Let _F_ be _constructorInfo_.[[Closure]].
1. If |ClassHeritage_opt| is present and _protoParent_ is not *null*, then set _F_.[[ConstructorKind]] to `"derived"`.
1. Perform MakeConstructor(_F_, *false*, _proto_).
1. Perform MakeClassConstructor(_F_).
1. Perform CreateMethodProperty(_proto_, `"constructor"`, _F_).
1. If |ClassBody_opt| is not present, let _methods_ be a new empty List.
1. Else, let _elements_ be NonConstructorMethodDefinitions of |ClassBody|.
1. Let _instanceFields_ be a new empty List.
1. 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*.
1. Else,
1. Let _field_ be the result of performing PropertyDefinitionEvaluation for _m_ClassElementEvaluation for _e_ with arguments _F_ and *false*.
1. If _field_ is an abrupt completion, then
1. Set the running execution context's LexicalEnvironment to _lex_.
1. Set the running execution context's PrivateEnvironment to _outerPrivateEnvironment_.
1. Return Completion(_field_).
1. If _field_ is not ~empty~, append _field_ to _instanceFields_.
1. Set the running execution context's LexicalEnvironment to _lex_.
1. If _className_ is not *undefined*, then
1. Perform _classScopeEnvRec_.InitializeBinding(_className_, _F_).
1. Set _F_.[[Fields]] to _instanceFields_.
1. <ins>If PrivateBoundIdentifiers of |ClassBody| contains a Private Name _P_ such that the _P_'s [[Kind]] field is either `"method"` or `"accessor"`,</ins>
1. <ins>Set _F_.[[PrivateBrand]] to _proto_.</ins>
1. Set the running execution context's PrivateEnvironment to _outerPrivateEnvironment_.
1. Return _F_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-define-ordinary-method" aoid="DefineOrdinaryMethod">
<h1>DefineOrdinaryMethod ( _key_, _homeObject_, _closure_, _enumerable_ )</h1>
<emu-alg>
1. Perform SetFunctionName(_closure_, _key_).
1. If _key_ is a Private Name,
1. Assert: _key_ does not have a [[Kind]] field.
1. Set _key_.[[Kind]] to `"method"`.
1. Set _key_.[[Value]] to _closure_.
1. Set _key_.[[Brand]] to _homeObject_.
1. Else,
1. Let _desc_ be the PropertyDescriptor{[[Value]]: _closure_, [[Writable]]: *true*, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}.
1. Perform ? DefinePropertyOrThrow(_homeObject_, _key_, _desc_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-method-definitions-runtime-semantics-classelementevaluation" aoid=ClassElementEvaluation>
<h1>Runtime Semantics: ClassElementEvaluation</h1>
<p>With parameters _homeObject_ and _enumerable_.</p>
<emu-see-also-para op="PropertyDefinitionEvaluation"></emu-see-also-para>
<emu-grammar>ClassElement : MethodDefinition</emu-grammar>
<emu-alg>
1. Return ClassElementEvaluation of |MethodDefinition| with arguments ! Get(_homeObject_, `"prototype"`),_enumerable_, and `"prototype"`.
</emu-alg>
<emu-grammar>ClassElement : `static` MethodDefinition</emu-grammar>
<emu-alg>
1. Return ClassElementEvaluation of |MethodDefinition| with arguments _homeObject_, _enumerable_ and `"static"`.
</emu-alg>
<emu-grammar>MethodDefinition : ClassElementName `(` UniqueFormalParameters `)` `{` FunctionBody `}`</emu-grammar>
<emu-alg>
1. Let _methodDef_ be DefineMethod of |MethodDefinition| with argument _homeObject_.
1. ReturnIfAbrupt(_methodDef_).
1. <del>Perform SetFunctionName(_methodDef_.[[Closure]], _methodDef_.[[Key]]).</del>
1. <del>Let _desc_ be the PropertyDescriptor{[[Value]]: _methodDef_.[[Closure]], [[Writable]]: *true*, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}.</del>
1. <del>Return ? DefinePropertyOrThrow(_homeObject_, _methodDef_.[[Key]], _desc_).</del>
1. <ins>Perform ? DefineOrdinaryMethod(_methodDef_.[[Key]], _homeObject_, _methodDef_.[[Closure]], _enumerable_).</ins>
</emu-alg>
<emu-grammar>MethodDefinition : `get` ClassElementName `(` `)` `{` FunctionBody `}`</emu-grammar>
<emu-alg>
1. Let _key_ be the result of evaluating |ClassElementName|.
1. ReturnIfAbrupt(_key_).
1. If the function code for this |MethodDefinition| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
1. Let _scope_ be the running execution context's LexicalEnvironment.
1. Let _formalParameterList_ be an instance of the production <emu-grammar>FormalParameters : [empty]</emu-grammar>.
1. Let _closure_ be FunctionCreate(~Method~, _formalParameterList_, |FunctionBody|, _scope_, _strict_).
1. Perform MakeMethod(_closure_, _homeObject_).
1. Perform SetFunctionName(_closure_, _key_, `"get"`).
1. <ins>If _key_ is a Private Name,</ins>
1. <ins>If _key_ has a [[Kind]] field,</ins>
1. <ins>Assert: _key_.[[Kind]] is `"accessor"`.</ins>
1. <ins>Assert: _key_.[[Brand]] is _homeObject_.</ins>
1. <ins>Assert: _key_ does not have a [[Get]] field.</ins>
1. <ins>Set _key_.[[Get]] to _closure_.</ins>
1. <ins>Else,</ins>
1. <ins>Set _key_.[[Kind]] to `"accessor"`.</ins>
1. <ins>Set _key_.[[Brand]] to _homeObject_.</ins>
1. <ins>Set _key_.[[Get]] to _closure_.</ins>
1. <ins>Else,</ins>
1. Let _desc_ be the PropertyDescriptor{[[Get]]: _closure_, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}.
1. Perform ? DefinePropertyOrThrow(_homeObject_, _key_, _desc_).
</emu-alg>
<emu-grammar>MethodDefinition : `set` ClassElementName `(` PropertySetParameterList `)` `{` FunctionBody `}`</emu-grammar>
<emu-alg>
1. Let _key_ be the result of evaluating |ClassElementName|.
1. ReturnIfAbrupt(_key_).
1. If the function code for this |MethodDefinition| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
1. Let _scope_ be the running execution context's LexicalEnvironment.
1. Let _closure_ be FunctionCreate(~Method~, |PropertySetParameterList|, |FunctionBody|, _scope_, _strict_).
1. Perform MakeMethod(_closure_, _homeObject_).
1. Perform SetFunctionName(_closure_, _key_, `"set"`).
1. <ins>If _key_ is a Private Name,</ins>
1. <ins>If _key_ has a [[Kind]] field,</ins>
1. <ins>Assert: _key_.[[Kind]] is `"accessor"`.</ins>
1. <ins>Assert: _key_.[[Brand]] is _homeObject_.</ins>
1. <ins>Assert: _key_ does not have a [[Set]] field.</ins>
1. <ins>Set _key_.[[Set]] to _closure_.</ins>
1. <ins>Else,</ins>
1. <ins>Set _key_.[[Kind]] to `"accessor"`.</ins>
1. <ins>Set _key_.[[Brand]] to _homeObject_.</ins>
1. <ins>Set _key_.[[Set]] to _closure_.</ins>
1. <ins>Else,</ins>
1. Let _desc_ be the PropertyDescriptor{[[Set]]: _closure_, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}.
1. Perform ? DefinePropertyOrThrow(_homeObject_, _key_, _desc_).
</emu-alg>
<emu-grammar>GeneratorMethod : `*` ClassElementName `(` UniqueFormalParameters `)` `{` GeneratorBody `}`</emu-grammar>
<emu-alg>
1. Let _key_ be the result of evaluating |ClassElementName|.
1. ReturnIfAbrupt(_key_).
1. If the function code for this |GeneratorMethod| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
1. Let _scope_ be the running execution context's LexicalEnvironment.
1. Let _closure_ be GeneratorFunctionCreate(~Method~, |UniqueFormalParameters|, |GeneratorBody|, _scope_, _strict_).
1. Perform MakeMethod(_closure_, _homeObject_).
1. Let _prototype_ be ObjectCreate(%GeneratorPrototype%).
1. Perform DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
1. <del>Perform SetFunctionName(_closure_, _propKey_).</del>
1. <del>Let _desc_ be the PropertyDescriptor{[[Value]]: _closure_, [[Writable]]: *true*, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}.</del>
1. <del>Return ? DefinePropertyOrThrow(_homeObject_, _propKey_, _desc_).</del>
1. <ins>Return DefineOrdinaryMethod(_key_, _homeObject_, _closure_, _enumerable_).</ins>
</emu-alg>
<emu-grammar>
AsyncMethod : `async` [no LineTerminator here] ClassElementName `(` UniqueFormalParameters `)` `{` AsyncFunctionBody `}`
</emu-grammar>
<emu-alg>
1. Let _key_ be the result of evaluating |ClassElementName|.
1. ReturnIfAbrupt(_key_).
1. If the function code for this |AsyncMethod| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
1. Let _scope_ be the LexicalEnvironment of the running execution context.
1. Let _closure_ be ! AsyncFunctionCreate(~Method~, |UniqueFormalParameters|, |AsyncFunctionBody|, _scope_, _strict_).
1. Perform ! MakeMethod(_closure_, _homeObject_).
1. <del>Perform ! SetFunctionName(_closure_, _key_).</ins>
1. <del>Let _desc_ be the PropertyDescriptor{[[Value]]: _closure_, [[Writable]]: *true*, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}.</ins>
1. <del>Return ? DefinePropertyOrThrow(_homeObject_, _propKey_, _desc_).</ins>
1. <ins>Perform ? DefineOrdinaryMethod(_key_, _homeObject_, _closure_, _enumerable_).</ins>
</emu-alg>
<emu-grammar>
AsyncGeneratorMethod : `async` [no LineTerminator here] `*` ClassElementName `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}`
</emu-grammar>
<emu-alg>
1. Let _key_ be the result of evaluating |ClassElementName|.
1. ReturnIfAbrupt(_key_).
1. If the function code for this |AsyncGeneratorMethod| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
1. Let _scope_ be the running execution context's LexicalEnvironment.
1. Let _closure_ be ! AsyncGeneratorFunctionCreate(~Method~, |UniqueFormalParameters|, |AsyncGeneratorBody|, _scope_, _strict_).
1. Perform ! MakeMethod(_closure_, _object_).
1. Let _prototype_ be ! ObjectCreate(%AsyncGeneratorPrototype%).
1. Perform ! DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor { [[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false* }).
1. <del>Perform ! SetFunctionName(_closure_, _propKey_).</del>
1. <del>Let _desc_ be PropertyDescriptor { [[Value]]: _closure_, [[Writable]]: *true*, [[Enumerable]]: _enumerable_, [[Configurable]]: *true* }.</del>
1. <del>Return ? DefinePropertyOrThrow(_object_, _propKey_, _desc_).</del>
1. <ins>Perform ? DefineOrdinaryMethod(_key_, _homeObject_, _closure_, _enumerable_).</ins>
</emu-alg>
</emu-clause>
<emu-clause id="the-super-keyword">
<h1>The `super` Keyword</h1>
<emu-clause id="sec-super-keyword-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>SuperCall : `super` Arguments</emu-grammar>
<emu-alg>
1. Let _newTarget_ be GetNewTarget().
1. If _newTarget_ is *undefined*, throw a *ReferenceError* exception.
1. Let _func_ be ? GetSuperConstructor().
1. Let _argList_ be ArgumentListEvaluation of |Arguments|.
1. ReturnIfAbrupt(_argList_).
1. Let _result_ be ? Construct(_func_, _argList_, _newTarget_).
1. Let _thisER_ be GetThisEnvironment( ).
1. Let _F_ be _thisER_.[[FunctionObject]].
1. Assert: _F_ is an ECMAScript function object.
1. Perform ? InitializeInstance<del>Fields</del><ins>Elements</ins>(_result_, _F_).
1. Return ? _thisER_.BindThisValue(_result_).
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="[[construct]]">
<h1>[[Construct]] ( _argumentsList_, _newTarget_)</h1>
<p>
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:
</p>
<emu-alg>
1. Assert: _F_ is an ECMAScript function object.
1. Assert: Type(_newTarget_) is Object.
1. Let _callerContext_ be the running execution context.
1. Let _kind_ be _F_.[[ConstructorKind]].
1. If _kind_ is `"base"`, then
1. Let _thisArgument_ be ? OrdinaryCreateFromConstructor(_newTarget_, `"%ObjectPrototype%"`).
1. Let _calleeContext_ be PrepareForOrdinaryCall(_F_, _newTarget_).
1. Assert: _calleeContext_ is now the running execution context.
1. If _kind_ is `"base"`, then
1. Perform OrdinaryCallBindThis(_F_, _calleeContext_, _thisArgument_).
1. Let _result_ be InitializeInstance<del>Fields</del><ins>Elements</ins>(_thisArgument_, _F_).
1. If _result_ is an abrupt completion, then
1. Remove _calleeContext_ from execution context stack and restore
_callerContext_ as the running execution context.
1. Return Completion(_result_).
1. Let _constructorEnv_ be the LexicalEnvironment of _calleeContext_.
1. Let _envRec_ be _constructorEnv_'s EnvironmentRecord.
1. Let _result_ be OrdinaryCallEvaluateBody(_F_, _argumentsList_).
1. Remove _calleeContext_ from the execution context stack and restore _callerContext_ as the running execution context.
1. If _result_.[[Type]] is ~return~, then
1. If Type(_result_.[[Value]]) is Object, return NormalCompletion(_result_.[[Value]]).
1. If _kind_ is `"base"`, return NormalCompletion(_thisArgument_).
1. If _result_.[[Value]] is not *undefined*, throw a *TypeError* exception.
1. Else, ReturnIfAbrupt(_result_).
1. Return ? _envRec_.GetThisBinding().
</emu-alg>
<emu-note type=editor>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 <a href="https://github.com/tc39/proposal-private-fields/issues/17">this GitHub thread</a> for more discussion.</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-private-names">
<h1>Private Names and references</h1>
<p>The <dfn>Private Name</dfn> specification type is used to describe a globally unique record which represents a private <del>field</del><ins>class element (field, method, or accessor)</ins>. A Private Name may be installed on any ECMAScript object with the PrivateFieldAdd internal algorithm, and then read or written using PrivateFieldGet and PrivateFieldSet.</p>
<p>Each Private Name holds the following information:</p>
<emu-table id="private-name-record" caption="Fields of the Private Name">
<table>
<thead>
<tr>
<th>
Field
</th>
<th>
Type
</th>
<th>
<ins>For which types is it present</ins>
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
[[Description]]
</td>
<td>
~string~
</td>
<td>
<ins>All</ins>
</td>
<td>
The string value passed to NewPrivateName when creating this Private Name.
</td>
</tr>
<tr>
<td>
<ins>[[Kind]]</ins>
</td>
<td>
<ins>`"field"`, `"method"` or `"accessor"`</ins>
</td>
<td>
<ins>All</ins>
</td>
<td>
<ins>Indicates what the private name is used for.</ins>
</td>
</tr>
<tr>
<td>
<ins>[[Brand]]</ins>
</td>
<td>
<ins>an ECMAScript value</ins>
</td>
<td>
<ins>`"method"` or `"accessor"`</ins>
</td>
<td>
<ins>The "original" class of the private method or accessor; checked for in the [[PrivateBrands]] internal slot of instances before access is provided.</ins>
</td>
</tr>
<tr>
<td>
<ins>[[Value]]</ins>
</td>
<td>
<ins>Function</ins>
</td>
<td>
<ins>`"method"`</ins>
</td>
<td>
<ins>The value of the private method.</ins>
</td>
</tr>
<tr>
<td>
<ins>[[Get]]</ins>
</td>
<td>
<ins>Function</ins>
</td>
<td>
<ins>`"accessor"`</ins>
</td>
<td>
<ins>The getter for a private accessor.</ins>
</td>
</tr>
<tr>
<td>
<ins>[[Set]]</ins>
</td>
<td>
<ins>Function</ins>
</td>
<td>
<ins>`"accessor"`</ins>
</td>
<td>
<ins>The setter for a private accessor.</ins>
</td>
</tr>
</tbody>
</table>
</emu-table>
<p>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.</p>
<emu-note type=editor>
<p>Although this specification uses logic of a [[PrivateBrand]] List which is held per-instance, the use of this list obeys certain invariants:</p>
<ul>
<li>Nothing is removed from the list; things are only added to the end.</li>
<li>There is no way to distinguish different copies of the list.</li>
<li>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.</li>
</ul>
</emu-note>
<emu-clause id="sec-privatebrandcheck" aoid="PrivateBrandCheck" oldids="sec-privatebrandcontains">
<h1>PrivateBrandCheck(_O_, _P_)</h1>
<emu-alg>
1. If _O_.[[PrivateBrands]] does not contain an entry _e_ such that SameValue(_e_, _P_.[[Brand]]) is *true*,
1. Throw a *TypeError* exception.
</emu-alg>
</emu-clause>
<emu-clause id="sec-privatebrandadd" aoid="PrivateBrandAdd">
<h1>PrivateBrandAdd(_O_, _brand_)</h1>
<emu-alg>
1. If _O_.[[PrivateBrands]] contains an entry _e_ such that SameValue(_e_, _brand_) is *true*,
1. Throw a *TypeError* exception.
1. Append _brand_ to _O_.[[PrivateBrands]].
</emu-alg>
</emu-clause>
<emu-clause id="sec-privatefieldget" aoid="PrivateFieldGet">
<h1>PrivateFieldGet (_P_, _O_ )</h1>
<emu-alg>
1. Assert: _P_ is a Private Name.
1. If _O_ is not an object, throw a *TypeError* exception.
1. <ins>If _P_.[[Kind]] is `"field"`,</ins>
1. Let _entry_ be PrivateFieldFind(_P_, _O_).
1. If _entry_ is ~empty~, throw a *TypeError* exception.
1. Return _entry_.[[PrivateFieldValue]].
1. <ins>Perform ? PrivateBrandCheck(_O_, _P_).</ins>
1. <ins>If _P_.[[Kind]] is `"method"`,</ins>
1. <ins>Return _P_.[[Value]].</ins>
1. <ins>Else,</ins>
1. <ins>Assert: _P_.[[Kind]] is `"accessor"`.</ins>
1. <ins>If _P_ does not have a [[Get]] field, throw a *TypeError* exception.</ins>
1. <ins>Let _getter_ be _P_.[[Get]].</ins>
1. <ins>Return ? Call(_getter_, _O_).</ins>
</emu-alg>
</emu-clause>
<emu-clause id="sec-privatefieldset" aoid="PrivateFieldSet">
<h1>PrivateFieldSet (_P_, _O_, _value_ )</h1>
<emu-alg>
1. Assert: _P_ is a Private Name.
1. If _O_ is not an object, throw a *TypeError* exception.
1. <ins>If _P_.[[Kind]] is `"field"`,</ins>
1. Let _entry_ be PrivateFieldFind(_P_, _O_).
1. If _entry_ is ~empty~, throw a *TypeError* exception.
1. Set _entry_.[[PrivateFieldValue]] to _value_.
1. <ins>Return.</ins>
1. <ins>If _P_.[[Kind]] is `"method"`, throw a *TypeError* exception.</ins>
1. <ins>Else,</ins>
1. <ins>Assert: _P_.[[Kind]] is `"accessor"`.</ins>
1. <ins>Perform ? PrivateBrandCheck(_O_, _P_).</ins>
1. <ins>If _P_ does not have a [[Set]] field, throw a *TypeError* exception.</ins>
1. <ins>Let _setter_ be _P_.[[Set]].</ins>
1. <ins>Perform ? Call(_setter_, _O_, _value_).</ins>
1. <ins>Return.</ins>
</emu-alg>
</emu-clause>
</emu-clause>