This repository was archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathdefinitions.html
255 lines (231 loc) · 14.5 KB
/
definitions.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
<h2>Syntax</h2>
<emu-grammar>
AsyncGeneratorMethod[Yield, Await] :
`async` [no LineTerminator here] `*` PropertyName[?Yield, ?Await] `(` UniqueFormalParameters[+Yield, +Await] `)` `{` AsyncGeneratorBody `}`
AsyncGeneratorDeclaration[Yield, Await, Default] :
`async` [no LineTerminator here] `function` `*` BindingIdentifier[?Yield, ?Await] `(` FormalParameters[+Yield, +Await] `)` `{` AsyncGeneratorBody `}`
[+Default] `async` [no LineTerminator here] `function` `*` `(` FormalParameters[+Yield, +Await] `)` `{` AsyncGeneratorBody `}`
AsyncGeneratorExpression :
`async` [no LineTerminator here] `function` `*` BindingIdentifier[+Yield, +Await]? `(` FormalParameters[+Yield, +Await] `)` `{` AsyncGeneratorBody `}`
AsyncGeneratorBody :
FunctionBody[+Yield, +Await]
</emu-grammar>
<emu-note>
<p>|YieldExpression| and |AwaitExpression| cannot be used within the |FormalParameters| of an async generator function because any expressions that are part of |FormalParameters| are evaluated before the resulting async generator object is in a resumable state.</p>
</emu-note>
<emu-note>
<p>Abstract operations relating to async generator objects are defined in <emu-xref href="#sec-asyncgenerator-abstract-operations"></emu-xref>.</p>
</emu-note>
<emu-clause id="sec-async-generator-function-definitions-static-semantics-early-errors">
<h1>Static Semantics: Early Errors</h1>
<emu-grammar>AsyncGeneratorMethod : `*` PropertyName `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}`</emu-grammar>
<ul>
<li>It is a Syntax Error if HasDirectSuper of |AsyncGeneratorMethod| is *true*.</li>
<li>It is a Syntax Error if |UniqueFormalParameters| Contains |YieldExpression| is *true*.</li>
<li>It is a Syntax Error if |UniqueFormalParameters| Contains |AwaitExpression| is *true*.</li>
<li>It is a Syntax Error if ContainsUseStrict of |AsyncGeneratorBody| is *true* and IsSimpleParameterList of |UniqueFormalParameters| is *false*.</li>
<li>It is a Syntax Error if any element of the BoundNames of |UniqueFormalParameters| also occurs in the LexicallyDeclaredNames of |AsyncGeneratorBody|.</li>
</ul>
<emu-grammar>
AsyncGeneratorDeclaration : `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
AsyncGeneratorDeclaration : `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
AsyncGeneratorDeclaration : `function` `*` BindingIdentifier? `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
</emu-grammar>
<ul>
<li>If the source code matching this production is strict mode code, the Early Error rules for <emu-grammar>UniqueFormalParameters : FormalParameters</emu-grammar> are applied.</li>
<li>If the source code matching this production is strict mode code, it is a Syntax Error if |BindingIdentifier| is the |IdentifierName| `eval` or the |IdentifierName| `arguments`.</li>
<li>It is a Syntax Error if ContainsUseStrict of |AsyncGeneratorBody| is *true* and IsSimpleParameterList of |FormalParameters| is *false*.</li>
<li>It is a Syntax Error if any element of the BoundNames of |FormalParameters| also occurs in the LexicallyDeclaredNames of |AsyncGeneratorBody|.</li>
<li>It is a Syntax Error if |FormalParameters| Contains |YieldExpression| is *true*.</li>
<li>It is a Syntax Error if |FormalParameters| Contains |AwaitExpression| is *true*.</li>
<li>It is a Syntax Error if |FormalParameters| Contains |SuperProperty| is *true*.</li>
<li>It is a Syntax Error if |AsyncGeneratorBody| Contains |SuperProperty| is *true*.</li>
<li>It is a Syntax Error if |FormalParameters| Contains |SuperCall| is *true*.</li>
<li>It is a Syntax Error if |AsyncGeneratorBody| Contains |SuperCall| is *true*.</li>
</ul>
</emu-clause>
<emu-clause id="sec-generator-function-definitions-static-semantics-boundnames">
<h1>Static Semantics: BoundNames</h1>
<emu-see-also-para op="BoundNames"></emu-see-also-para>
<emu-grammar>AsyncGeneratorDeclaration : `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}`</emu-grammar>
<emu-alg>
1. Return the BoundNames of |BindingIdentifier|.
</emu-alg>
<emu-grammar>AsyncGeneratorDeclaration : `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}`</emu-grammar>
<emu-alg>
1. Return « `"*default*"` ».
</emu-alg>
<emu-note>
<p>`"*default*"` is used within this specification as a synthetic name for hoistable anonymous functions that are defined using export declarations.</p>
</emu-note>
</emu-clause>
<emu-clause id="sec-generator-function-definitions-static-semantics-computedpropertycontains">
<h1>Static Semantics: ComputedPropertyContains</h1>
<p>With parameter _symbol_.</p>
<emu-see-also-para op="ComputedPropertyContains"></emu-see-also-para>
<emu-grammar>AsyncGeneratorMethod : `*` PropertyName `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}`</emu-grammar>
<emu-alg>
1. Return the result of ComputedPropertyContains for |PropertyName| with argument _symbol_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-generator-function-definitions-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>
AsyncGeneratorDeclaration : `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
AsyncGeneratorDeclaration : `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
AsyncGeneratorExpression : `function` `*` BindingIdentifier? `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
<emu-note>
<p>Static semantic rules that depend upon substructure generally do not look into function definitions.</p>
</emu-note>
</emu-clause>
<emu-clause id="sec-generator-function-definitions-static-semantics-hasdirectsuper">
<h1>Static Semantics: HasDirectSuper</h1>
<emu-see-also-para op="HasDirectSuper"></emu-see-also-para>
<emu-grammar>AsyncGeneratorMethod : `*` PropertyName `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}`</emu-grammar>
<emu-alg>
1. If |UniqueFormalParameters| Contains |SuperCall| is *true*, return *true*.
1. Return |AsyncGeneratorBody| Contains |SuperCall|.
</emu-alg>
</emu-clause>
<emu-clause id="sec-generator-function-definitions-static-semantics-hasname">
<h1>Static Semantics: HasName</h1>
<emu-see-also-para op="HasName"></emu-see-also-para>
<emu-grammar>AsyncGeneratorExpression : `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}`</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
<emu-grammar>AsyncGeneratorExpression : `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}`</emu-grammar>
<emu-alg>
1. Return *true*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-generator-function-definitions-static-semantics-isconstantdeclaration">
<h1>Static Semantics: IsConstantDeclaration</h1>
<emu-see-also-para op="IsConstantDeclaration"></emu-see-also-para>
<emu-grammar>
AsyncGeneratorDeclaration : `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
AsyncGeneratorDeclaration : `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-generator-function-definitions-static-semantics-isfunctiondefinition">
<h1>Static Semantics: IsFunctionDefinition</h1>
<emu-see-also-para op="IsFunctionDefinition"></emu-see-also-para>
<emu-grammar>AsyncGeneratorExpression : `function` `*` BindingIdentifier? `(` FormalParameters `)` `{` AsyncGeneratorBody `}`</emu-grammar>
<emu-alg>
1. Return *true*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-generator-function-definitions-static-semantics-propname">
<h1>Static Semantics: PropName</h1>
<emu-see-also-para op="PropName"></emu-see-also-para>
<emu-grammar>AsyncGeneratorMethod : `*` PropertyName `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}`</emu-grammar>
<emu-alg>
1. Return PropName of |PropertyName|.
</emu-alg>
</emu-clause>
<emu-clause id="sec-asyncgenerator-definitions-evaluatebody">
<h1>Runtime Semantics: EvaluateBody</h1>
<p>With parameters _functionObject_ and List _argumentsList_.</p>
<emu-grammar>
AsyncGeneratorBody : FunctionBody
</emu-grammar>
<emu-alg>
1. Perform ? FunctionDeclarationInstantiation(_functionObject_, _argumentsList_).
1. Let _generator_ be ? OrdinaryCreateFromConstructor(_functionObject_, `"%AsyncGeneratorPrototype%"`, « [[AsyncGeneratorState]], [[AsyncGeneratorContext]], [[AsyncGeneratorQueue]] »).
1. Perform ! AsyncGeneratorStart(_generator_, _FunctionBody_).
1. Return Completion{[[Type]]: ~return~, [[Value]]: _generator_, [[Target]]: ~empty~}.
</emu-alg>
</emu-clause>
<emu-clause id="sec-asyncgenerator-definitions-instantiatefunctionobject">
<h1>Runtime Semantics: InstantiateFunctionObject</h1>
<p>With parameter _scope_.</p>
<emu-grammar>
AsyncGeneratorDeclaration : `async` [no LineTerminator here] `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
</emu-grammar>
<emu-alg>
1. If the function code for |AsyncGeneratorDeclaration| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
1. Let _name_ be StringValue of |BindingIdentifier|.
1. Let _F_ be ! AsyncGeneratorFunctionCreate(~Normal~, |FormalParameters|, |AsyncGeneratorBody|, _scope_, _strict_).
1. Let _prototype_ be ! ObjectCreate(%AsyncGeneratorPrototype%).
1. Perform ! DefinePropertyOrThrow(_F_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
1. Perform ! SetFunctionName(_F_, _name_).
1. Return _F_.
</emu-alg>
<emu-grammar>
AsyncGeneratorDeclaration : `async` [no LineTerminator here] `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
</emu-grammar>
<emu-alg>
1. If the function code for |AsyncGeneratorDeclaration| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
1. Let _F_ be AsyncGeneratorFunctionCreate(~Normal~, |FormalParameters|, |AsyncGeneratorBody|, _scope_, _strict_).
1. Let _prototype_ be ObjectCreate(%AsyncGeneratorPrototype%).
1. Perform DefinePropertyOrThrow(_F_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
1. Perform SetFunctionName(_F_, `"default"`).
1. Return _F_.
</emu-alg>
<emu-note>
<p>An anonymous |AsyncGeneratorDeclaration| can only occur as part of an `export default` declaration.</p>
</emu-note>
</emu-clause>
<emu-clause id="sec-asyncgenerator-definitions-propertydefinitionevaluation">
<h1>Runtime Semantics: PropertyDefinitionEvaluation</h1>
<p>With parameter _object_ and _enumerable_.</p>
<emu-grammar>
AsyncGeneratorMethod : `async` [no LineTerminator here] `*` PropertyName `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}`
</emu-grammar>
<emu-alg>
1. Let _propKey_ be the result of evaluating |PropertyName|.
1. ReturnIfAbrupt(_propKey_).
1. If the function code for this |AsyncGeneratorMethod| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
1. Let _scope_ be the running execution context's LexicalEnvironment.
1. Let _closure_ be ! AsyncGeneratorFunctionCreate(~Method~, |UniqueFormalParameters|, |AsyncGeneratorBody|, _scope_, _strict_).
1. Perform ! MakeMethod(_closure_, _object_).
1. Let _prototype_ be ! ObjectCreate(%AsyncGeneratorPrototype%).
1. Perform ! DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
1. Perform ! SetFunctionName(_closure_, _propKey_).
1. Let _desc_ be PropertyDescriptor{[[Value]]: _closure_, [[Writable]]: *true*, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}.
1. Return ? DefinePropertyOrThrow(_object_, _propKey_, _desc_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-asyncgenerator-definitions-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>
AsyncGeneratorExpression : `async` [no LineTerminator here] `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
</emu-grammar>
<emu-alg>
1. If the function code for this |AsyncGeneratorExpression| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
1. Let _scope_ be the LexicalEnvironment of the running execution context.
1. Let _closure_ be ! AsyncGeneratorFunctionCreate(~Normal~, |FormalParameters|, |AsyncGeneratorBody|, _scope_, _strict_).
1. Let _prototype_ be ! ObjectCreate(%AsyncGeneratorPrototype%).
1. Perform ! DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
1. Return _closure_.
</emu-alg>
<emu-grammar>
AsyncGeneratorExpression : `async` [no LineTerminator here] `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
</emu-grammar>
<emu-alg>
1. If the function code for this |AsyncGeneratorExpression| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
1. Let _scope_ be the running execution context's LexicalEnvironment.
1. Let _funcEnv_ be ! NewDeclarativeEnvironment(_scope_).
1. Let _envRec_ be _funcEnv_'s EnvironmentRecord.
1. Let _name_ be StringValue of |BindingIdentifier|.
1. Perform ! _envRec_.CreateImmutableBinding(_name_).
1. Let _closure_ be ! AsyncGeneratorFunctionCreate(~Normal~, |FormalParameters|, |AsyncGeneratorBody|, _funcEnv_, _strict_).
1. Let _prototype_ be ! ObjectCreate(%AsyncGeneratorPrototype%).
1. Perform ! DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
1. Perform ! SetFunctionName(_closure_, _name_).
1. Perform ! _envRec_.InitializeBinding(_name_, _closure_).
1. Return _closure_.
</emu-alg>
<emu-note>
<p>The |BindingIdentifier| in an |AsyncGeneratorExpression| can be referenced from inside the |AsyncGeneratorExpression|'s |AsyncGeneratorBody| to allow the generator code to call itself recursively. However, unlike in an |AsyncGeneratorDeclaration|, the |BindingIdentifier| in an |AsyncGeneratorExpression| cannot be referenced from and does not affect the scope enclosing the |AsyncGeneratorExpression|.</p>
</emu-note>
</emu-clause>