Debian Codegraph @

js/src/tests/test262/built-ins/AsyncGeneratorFunction/instance-await-expr-in-param.js

raw
1 // |reftest| async
2 // Copyright (C) 2018 Valerie Young. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-asyncgeneratorfunction
6 description: Definition of instance `length` property
7 info: |
8 AsyncGeneratorFunction ( p1, p2, … , pn, body )
9 ...
10 3. Return CreateDynamicFunction(C, NewTarget, "async generator", args).
11
12 Runtime Semantics: CreateDynamicFunction
13 ...
14 29. If kind is "async" or "async generator", then
15 a. If parameters Contains AwaitExpression is true, throw a SyntaxError
16 exception.
17 features: [async-iteration]
18 flags: [async]
19 ---*/
20
21 var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor;
22
23 // AwaitExpression is permitted in function body.
24 AsyncGeneratorFunction('x = await 42');
25
26 assert.throws(SyntaxError, function() {
27 AsyncGeneratorFunction('x = await 42', '');
28 }, 'AwaitExpression not permitted in parameters');
29
30 var withinAsyncGenerator = async function*() {
31 AsyncGeneratorFunction('x = await 42', '');
32 };
33
34 withinAsyncGenerator().next().then(
35 function () {
36 throw new Test262Error("AwaitExpression not permitted when calling context is a async generator");
37 },
38 function (e) {
39 if (!(e instanceof SyntaxError)) {
40 throw new Test262Error("Expected SyntaxError but got " + e);
41 }
42 }
43 ).then($DONE, $DONE);