blob: 2f668fd36d9cfe91c17f6221125b3b8cc444800a (
plain)
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
|
// |reftest| async
// Copyright 2019 Google, LLC. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: prod-OptionalExpression
description: >
optional chain RHS of for await statement
info: |
IterationStatement
for await (LeftHandSideExpression of AssignmentExpression) Statement
features: [optional-chaining]
flags: [async]
---*/
const obj = {
iterable: {
[Symbol.asyncIterator]() {
return {
i: 0,
next() {
if (this.i < 3) {
return Promise.resolve({ value: this.i++, done: false });
}
return Promise.resolve({ done: true });
}
};
}
}
};
async function checkAssertions() {
let count = 0;
for await (const num of obj?.iterable) {
count += num;
}
assert.sameValue(3, count);
}
checkAssertions().then($DONE, $DONE);
|