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 113
/
spec.html
2335 lines (2170 loc) · 132 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
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<meta charset="utf8">
<pre class=metadata>
title: Public and private instance fields proposal
stage: 3
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 attempts to integrate the <a href="https://tc39.github.io/proposal-class-public-fields">public fields</a> and <a href="https://tc39.github.io/proposal-private-fields">private fields</a> proposals into a single, coherent, orthogonal whole. See <a href="https://github.com/littledan/proposal-class-fields">the explainer</a> for an overview.</p>
</emu-intro>
<emu-clause id=sec-syntax>
<h1>Syntax</h1>
<emu-clause id=sec-lexical-grammar>
<h1>Lexical Grammar</h1>
<emu-grammar>
<ins>PrivateIdentifier ::
`#` IdentifierName</ins>
CommonToken ::
IdentifierName
Punctuator
NumericLiteral
StringLiteral
Template
<ins>PrivateIdentifier</ins>
</emu-grammar>
</emu-clause>
<emu-clause id=sec-new-syntax>
<h1>New Syntactic Grammar Productions</h1>
<emu-grammar>
FieldDefinition[Yield, Await] :
ClassElementName[?Yield, ?Await] Initializer[+In, ~Yield, ~Await]?
ClassElementName[Yield, Await] :
PropertyName[?Yield, ?Await]
PrivateIdentifier
</emu-grammar>
</emu-clause>
<emu-clause id=sec-updated-syntax>
<h1>Updated Syntactic Grammar Productions</h1>
<emu-grammar>
ClassElement[Yield, Await] :
MethodDefinition[?Yield, ?Await]
`static` MethodDefinition[?Yield, ?Await]
<ins>FieldDefinition[?Yield, ?Await] `;`</ins>
`;`
MemberExpression[Yield, Await] :
PrimaryExpression[?Yield, ?Await]
MemberExpression[?Yield, ?Await] `[` Expression[+In, ?Yield, ?Await] `]`
MemberExpression[?Yield, ?Await] `.` IdentifierName
MemberExpression[?Yield, ?Await] TemplateLiteral[?Yield, ?Await]
SuperProperty[?Yield, ?Await]
MetaProperty
`new` MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]
<ins>MemberExpression[?Yield, ?Await] `.` PrivateIdentifier</ins>
CallExpression[Yield, Await] :
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await] #callcover
SuperCall[?Yield, ?Await]
CallExpression[?Yield, ?Await] Arguments[?Yield, ?Await]
CallExpression[?Yield, ?Await] `[` Expression[+In, ?Yield, ?Await] `]`
CallExpression[?Yield, ?Await] `.` IdentifierName
CallExpression[?Yield, ?Await] TemplateLiteral[?Yield, ?Await]
<ins>CallExpression[?Yield, ?Await] `.` PrivateIdentifier</ins>
OptionalChain[Yield, Await] :
`?.` `[` Expression[+In, ?Yield, ?Await] `]`
`?.` IdentifierName
`?.` Arguments[?Yield, ?Await]
`?.` TemplateLiteral[?Yield, ?Await, +Tagged]
<ins>`?.` PrivateIdentifier</ins>
OptionalChain[?Yield, ?Await] `[` Expression[+In, ?Yield, ?Await] `]`
OptionalChain[?Yield, ?Await] `.` IdentifierName
OptionalChain[?Yield, ?Await] Arguments[?Yield, ?Await]
OptionalChain[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged]
<ins>OptionalChain[?Yield, ?Await] `.` PrivateIdentifier</ins>
</emu-grammar>
</emu-clause>
<emu-clause id="sec-static-semantics-early-errors">
<h1>Static Semantics: Early Errors</h1>
<emu-grammar>
FieldDefinition :
ClassElementName Initializer?
</emu-grammar>
<ul>
<li>It is a Syntax Error if ContainsArguments of |Initializer| is *true*.</li>
<li>It is a Syntax Error if |Initializer| is present and |Initializer| Contains |SuperCall| is *true*.</li>
</ul>
<emu-grammar>
ClassBody : ClassElementList
</emu-grammar>
<ul>
<li>It is a Syntax Error if PrivateBoundIdentifiers of |ClassBody| contains any duplicate entries.</li>
</ul>
<emu-grammar>ClassElement : FieldDefinition `;`</emu-grammar>
<ul>
<li>
It is a Syntax Error if PropName of |FieldDefinition| is `"constructor"`.
</li>
</ul>
<emu-grammar>ClassElementName : PrivateIdentifier `;`</emu-grammar>
<ul>
<li>
It is a Syntax Error if StringValue of |PrivateIdentifier| is `"#constructor"`.
</li>
</ul>
<emu-note>
<p>These static rules have been modified to produce an early error if the `delete` operator is applied to a private reference.</p>
</emu-note>
<emu-grammar>UnaryExpression : `delete` UnaryExpression</emu-grammar>
<ul>
<li>
It is a Syntax Error if the |UnaryExpression| is contained in strict mode code and the derived |UnaryExpression| is <emu-grammar>PrimaryExpression : IdentifierReference</emu-grammar>, <ins><emu-grammar>MemberExpression : MemberExpression `.` PrivateIdentifier</emu-grammar>, <emu-grammar>CallExpression : CallExpression `.` PrivateIdentifier</emu-grammar>, <emu-grammar>OptionalChain : `?.` PrivateIdentifier</emu-grammar>, or <emu-grammar>OptionalChain : OptionalChain `.` PrivateIdentifier</emu-grammar></ins>.
</li>
<li>
<p>It is a Syntax Error if the derived |UnaryExpression| is
<br>
<emu-grammar>PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList</emu-grammar>
<br>
and |CoverParenthesizedExpressionAndArrowParameterList| ultimately derives a phrase that, if used in place of |UnaryExpression|, would produce a Syntax Error according to these rules. This rule is recursively applied.</p>
</li>
</ul>
<emu-note>
<p>The last rule means that expressions such as `delete (((foo)))` produce early errors because of recursive application of the first rule.</p>
</emu-note>
<emu-note type=editor>Private fields may not be deleted in any case. There are only ever |PrivateIdentifier|s defined inside class bodies. Inside of a class body, code will be in strict mode, and the above rule applies. Outside of a class body, there will be no |PrivateIdentifier|s defined, so the below rule will apply.</emu-note>
<emu-grammar>ScriptBody : StatementList</emu-grammar>
<ul>
<li>It is a Syntax Error if AllPrivateIdentifiersValid of |StatementList| with an empty List as an argument is *false* unless the source code is eval code that is being processed by a direct eval.</li>
</ul>
<emu-grammar>ModuleBody : ModuleItemList</emu-grammar>
<ul>
<li>It is a Syntax Error if AllPrivateIdentifiersValid of |ModuleItemList| with an empty List as an argument is *false*.</li>
</ul>
<emu-note type=editor>References to |PrivateIdentifier|s which are not lexically present cause an early error.</emu-note>
</emu-clause>
<emu-clause id="sec-all-private-identifiers-valid" aoid="AllPrivateIdentifiersValid" oldids="sec-all-private-names-valid">
<h1>Static Semantics: AllPrivateIdentifiersValid</h1>
AllPrivateIdentifiersValid is an abstract operation which takes _names_ as an argument.
<emu-grammar>MemberExpression[Yield, Await] : MemberExpression[?Yield, ?Await] `.` PrivateIdentifier</emu-grammar>
<emu-alg>
1. If StringValue of |PrivateIdentifier| is in _names_, return *true*.
1. Return *false*.
</emu-alg>
<emu-grammar>CallExpression[Yield, Await] : CallExpression[?Yield, ?Await] `.` PrivateIdentifier</emu-grammar>
<emu-alg>
1. If StringValue of |PrivateIdentifier| is in _names_, return *true*.
1. Return *false*.
</emu-alg>
<emu-grammar>OptionalChain[Yield, Await] : `?.` PrivateIdentifier</emu-grammar>
<emu-alg>
1. If StringValue of |PrivateIdentifier| is in _names_, return *true*.
1. Return *false*.
</emu-alg>
<emu-grammar>OptionalChain[Yield, Await] : OptionalChain[?Yield, ?Await] `.` PrivateIdentifier</emu-grammar>
<emu-alg>
1. If StringValue of |PrivateIdentifier| is in _names_, return *true*.
1. Return *false*.
</emu-alg>
<emu-grammar> ClassBody[Yield, Await] : ClassElementList[?Yield, ?Await] </emu-grammar>
<emu-alg>
1. Let _newNames_ be the concatenation of _names_ with PrivateBoundIdentifiers of |ClassBody|.
1. Return AllPrivateIdentifiersValid of |ClassElementList| with the argument _newNames_.
</emu-alg>
For all other grammatical productions, recurse on subexpressions/substatements, passing in the _names_ of the caller. If all pieces return *true*, then return *true*. If any returns *false*, return *false*.
<emu-note type=editor>TODO: Elaborate the preceding paragraph with spec text inserted in each relevant place</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] : PropertyName[?Yield, ?Await]
</emu-grammar>
<emu-alg>
1. Return the result of evaluating |PropertyName|.
</emu-alg>
<emu-grammar>
ClassElementName[Yield, Await] : PrivateIdentifier
</emu-grammar>
<emu-alg>
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. Return _scopeEnvRec_.GetBindingValue(_bindingName_).
</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="static-semantics-class-element-evaluation">
<h1>Runtime Semantics: ClassElementEvaluation</h1>
<p>With parameters _object_ and _enumerable_.</p>
<emu-grammar>ClassElement : FieldDefinition `;`</emu-grammar>
<emu-alg>
1. Return ClassFieldDefinitionEvaluation of |FieldDefinition| with parameter _object_.
</emu-alg>
<emu-grammar>
ClassElement : MethodDefinition
ClassElement : `static` MethodDefinition
</emu-grammar>
<emu-alg>
1. Perform ? PropertyDefinitionEvaluation with parameters _object_ and _enumerable_.
1. Return ~empty~.
</emu-alg>
</emu-clause>
<emu-clause id="runtime-semantics-class-field-definition-evaluation">
<h1>Runtime Semantics: ClassFieldDefinitionEvaluation</h1>
<p>With parameter _homeObject_.</p>
<emu-grammar>
FieldDefinition : ClassElementName Initializer?
</emu-grammar>
<emu-alg>
1. Let _name_ be the result of evaluating |ClassElementName|.
1. ReturnIfAbrupt(_name_).
1. If |Initializer_opt| is present,
1. Let _lex_ be the Lexical Environment of the running execution context.
1. Let _formalParameterList_ be an instance of the production <emu-grammar>FormalParameters : [empty]</emu-grammar>.
1. Let _privateScope_ be the PrivateEnvironment of the running execution context.
1. Let _initializer_ be FunctionCreate(~Method~, _formalParameterList_, |Initializer|, _lex_, *true*, _privateScope_).
1. Perform MakeMethod(_initializer_, _homeObject_).
1. Let _isAnonymousFunctionDefinition_ be IsAnonymousFunctionDefinition(|Initializer|).
1. Else,
1. Let _initializer_ be ~empty~.
1. Let _isAnonymousFunctionDeclaration_ be *false*.
1. Return a Record {
[[Name]]: _name_,
[[Initializer]]: _initializer_,
[[IsAnonymousFunctionDefinition]]: _isAnonymousFunctionDefinition_
}.
</emu-alg>
</emu-clause>
<emu-clause id="runtime-semantics-class-public-field-definition-evaluation">
<h1>Runtime Semantics: EvaluateBody</h1>
<p>With parameter _functionObject_ and List _argumentsList_.</p>
<emu-grammar>
Initializer :
`=` AssignmentExpression
</emu-grammar>
<emu-alg>
1. Assert: _argumentsList_ is empty.
1. Let _exprRef_ be the result of evaluating |AssignmentExpression|.
1. Let _exprValue_ be ? GetValue(_exprRef_).
1. Return Completion { [[Type]]: ~return~, [[Value]]: _exprValue_, [[Target]]: ~empty~ }.
</emu-alg>
<emu-note>FunctionDeclarationInstantiation would not have any observable behaviour here, so its call is omitted.</emu-note>
</emu-clause>
<!-- es6num="9.2.11" -->
<emu-clause id="sec-setfunctionname" aoid="SetFunctionName">
<h1>SetFunctionName ( _F_, _name_ [ , _prefix_ ] )</h1>
<p>The abstract operation SetFunctionName requires a Function argument _F_, a String, Symbol, <ins>or Private Name</ins> argument _name_ and optionally a String argument _prefix_. This operation adds a `name` property to _F_ by performing the following steps:</p>
<emu-alg>
1. Assert: _F_ is an extensible object that does not have a `name` own property.
1. Assert: Type(_name_) is either Symbol, String, <ins>or Private Name</ins>.
1. Assert: If _prefix_ was passed, then Type(_prefix_) is String.
1. If Type(_name_) is Symbol, then
1. Let _description_ be _name_'s [[Description]] value.
1. If _description_ is *undefined*, set _name_ to the empty String.
1. Else, set _name_ to the concatenation of `"["`, _description_, and `"]"`.
1. <ins>Else if _name_ is a Private Name,</ins>
1. <ins>Set _name_ to _name_'s [[Description]] value.</ins>
1. If _prefix_ was passed, then
1. Set _name_ to the concatenation of _prefix_, code unit 0x0020 (SPACE), and _name_.
1. Return ! DefinePropertyOrThrow(_F_, `"name"`, PropertyDescriptor{[[Value]]: _name_, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true*}).
</emu-alg>
</emu-clause>
<emu-clause id="sec-define-field" aoid="DefineField">
<h1>DefineField(_receiver_, _fieldRecord_)</h1>
<emu-alg>
1. Assert: Type(_receiver_) is Object.
1. Assert: _fieldRecord_ is a Record as created by ClassFieldDefinitionEvaluation.
1. Let _fieldName_ be _fieldRecord_.[[Name]].
1. Let _initializer_ be _fieldRecord_.[[Initializer]].
1. If _initializer_ is not ~empty~, then
1. Let _initValue_ be ? Call(_initializer_, _receiver_).
1. Else, let _initValue_ be *undefined*.
1. If _fieldRecord_.[[IsAnonymousFunctionDefinition]] is *true*, then
1. Let _hasNameProperty_ be ? HasOwnProperty(_initValue_, `"name"`).
1. If _hasNameProperty_ is *false*, perform SetFunctionName(_initValue_, _fieldName_).
1. If _fieldName_ is a Private Name,
1. Perform ? PrivateFieldAdd(_fieldName_, _receiver_, _initValue_).
1. Else,
1. Assert: IsPropertyKey(_fieldName_) is *true*.
1. Perform ? CreateDataPropertyOrThrow(_receiver_, _fieldName_, _initValue_).
1. Return.
</emu-alg>
</emu-clause>
<emu-clause id="initialize-public-instance-fields" aoid="InitializeInstanceFields">
<h1>InitializeInstanceFields ( _O_, _constructor_ )</h1>
<emu-alg>
1. Assert: Type ( _O_ ) is Object.
1. Assert: _constructor_ is an ECMAScript function object.
1. Let _fields_ be the value of _constructor_.[[Fields]].
1. For each item _fieldRecord_ in order from _fields_,
1. Perform ? DefineField(_O_, _fieldRecord_).
1. Return.
</emu-alg>
<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-names-static-semantics-stringvalue">
<h1>Static Semantics: StringValue</h1>
<emu-see-also-para op="StringValue"></emu-see-also-para>
<emu-grammar>
PrivateIdentifier ::
`#` IdentifierName
</emu-grammar>
<emu-alg>
1. Return the String value consisting of the sequence of code units corresponding to |PrivateIdentifier|. In determining the sequence any occurrences of `\\` |UnicodeEscapeSequence| are first replaced with the code point represented by the |UnicodeEscapeSequence| and then the code points of the entire |PrivateIdentifier| are converted to code units by UTF16Encoding (<emu-xref href="#sec-utf16encoding"></emu-xref>) each code point.
</emu-alg>
</emu-clause>
<emu-clause id="sec-private-bound-identifiers" aoid="PrivateBoundIdentifiers" oldids="sec-private-bound-names">
<h1>Static Semantics: PrivateBoundIdentifiers</h1>
<emu-grammar>
FieldDefinition : ClassElementName Initializer?
</emu-grammar>
<emu-alg>
1. Return PrivateBoundIdentifiers of |ClassElementName|
</emu-alg>
<emu-grammar>
ClassElementName : PrivateIdentifier
</emu-grammar>
<emu-alg>
1. Return a new List containing the StringValue of |PrivateIdentifier|.
</emu-alg>
<emu-grammar>
ClassElementName : PropertyName
</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
<emu-grammar>
ClassElement : MethodDefinition `;`
ClassElement : `static` MethodDefinition `;`
ClassElement : `;`
</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
<emu-grammar>
ClassElementList : ClassElement
</emu-grammar>
<emu-alg>
1. Return PrivateBoundIdentifiers of |ClassElement|.
</emu-alg>
<emu-grammar>
ClassElementList : ClassElementList ClassElement
</emu-grammar>
<emu-alg>
1. Let _names_ be PrivateBoundIdentifiers of |ClassElementList|.
1. Append to _names_ the elements of PrivateBoundIdentifiers of |ClassElement|.
1. Return _names_.
</emu-alg>
<emu-grammar>
ClassBody : ClassElementList
</emu-grammar>
<emu-alg>
1. Return PrivateBoundIdentifiers of |ClassElementList|.
</emu-alg>
</emu-clause>
<emu-clause id="sec-static-semantics-contains-arguments">
<h1>Static Semantics: ContainsArguments</h1>
<emu-grammar>
IdentifierReference : Identifier
</emu-grammar>
<emu-alg>
1. If the StringValue of |Identifier| is `"arguments"`, return *true*.
2. Else, return *false*.
</emu-alg>
<emu-grammar>
FunctionDeclaration : `function` BindingIdentifier `(` FormalParameters `)` `{` FunctionBody `}`
FunctionDeclaration : `function` `(` FormalParameters `)` `{` FunctionBody `}`
FunctionExpression : `function` BindingIdentifier? `(` FormalParameters `)` `{` FunctionBody `}`
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
<emu-grammar>
MethodDefinition :
PropertyName `(` UniqueFormalParameters `)` `{` FunctionBody `}`
`get` PropertyName `(` `)` `{` FunctionBody `}`
`set` PropertyName `(` PropertySetParameterList `)` `{` FunctionBody `}`
</emu-grammar>
<emu-alg>
1. Return the result of ContainsArguments for |PropertyName|.
</emu-alg>
<emu-grammar>
GeneratorMethod : `*` PropertyName `(` UniqueFormalParameters `)` `{` GeneratorBody `}`
</emu-grammar>
<emu-alg>
1. Return the result of ContainsArguments for |PropertyName|.
</emu-alg>
<emu-grammar>
GeneratorDeclaration : `function` `*` BindingIdentifier `(` FormalParameters `)` `{` GeneratorBody `}`
GeneratorDeclaration : `function` `*` `(` FormalParameters `)` `{` GeneratorBody `}`
GeneratorExpression : `function` `*` BindingIdentifier? `(` FormalParameters `)` `{` GeneratorBody `}`
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
<emu-grammar>ClassBody : ClassElementList</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
<emu-grammar>
AsyncMethod : `async` [no LineTerminator here] PropertyName `(` UniqueFormalParameters `)` `{` AsyncFunctionBody `}`
</emu-grammar>
<emu-alg>
1. Return the result of ContainsArguments for |PropertyName|.
</emu-alg>
<emu-grammar>
AsyncFunctionDeclaration : `async` [no LineTerminator here] `function` BindingIdentifier `(` FormalParameters `)` `{` AsyncFunctionBody `}`
AsyncFunctionDeclaration : `async` [no LineTerminator here] `function` `(` FormalParameters `)` `{` AsyncFunctionBody `}`
AsyncFunctionExpression : `async` [no LineTerminator here] `function` `(` FormalParameters `)` `{` AsyncFunctionBody `}`
AsyncFunctionExpression : `async` [no LineTerminator here] `function` BindingIdentifier `(` FormalParameters `)` `{` AsyncFunctionBody `}`
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
For all other grammatical productions, recurse on all nonterminals. If any piece returns *true*, then return *true*. Otherwise return *false*.
<emu-note type=editor>TODO: Elaborate the preceding paragraph with spec text inserted in each relevant place</emu-note>
</emu-clause>
<emu-clause id="class-definitions">
<h1>Class Definitions</h1>
<emu-clause id="static-semantics-is-static">
<h1>Static Semantics: IsStatic</h1>
<ins class="block">
<emu-grammar>ClassElement : FieldDefinition</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
</ins>
</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. <ins>Let _outerPrivateEnvironment_ be the PrivateEnvironment of the running execution context.</ins>
1. <ins>Let _classPrivateEnvironment_ be NewDeclarativeEnvironment(_outerPrivateEnvironment_).</ins>
1. <ins>Let _classPrivateEnvRec_ be _classPrivateEnvironment_'s EnvironmentRecord.</ins>
1. <ins>If |ClassBody_opt| is present, then</ins>
1. <ins>For each element _dn_ of the PrivateBoundIdentifiers of |ClassBody_opt|,</ins>
1. <ins>Perform _classPrivateEnvRec_.CreateImmutableBinding(_dn_, *true*).</ins>
1. <ins>Let _privateName_ be NewPrivateName(_dn_).</ins>
1. <ins>Perform ! _classPrivateEnvRec_.InitializeBinding(_dn_, _privateName_).</ins>
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. <ins>NOTE: The running execution context's PrivateEnvironment is _outerPrivateEnvironment_ when evaluating |ClassHeritage|.</ins>
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. <ins>Set the running execution context's PrivateEnvironment to _classPrivateEnvironment_.</ins>
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 <del>_methods_</del><ins>_elements_</ins> be a new empty List.
1. Else, let <del>_methods_</del><ins>_elements_</ins> be NonConstructorMethodDefinitions of |ClassBody|.
1. <ins>Let _instanceFields_ be a new empty List.</ins>
1. For each |ClassElement| <del>_m_</del><ins>_e_</ins> in order from <del>_methods_</del><ins>_elements_</ins>
1. If IsStatic of <del>_m_</del><ins>_e_</ins> is *false*, then
1. Let _field_ be the result of performing <del>PropertyDefinitionEvaluation for _m_</del><ins>ClassElementEvaluation for _e_</ins> with arguments _proto_ and *false*.
1. Else,
1. Let _field_ be the result of performing <del>PropertyDefinitionEvaluation for _m_</del><ins>ClassElementEvaluation for _e_</ins> with arguments _F_ and *false*.
1. If _field_ is an abrupt completion, then
1. Set the running execution context's LexicalEnvironment to _lex_.
1. <ins>Set the running execution context's PrivateEnvironment to _outerPrivateEnvironment_.</ins>
1. Return Completion(_field_).
1. <ins>If _field_ is not ~empty~, append _field_ to _instanceFields_.</ins>
1. Set the running execution context's LexicalEnvironment to _lex_.
1. If _className_ is not *undefined*, then
1. Perform _classScopeEnvRec_.InitializeBinding(_className_, _F_).
1. <ins>Set _F_.[[Fields]] to _instanceFields_.</ins>
1. <ins>Set the running execution context's PrivateEnvironment to _outerPrivateEnvironment_.</ins>
1. Return _F_.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-ecmascript-function-objects-construct-argumentslist-newtarget">
<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. <ins>Let _result_ be InitializeInstanceFields(_thisArgument_, _F_).</ins>
1. <ins>If _result_ is an abrupt completion, then</ins>
1. <ins>Remove _calleeContext_ from execution context stack and restore
_callerContext_ as the running execution context.</ins>
1. <ins>Return Completion(_result_).</ins>
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 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. <del>Return</del><ins>Perform</ins> ? _thisER_.BindThisValue(_result_).
1. <ins>Let _F_ be _thisER_.[[FunctionObject]].</ins>
1. <ins>Assert: _F_ is an ECMAScript function object.</ins>
1. <ins>Perform ? InitializeInstanceFields(_result_, _F_).</ins>
1. <ins>Return _result_.</ins>
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-delete-operator">
<h1>The `delete` Operator</h1>
<emu-clause id="sec-delete-operator-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>UnaryExpression : `delete` UnaryExpression</emu-grammar>
<emu-alg>
1. Let _ref_ be the result of evaluating |UnaryExpression|.
1. ReturnIfAbrupt(_ref_).
1. If Type(_ref_) is not Reference, return *true*.
1. If IsUnresolvableReference(_ref_) is *true*, then
1. Assert: IsStrictReference(_ref_) is *false*.
1. Return *true*.
1. If IsPropertyReference(_ref_) is *true*, then
1. <ins>Assert: IsPrivateReference(_ref_) is *false*.</ins>
1. If IsSuperReference(_ref_), throw a *ReferenceError* exception.
1. Let _baseObj_ be ! ToObject(GetBase(_ref_)).
1. Let _deleteStatus_ be ? _baseObj_.[[Delete]](GetReferencedName(_ref_)).
1. If _deleteStatus_ is *false* and IsStrictReference(_ref_) is *true*, throw a *TypeError* exception.
1. Return _deleteStatus_.
1. Else _ref_ is a Reference to an Environment Record binding,
1. Let _bindings_ be GetBase(_ref_).
1. Return ? _bindings_.DeleteBinding(GetReferencedName(_ref_)).
</emu-alg>
<emu-note>
<p>When a `delete` operator occurs within strict mode code, a *SyntaxError* exception is thrown if its |UnaryExpression| is a direct reference to a variable, function argument, or function name. In addition, if a `delete` operator occurs within strict mode code and the property to be deleted has the attribute { [[Configurable]]: *false* }, a *TypeError* exception is thrown.</p>
</emu-note>
</emu-clause>
</emu-clause>
<!-- es6num="19.2.1.1.1" -->
<emu-clause id="sec-createdynamicfunction" aoid="CreateDynamicFunction">
<h1>Runtime Semantics: CreateDynamicFunction( _constructor_, _newTarget_, _kind_, _args_ )</h1>
<p>The abstract operation CreateDynamicFunction is called with arguments _constructor_, _newTarget_, _kind_, and _args_. _constructor_ is the constructor function that is performing this action, _newTarget_ is the constructor that `new` was initially applied to, _kind_ is either `"normal"`, `"generator"`, or `"async"`, and _args_ is a List containing the actual argument values that were passed to _constructor_. The following steps are taken:</p>
<emu-alg>
1. Assert: The execution context stack has at least two elements.
1. Let _callerContext_ be the second to top element of the execution context stack.
1. Let _callerRealm_ be _callerContext_'s Realm.
1. Let _calleeRealm_ be the current Realm Record.
1. Perform ? HostEnsureCanCompileStrings(_callerRealm_, _calleeRealm_).
1. If _newTarget_ is *undefined*, set _newTarget_ to _constructor_.
1. If _kind_ is `"normal"`, then
1. Let _goal_ be the grammar symbol |FunctionBody[~Yield, ~Await]|.
1. Let _parameterGoal_ be the grammar symbol |FormalParameters[~Yield, ~Await]|.
1. Let _fallbackProto_ be `"%FunctionPrototype%"`.
1. Else if _kind_ is `"generator"`, then
1. Let _goal_ be the grammar symbol |GeneratorBody|.
1. Let _parameterGoal_ be the grammar symbol |FormalParameters[+Yield, ~Await]|.
1. Let _fallbackProto_ be `"%Generator%"`.
1. Else,
1. Assert: _kind_ is `"async"`.
1. Let _goal_ be the grammar symbol |AsyncFunctionBody|.
1. Let _parameterGoal_ be the grammar symbol |FormalParameters[~Yield, +Await]|.
1. Let _fallbackProto_ be `"%AsyncFunctionPrototype%"`.
1. Let _argCount_ be the number of elements in _args_.
1. Let _P_ be the empty String.
1. If _argCount_ = 0, let _bodyText_ be the empty String.
1. Else if _argCount_ = 1, let _bodyText_ be _args_[0].
1. Else _argCount_ > 1,
1. Let _firstArg_ be _args_[0].
1. Set _P_ to ? ToString(_firstArg_).
1. Let _k_ be 1.
1. Repeat, while _k_ < _argCount_-1
1. Let _nextArg_ be _args_[_k_].
1. Let _nextArgString_ be ? ToString(_nextArg_).
1. Set _P_ to the result of concatenating the previous value of _P_, the String `","` (a comma), and _nextArgString_.
1. Increase _k_ by 1.
1. Let _bodyText_ be _args_[_k_].
1. Set _bodyText_ to ? ToString(_bodyText_).
1. Let _parameters_ be the result of parsing _P_, interpreted as UTF-16 encoded Unicode text as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>, using _parameterGoal_ as the goal symbol. Throw a *SyntaxError* exception if the parse fails.
1. Let _body_ be the result of parsing _bodyText_, interpreted as UTF-16 encoded Unicode text as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>, using _goal_ as the goal symbol. Throw a *SyntaxError* exception if the parse fails.
1. Let _strict_ be ContainsUseStrict of _body_.
1. If any static semantics errors are detected for _parameters_ or _body_, throw a *SyntaxError* or a *ReferenceError* exception, depending on the type of the error. If _strict_ is *true*, the Early Error rules for <emu-grammar>UniqueFormalParameters : FormalParameters</emu-grammar> are applied. Parsing and early error detection may be interweaved in an implementation-dependent manner.
1. If _strict_ is *true* and IsSimpleParameterList of _parameters_ is *false*, throw a *SyntaxError* exception.
1. If any element of the BoundNames of _parameters_ also occurs in the LexicallyDeclaredNames of _body_, throw a *SyntaxError* exception.
1. If _body_ Contains |SuperCall| is *true*, throw a *SyntaxError* exception.
1. If _parameters_ Contains |SuperCall| is *true*, throw a *SyntaxError* exception.
1. If _body_ Contains |SuperProperty| is *true*, throw a *SyntaxError* exception.
1. If _parameters_ Contains |SuperProperty| is *true*, throw a *SyntaxError* exception.
1. If _kind_ is `"generator"`, then
1. If _parameters_ Contains |YieldExpression| is *true*, throw a *SyntaxError* exception.
1. If _kind_ is `"async"`, then
1. If _parameters_ Contains |AwaitExpression| is *true*, throw a *SyntaxError* exception.
1. If _strict_ is *true*, then
1. If BoundNames of _parameters_ contains any duplicate elements, throw a *SyntaxError* exception.
1. <ins>Let _privateIdentifiers_ be an empty List.</ins>
1. <ins>If AllPrivateIdentifiersValid of _body_ with the argument _privateIdentifiers_ is *false*, throw a *SyntaxError* exception.</ins>
1. <ins>If AllPrivateIdentifiersValid of _parameters_ with the argument _privateIdentifiers_ is *false*, throw a *SyntaxError* exception.</ins>
1. Let _proto_ be ? GetPrototypeFromConstructor(_newTarget_, _fallbackProto_).
1. Let _F_ be FunctionAllocate(_proto_, _strict_, _kind_).
1. Let _realmF_ be _F_.[[Realm]].
1. Let _scope_ be _realmF_.[[GlobalEnv]].
1. <ins>Let _privateScope_ be NewDeclarativeEnvironment(*null*).</ins>
1. Perform FunctionInitialize(_F_, ~Normal~, _parameters_, _body_, _scope_<ins>, _privateScope_</ins>).
1. If _kind_ is `"generator"`, then
1. Let _prototype_ be ObjectCreate(%GeneratorPrototype%).
1. Perform DefinePropertyOrThrow(_F_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
1. Else if _kind_ is `"normal"`, perform MakeConstructor(_F_).
1. NOTE: Async functions are not constructable and do not have a [[Construct]] internal method or a `"prototype"` property.
1. Perform SetFunctionName(_F_, `"anonymous"`).
1. Return _F_.
</emu-alg>
<emu-note>
<p>A `prototype` property is created for every non-async function created using CreateDynamicFunction to provide for the possibility that the function will be used as a constructor.</p>
</emu-note>
</emu-clause>
<emu-clause id="sec-eval-x">
<h1>eval ( _x_ )</h1>
<emu-clause id="sec-performeval">
<h1>Runtime Semantics: PerformEval ( _x_, _evalRealm_, _strictCaller_, _direct_ )</h1>
<p>The abstract operation PerformEval with arguments _x_, _evalRealm_, _strictCaller_, and _direct_ performs the following steps:</p>
<emu-alg>
1. Assert: If _direct_ is *false*, then _strictCaller_ is also *false*.
1. If Type(_x_) is not String, return _x_.
1. Let _thisEnvRec_ be ! GetThisEnvironment().
1. If _thisEnvRec_ is a function Environment Record, then
1. Let _F_ be _thisEnvRec_.[[FunctionObject]].
1. Let _inFunction_ be *true*.
1. Let _inMethod_ be _thisEnvRec_.HasSuperBinding().
1. If _F_.[[ConstructorKind]] is `"derived"`, let _inDerivedConstructor_ be *true*; otherwise, let _inDerivedConstructor_ be *false*.
1. Else,
1. Let _inFunction_ be *false*.
1. Let _inMethod_ be *false*.
1. Let _inDerivedConstructor_ be *false*.
1. Let _script_ be the ECMAScript code that is the result of parsing _x_, interpreted as UTF-16 encoded Unicode text as described in <emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>, for the goal symbol |Script|. If _inFunction_ is *false*, additional early error rules from <emu-xref href="#sec-performeval-rules-outside-functions"></emu-xref> are applied. If _inMethod_ is *false*, additional early error rules from <emu-xref href="#sec-performeval-rules-outside-methods"></emu-xref> are applied. If _inDerivedConstructor_ is *false*, additional early error rules from <emu-xref href="#sec-performeval-rules-outside-constructors"></emu-xref> are applied. If the parse fails, throw a *SyntaxError* exception. If any early errors are detected, throw a *SyntaxError* or a *ReferenceError* exception, depending on the type of the error (but see also clause <emu-xref href="#sec-error-handling-and-language-extensions"></emu-xref>). Parsing and early error detection may be interweaved in an implementation-dependent manner.
1. If _script_ Contains |ScriptBody| is *false*, return *undefined*.
1. Let _body_ be the |ScriptBody| of _script_.
1. If _strictCaller_ is *true*, let _strictEval_ be *true*.
1. Else, let _strictEval_ be IsStrict of _script_.
1. Let _ctx_ be the running execution context.
1. NOTE: If _direct_ is *true*, _ctx_ will be the execution context that performed the direct eval. If _direct_ is *false*, _ctx_ will be the execution context for the invocation of the `eval` function.
1. If _direct_ is *true*, then
1. Let _lexEnv_ be NewDeclarativeEnvironment(_ctx_'s LexicalEnvironment).
1. Let _varEnv_ be _ctx_'s VariableEnvironment.
1. <ins>Let _privateEnv_ be _ctx_'s PrivateEnvironment.</ins>
1. Else,
1. Let _lexEnv_ be NewDeclarativeEnvironment(_evalRealm_.[[GlobalEnv]]).
1. Let _varEnv_ be _evalRealm_.[[GlobalEnv]].
1. <ins>Let _privateEnv_ be NewDeclarativeEnvironment(*null*).</ins>
1. If _strictEval_ is *true*, set _varEnv_ to _lexEnv_.
1. If _ctx_ is not already suspended, suspend _ctx_.
1. Let _evalCxt_ be a new ECMAScript code execution context.
1. Set the _evalCxt_'s Function to *null*.
1. Set the _evalCxt_'s Realm to _evalRealm_.
1. Set the _evalCxt_'s ScriptOrModule to _ctx_'s ScriptOrModule.
1. Set the _evalCxt_'s VariableEnvironment to _varEnv_.
1. Set the _evalCxt_'s LexicalEnvironment to _lexEnv_.
1. <ins>Set the _evalCxt_'s PrivateEnvironment to _privateEnv_.</ins>
1. Push _evalCxt_ on to the execution context stack; _evalCxt_ is now the running execution context.
1. Let _result_ be EvalDeclarationInstantiation(_body_, _varEnv_, _lexEnv_, <ins>_privateEnv_, </ins>_strictEval_).
1. If _result_.[[Type]] is ~normal~, then
1. Set _result_ to the result of evaluating _body_.
1. If _result_.[[Type]] is ~normal~ and _result_.[[Value]] is ~empty~, then
1. Set _result_ to NormalCompletion(*undefined*).
1. Suspend _evalCxt_ and remove it from the execution context stack.
1. Resume the context that is now on the top of the execution context stack as the running execution context.
1. Return Completion(_result_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-performeval-rules-in-initializer">
<h1>Additional Early Error Rules for Eval Inside |Initializer|</h1>
<p>These static semantics are applied by PerformEval when a direct eval call occurs inside a class field initializer.</p>
<emu-grammar>ScriptBody : StatementList</emu-grammar>
<ul>
<li>It is a Syntax Error if ContainsArguments of |StatementList| is *true*.</li>
<li>The remaining eval rules apply as <a href="https://tc39.github.io/ecma262/#sec-performeval-rules-outside-constructors">outside a constructor</a>, <a href="https://tc39.github.io/ecma262/#sec-performeval-rules-outside-methods">inside a method</a>, and <a href="https://tc39.github.io/ecma262/#sec-performeval-rules-outside-functions">inside a function</a>.</li>
</ul>
</emu-clause>
<emu-clause id="sec-evaldeclarationinstantiation" aoid="EvalDeclarationInstantiation">
<h1>Runtime Semantics: EvalDeclarationInstantiation( _body_, _varEnv_, _lexEnv_, <ins>_privateEnv_,</ins> _strict_ )</h1>
<p>When the abstract operation EvalDeclarationInstantiation is called with arguments _body_, _varEnv_, _lexEnv_, _privateEnv_, and _strict_, the following steps are taken:</p>
<emu-alg>
1. Let _varNames_ be the VarDeclaredNames of _body_.
1. Let _varDeclarations_ be the VarScopedDeclarations of _body_.
1. Let _lexEnvRec_ be _lexEnv_'s EnvironmentRecord.
1. Let _varEnvRec_ be _varEnv_'s EnvironmentRecord.
1. If _strict_ is *false*, then
1. If _varEnvRec_ is a global Environment Record, then
1. For each _name_ in _varNames_, do
1. If _varEnvRec_.HasLexicalDeclaration(_name_) is *true*, throw a *SyntaxError* exception.
1. NOTE: `eval` will not create a global var declaration that would be shadowed by a global lexical declaration.
1. Let _thisLex_ be _lexEnv_.
1. Assert: The following loop will terminate.
1. Repeat while _thisLex_ is not the same as _varEnv_,
1. Let _thisEnvRec_ be _thisLex_'s EnvironmentRecord.
1. If _thisEnvRec_ is not an object Environment Record, then
1. NOTE: The environment of with statements cannot contain any lexical declaration so it doesn't need to be checked for var/let hoisting conflicts.
1. For each _name_ in _varNames_, do
1. If _thisEnvRec_.HasBinding(_name_) is *true*, then
1. Throw a *SyntaxError* exception.
1. NOTE: Annex <emu-xref href="#sec-variablestatements-in-catch-blocks"></emu-xref> defines alternate semantics for the above step.
1. NOTE: A direct eval will not hoist var declaration over a like-named lexical declaration.
1. Let _thisLex_ be _thisLex_'s outer environment reference.
1. <ins>Let _privateIdentifiers_ be an empty List.</ins>
1. <ins>Let _privateEnv_ be _privateEnv_.</ins>
1. <ins>Repeat while _privateEnv_ is not *null*,</ins>
1. <ins>For each binding named _N_ in _privateEnv_,</ins>
1. <ins>If _privateIdentifiers_ does not contain _N_, append _N_ to _privateIdentifiers_.</ins>
1. <ins>Let _privateEnv_ be _privateEnv_'s outer environment reference.</ins>
1. <ins>If AllPrivateIdentifiersValid of _body_ with the argument _privateIdentifiers_ is *false*, throw a *SyntaxError* exception.</ins>
1. Let _functionsToInitialize_ be a new empty List.
1. Let _declaredFunctionNames_ be a new empty List.
1. For each _d_ in _varDeclarations_, in reverse list order do
1. If _d_ is neither a |VariableDeclaration| nor a |ForBinding| nor a |BindingIdentifier|, then
1. Assert: _d_ is either a |FunctionDeclaration|, a |GeneratorDeclaration|, or an |AsyncFunctionDeclaration|.
1. NOTE If there are multiple function declarations for the same name, the last declaration is used.
1. Let _fn_ be the sole element of the BoundNames of _d_.
1. If _fn_ is not an element of _declaredFunctionNames_, then
1. If _varEnvRec_ is a global Environment Record, then
1. Let _fnDefinable_ be ? _varEnvRec_.CanDeclareGlobalFunction(_fn_).
1. If _fnDefinable_ is *false*, throw a *TypeError* exception.
1. Append _fn_ to _declaredFunctionNames_.
1. Insert _d_ as the first element of _functionsToInitialize_.
1. NOTE: Annex <emu-xref href="#sec-web-compat-evaldeclarationinstantiation"></emu-xref> adds additional steps at this point.
1. Let _declaredVarNames_ be a new empty List.
1. For each _d_ in _varDeclarations_, do
1. If _d_ is a |VariableDeclaration|, a |ForBinding|, or a |BindingIdentifier|, then
1. For each String _vn_ in the BoundNames of _d_, do
1. If _vn_ is not an element of _declaredFunctionNames_, then
1. If _varEnvRec_ is a global Environment Record, then
1. Let _vnDefinable_ be ? _varEnvRec_.CanDeclareGlobalVar(_vn_).
1. If _vnDefinable_ is *false*, throw a *TypeError* exception.
1. If _vn_ is not an element of _declaredVarNames_, then
1. Append _vn_ to _declaredVarNames_.
1. NOTE: No abnormal terminations occur after this algorithm step unless _varEnvRec_ is a global Environment Record and the global object is a Proxy exotic object.
1. Let _lexDeclarations_ be the LexicallyScopedDeclarations of _body_.
1. For each element _d_ in _lexDeclarations_ do
1. NOTE Lexically declared names are only instantiated here but not initialized.
1. For each element _dn_ of the BoundNames of _d_ do
1. If IsConstantDeclaration of _d_ is *true*, then
1. Perform ? _lexEnvRec_.CreateImmutableBinding(_dn_, *true*).
1. Else,
1. Perform ? _lexEnvRec_.CreateMutableBinding(_dn_, *false*).
1. For each Parse Node _f_ in _functionsToInitialize_, do
1. Let _fn_ be the sole element of the BoundNames of _f_.
1. Let _fo_ be the result of performing InstantiateFunctionObject for _f_ with argument<ins>s</ins> _lexEnv_ <ins>and _privateEnv_</ins>.
1. If _varEnvRec_ is a global Environment Record, then
1. Perform ? _varEnvRec_.CreateGlobalFunctionBinding(_fn_, _fo_, *true*).
1. Else,
1. Let _bindingExists_ be _varEnvRec_.HasBinding(_fn_).
1. If _bindingExists_ is *false*, then
1. Let _status_ be ! _varEnvRec_.CreateMutableBinding(_fn_, *true*).
1. Assert: _status_ is not an abrupt completion because of validation preceding step 12.
1. Perform ! _varEnvRec_.InitializeBinding(_fn_, _fo_).
1. Else,
1. Perform ! _varEnvRec_.SetMutableBinding(_fn_, _fo_, *false*).
1. For each String _vn_ in _declaredVarNames_, in list order do
1. If _varEnvRec_ is a global Environment Record, then
1. Perform ? _varEnvRec_.CreateGlobalVarBinding(_vn_, *true*).
1. Else,
1. Let _bindingExists_ be _varEnvRec_.HasBinding(_vn_).
1. If _bindingExists_ is *false*, then
1. Let _status_ be ! _varEnvRec_.CreateMutableBinding(_vn_, *true*).
1. Assert: _status_ is not an abrupt completion because of validation preceding step 12.
1. Perform ! _varEnvRec_.InitializeBinding(_vn_, *undefined*).
1. Return NormalCompletion(~empty~).
</emu-alg>
</emu-clause>
</emu-clause>