forked from tc39/proposal-optional-chaining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.html
685 lines (620 loc) · 30.6 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
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="icon" href="favicon.ico">
<link href="ecmarkup.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<script src="ecmarkup.js"></script>
<style>
ins .hljs.hljs {
background-color: inherit;
}
</style>
<script>
if (location.hostname.endsWith('.github.io') && location.protocol !== 'https:') {
location.protocol = 'https:';
}
</script>
<pre class=metadata>
title: Optional Chaining
status: proposal
stage: 1
location: https://claudepache.github.io/es-nil
copyright: false
contributors: Claude Pache, ECMA International
</pre>
<emu-clause id="sec-scope">
<h1>Scope</h1>
<p>This is the spec text of the <a href="https://github.com/tc39/proposal-optional-chaining/">Optional Chaining proposal</a> in ECMAScript. </p>
<p>For the syntax, we use the `?.` token, with a lookahead at the level of the lexical grammar that allows to discriminate between `a?.b` (optional chaining) and `a?.3:0` (conditional operator, whose meaning cannot be changed due to backward compatibility constraints).</p>
<p>The definitive syntax is still an open issue at this point.<p>
<p>An <a href="https://claudepache.github.io/es-optional-chaining/">early version of this proposal</a> used a Nil reference to express short-circuiting. This one is based on syntax only.</p>
<p>Normative additions are marked <ins>like this</ins>. In order to avoid distraction, we don’t mark mere editorial amendments.</p>
<p>List of significant editorial modifications:</p>
<ul>
<li><a href="#sec-property-accessors">Property Accessors</a>: Factoring part of the property access operations in the new EvaluateDynamicPropertyAccess and EvaluateStaticPropertyAccess abstract operations.</li>
<li>In new content, adoption of calling convention for directed operations of PR <a href="https://github.com/tc39/ecma262/pull/955">tc39/ecma262##955</a>.</li>
</ul>
<p>The following features may not be evident at a cursory read:</p>
<ul>
<li>Optional chaining is forbidden in write contexts such as `a?.b = c`. This is handled by defining properly the IsValidSimpleAssignmentTarget static semantics rule (<emu-xref href="#sec-static-semantics-static-semantics-isvalidsimpleassignmenttarget"></emu-xref>).</li>
<li>Optional deletion as in: `delete a ?.b` is supported. There is no change needed in Section <emu-xref href="#sec-delete-operator">The delete Operator</emu-xref>.</li>
</ul>
</emu-clause>
<!--
<emu-clause id="sec-ecmascript-language-lexical-grammar">
<h1>ECMAScript Language: Lexical Grammar (<a href="https://tc39.github.io/ecma262/#sec-ecmascript-language-lexical-grammar">11</a>)</h1>
-->
<emu-clause id="sec-punctuators">
<h1>Punctuators (<a href="https://tc39.github.io/ecma262/#sec-punctuators">11.7</a>)</h1>
<h2>Syntax</h2>
<emu-grammar>
<ins class="block">
OptionalChainingPunctuator ::
`?.` [lookahead <! DecimalDigit
</ins>
OtherPunctuator :: one of
`{` `(` `)` `[` `]`
`.` `...` `;` `,`
`<` `>` `<=` `>=`
`==` `!=` `===` `!==`
`+` `-` `*` `%` `**`
`++` `--`
`<<` `>>` `>>>`
`&` `|` `^`
`!` `~`
`&&` `||`
`?` `:`
`=` `+=` `-=` `*=` `%=` `**=` `<<=` `>>=` `>>>=` `&=` `|=` `^=`
`=>`
Punctuator ::
<ins>OptionalChainingPunctuator</ins>
OtherPunctuator
DivPunctuator ::
`/`
`/=`
RightBracePunctuator ::
`}`
</emu-grammar>
</emu-clause>
<!--
</emu-clause>
-->
<!--
<emu-clause id="sec-ecmascript-language-expressions">
<h1>ECMAScript Language: Expressions (<a href="https://tc39.github.io/ecma262/#sec-ecmascript-language-expressions">12</a>)</h1>
-->
<emu-clause id="sec-left-hand-side-expressions">
<h1>Left-Hand-Side Expressions (<a href="https://tc39.github.io/ecma262/#sec-left-hand-side-expressions">12.3</a>)</h1>
<h2>Syntax</h2>
<emu-grammar>
MemberExpression[Yield, Await] :
PrimaryExpression[?Yield, ?Await]
MemberExpression[?Yield, ?Await] `[` Expression[+In, ?Yield, ?Await] `]`
MemberExpression[?Yield, ?Await] `.` IdentifierName
MemberExpression[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged]
SuperProperty[?Yield, ?Await]
MetaProperty
`new` MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]
SuperProperty[Yield, Await] :
`super` `[` Expression[+In, ?Yield, ?Await] `]`
`super` `.` IdentifierName
MetaProperty :
NewTarget
NewTarget :
`new` `.` `target`
NewExpression[Yield, Await] :
MemberExpression[?Yield, ?Await]
`new` NewExpression[?Yield, ?Await]
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, +Tagged]
SuperCall[Yield, Await] :
`super` Arguments[?Yield, ?Await]
Arguments[Yield, Await] :
`(` `)`
`(` ArgumentList[?Yield, ?Await] `)`
`(` ArgumentList[?Yield, ?Await] `,` `)`
ArgumentList[Yield, Await] :
AssignmentExpression[+In, ?Yield, ?Await]
`...` AssignmentExpression[+In, ?Yield, ?Await]
ArgumentList[?Yield, ?Await] `,` AssignmentExpression[+In, ?Yield, ?Await]
ArgumentList[?Yield, ?Await] `,` `...` AssignmentExpression[+In, ?Yield, ?Await]
<ins class="block">
OptionalExpression[Yield, Await] :
MemberExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await]
CallExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await]
OptionalExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await]
OptionalChain[Yield, Await] :
OptionalChainingPunctuator `[` Expression[+In, ?Yield, ?Await] `]`
OptionalChainingPunctuator IdentifierName
OptionalChainingPunctuator Arguments[?Yield, ?Await]
OptionalChainingPunctuator TemplateLiteral[?Yield, ?Await, +Tagged]
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>
LeftHandSideExpression[Yield, Await] :
NewExpression[?Yield, ?Await]
CallExpression[?Yield, ?Await]
<ins>OptionalExpression[?Yield, ?Await]</ins>
</emu-grammar>
<h2>Supplemental Syntax</h2>
<p>When processing an instance of the production <emu-grammar>CallExpression : CoverCallExpressionAndAsyncArrowHead</emu-grammar> the interpretation of |CoverCallExpressionAndAsyncArrowHead| is refined using the following grammar:</p>
<emu-grammar type="definition">
CallMemberExpression[Yield, Await] :
MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]
</emu-grammar>
<emu-clause id="sec-static-semantics">
<h1>Static Semantics (<a href="https://tc39.github.io/ecma262/#sec-static-semantics">12.3.1</a>)</h1>
<ins class="block">
<emu-clause id="sec-left-hand-side-expressions-static-semantics-early-errors">
<h1>Static Semantics: Early Errors</h1>
<emu-grammar>
OptionalChain[Yield, Await] :
OptionalChainingPunctuator TemplateLiteral[?Yield, ?Await, +Tagged]
OptionalChain[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged]
</emu-grammar>
<ul>
<li>
It is a Syntax Error if any code matches this production.
</li>
</ul>
<emu-note>
<p>This production exists in order to prevent automatic semicolon insertion rules (<emu-xref href="#sec-automatic-semicolon-insertion"></emu-xref>) to be applied to the following code:</p>
<pre><code class="javascript">
a?.b
`c`
</code></pre>
<p>so that it would be interpreted as two valid statements. The purpose is to maintain consistency with similar code without optional chaining operator:</p>
<pre><code class="javascript">
a.b
`c`
</code></pre>
<p>which is a valid statement and where automatic semicolon insertion does not apply.</p>
</emu-note>
</emu-clause>
</ins>
<emu-clause id="sec-left-hand-side-expressions-static-semantics-coveredcallexpression">
<h1>Static Semantics: CoveredCallExpression</h1>
<emu-grammar>
CallExpression : CoverCallExpressionAndAsyncArrowHead
</emu-grammar>
<emu-alg>
1. Return the |CallMemberExpression| that is covered by |CoverCallExpressionAndAsyncArrowHead|.
</emu-alg>
</emu-clause>
<emu-clause id="sec-static-semantics-static-semantics-contains">
<h1>Static Semantics: Contains</h1>
<p>With parameter _symbol_.</p>
<emu-see-also-para op="Contains"></emu-see-also-para>
<emu-grammar>MemberExpression : MemberExpression `.` IdentifierName</emu-grammar>
<emu-alg>
1. If |MemberExpression| Contains _symbol_ is *true*, return *true*.
1. If _symbol_ is a |ReservedWord|, return *false*.
1. If _symbol_ is an |Identifier| and StringValue of _symbol_ is the same value as the StringValue of |IdentifierName|, return *true*.
1. Return *false*.
</emu-alg>
<emu-grammar>SuperProperty : `super` `.` IdentifierName</emu-grammar>
<emu-alg>
1. If _symbol_ is the |ReservedWord| `super`, return *true*.
1. If _symbol_ is a |ReservedWord|, return *false*.
1. If _symbol_ is an |Identifier| and StringValue of _symbol_ is the same value as the StringValue of |IdentifierName|, return *true*.
1. Return *false*.
</emu-alg>
<emu-grammar>CallExpression : CallExpression `.` IdentifierName</emu-grammar>
<emu-alg>
1. If |CallExpression| Contains _symbol_ is *true*, return *true*.
1. If _symbol_ is a |ReservedWord|, return *false*.
1. If _symbol_ is an |Identifier| and StringValue of _symbol_ is the same value as the StringValue of |IdentifierName|, return *true*.
1. Return *false*.
</emu-alg>
<ins class="block">
<emu-grammar>OptionalChain : OptionalChainingPunctuator IdentifierName</emu-grammar>
<emu-alg>
1. If _symbol_ is a |ReservedWord|, return *false*.
1. If _symbol_ is an |Identifier| and StringValue of _symbol_ is the same value as the StringValue of |IdentifierName|, return *true*.
1. Return *false*.
</emu-alg>
<emu-grammar>OptionalChain : OptionalChain `.` IdentifierName</emu-grammar>
<emu-alg>
1. If |OptionalChain| Contains _symbol_ is *true*, return *true*.
1. If _symbol_ is a |ReservedWord|, return *false*.
1. If _symbol_ is an |Identifier| and StringValue of _symbol_ is the same value as the StringValue of |IdentifierName|, return *true*.
1. Return *false*.
</emu-alg>
</ins>
</emu-clause>
<emu-clause id="sec-static-semantics-static-semantics-isfunctiondefinition">
<h1>Static Semantics: IsFunctionDefinition</h1>
<emu-see-also-para op="IsFunctionDefinition"></emu-see-also-para>
<emu-grammar>
MemberExpression :
MemberExpression `[` Expression `]`
MemberExpression `.` IdentifierName
MemberExpression TemplateLiteral
SuperProperty
MetaProperty
`new` MemberExpression Arguments
NewExpression :
`new` NewExpression
LeftHandSideExpression :
CallExpression
<ins>OptionalExpression</ins>
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-static-semantics-static-semantics-isdestructuring">
<h1>Static Semantics: IsDestructuring</h1>
<emu-see-also-para op="IsDestructuring"></emu-see-also-para>
<emu-grammar>MemberExpression : PrimaryExpression</emu-grammar>
<emu-alg>
1. If |PrimaryExpression| is either an |ObjectLiteral| or an |ArrayLiteral|, return *true*.
1. Return *false*.
</emu-alg>
<emu-grammar>
MemberExpression :
MemberExpression `[` Expression `]`
MemberExpression `.` IdentifierName
MemberExpression TemplateLiteral
SuperProperty
MetaProperty
`new` MemberExpression Arguments
NewExpression :
`new` NewExpression
LeftHandSideExpression :
CallExpression
<ins>OptionalExpression</ins>
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-static-semantics-static-semantics-isidentifierref">
<h1>Static Semantics: IsIdentifierRef</h1>
<emu-see-also-para op="IsIdentifierRef"></emu-see-also-para>
<emu-grammar>
MemberExpression :
MemberExpression `[` Expression `]`
MemberExpression `.` IdentifierName
MemberExpression TemplateLiteral
SuperProperty
MetaProperty
`new` MemberExpression Arguments
NewExpression :
`new` NewExpression
LeftHandSideExpression :
CallExpression
<ins>OptionalExpression</ins>
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-static-semantics-static-semantics-isvalidsimpleassignmenttarget">
<h1>Static Semantics: IsValidSimpleAssignmentTarget</h1>
<emu-see-also-para op="IsValidSimpleAssignmentTarget"></emu-see-also-para>
<emu-grammar>
CallExpression :
CallExpression `[` Expression `]`
CallExpression `.` IdentifierName
MemberExpression :
MemberExpression `[` Expression `]`
MemberExpression `.` IdentifierName
SuperProperty
</emu-grammar>
<emu-alg>
1. Return *true*.
</emu-alg>
<emu-grammar>
CallExpression :
CoverCallExpressionAndAsyncArrowHead
SuperCall
CallExpression Arguments
CallExpression TemplateLiteral
NewExpression :
`new` NewExpression
MemberExpression :
MemberExpression TemplateLiteral
`new` MemberExpression Arguments
NewTarget :
`new` `.` `target`
<ins class="block">
LeftHandSideExpression :
OptionalExpression
</ins>
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-property-accessors">
<h1>Property Accessors (<a href="https://tc39.github.io/ecma262/#sec-property-accessors">12.3.2</a>)</h1>
<emu-note>
<p>Properties are accessed by name, using either the dot notation:</p>
<div class="rhs">
|MemberExpression| `.` |IdentifierName|
<br>
|CallExpression| `.` |IdentifierName|
</div>
<p>or the bracket notation:</p>
<div class="rhs">
|MemberExpression| `[` |Expression| `]`
<br>
|CallExpression| `[` |Expression| `]`
</div>
<p>The dot notation is explained by the following syntactic conversion:</p>
<div class="rhs">
|MemberExpression| `.` |IdentifierName|
</div>
<p>is identical in its behaviour to</p>
<div class="rhs">
|MemberExpression| `[` <<i>identifier-name-string</i>> `]`
</div>
<p>and similarly</p>
<div class="rhs">
|CallExpression| `.` |IdentifierName|
</div>
<p>is identical in its behaviour to</p>
<div class="rhs">
|CallExpression| `[` <<i>identifier-name-string</i>> `]`
</div>
<p>where <<i>identifier-name-string</i>> is the result of evaluating StringValue of |IdentifierName|.</p>
</emu-note>
<emu-clause id="sec-property-accessors-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>MemberExpression : MemberExpression `[` Expression `]`</emu-grammar>
<emu-alg>
1. Let _baseReference_ be the result of evaluating |MemberExpression|.
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. If the code matched by this |MemberExpression| is strict mode code, let _strict_ be *true*, else let _strict_ be *false*.
1. Return ? EvaluateDynamicPropertyAccess(_baseValue_, |Expression|, _strict_).
</emu-alg>
<emu-grammar>MemberExpression : MemberExpression `.` IdentifierName</emu-grammar>
<emu-alg>
1. Let _baseReference_ be the result of evaluating |MemberExpression|.
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. If the code matched by this |MemberExpression| is strict mode code, let _strict_ be *true*, else let _strict_ be *false*.
1. Return ? EvaluateStaticPropertyAccess(_baseValue_, |IdentifierName|, _strict_);
</emu-alg>
<emu-grammar>CallExpression : CallExpression `[` Expression `]`</emu-grammar>
<emu-alg>
1. Let _baseReference_ be the result of evaluating |CallExpression|.
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. If the code matched by this |CallExpression| is strict mode code, let _strict_ be *true*, else let _strict_ be *false*.
1. Return ? EvaluateDynamicPropertyAccess(_baseValue_, |Expression|, _strict_).
</emu-alg>
<emu-grammar>CallExpression : CallExpression `.` IdentifierName</emu-grammar>
<emu-alg>
1. Let _baseReference_ be the result of evaluating |CallExpression|.
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. If the code matched by this |CallExpression| is strict mode code, let _strict_ be *true*, else let _strict_ be *false*.
1. Return ? EvaluateStaticPropertyAccess(_baseValue_, |IdentifierName|, _strict_);
</emu-alg>
</emu-clause>
<emu-clause id="sec-evaluate-dynamic-property-access" aoid="EvaluateDynamicPropertyAccess">
<h1>Runtime Semantics: EvaluateDynamicPropertyAccess(_baseValue_, _expression_, _strict_ )</h1>
<p>The abstract operation EvaluateDynamicPropertyAccess takes as arguments a value _baseValue_, a Parse Node _expression_, and a Boolean argument _strict_. It performs the following steps:</p>
<emu-alg>
1. Let _propertyNameReference_ be the result of evaluating _expression_.
1. Let _propertyNameValue_ be ? GetValue(_propertyNameReference_).
1. Let _bv_ be ? RequireObjectCoercible(_baseValue_).
1. Let _propertyKey_ be ? ToPropertyKey(_propertyNameValue_).
1. Return a value of type Reference whose base value component is _bv_, whose referenced name component is _propertyKey_, and whose strict reference flag is _strict_.
</emu-clause>
<emu-clause id="sec-evaluate-static-property-access" aoid="EvaluateStaticPropertyAccess">
<h1>Runtime Semantics: EvaluateStaticPropertyAccess(_baseValue_, _identifierName_, _strict_ )</h1>
<p>The abstract operation EvaluateStaticPropertyAccess takes as arguments a value _baseValue_, a Parse Node _identifierName_, and a Boolean argument _strict_. It performs the following steps:</p>
<emu-alg>
1. Let _bv_ be ? RequireObjectCoercible(_baseValue_).
1. Let _propertyNameString_ be StringValue of _identifierName_.
1. Return a value of type Reference whose base value component is _bv_, whose referenced name component is _propertyNameString_, and whose strict reference flag is _strict_.
</emu-clause>
</emu-clause>
<emu-clause id="sec-new-operator">
<h1>The `new` Operator (<a href="https://tc39.github.io/ecma262/#sec-new-operator">12.3.3</a>)</h1>
<p><i>(not modified)</i></p>
</emu-clause>
<emu-clause id="sec-function-calls">
<h1>Function Calls (<a href="https://tc39.github.io/ecma262/#sec-function-calls">12.3.4</a>)</h1>
<emu-clause id="sec-function-calls-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>CallExpression : CoverCallExpressionAndAsyncArrowHead</emu-grammar>
<emu-alg>
1. Let _expr_ be CoveredCallExpression of |CoverCallExpressionAndAsyncArrowHead|.
1. Let _memberExpr_ be the |MemberExpression| of _expr_.
1. Let _arguments_ be the |Arguments| of _expr_.
1. Let _ref_ be the result of evaluating _memberExpr_.
1. Let _func_ be ? GetValue(_ref_).
1. If Type(_ref_) is Reference, IsPropertyReference(_ref_) is *false*, and GetReferencedName(_ref_) is `"eval"`, then
1. If SameValue(_func_, %eval%) is *true*, then
1. Let _argList_ be ? ArgumentListEvaluation of _arguments_.
1. If _argList_ has no elements, return *undefined*.
1. Let _evalText_ be the first element of _argList_.
1. If the source code matching this |CallExpression| is strict mode code, let _strictCaller_ be *true*. Otherwise let _strictCaller_ be *false*.
1. Let _evalRealm_ be the current Realm Record.
1. Perform ? HostEnsureCanCompileStrings(_evalRealm_, _evalRealm_).
1. Return ? PerformEval(_evalText_, _evalRealm_, _strictCaller_, *true*).
1. Let _thisCall_ be this |CallExpression|.
1. Let _tailCall_ be IsInTailPosition(_thisCall_).
1. Return ? EvaluateCall(_func_, _ref_, _arguments_, _tailCall_).
</emu-alg>
<p>A |CallExpression| evaluation that executes step 6.a.vii is a <dfn>direct eval</dfn>.</p>
<emu-grammar>CallExpression : CallExpression Arguments</emu-grammar>
<emu-alg>
1. Let _ref_ be the result of evaluating |CallExpression|.
1. Let _func_ be ? GetValue(_ref_).
1. Let _thisCall_ be this |CallExpression|.
1. Let _tailCall_ be IsInTailPosition(_thisCall_).
1. Return ? EvaluateCall(_func_, _ref_, |Arguments|, _tailCall_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-evaluatecall" aoid="EvaluateCall" oldids="sec-evaluatedirectcall">
<h1>Runtime Semantics: EvaluateCall ( _func_, _ref_, _arguments_, _tailPosition_ )</h1>
<p>The abstract operation EvaluateCall takes as arguments a value _func_, a value _ref_, a Parse Node _arguments_, and a Boolean argument _tailPosition_. It performs the following steps:</p>
<emu-alg>
1. If Type(_ref_) is Reference, then
1. If IsPropertyReference(_ref_) is *true*, then
1. Let _thisValue_ be GetThisValue(_ref_).
1. Else the base of _ref_ is an Environment Record,
1. Let _refEnv_ be GetBase(_ref_).
1. Let _thisValue_ be _refEnv_.WithBaseObject().
1. Else Type(_ref_) is not Reference,
1. Let _thisValue_ be *undefined*.
1. Let _argList_ be ArgumentListEvaluation of _arguments_.
1. ReturnIfAbrupt(_argList_).
1. If Type(_func_) is not Object, throw a *TypeError* exception.
1. If IsCallable(_func_) is *false*, throw a *TypeError* exception.
1. If _tailPosition_ is *true*, perform PrepareForTailCall().
1. Let _result_ be Call(_func_, _thisValue_, _argList_).
1. Assert: If _tailPosition_ is *true*, the above call will not return here, but instead evaluation will continue as if the following return has already occurred.
1. Assert: If _result_ is not an abrupt completion, then Type(_result_) is an ECMAScript language type.
1. Return _result_.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-super-keyword">
<h1>The `super` Keyword (<a href="https://tc39.github.io/ecma262/#sec-super-keyword">12.3.5</a>)</h1>
<p><i>(not modified)</i></p>
</emu-clause>
<emu-clause id="sec-argument-lists">
<h1>Argument Lists (<a href="https://tc39.github.io/ecma262/#sec-argument-lists">12.3.6</a>)</h1>
<p><i>(not modified)</i></p>
</emu-clause>
<emu-clause id="sec-tagged-templates">
<h1>Tagged Templates (<a href="https://tc39.github.io/ecma262/#sec-tagged-templates">12.3.7</a>)</h1>
<p><i>(not modified)</i></p>
</emu-clause>
<ins class="block">
<emu-clause id="sec-optional-chains">
<h1>Optional Chains</h1>
<emu-note>An optional chain is a chain of property accesses and function calls introduced by an |OptionalChainingPunctuator|.</emu-note>
</emu-note>
<emu-clause id="sec-optional-chaining-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>
OptionalExpression :
MemberExpression OptionalChain
CallExpression OptionalChain
OptionalExpression OptionalChain
</emu-grammar>
<emu-alg>
1. Let _baseExpression_ be the first child of this production (i.e., this |MemberExpression|, |CallExpression|, or |OptionalExpression|).
1. Let _baseReference_ be ? _baseExpression_.Evaluation().
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. If _baseValue_ is *undefined* or *null*, then
1. Return *undefined*.
1. Let _optionalChain_ be this |OptionalChain|.
1. Return ? _optionalChain_.ChainEvaluation(_baseValue_, _baseReference_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-optional-chaining-chain-evaluation">
<h1>Runtime Semantics: ChainEvaluation</h1>
<p>With parameters _baseValue_ and _baseReference_.</p>
<emu-grammar>OptionalChain : OptionalChainingPunctuator `[` Expression `]`</emu-grammar>
<emu-alg>
1. If the code matched by this production is strict mode code, let _strict_ be *true*, else let _strict_ be *false*.
1. Return ? EvaluateDynamicPropertyAccess(_baseValue_, |Expression|, _strict_).
</emu-alg>
<emu-grammar>OptionalChain : OptionalChainingPunctuator IdentifierName</emu-grammar>
<emu-alg>
1. If the code matched by this production is strict mode code, let _strict_ be *true*, else let _strict_ be *false*.
1. Return ? EvaluateStaticPropertyAccess(_baseValue_, |IdentifierName|, _strict_).
</emu-alg>
<emu-grammar>OptionalChain : OptionalChainingPunctuator Arguments</emu-grammar>
<emu-alg>
1. Let _thisChain_ be this production.
1. Let _tailCall_ be IsInTailPosition(_thisChain_).
1. Return ? EvaluateCall(_baseValue_, _baseReference_, |Arguments|, _tailCall_).
</emu-alg>
<emu-grammar>OptionalChain : OptionalChain `[` Expression `]`</emu-grammar>
<emu-alg>
1. Let _optionalChain_ be this |OptionalChain|.
1. Let _newReference_ be ? _optionalChain_.ChainEvaluation(_baseValue_, _baseReference_).
1. Let _newValue_ be ? GetValue(_newReference_).
1. If the code matched by this production is strict mode code, let _strict_ be *true*, else let _strict_ be *false*.
1. Return ? EvaluateDynamicPropertyAccess(_newValue_, |Expression|, _strict_).
</emu-alg>
<emu-grammar>OptionalChain : OptionalChain `.` IdentifierName</emu-grammar>
<emu-alg>
1. Let _optionalChain_ be this |OptionalChain|.
1. Let _newReference_ be ? _optionalChain_.ChainEvaluation(_baseValue_, _baseReference_).
1. Let _newValue_ be ? GetValue(_newReference_).
1. If the code matched by this production is strict mode code, let _strict_ be *true*, else let _strict_ be *false*.
1. Return ? EvaluateStaticPropertyAccess(_newValue_, |IdentifierName|, _strict_).
</emu-alg>
<emu-grammar>OptionalChain : OptionalChain Arguments</emu-grammar>
<emu-alg>
1. Let _optionalChain_ be this |OptionalChain|.
1. Let _newReference_ be ? _optionalChain_.ChainEvaluation(_baseValue_, _baseReference_).
1. Let _newValue_ be ? GetValue(_newReference_).
1. Let _thisChain_ be this production.
1. Let _tailCall_ be IsInTailPosition(_thisChain_).
1. Return ? EvaluateCall(_newValue_, _newReference_, |Arguments|, _tailCall_).
</emu-alg>
</emu-clause>
</emu-clause>
</ins>
<emu-clause id="sec-meta-properties">
<h1>Meta Properties (<a href="https://tc39.github.io/ecma262/#sec-meta-properties">12.3.8</a>)</h1>
<p><i>(not modified)</i></p>
</emu-clause>
</emu-clause>
<!--
</emu-clause>
-->
<!--
<emu-clause id="sec-ecmascript-language-functions-and-classes">
<h1>ECMAScript Language: Functions and Classes (<a href="https://tc39.github.io/ecma262/#sec-ecmascript-language-functions-and-classes">14</a>)</h1>
-->
<emu-clause id="sec-tail-position-calls">
<h1>Tail Position Calls (<a href="https://tc39.github.io/ecma262/#sec-tail-position-calls">14.8</a>)</h1>
<emu-clause id="sec-static-semantics-hascallintailposition">
<h1>Static Semantics: HasCallInTailPosition (<a href="https://tc39.github.io/ecma262/#sec-static-semantics-hascallintailposition">14.8.2</a>)</h1>
<p>With parameter _call_.</p>
<emu-clause id="sec-expression-rules">
<h1>Expression Rules</h1>
<p><i>The following cases are added:</i></p>
<ins class="block">
<emu-grammar>
OptionalExpression :
MemberExpression OptionalChain
CallExpression OptionalChain
OptionalExpression OptionalChain
</emu-grammar>
<emu-alg>
1. Return HasCallInTailPosition of |OptionalChain| with argument _call_.
</emu-alg>
<emu-grammar>
OptionalChain :
OptionalChainingPunctuator `[` Expression `]`
OptionalChainingPunctuator IdentifierName
OptionalChain `[` Expression `]`
OptionalChain `.` IdentifierName
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
<emu-grammar>
OptionalChain :
OptionalChainingPunctuator Arguments
OptionalChain Arguments
</emu-grammar>
<emu-alg>
1. If this |OptionalChain| is _call_, return *true*.
1. Return *false*.
</emu-alg>
</ins>
</emu-clause>
</emu-clause>
</emu-clause>
<!--
</emu-clause>
-->