-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathspec.html
717 lines (649 loc) · 31.3 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
<pre class=metadata>
title: ES call-this operator (2021)
status: proposal
stage: 1
location: https://github.com/js-choi/proposal-bind-this
copyright: false
contributors: J. S. Choi
</pre>
<script src=ecmarkup.js defer></script>
<link rel=stylesheet href=ecmarkup.css>
<emu-intro id=introduction>
<h1>Introduction</h1>
<p><strong>Warning! This spec is out of date!</strong></p>
<p>This is the formal specification
for a proposed bind-this operator `~>` in JavaScript.
It modifies the original <a
href=https://tc39.github.io/ecma262/>ECMAScript specification</a> with
several new or revised clauses. See <a
href=https://github.com/js-choi/proposal-bind-operator/blob/main/README.md>the
proposal's explainer</a>
for the proposal's background, motivation, and usage examples.</p>
</emu-intro>
<emu-clause id="sec-syntax-directed-operations">
<h1>Syntax-Directed Operations</h1>
<emu-clause id="sec-syntax-directed-operations-function-name-inference">
<h1>Function Name Inference</h1>
<emu-clause id="sec-static-semantics-isfunctiondefinition" type="sdo"
aoid="IsFunctionDefinition">
<h1>Static Semantics: IsFunctionDefinition</h1>
<emu-note type=editor>
<p>This section augments the <a
href=https://tc39.es/ecma262/#sec-static-semantics-isfunctiondefinition>original
IsFunctionDefinition clause</a>.</p>
</emu-note>
<emu-grammar>
<ins class="block">
SimpleMemberExpression :
IdentifierReference
SimpleMemberExpression `.` IdentifierName
SimpleMemberExpression `.` PrivateIdentifier
</ins>
LeftHandSideExpression :
<ins>BindThisExpression</ins>
CallExpression
OptionalExpression
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-static-semantics-isidentifierref" type="sdo"
aoid="IsIdentifierRef">
<h1>Static Semantics: IsIdentifierRef</h1>
<emu-note type=editor>
<p>This section augments the <a
href=https://tc39.es/ecma262/#sec-static-semantics-isidentifierref>original IsIdentifierRef
clause</a>.</p>
</emu-note>
<emu-grammar>
<ins class="block">
SimpleMemberExpression :
IdentifierReference
SimpleMemberExpression `.` IdentifierName
SimpleMemberExpression `.` PrivateIdentifier
`(` Expression `)`
BindThisExpression :
MemberExpression `~>` SimpleMemberExpression
BindThisExpression `~>` SimpleMemberExpression
</ins>
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-syntax-directed-operations-contains">
<h1>Contains</h1>
<emu-note type=editor>
<p>This section augments the <a
href=https://tc39.es/ecma262/#sec-syntax-directed-operations-contains>original
Contains clause</a>.</p>
</emu-note>
<emu-clause id="sec-static-semantics-contains" type="sdo" aoid="Contains">
<h1>Static Semantics: Contains</h1>
<p>With parameter _symbol_.</p>
<ins class="block">
<emu-grammar>
SimpleMemberExpression :
IdentifierReference
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
<emu-grammar>
SimpleMemberExpression :
SimpleMemberExpression `.` IdentifierName
SimpleMemberExpression `.` PrivateIdentifier
</emu-grammar>
<emu-alg>
1. If |SimpleMemberExpression| Contains _symbol_ is *true*, return *true*.
1. Return *false*.
</emu-alg>
</ins>
</emu-clause>
</emu-clause>
<emu-clause id="sec-syntax-directed-operations-miscellaneous">
<h1>Miscellaneous</h1>
<emu-clause id="sec-static-semantics-assignmenttargettype" type="sdo"
aoid="AssignmentTargetType">
<h1>Static Semantics: AssignmentTargetType</h1>
<emu-note type=editor>
<p>This section augments the <a
href=https://tc39.es/ecma262/#sec-static-semantics-assignmenttargettype>original
AssignmentTargetType clause</a>.</p>
</emu-note>
<emu-grammar>
<ins class="block">
BindThisExpression :
MemberExpression `~>` SimpleMemberExpression
MemberExpression `~>` TemplateLiteral
BindThisExpression `~>` SimpleMemberExpression
BindThisExpression `~>` TemplateLiteral
</ins>
CallExpression :
CoverCallExpressionAndAsyncArrowHead
<ins>BindThisExpression Arguments</ins>
SuperCall
ImportCall
CallExpression Arguments
CallExpression `[` Expression `]`
CallExpression `.` IdentifierName
<ins>CallExpression `~>` SimpleMemberExpression</ins>
CallExpression TemplateLiteral
CallExpression `.` PrivateIdentifier
</emu-grammar>
<emu-alg>
1. Return ~invalid~.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id=sec-ecmascript-language-lexical-grammar>
<h1>ECMAScript Language: Lexical Grammar</h1>
<emu-clause id=sec-punctuators>
<h1>Punctuators</h1>
<emu-note type=editor>
<p>This section augments the <a
href=https://tc39.github.io/ecma262/#sec-punctuators>original
Punctuators clause</a>.</p>
</emu-note>
<emu-grammar>
OtherPunctuator ~> one of
`{` `(` `)` `[` `]`
`.` <ins>`~>`</ins> `...` `;` `,`
`<` `>` `<=` `>=`
`==` `!=` `===` `!==`
`+` `-` `*` `%` `**`
`++` `--`
`<<` `>>` `>>>`
`!` `|` `^`
`!` `~`
`!!` `||` `??`
`?` `:`
`=` `+=` `-=` `*=` `%=` `**=`
`<<=` `>>=` `>>>=` `!=` `|=` `^=`
`!!=` `||=` `??=`
`=>`
</emu-grammar>
</emu-clause>
</emu-clause>
<emu-clause id=sec-ecmascript-language-expressions>
<h1>ECMAScript Language: Expressions</h1>
<emu-clause id="sec-left-hand-side-expressions">
<h1>Left-Hand-Side Expressions</h1>
<emu-note type=editor>
<p>This section augments the <a
href=https://tc39.github.io/ecma262/#sec-left-hand-side-expressions>original
Left-Hand-Side Expressions clause</a>.</p>
</emu-note>
<h2>Syntax</h2>
<emu-grammar type="definition">
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]
MemberExpression[?Yield, ?Await] `.` PrivateIdentifier
<ins class="block">
SimpleMemberExpression[Yield, Await] :
IdentifierReference[?Yield, ?Await]
SimpleMemberExpression[?Yield, ?Await] `.` IdentifierName
SimpleMemberExpression[?Yield, ?Await] `.` PrivateIdentifier
`(` Expression[+In, ?Yield, ?Await] `)`
</ins>
NewExpression[Yield, Await] :
MemberExpression[?Yield, ?Await]
`new` NewExpression[?Yield, ?Await]
<ins class="block">
BindThisExpression[Yield, Await] :
MemberExpression[?Yield, ?Await] `~>` SimpleMemberExpression[?Yield, ?Await]
MemberExpression[?Yield, ?Await] `~>` TemplateLiteral[?Yield, ?Await]
BindThisExpression[?Yield, ?Await] `~>` SimpleMemberExpression[?Yield, ?Await]
BindThisExpression[?Yield, ?Await] `~>` TemplateLiteral[?Yield, ?Await]
</ins>
CallExpression[Yield, Await] :
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await] #callcover
<ins>BindThisExpression[?Yield, ?Await] Arguments[?Yield, ?Await]</ins>
SuperCall[?Yield, ?Await]
ImportCall[?Yield, ?Await]
CallExpression[?Yield, ?Await] Arguments[?Yield, ?Await]
CallExpression[?Yield, ?Await] `[` Expression[+In, ?Yield, ?Await] `]`
CallExpression[?Yield, ?Await] `.` IdentifierName
<ins class="block">
CallExpression[?Yield, ?Await] `~>` SimpleMemberExpression[?Yield, ?Await]
CallExpression[?Yield, ?Await] `~>` TemplateLiteral[?Yield, ?Await, +Tagged]
</ins>
CallExpression[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged]
CallExpression[?Yield, ?Await] `.` PrivateIdentifier
SuperCall[Yield, Await] :
`super` Arguments[?Yield, ?Await]
ImportCall[Yield, Await] :
`import` `(` AssignmentExpression[+In, ?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]
OptionalExpression[Yield, Await] :
MemberExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await]
<ins>BindThisExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await]</ins>
CallExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await]
OptionalExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await]
OptionalChain[Yield, Await] :
`?.` Arguments[?Yield, ?Await]
`?.` `[` Expression[+In, ?Yield, ?Await] `]`
`?.` IdentifierName
<ins>`?.` `~>` SimpleMemberExpression[?Yield, ?Await]</ins>
`?.` TemplateLiteral[?Yield, ?Await, +Tagged]
`?.` PrivateIdentifier
OptionalChain[?Yield, ?Await] Arguments[?Yield, ?Await]
OptionalChain[?Yield, ?Await] `[` Expression[+In, ?Yield, ?Await] `]`
OptionalChain[?Yield, ?Await] `.` IdentifierName
<ins class="block">
OptionalChain[?Yield, ?Await] `~>` SimpleMemberExpression[?Yield, ?Await] [lookahead != `.`]
OptionalChain[?Yield, ?Await] `~>` TemplateLiteral[?Yield, ?Await, +Tagged]
</ins>
OptionalChain[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged]
OptionalChain[?Yield, ?Await] `.` PrivateIdentifier
LeftHandSideExpression[Yield, Await] :
NewExpression[?Yield, ?Await]
<ins>BindThisExpression[?Yield, ?Await]</ins>
CallExpression[?Yield, ?Await]
OptionalExpression[?Yield, ?Await]
</emu-grammar>
<emu-clause id="sec-static-semantics">
<h1>Static Semantics</h1>
<emu-clause id="sec-left-hand-side-expressions-static-semantics-early-errors">
<h1>Static Semantics: Early Errors</h1>
<emu-note type=editor>
<p>This section augments the <a
href=https://tc39.github.io/ecma262/#sec-left-hand-side-expressions-static-semantics-early-errors
>original Left-Hand-Side Expressions, Static Semantics:
Early Errors clause</a>.</p>
</emu-note>
<ins class="block">
<emu-grammar>
BindThisExpression :
MemberExpression `~>` TemplateLiteral
BindThisExpression `~>` TemplateLiteral
</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>) from being applied to the following code with the bind-this operator:</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 the bind-this 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-grammar>
CallExpression :
CallExpression `~>` TemplateLiteral
</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>) from being applied to the following code with the bind-this operator:</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 the bind-this 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-grammar>
OptionalChain :
OptionalChain `~>` TemplateLiteral
</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>) from being applied to the following code with the bind-this operator:</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 the bind-this 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>
</ins>
</emu-clause>
</emu-clause>
<emu-clause id="sec-function-calls">
<h1>Function Calls</h1>
<p>This section augments the <a
href=https://tc39.es/ecma262/#sec-function-calls>original
Function Calls clause</a>.</p>
<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 the |CallMemberExpression| that is covered by |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 _ref_ is a Reference Record, IsPropertyReference(_ref_) is *false*, and _ref_.[[ReferencedName]] 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 _evalArg_ 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. [id="step-callexpression-evaluation-direct-eval"] Return ? PerformEval(_evalArg_, _evalRealm_, _strictCaller_, *true*).
1. Let _thisCall_ be this |CallExpression|.
1. Let _tailCall_ be IsInTailPosition(_thisCall_).
1. Return ? EvaluateCall(_func_, _ref_, _arguments_, _tailCall_).
</emu-alg>
<ins class="block">
<emu-grammar>CallExpression : BindThisExpression Arguments</emu-grammar>
<emu-note>
<p>See also the <emu-xref href=#sec-bind-this-operator>bind-this operator</emu-xref>.</p>
</emu-note>
<emu-alg>
1. Let _thisExpr_ be the |MemberExpression| of |BindThisExpression|.
1. Let _bindThisRHS_ be the |SimpleMemberExpression| of _memberExpr_.
1. Let _funcExpr_ be the |MemberExpression| that is covered by _bindThisRHS_.
1. Let _thisRef_ be the result of evaluating _thisExpr_.
1. Let _thisValue_ be ? GetValue(_thisRef_).
1. Let _funcRef_ be the result of evaluating _funcExpr_.
1. Let _func_ be ? GetValue(_funcRef_).
1. Let _thisCall_ be this |CallExpression|.
1. Let _tailCall_ be IsInTailPosition(_thisCall_).
1. Return EvaluateCall(_func_, _thisValue_, |Arguments|, _tailCall_).
</emu-alg>
</ins>
<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>
<emu-clause id="sec-bind-this-operator">
<h1>Bind-this operator</h1>
<emu-note type=editor>
<p>This section is a wholly new subclause to be inserted after the <a
href=https://tc39.github.io/ecma262/#sec-left-hand-side-expressions>`new` Operator clause</a>.</p>
</emu-note>
<emu-clause id="sec-bind-operator-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-clause id="sec-property-accessors-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-note>
<p>For evaluation of the production <emu-grammar>CallExpression : BindThisExpression Arguments</emu-grammar>, see clause <emu-xref href=#sec-function-calls-runtime-semantics-evaluation></emu-xref>.</p>
<p>For evaluation of the productions <emu-grammar>OptionalChain : `?.` `~>` SimpleMemberExpression</emu-grammar> and <emu-grammar>OptionalChain : OptionalChain `~>` SimpleMemberExpression</emu-grammar>, see clause <emu-xref href=#sec-function-calls-runtime-semantics-evaluation></emu-xref>.</p>
</emu-note>
<emu-grammar>BindThisExpression : MemberExpression `~>` SimpleMemberExpression</emu-grammar>
<emu-alg>
1. Let _baseReference_ be the result of evaluating |MemberExpression|.
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. Let _funcExpr_ be the |MemberExpression| that is covered by |SimpleMemberExpression|.
1. Let _funcRef_ be the result of evaluating _funcExpr_.
1. Let _func_ be ? GetValue(_funcRef_).
1. Return BindThis(_baseValue_, _func_).
</emu-alg>
<emu-grammar>BindThisExpression : BindThisExpression `~>` SimpleMemberExpression</emu-grammar>
<emu-alg>
1. Let _baseReference_ be the result of evaluating |BindThisExpression|.
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. Let _funcExpr_ be the |MemberExpression| that is covered by |SimpleMemberExpression|.
1. Let _funcRef_ be the result of evaluating _funcExpr_.
1. Let _func_ be ? GetValue(_funcRef_).
1. Return BindThis(_baseValue_, _func_).
</emu-alg>
<emu-grammar>CallExpression : CallExpression `~>` SimpleMemberExpression</emu-grammar>
<emu-alg>
1. Let _baseReference_ be the result of evaluating |CallExpression|.
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. Let _funcExpr_ be the |MemberExpression| that is covered by |SimpleMemberExpression|.
1. Let _funcRef_ be the result of evaluating _funcExpr_.
1. Let _func_ be ? GetValue(_funcRef_).
1. Return BindThis(_baseValue_, _func_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-extract-method" type="abstract operation">
<h1>
BindThis (
_baseValue_: an ECMAScript language value,
_func_: another ECMAScript language value,
)
</h1>
<dl class="header">
</dl>
<emu-alg>
1. If IsCallable(_func_) is *false*, throw a *TypeError* exception.
1. Let _F_ be ? BoundFunctionCreate(_func_, _baseValue_, « »).
1. Let _L_ be 0.
1. Let _methodHasLength_ be ? HasOwnProperty(_method_, *"length"*).
1. If _methodHasLength_ is *true*, then
1. Let _methodLen_ be ? Get(_method_, *"length"*).
1. If Type(_methodLen_) is Number, then
1. If _methodLen_ is *+∞*<sub>𝔽</sub>, set _L_ to +∞.
1. Else if _methodLen_ is *-∞*<sub>𝔽</sub>, set _L_ to 0.
1. Else,
1. Let _methodLenAsInt_ be ! ToIntegerOrInfinity(_methodLen_).
1. Assert: _methodLenAsInt_ is finite.
1. Set _L_ to max(_methodLenAsInt_, 0).
1. Perform ! SetFunctionLength(_F_, _L_).
1. Let _methodName_ be ? Get(_method_, *"name"*).
1. If Type(_methodName_) is not String, set _methodName_ to the empty String.
1. Perform SetFunctionName(_F_, _methodName_, *"bound"*).
1. Return _F_.
</emu-alg>
<emu-note>
<p>Function objects created using the bind-this operator are exotic objects. They also do not have a *"prototype"* property.</p>
</emu-note>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-optional-chains">
<h1>Optional Chains</h1>
<emu-note type=editor>
<p>This section augments the <a
href=https://tc39.github.io/ecma262/#sec-optional-chains>original
Optional Chains clause</a>.</p>
</emu-note>
<emu-clause id="sec-optional-chaining-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>
OptionalExpression :
MemberExpression OptionalChain
</emu-grammar>
<emu-alg>
1. Let _baseReference_ be the result of evaluating |MemberExpression|.
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. If _baseValue_ is *undefined* or *null*, then
1. Return *undefined*.
1. Return the result of performing ChainEvaluation of |OptionalChain| with arguments _baseValue_ and _baseReference_.
</emu-alg>
<ins class="block">
<emu-grammar>
OptionalExpression :
BindThisExpression OptionalChain
</emu-grammar>
<emu-alg>
1. Let _baseReference_ be the result of evaluating |BindThisExpression|.
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. If _baseValue_ is *undefined* or *null*, then
1. Return *undefined*.
1. Return the result of performing ChainEvaluation of |OptionalChain| with arguments _baseValue_ and _baseReference_.
</emu-alg>
</ins>
<emu-grammar>
OptionalExpression :
CallExpression OptionalChain
</emu-grammar>
<emu-alg>
1. Let _baseReference_ be the result of evaluating |CallExpression|.
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. If _baseValue_ is *undefined* or *null*, then
1. Return *undefined*.
1. Return the result of performing ChainEvaluation of |OptionalChain| with arguments _baseValue_ and _baseReference_.
</emu-alg>
<emu-grammar>
OptionalExpression :
OptionalExpression OptionalChain
</emu-grammar>
<emu-alg>
1. Let _baseReference_ be the result of evaluating |OptionalExpression|.
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. If _baseValue_ is *undefined* or *null*, then
1. Return *undefined*.
1. Return the result of performing ChainEvaluation of |OptionalChain| with arguments _baseValue_ and _baseReference_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-optional-chaining-chain-evaluation" type="sdo">
<h1>
Runtime Semantics: ChainEvaluation (
_baseValue_: unknown,
_baseReference_: unknown,
)
</h1>
<dl class="header">
</dl>
<emu-grammar>OptionalChain : `?.` Arguments</emu-grammar>
<emu-alg>
1. Let _thisChain_ be this |OptionalChain|.
1. Let _tailCall_ be IsInTailPosition(_thisChain_).
1. Return ? EvaluateCall(_baseValue_, _baseReference_, |Arguments|, _tailCall_).
</emu-alg>
<emu-grammar>OptionalChain : `?.` `[` Expression `]`</emu-grammar>
<emu-alg>
1. If the code matched by this |OptionalChain| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*.
1. Return ? EvaluatePropertyAccessWithExpressionKey(_baseValue_, |Expression|, _strict_).
</emu-alg>
<emu-grammar>OptionalChain : `?.` IdentifierName</emu-grammar>
<emu-alg>
1. If the code matched by this |OptionalChain| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*.
1. Return ! EvaluatePropertyAccessWithIdentifierKey(_baseValue_, |IdentifierName|, _strict_).
</emu-alg>
<ins class="block">
<emu-grammar>OptionalChain : `?.` `~>` SimpleMemberExpression</emu-grammar>
<emu-note>
<p>See also the <emu-xref href=#sec-bind-this-operator>bind-this operator</emu-xref>.</p>
</emu-note>
<emu-alg>
1. Let _funcExpr_ be the |MemberExpression| that is covered by |SimpleMemberExpression|.
1. Let _funcRef_ be the result of evaluating _funcExpr_.
1. Let _func_ be ? GetValue(_funcRef_).
1. Return BindThis(_baseValue_, _func_).
</emu-alg>
</ins>
<emu-grammar>OptionalChain : `?.` PrivateIdentifier</emu-grammar>
<emu-alg>
1. Let _fieldNameString_ be the StringValue of |PrivateIdentifier|.
1. Return ! MakePrivateReference(_baseValue_, _fieldNameString_).
</emu-alg>
<emu-grammar>OptionalChain : OptionalChain Arguments</emu-grammar>
<emu-alg>
1. Let _optionalChain_ be |OptionalChain|.
1. Let _newReference_ be ? ChainEvaluation of _optionalChain_ with arguments _baseValue_ and _baseReference_.
1. Let _newValue_ be ? GetValue(_newReference_).
1. Let _thisChain_ be this |OptionalChain|.
1. Let _tailCall_ be IsInTailPosition(_thisChain_).
1. Return ? EvaluateCall(_newValue_, _newReference_, |Arguments|, _tailCall_).
</emu-alg>
<emu-note>
<p>If |OptionalChain| (in <emu-grammar>OptionalChain : OptionalChain Arguments</emu-grammar>) is, in turn, covering the production <emu-grammar>OptionalChain : `?.` `~>` SimpleMemberExpression</emu-grammar>, then the preceding algorithm is indistinguishable from the following:</p>
<emu-alg>
1. Let _optionalBindThisChain_ be the <emu-grammar>OptionalChain : `?.` `~>` SimpleMemberExpression</emu-grammar> that is covered by |OptionalChain|.
1. Let _bindThisRHS_ be the |SimpleMemberExpression| of _optionalBindThisChain_.
1. Let _funcExpr_ be the |MemberExpression| that is covered by _bindThisRHS_.
1. Let _funcRef_ be the result of evaluating _funcExpr_.
1. Let _func_ be ? GetValue(_funcRef_).
1. Let _thisChain_ be this |OptionalChain|.
1. Let _tailCall_ be IsInTailPosition(_thisChain_).
1. Return EvaluateCall(_func_, _baseValue_, |Arguments|, _tailCall_).
</emu-alg>
<p>If |OptionalChain| (in <emu-grammar>OptionalChain : OptionalChain Arguments</emu-grammar>) is, in turn, covering the production <emu-grammar>OptionalChain : OptionalChain `~>` SimpleMemberExpression</emu-grammar>, then the preceding algorithm is indistinguishable from the following:</p>
<emu-alg>
1. Let _bindThisOptionalChain_ be the <emu-grammar>OptionalChain : OptionalChain `~>` SimpleMemberExpression</emu-grammar> that is covered by |OptionalChain|.
1. Let _bindThisRHS_ be the |SimpleMemberExpression| of _bindThisOptionalChain_.
1. Let _funcExpr_ be the |MemberExpression| that is covered by _bindThisRHS_.
1. Let _thisRef_ be the result of evaluating ? ChainEvaluation of _thisOptionalChain_ with arguments _baseValue_ and _baseReference_.
1. Let _thisValue_ be ? GetValue(_thisRef_).
1. Let _funcRef_ be the result of evaluating _funcExpr_.
1. Let _func_ be ? GetValue(_funcRef_).
1. Let _thisChain_ be this |OptionalChain|.
1. Let _tailCall_ be IsInTailPosition(_thisChain_).
1. Return EvaluateCall(_func_, _thisValue_, |Arguments|, _tailCall_).
</emu-alg>
</emu-note>
<emu-grammar>OptionalChain : OptionalChain `[` Expression `]`</emu-grammar>
<emu-alg>
1. Let _optionalChain_ be |OptionalChain|.
1. Let _newReference_ be ? ChainEvaluation of _optionalChain_ with arguments _baseValue_ and _baseReference_.
1. Let _newValue_ be ? GetValue(_newReference_).
1. If the code matched by this |OptionalChain| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*.
1. Return ? EvaluatePropertyAccessWithExpressionKey(_newValue_, |Expression|, _strict_).
</emu-alg>
<emu-grammar>OptionalChain : OptionalChain `.` IdentifierName</emu-grammar>
<emu-alg>
1. Let _optionalChain_ be |OptionalChain|.
1. Let _newReference_ be ? ChainEvaluation of _optionalChain_ with arguments _baseValue_ and _baseReference_.
1. Let _newValue_ be ? GetValue(_newReference_).
1. If the code matched by this |OptionalChain| is strict mode code, let _strict_ be *true*; else let _strict_ be *false*.
1. Return ! EvaluatePropertyAccessWithIdentifierKey(_newValue_, |IdentifierName|, _strict_).
</emu-alg>
<ins class="block">
<emu-grammar>OptionalChain : OptionalChain `~>` SimpleMemberExpression</emu-grammar>
<emu-note>
<p>See also the <emu-xref href=#sec-bind-this-operator>bind-this operator</emu-xref>.</p>
</emu-note>
<emu-alg>
1. Let _optionalChain_ be |OptionalChain|.
1. Let _newReference_ be ? ChainEvaluation of _optionalChain_ with arguments _baseValue_ and _baseReference_.
1. Let _newValue_ be ? GetValue(_newReference_).
1. Let _funcExpr_ be the |MemberExpression| that is covered by |SimpleMemberExpression|.
1. Let _funcRef_ be the result of evaluating _funcExpr_.
1. Let _func_ be ? GetValue(_funcRef_).
1. Return BindThis(_newValue_, _func_).
</emu-alg>
</ins>
<emu-grammar>OptionalChain : OptionalChain `.` PrivateIdentifier</emu-grammar>
<emu-alg>
1. Let _optionalChain_ be |OptionalChain|.
1. Let _newReference_ be ? ChainEvaluation of _optionalChain_ with arguments _baseValue_ and _baseReference_.
1. Let _newValue_ be ? GetValue(_newReference_).
1. Let _fieldNameString_ be the StringValue of |PrivateIdentifier|.
1. Return ! MakePrivateReference(_newValue_, _fieldNameString_).
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>