21 | remove the forward-incompatible requirement
22 |
23 | If the implementation cannot produce a source code string that meets these criteria then it must return a string for which `eval` will throw a *SyntaxError* exception.
24 |
25 |
clarify the "functionally equivalent" requirement
26 |
standardise the string representation of built-in functions and host objects
27 |
clarify requirement of representation based on the "actual characteristics" of an object
28 |
29 |
30 |
The goals were later revised to include
31 |
32 |
33 |
ensure that the string's parse contains the same function body and parameter list as the original
34 |
35 |
36 |
The goals were revised again to include
37 |
38 |
39 |
for functions defined using ECMAScript code, `toString` must return source text slice from beginning of first token to end of last token matched by the appropriate grammar production
40 |
for built-in function objects and bound function exotic objects, `toString` must not return anything other than |NativeFunction|
41 |
for callable objects which were not defined using ECMAScript code, `toString` must return |NativeFunction|
42 |
for functions created dynamically (through the *Function* and *GeneratorFunction* constructors), `toString` must synthesise a source text
43 |
for all other objects, `toString` must throw a *TypeError* exception
44 |
45 |
46 |
The goals were revised yet again to include
47 |
48 |
49 |
implementations must not be required to retain source text for all functions defined using ECMAScript code
50 |
51 |
52 |
53 |
54 |
55 |
56 |
(5.2) Algorithm Conventions
57 |
The specification often uses a numbered list to specify steps in an algorithm. These algorithms are used to precisely specify the required semantics of ECMAScript language constructs. The algorithms are not intended to imply the use of any specific implementation technique. In practice, there may be more efficient algorithms available to implement a given feature.
58 |
Algorithms may be explicitly parameterized, in which case the names and usage of the parameters must be provided as part of the algorithm's definition. In order to facilitate their use in multiple parts of this specification, some algorithms, called abstract operations, are named and written in parameterized functional form so that they may be referenced by name from within other algorithms. Abstract operations are typically referenced using a functional application style such as operationName(_arg1_, _arg2_). Some abstract operations are treated as polymorphically dispatched methods of class-like specification abstractions. Such method-like abstract operations are typically referenced using a method application style such as _someValue_.operationName(_arg1_, _arg2_).
59 |
Calls to abstract operations return Completion Records. Abstract operations referenced using the functional application style and the method application style that are prefixed by `?` indicate that ReturnIfAbrupt should be applied to the resulting Completion Record. For example, ? operationName() is equivalent to ReturnIfAbrupt(operationName()). Similarly, ? _someValue_.operationName() is equivalent to ReturnIfAbrupt(_someValue_.operationName()).
60 |
The prefix `!` is used to indicate that an abstract operation will never return an abrupt completion and that the resulting Completion Record's value field should be used in place of the return value of the operation. For example, “Let _val_ be ! operationName()” is equivalent to the following algorithm steps:
61 |
62 | 1. Let _val_ be operationName().
63 | 1. Assert: _val_ is never an abrupt completion.
64 | 1. If _val_ is a Completion Record, let _val_ be _val_.[[Value]].
65 |
66 |
Algorithms may be associated with productions of one of the ECMAScript grammars. A production that has multiple alternative definitions will typically have a distinct algorithm for each alternative. When an algorithm is associated with a grammar production, it may reference the terminal and nonterminal symbols of the production alternative as if they were parameters of the algorithm. When used in this manner, nonterminal symbols refer to the actual alternative definition that is matched when parsing the source text. The source text matched by a grammar production is the portion of the source text that starts at the beginning of the first terminal that participated in the match and ends at the end of the last terminal that participated in the match.
67 |
When an algorithm is associated with a production alternative, the alternative is typically shown without any “[ ]” grammar annotations. Such annotations should only affect the syntactic recognition of the alternative and have no effect on the associated semantics for the alternative.
68 |
Unless explicitly specified otherwise, all chain productions have an implicit definition for every algorithm that might be applied to that production's left-hand side nonterminal. The implicit definition simply reapplies the same algorithm name with the same parameters, if any, to the chain production's sole right-hand side nonterminal and then returns the result. For example, assume there is a production:
but there is no corresponding Evaluation algorithm that is explicitly specified for that production. If in some algorithm there is a statement of the form: “Return the result of evaluating |Block|” it is implicit that an Evaluation algorithm exists of the form:
74 |
Runtime Semantics: Evaluation
75 | Block : `{` StatementList `}`
76 |
77 | 1. Return the result of evaluating |StatementList|.
78 |
79 |
For clarity of expression, algorithm steps may be subdivided into sequential substeps. Substeps are indented and may themselves be further divided into indented substeps. Outline numbering conventions are used to identify substeps with the first level of substeps labelled with lower case alphabetic characters and the second level of substeps labelled with lower case roman numerals. If more than three levels are required these rules repeat with the fourth level using numeric labels. For example:
A step or substep may be written as an “if” predicate that conditions its substeps. In this case, the substeps are only applied if the predicate is true. If a step or substep begins with the word “else”, it is a predicate that is the negation of the preceding “if” predicate step at the same level.
90 |
A step may specify the iterative application of its substeps.
91 |
A step that begins with “Assert:” asserts an invariant condition of its algorithm. Such assertions are used to make explicit algorithmic invariants that would otherwise be implicit. Such assertions add no additional semantic requirements and hence need not be checked by an implementation. They are used simply to clarify algorithms.
92 |
Mathematical operations such as addition, subtraction, negation, multiplication, division, and the mathematical functions defined later in this clause should always be understood as computing exact mathematical results on mathematical real numbers, which unless otherwise noted do not include infinities and do not include a negative zero that is distinguished from positive zero. Algorithms in this standard that model floating-point arithmetic include explicit steps, where necessary, to handle infinities and signed zero and to perform rounding. If a mathematical operation or function is applied to a floating-point number, it should be understood as being applied to the exact mathematical value represented by that floating-point number; such a floating-point number must be finite, and if it is *+0* or *-0* then the corresponding mathematical value is simply 0.
93 |
The mathematical function abs(_x_) produces the absolute value of _x_, which is -_x_ if _x_ is negative (less than zero) and otherwise is _x_ itself.
94 |
The mathematical function min(_x1_, _x2_, ..., _xN_) produces the mathematically smallest of _x1_ through _xN_. The mathematical function max(_x1_, _x2_, ..., _xN_) produces the mathematically largest of _x1_ through _xN_. The domain and range of these mathematical functions include *+∞* and *-∞*.
95 |
The notation “_x_ modulo _y_” (_y_ must be finite and nonzero) computes a value _k_ of the same sign as _y_ (or zero) such that abs(_k_) < abs(_y_) and _x_-_k_ = _q_ × _y_ for some integer _q_.
96 |
The mathematical function floor(_x_) produces the largest integer (closest to positive infinity) that is not larger than _x_.
97 |
98 |
floor(_x_) = _x_-(_x_ modulo 1).
99 |
100 |
101 |
102 |
103 |
104 |
105 |
(9.2) ECMAScript Function Objects
106 |
ECMAScript function objects encapsulate parameterized ECMAScript code closed over a lexical environment and support the dynamic evaluation of that code. An ECMAScript function object is an ordinary object and has the same internal slots and the same internal methods as other ordinary objects. The code of an ECMAScript function object may be either strict mode code () or non-strict mode code. An ECMAScript function object whose code is strict mode code is called a strict function. One whose code is not strict mode code is called a non-strict function.
107 |
ECMAScript function objects have the additional internal slots listed in .
108 |
109 |
110 |
111 |
Internal Slot
Type
Description
112 |
[[Environment]]
Lexical Environment
The Lexical Environment that the function was closed over. Used as the outer environment when evaluating the code of the function.
113 |
[[FormalParameters]]
Parse Node
The root parse node of the source text that defines the function's formal parameter list.
114 |
[[FunctionKind]]
String
Either `"normal"`, `"classConstructor"` or `"generator"`.
115 |
[[ECMAScriptCode]]
Parse Node
The root parse node of the source text that defines the function's body.
116 |
[[ConstructorKind]]
String
Either `"base"` or `"derived"`.
117 |
[[Realm]]
Realm Record
The realm in which the function was created and which provides any intrinsic objects that are accessed when evaluating the function.
118 |
[[ScriptOrModule]]
Script Record or Module Record
The script or module in which the function was created.
119 |
[[ThisMode]]
(lexical, strict, global)
Defines how `this` references are interpreted within the formal parameters and code body of the function. ~lexical~ means that `this` refers to the *this* value of a lexically enclosing function. ~strict~ means that the *this* value is used exactly as provided by an invocation of the function. ~global~ means that a *this* value of *undefined* is interpreted as a reference to the global object.
120 |
[[Strict]]
Boolean
*true* if this is a strict mode function, *false* if this is not a strict mode function.
121 |
[[HomeObject]]
Object
If the function uses `super`, this is the object whose [[GetPrototypeOf]] provides the object where `super` property lookups begin.
122 |
123 |
[[SourceText]]
124 |
String
125 |
The source text that defines the function.
126 |
127 |
128 |
129 |
130 |
All ECMAScript function objects have the [[Call]] internal method defined here. ECMAScript functions that are also constructors in addition have the [[Construct]] internal method.
138 |
139 | FunctionDeclaration : `function` BindingIdentifier `(` FormalParameters `)` `{` FunctionBody `}`
140 |
141 | 1. If the function code for |FunctionDeclaration| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
142 | 1. Let _name_ be StringValue of |BindingIdentifier|.
143 | 1. Let _F_ be FunctionCreate(~Normal~, |FormalParameters|, |FunctionBody|, _scope_, _strict_).
144 | 1. Perform MakeConstructor(_F_).
145 | 1. Perform SetFunctionName(_F_, _name_).
146 | 1. Set _F_.[[SourceText]] to the source text matched by |FunctionDeclaration|.
147 | 1. Return _F_.
148 |
149 | FunctionDeclaration : `function` `(` FormalParameters `)` `{` FunctionBody `}`
150 |
151 | 1. If the function code for |FunctionDeclaration| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
152 | 1. Let _F_ be FunctionCreate(~Normal~, |FormalParameters|, |FunctionBody|, _scope_, _strict_).
153 | 1. Perform MakeConstructor(_F_).
154 | 1. Perform SetFunctionName(_F_, `"default"`).
155 | 1. Set _F_.[[SourceText]] to the source text matched by |FunctionDeclaration|.
156 | 1. Return _F_.
157 |
158 |
159 |
An anonymous |FunctionDeclaration| can only occur as part of an `export default` declaration.
173 |
174 | FunctionDeclaration : `function` `(` FormalParameters `)` `{` FunctionBody `}`
175 |
176 | 1. Return NormalCompletion(~empty~).
177 |
178 | FunctionExpression : `function` `(` FormalParameters `)` `{` FunctionBody `}`
179 |
180 | 1. If the function code for |FunctionExpression| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
181 | 1. Let _scope_ be the LexicalEnvironment of the running execution context.
182 | 1. Let _closure_ be FunctionCreate(~Normal~, |FormalParameters|, |FunctionBody|, _scope_, _strict_).
183 | 1. Perform MakeConstructor(_closure_).
184 | 1. Set _closure_.[[SourceText]] to the source text matched by |FunctionExpression|.
185 | 1. Return _closure_.
186 |
187 | FunctionExpression : `function` BindingIdentifier `(` FormalParameters `)` `{` FunctionBody `}`
188 |
189 | 1. If the function code for |FunctionExpression| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
190 | 1. Let _scope_ be the running execution context's LexicalEnvironment.
191 | 1. Let _funcEnv_ be NewDeclarativeEnvironment(_scope_).
192 | 1. Let _envRec_ be _funcEnv_'s EnvironmentRecord.
193 | 1. Let _name_ be StringValue of |BindingIdentifier|.
194 | 1. Perform _envRec_.CreateImmutableBinding(_name_, *false*).
195 | 1. Let _closure_ be FunctionCreate(~Normal~, |FormalParameters|, |FunctionBody|, _funcEnv_, _strict_).
196 | 1. Perform MakeConstructor(_closure_).
197 | 1. Perform SetFunctionName(_closure_, _name_).
198 | 1. Set _closure_.[[SourceText]] to the source text matched by |FunctionExpression|.
199 | 1. Perform _envRec_.InitializeBinding(_name_, _closure_).
200 | 1. Return _closure_.
201 |
202 |
203 |
The |BindingIdentifier| in a |FunctionExpression| can be referenced from inside the |FunctionExpression|'s |FunctionBody| to allow the function to call itself recursively. However, unlike in a |FunctionDeclaration|, the |BindingIdentifier| in a |FunctionExpression| cannot be referenced from and does not affect the scope enclosing the |FunctionExpression|.
204 |
205 |
206 |
A `prototype` property is automatically created for every function defined using a |FunctionDeclaration| or |FunctionExpression|, to allow for the possibility that the function will be used as a constructor.
218 | ArrowFunction : ArrowParameters `=>` ConciseBody
219 |
220 | 1. If the function code for this |ArrowFunction| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
221 | 1. Let _scope_ be the LexicalEnvironment of the running execution context.
222 | 1. Let _parameters_ be CoveredFormalsList of |ArrowParameters|.
223 | 1. Let _closure_ be FunctionCreate(~Arrow~, _parameters_, |ConciseBody|, _scope_, _strict_).
224 | 1. Set _closure_.[[SourceText]] to the source text matched by |ArrowFunction|.
225 | 1. Return _closure_.
226 |
227 |
228 |
An |ArrowFunction| does not define local bindings for `arguments`, `super`, `this`, or `new.target`. Any reference to `arguments`, `super`, `this`, or `new.target` within an |ArrowFunction| must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function. Even though an |ArrowFunction| may contain references to `super`, the function object created in step 4 is not made into a method by performing MakeMethod. An |ArrowFunction| that references `super` is always contained within a non-|ArrowFunction| and the necessary state to implement `super` is accessible via the _scope_ that is captured by the function object of the |ArrowFunction|.
229 |
230 |
231 |
232 |
233 |
234 |
235 |
(14.3.8) Runtime Semantics: DefineMethod
236 |
With parameters _object_ and optional parameter _functionPrototype_.
237 | MethodDefinition : PropertyName `(` StrictFormalParameters `)` `{` FunctionBody `}`
238 |
239 | 1. Let _propKey_ be the result of evaluating |PropertyName|.
240 | 1. ReturnIfAbrupt(_propKey_).
241 | 1. If the function code for this |MethodDefinition| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
242 | 1. Let _scope_ be the running execution context's LexicalEnvironment.
243 | 1. If _functionPrototype_ was passed as a parameter, let _kind_ be ~Normal~; otherwise let _kind_ be ~Method~.
244 | 1. Let _closure_ be FunctionCreate(_kind_, |StrictFormalParameters|, |FunctionBody|, _scope_, _strict_). If _functionPrototype_ was passed as a parameter, then pass its value as the _prototype_ optional argument of FunctionCreate.
245 | 1. Perform MakeMethod(_closure_, _object_).
246 | 1. Set _closure_.[[SourceText]] to the source text matched by |MethodDefinition|.
247 | 1. Return the Record{[[Key]]: _propKey_, [[Closure]]: _closure_}.
248 |
249 |
250 |
251 |
252 |
253 |
254 |
256 |
257 | MethodDefinition : PropertyName `(` StrictFormalParameters `)` `{` FunctionBody `}`
258 |
259 | 1. Let _methodDef_ be DefineMethod of |MethodDefinition| with argument _object_.
260 | 1. ReturnIfAbrupt(_methodDef_).
261 | 1. Perform SetFunctionName(_methodDef_.[[Closure]], _methodDef_.[[Key]]).
262 | 1. Let _desc_ be the PropertyDescriptor{[[Value]]: _methodDef_.[[Closure]], [[Writable]]: *true*, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}.
263 | 1. Return ? DefinePropertyOrThrow(_object_, _methodDef_.[[Key]], _desc_).
264 |
265 | MethodDefinition : GeneratorMethod
266 |
See .
267 | MethodDefinition : `get` PropertyName `(` `)` `{` FunctionBody `}`
268 |
269 | 1. Let _propKey_ be the result of evaluating |PropertyName|.
270 | 1. ReturnIfAbrupt(_propKey_).
271 | 1. If the function code for this |MethodDefinition| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
272 | 1. Let _scope_ be the running execution context's LexicalEnvironment.
273 | 1. Let _formalParameterList_ be the production FormalParameters : [empty].
274 | 1. Let _closure_ be FunctionCreate(~Method~, _formalParameterList_, |FunctionBody|, _scope_, _strict_).
275 | 1. Perform MakeMethod(_closure_, _object_).
276 | 1. Perform SetFunctionName(_closure_, _propKey_, `"get"`).
277 | 1. Set _closure_.[[SourceText]] to the source text matched by |MethodDefinition|.
278 | 1. Let _desc_ be the PropertyDescriptor{[[Get]]: _closure_, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}.
279 | 1. Return ? DefinePropertyOrThrow(_object_, _propKey_, _desc_).
280 |
281 | MethodDefinition : `set` PropertyName `(` PropertySetParameterList `)` `{` FunctionBody `}`
282 |
283 | 1. Let _propKey_ be the result of evaluating |PropertyName|.
284 | 1. ReturnIfAbrupt(_propKey_).
285 | 1. If the function code for this |MethodDefinition| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
286 | 1. Let _scope_ be the running execution context's LexicalEnvironment.
287 | 1. Let _closure_ be FunctionCreate(~Method~, |PropertySetParameterList|, |FunctionBody|, _scope_, _strict_).
288 | 1. Perform MakeMethod(_closure_, _object_).
289 | 1. Perform SetFunctionName(_closure_, _propKey_, `"set"`).
290 | 1. Set _closure_.[[SourceText]] to the source text matched by |MethodDefinition|.
291 | 1. Let _desc_ be the PropertyDescriptor{[[Set]]: _closure_, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}.
292 | 1. Return ? DefinePropertyOrThrow(_object_, _propKey_, _desc_).
293 |
294 |
295 |
296 |
297 |
298 |
299 |
333 |
334 | GeneratorMethod : `*` PropertyName `(` StrictFormalParameters `)` `{` GeneratorBody `}`
335 |
336 | 1. Let _propKey_ be the result of evaluating |PropertyName|.
337 | 1. ReturnIfAbrupt(_propKey_).
338 | 1. If the function code for this |GeneratorMethod| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
339 | 1. Let _scope_ be the running execution context's LexicalEnvironment.
340 | 1. Let _closure_ be GeneratorFunctionCreate(~Method~, |StrictFormalParameters|, |GeneratorBody|, _scope_, _strict_).
341 | 1. Perform MakeMethod(_closure_, _object_).
342 | 1. Let _prototype_ be ObjectCreate(%GeneratorPrototype%).
343 | 1. Perform DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
344 | 1. Perform SetFunctionName(_closure_, _propKey_).
345 | 1. Set _closure_.[[SourceText]] to the source text matched by |GeneratorMethod|.
346 | 1. Let _desc_ be the PropertyDescriptor{[[Value]]: _closure_, [[Writable]]: *true*, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}.
347 | 1. Return ? DefinePropertyOrThrow(_object_, _propKey_, _desc_).
348 |
349 |
350 |
351 |
352 |
353 |
354 |
(14.4.14) Runtime Semantics: Evaluation
355 | GeneratorExpression : `function` `*` `(` FormalParameters `)` `{` GeneratorBody `}`
356 |
357 | 1. If the function code for this |GeneratorExpression| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
358 | 1. Let _scope_ be the LexicalEnvironment of the running execution context.
359 | 1. Let _closure_ be GeneratorFunctionCreate(~Normal~, |FormalParameters|, |GeneratorBody|, _scope_, _strict_).
360 | 1. Let _prototype_ be ObjectCreate(%GeneratorPrototype%).
361 | 1. Perform DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
362 | 1. Set _closure_.[[SourceText]] to the source text matched by |GeneratorExpression|.
363 | 1. Return _closure_.
364 |
365 | GeneratorExpression : `function` `*` BindingIdentifier `(` FormalParameters `)` `{` GeneratorBody `}`
366 |
367 | 1. If the function code for this |GeneratorExpression| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
368 | 1. Let _scope_ be the running execution context's LexicalEnvironment.
369 | 1. Let _funcEnv_ be NewDeclarativeEnvironment(_scope_).
370 | 1. Let _envRec_ be _funcEnv_'s EnvironmentRecord.
371 | 1. Let _name_ be StringValue of |BindingIdentifier|.
372 | 1. Perform _envRec_.CreateImmutableBinding(_name_, *false*).
373 | 1. Let _closure_ be GeneratorFunctionCreate(~Normal~, |FormalParameters|, |GeneratorBody|, _funcEnv_, _strict_).
374 | 1. Let _prototype_ be ObjectCreate(%GeneratorPrototype%).
375 | 1. Perform DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
376 | 1. Perform SetFunctionName(_closure_, _name_).
377 | 1. Perform _envRec_.InitializeBinding(_name_, _closure_).
378 | 1. Set _closure_.[[SourceText]] to the source text matched by |GeneratorExpression|.
379 | 1. Return _closure_.
380 |
381 |
382 |
The |BindingIdentifier| in a |GeneratorExpression| can be referenced from inside the |GeneratorExpression|'s |FunctionBody| to allow the generator code to call itself recursively. However, unlike in a |GeneratorDeclaration|, the |BindingIdentifier| in a |GeneratorExpression| cannot be referenced from and does not affect the scope enclosing the |GeneratorExpression|.
427 |
428 | AsyncGeneratorMethod : `async` [no LineTerminator here] `*` PropertyName `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}`
429 |
430 |
431 | 1. Let _propKey_ be the result of evaluating |PropertyName|.
432 | 1. ReturnIfAbrupt(_propKey_).
433 | 1. If the function code for this |AsyncGeneratorMethod| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
434 | 1. Let _scope_ be the running execution context's LexicalEnvironment.
435 | 1. Let _closure_ be ! AsyncGeneratorFunctionCreate(~Method~, |UniqueFormalParameters|, |AsyncGeneratorBody|, _scope_, _strict_).
436 | 1. Perform ! MakeMethod(_closure_, _object_).
437 | 1. Let _prototype_ be ! ObjectCreate(%AsyncGeneratorPrototype%).
438 | 1. Perform ! DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
439 | 1. Perform ! SetFunctionName(_closure_, _propKey_).
440 | 1. Set _closure_.[[SourceText]] to the source text matched by |AsyncGeneratorMethod|.
441 | 1. Let _desc_ be PropertyDescriptor{[[Value]]: _closure_, [[Writable]]: *true*, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}.
442 | 1. Return ? DefinePropertyOrThrow(_object_, _propKey_, _desc_).
443 |
444 |
445 |
446 |
447 |
448 |
449 |
(14.5.13) Runtime Semantics: Evaluation
450 |
451 |
452 | AsyncGeneratorExpression : `async` [no LineTerminator here] `function` `*` `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
453 |
454 |
455 | 1. If the function code for this |AsyncGeneratorExpression| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
456 | 1. Let _scope_ be the LexicalEnvironment of the running execution context.
457 | 1. Let _closure_ be ! AsyncGeneratorFunctionCreate(~Normal~, |FormalParameters|, |AsyncGeneratorBody|, _scope_, _strict_).
458 | 1. Let _prototype_ be ! ObjectCreate(%AsyncGeneratorPrototype%).
459 | 1. Perform ! DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
460 | 1. Set _closure_.[[SourceText]] to the source text matched by |AsyncGeneratorExpression|.
461 | 1. Return _closure_.
462 |
463 |
464 |
465 | AsyncGeneratorExpression : `async` [no LineTerminator here] `function` `*` BindingIdentifier `(` FormalParameters `)` `{` AsyncGeneratorBody `}`
466 |
467 |
468 | 1. If the function code for this |AsyncGeneratorExpression| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
469 | 1. Let _scope_ be the running execution context's LexicalEnvironment.
470 | 1. Let _funcEnv_ be ! NewDeclarativeEnvironment(_scope_).
471 | 1. Let _envRec_ be _funcEnv_'s EnvironmentRecord.
472 | 1. Let _name_ be StringValue of |BindingIdentifier|.
473 | 1. Perform ! _envRec_.CreateImmutableBinding(_name_).
474 | 1. Let _closure_ be ! AsyncGeneratorFunctionCreate(~Normal~, |FormalParameters|, |AsyncGeneratorBody|, _funcEnv_, _strict_).
475 | 1. Let _prototype_ be ! ObjectCreate(%AsyncGeneratorPrototype%).
476 | 1. Perform ! DefinePropertyOrThrow(_closure_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
477 | 1. Perform ! SetFunctionName(_closure_, _name_).
478 | 1. Perform ! _envRec_.InitializeBinding(_name_, _closure_).
479 | 1. Set _closure_.[[SourceText]] to the source text matched by |AsyncGeneratorExpression|.
480 | 1. Return _closure_.
481 |
482 |
483 |
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|.
491 | ClassDeclaration : `class` BindingIdentifier ClassTail
492 |
493 | 1. Let _className_ be StringValue of |BindingIdentifier|.
494 | 1. Let _value_ be the result of ClassDefinitionEvaluation of |ClassTail| with argument _className_.
495 | 1. ReturnIfAbrupt(_value_).
496 | 1. Let _hasNameProperty_ be ? HasOwnProperty(_value_, `"name"`).
497 | 1. If _hasNameProperty_ is *false*, perform SetFunctionName(_value_, _className_).
498 | 1. Set _value_.[[SourceText]] to the source text matched by |ClassDeclaration|.
499 | 1. Let _env_ be the running execution context's LexicalEnvironment.
500 | 1. Perform ? InitializeBoundName(_className_, _value_, _env_).
501 | 1. Return _value_.
502 |
503 | ClassDeclaration : `class` ClassTail
504 |
505 | 1. ReturnLet _value_ be the result of ClassDefinitionEvaluation of |ClassTail| with argument *undefined*.
506 | 1. Set _value_.[[SourceText]] to the source text matched by |ClassDeclaration|.
507 | 1. Return _value_.
508 |
509 |
510 |
ClassDeclaration : `class` ClassTail only occurs as part of an |ExportDeclaration| and the setting of a name property and establishing its binding are handled as part of the evaluation action for that production. See .
511 |
512 |
513 |
514 |
515 |
516 |
(14.5.16) Runtime Semantics: Evaluation
517 | ClassDeclaration : `class` BindingIdentifier ClassTail
518 |
519 | 1. Let _status_ be the result of BindingClassDeclarationEvaluation of this |ClassDeclaration|.
520 | 1. ReturnIfAbrupt(_status_).
521 | 1. Return NormalCompletion(~empty~).
522 |
523 |
524 |
ClassDeclaration : `class` ClassTail only occurs as part of an |ExportDeclaration| and is never directly evaluated.
525 |
526 | ClassExpression : `class` BindingIdentifier? ClassTail
527 |
528 | 1. If |BindingIdentifier_opt| is not present, let _className_ be *undefined*.
529 | 1. Else, let _className_ be StringValue of |BindingIdentifier|.
530 | 1. Let _value_ be the result of ClassDefinitionEvaluation of |ClassTail| with argument _className_.
531 | 1. ReturnIfAbrupt(_value_).
532 | 1. If _className_ is not *undefined*, then
533 | 1. Let _hasNameProperty_ be ? HasOwnProperty(_value_, `"name"`).
534 | 1. If _hasNameProperty_ is *false*, then
535 | 1. Perform SetFunctionName(_value_, _className_).
536 | 1. Set _value_.[[SourceText]] to the source text matched by |ClassExpression|.
537 | 1. Return NormalCompletion(_value_).
538 |
539 |
540 |
If the class definition included a `name` static method then that method is not over-written with a `name` data property for the class name.
577 |
578 | AsyncMethod : `async` [no LineTerminator here] PropertyName `(` UniqueFormalParameters `)` `{` AsyncFunctionBody `}`
579 |
580 |
581 | 1. Let _propKey_ be the result of evaluating |PropertyName|.
582 | 1. ReturnIfAbrupt(_propKey_).
583 | 1. If the function code for this |AsyncMethod| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
584 | 1. Let _scope_ be the LexicalEnvironment of the running execution context.
585 | 1. Let _closure_ be ! AsyncFunctionCreate(~Method~, |UniqueFormalParameters|, |AsyncFunctionBody|, _scope_, _strict_).
586 | 1. Perform ! MakeMethod(_closure_, _object_).
587 | 1. Perform ! SetFunctionName(_closure_, _propKey_).
588 | 1. Set _closure_.[[SourceText]] to the source text matched by |AsyncMethod|.
589 | 1. Let _desc_ be the PropertyDescriptor{[[Value]]: _closure_, [[Writable]]: *true*, [[Enumerable]]: _enumerable_, [[Configurable]]: *true*}.
590 | 1. Return ? DefinePropertyOrThrow(_object_, _propKey_, _desc_).
591 |
592 |
593 |
594 |
595 |
596 |
597 |
(14.7.13) Runtime Semantics: Evaluation
598 |
599 | AsyncFunctionDeclaration : `async` [no LineTerminator here] `function` BindingIdentifier `(` FormalParameters `)` `{` AsyncFunctionBody `}`
600 |
601 |
602 | 1. Return NormalCompletion(~empty~).
603 |
604 |
605 |
606 | AsyncFunctionDeclaration : `async` [no LineTerminator here] `function` `(` FormalParameters `)` `{` AsyncFunctionBody `}`
607 |
608 |
609 | 1. Return NormalCompletion(~empty~).
610 |
611 |
612 |
613 | AsyncFunctionExpression : `async` [no LineTerminator here] `function` `(` FormalParameters `)` `{` AsyncFunctionBody `}`
614 |
615 |
616 | 1. If the function code for |AsyncFunctionExpression| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
617 | 1. Let _scope_ be the LexicalEnvironment of the running execution context.
618 | 1. Let _closure_ be ! AsyncFunctionCreate(~Normal~, |FormalParameters|, |AsyncFunctionBody|, _scope_, _strict_).
619 | 1. Set _closure_.[[SourceText]] to the source text matched by |AsyncFunctionExpression|.
620 | 1. Return _closure_.
621 |
622 |
623 |
624 | AsyncFunctionExpression : `async` [no LineTerminator here] `function` BindingIdentifier `(` FormalParameters `)` `{` AsyncFunctionBody `}`
625 |
626 |
627 | 1. If the function code for |AsyncFunctionExpression| is strict mode code, let _strict_ be *true*. Otherwise let _strict_ be *false*.
628 | 1. Let _scope_ be the LexicalEnvironment of the running execution context.
629 | 1. Let _funcEnv_ be ! NewDeclarativeEnvironment(_scope_).
630 | 1. Let _envRec_ be _funcEnv_'s EnvironmentRecord.
631 | 1. Let _name_ be StringValue of |BindingIdentifier|.
632 | 1. Perform ! _envRec_.CreateImmutableBinding(_name_).
633 | 1. Let _closure_ be ! AsyncFunctionCreate(~Normal~, |FormalParameters|, |AsyncFunctionBody|, _funcEnv_, _strict_).
634 | 1. Perform ! SetFunctionName(_closure_, _name_).
635 | 1. Perform ! _envRec_.InitializeBinding(_name_, _closure_).
636 | 1. Set _closure_.[[SourceText]] to the source text matched by |AsyncFunctionExpression|.
637 | 1. Return _closure_.
638 |
639 |
640 |
641 | AwaitExpression : `await` UnaryExpression
642 |
643 |
644 | 1. Let _exprRef_ be the result of evaluating |UnaryExpression|.
645 | 1. Let _value_ be ? GetValue(_exprRef_).
646 | 1. Return ? Await(_value_).
647 |
648 |
649 |
650 |
651 |
652 |
653 |
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:
655 |
656 | 1. Assert: The execution context stack has at least two elements.
657 | 1. Let _callerContext_ be the second to top element of the execution context stack.
658 | 1. Let _callerRealm_ be _callerContext_'s Realm.
659 | 1. Let _calleeRealm_ be the current Realm Record.
660 | 1. Perform ? HostEnsureCanCompileStrings(_callerRealm_, _calleeRealm_).
661 | 1. If _newTarget_ is *undefined*, let _newTarget_ be _constructor_.
662 | 1. If _kind_ is `"normal"`, then
663 | 1. Let _goal_ be the grammar symbol |FunctionBody[~Yield, ~Await]|.
664 | 1. Let _parameterGoal_ be the grammar symbol |FormalParameters[~Yield, ~Await]|.
665 | 1. Let _fallbackProto_ be `"%FunctionPrototype%"`.
666 | 1. Else if _kind_ is `"generator"`, then
667 | 1. Let _goal_ be the grammar symbol |GeneratorBody|.
668 | 1. Let _parameterGoal_ be the grammar symbol |FormalParameters[+Yield, ~Await]|.
669 | 1. Let _fallbackProto_ be `"%Generator%"`.
670 | 1. Else,
671 | 1. Assert: _kind_ is `"async"`.
672 | 1. Let _goal_ be the grammar symbol |AsyncFunctionBody|.
673 | 1. Let _parameterGoal_ be the grammar symbol |FormalParameters[~Yield, +Await]|.
674 | 1. Let _fallbackProto_ be `"%AsyncFunctionPrototype%"`.
675 | 1. Let _argCount_ be the number of elements in _args_.
676 | 1. Let _P_ be the empty String.
677 | 1. If _argCount_ = 0, let _bodyText_ be the empty String.
678 | 1. Else if _argCount_ = 1, let _bodyText_ be _args_[0].
679 | 1. Else _argCount_ > 1,
680 | 1. Let _firstArg_ be _args_[0].
681 | 1. Let _P_ be ? ToString(_firstArg_).
682 | 1. Let _k_ be 1.
683 | 1. Repeat, while _k_ < _argCount_-1
684 | 1. Let _nextArg_ be _args_[_k_].
685 | 1. Let _nextArgString_ be ? ToString(_nextArg_).
686 | 1. Let _P_ be the result of concatenating the previous value of _P_, the String `","` (a comma), and _nextArgString_.
687 | 1. Increase _k_ by 1.
688 | 1. Let _bodyText_ be _args_[_k_].
689 | 1. Let _bodyText_ be ? ToString(_bodyText_).
690 | 1. Let _parameters_ be the result of parsing _P_, interpreted as UTF-16 encoded Unicode text as described in , using _parameterGoal_ as the goal symbol. Throw a *SyntaxError* exception if the parse fails.
691 | 1. Let _body_ be the result of parsing _bodyText_, interpreted as UTF-16 encoded Unicode text as described in , using _goal_ as the goal symbol. Throw a *SyntaxError* exception if the parse fails.
692 | 1. If _bodyText_ is strict mode code, then let _strict_ be *true*, else let _strict_ be *false*.
693 | 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 UniqueFormalParameters : FormalParameters are applied. Parsing and early error detection may be interweaved in an implementation dependent manner.
694 | 1. If ContainsUseStrict of _body_ is *true* and IsSimpleParameterList of _parameters_ is *false*, throw a *SyntaxError* exception.
695 | 1. If any element of the BoundNames of _parameters_ also occurs in the LexicallyDeclaredNames of _body_, throw a *SyntaxError* exception.
696 | 1. If _body_ Contains |SuperCall| is *true*, throw a *SyntaxError* exception.
697 | 1. If _parameters_ Contains |SuperCall| is *true*, throw a *SyntaxError* exception.
698 | 1. If _body_ Contains |SuperProperty| is *true*, throw a *SyntaxError* exception.
699 | 1. If _parameters_ Contains |SuperProperty| is *true*, throw a *SyntaxError* exception.
700 | 1. If _kind_ is `"generator"`, then
701 | 1. If _parameters_ Contains |YieldExpression| is *true*, throw a *SyntaxError* exception.
702 | 1. If _kind_ is `"async"`, then
703 | 1. If _parameters_ Contains |AwaitExpression| is *true*, throw a *SyntaxError* exception.
704 | 1. If _strict_ is *true*, then
705 | 1. If BoundNames of _parameters_ contains any duplicate elements, throw a *SyntaxError* exception.
706 | 1. Let _proto_ be ? GetPrototypeFromConstructor(_newTarget_, _fallbackProto_).
707 | 1. Let _F_ be FunctionAllocate(_proto_, _strict_, _kind_).
708 | 1. Let _realmF_ be _F_.[[Realm]].
709 | 1. Let _scope_ be _realmF_.[[GlobalEnv]].
710 | 1. Perform FunctionInitialize(_F_, ~Normal~, _parameters_, _body_, _scope_).
711 | 1. If _kind_ is `"generator"`, then
712 | 1. Let _prototype_ be ObjectCreate(%GeneratorPrototype%).
713 | 1. Perform DefinePropertyOrThrow(_F_, `"prototype"`, PropertyDescriptor{[[Value]]: _prototype_, [[Writable]]: *true*, [[Enumerable]]: *false*, [[Configurable]]: *false*}).
714 | 1. Else if _kind_ is `"normal"`, perform MakeConstructor(_F_).
715 | 1. NOTE: Async functions are not constructable and do not have a [[Construct]] internal method or a `"prototype"` property.
716 | 1. Perform SetFunctionName(_F_, `"anonymous"`).
717 | 1. Let _prefix_ be the prefix associated with _kind_ in .
718 | 1. Let _sourceText_ be the String value whose elements are, in order, the code units of _prefix_, the code units of `" anonymous("`, the code units of _P_, 0x000A (LINE FEED), the code units of `") {"`, 0x000A (LINE FEED), the code units of _bodyText_, 0x000A (LINE FEED), and the code units of `"}"`.
719 | 1. Set _F_.[[SourceText]] to _sourceText_.
720 | 1. Return _F_.
721 |
722 |
723 |
A `prototype` property is automatically created for every function created using CreateDynamicFunction, to provide for the possibility that the function will be used as a constructor.
724 |
725 |
726 |
727 |
728 |
729 |
Kind
Prefix
730 |
`"normal"`
`"function"`
731 |
`"generator"`
`"function*"`
732 |
`"async"`
`"async function"`
733 |
`"async generator"`
`"async function*"`
734 |
735 |
736 |
737 |
738 |
739 |
740 |
741 |
HostHasSourceTextAvailable ( _func_ )
742 |
HostHasSourceTextAvailable is an implementation-defined abstract operation that allows host environments to prevent the source text from being provided for a given function.
743 |
An implementation of HostHasSourceTextAvailable must complete normally in all cases. This operation must be idempotent. Each time it is called with a specific _func_ as its argument, it must return the same completion record. The default implementation of HostHasSourceTextAvailable is to unconditionally return a normal completion with a value of *true*.
744 |
745 |
746 |
747 |
748 |
749 |
(19.2.3.5) Function.prototype.toString ( )
750 |
751 |
When the `toString` method is called with an object _func_ as its *this* value, the following steps are taken:
752 |
753 |
754 |
755 | 1. If _func_ is a Bound Function exotic object, then
756 | 1. Return an implementation-dependent String source code representation of _func_. The representation must conform to the rules below. It is implementation dependent whether the representation includes bound function information or information about the target function.
757 | 1. If Type(_func_) is Object and is either a built-in function object or has an [[ECMAScriptCode]] internal slot, then
758 | 1. Return an implementation-dependent String source code representation of _func_. The representation must conform to the rules below.
759 | 1. Throw a *TypeError* exception.
760 |
761 |
`toString` Representation Requirements:
762 |
763 |
The string representation must have the syntax of a |FunctionDeclaration|, |FunctionExpression|, |GeneratorDeclaration|, |GeneratorExpression|, |ClassDeclaration|, |ClassExpression|, |ArrowFunction|, |MethodDefinition|, or |GeneratorMethod| depending upon the actual characteristics of the object.
764 |
The use and placement of white space, line terminators, and semicolons within the representation String is implementation-dependent.
765 |
If the object was defined using ECMAScript code and the returned string representation is not in the form of a |MethodDefinition| or |GeneratorMethod| then the representation must be such that if the string is evaluated, using `eval` in a lexical context that is equivalent to the lexical context used to create the original object, it will result in a new functionally equivalent object. In that case the returned source code must not mention freely any variables that were not mentioned freely by the original function's source code, even if these “extra” names were originally in scope.
766 |
If the implementation cannot produce a source code string that meets these criteria then it must return a string for which `eval` will throw a *SyntaxError* exception.
767 |
768 |
769 |
770 |
771 |
772 | 1. If _func_ is a Bound Function exotic object or a built-in Function object, then return an implementation-dependent String source code representation of _func_. The representation must have the syntax of a |NativeFunction|. Additionally, if _func_ is a Well-known Intrinsic Object and is not identified as an anonymous function, the portion of the returned String that would be matched by |PropertyName| must be the initial value of the *name* property of _func_.
773 | 1. If _func_ has a [[SourceText]] internal slot and Type(_func_.[[SourceText]]) is String and ! HostHasSourceTextAvailable(_func_) is *true*, then return _func_.[[SourceText]].
774 | 1. If Type(_func_) is Object and IsCallable(_func_) is *true*, then return an implementation-dependent String source code representation of _func_. The representation must have the syntax of a |NativeFunction|.
775 | 1. Throw a *TypeError* exception.
776 |
777 |
778 |
779 | NativeFunction :
780 | `function` PropertyName[~Yield, ~Await]? `(` FormalParameters[~Yield, ~Await] `)` `{` `[` `native` `code` `]` `}`
781 |
782 |
783 |
784 |
--------------------------------------------------------------------------------
/publi.sh:
--------------------------------------------------------------------------------
1 | CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
2 | TEMP_BRANCH=$(date +%s.%N | md5sum | cut -d ' ' -f 1)
3 | if [ "$TRAVIS" == true ]; then
4 | CURRENT_BRANCH="$TRAVIS_BRANCH"
5 | echo "TRAVIS_SECURE_ENV_VARS=$TRAVIS_SECURE_ENV_VARS"
6 | echo "TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST"
7 | echo "TRAVIS_BRANCH=$TRAVIS_BRANCH"
8 | [ "$TRAVIS_SECURE_ENV_VARS" == true -a "$TRAVIS_PULL_REQUEST" == false -a "$TRAVIS_BRANCH" == master ] || exit 1
9 | [ -n "$encrypted_1cf5552cca3f_key" -a -n "$encrypted_1cf5552cca3f_iv" ] || (echo "Travis CI decryption keys not found"; exit 1)
10 | openssl aes-256-cbc -K "$encrypted_1cf5552cca3f_key" -iv "$encrypted_1cf5552cca3f_iv" -in github-deploy-key.enc -out github-deploy-key -d
11 | chmod 600 github-deploy-key
12 | eval "$(ssh-agent -s)"
13 | ssh-add github-deploy-key
14 | rm github-deploy-key
15 | git remote set-url --push origin "git@github.com:$TRAVIS_REPO_SLUG.git"
16 | git config --global user.email "contact@travis-ci.com"
17 | git config --global user.name "Travis CI"
18 | echo "Publishing to gh-pages"
19 | fi
20 | set -x
21 | git checkout --orphan "$TEMP_BRANCH"
22 | npm install
23 | make
24 | git reset .
25 | git add -f index.html
26 | git commit -m 'gh-pages'
27 | git push -f origin HEAD:gh-pages
28 | git checkout -f "$CURRENT_BRANCH"
29 | git branch -D "$TEMP_BRANCH"
30 |
--------------------------------------------------------------------------------