summaryrefslogtreecommitdiff
path: root/test/language/expressions/optional-chaining/iteration-statement-for-await-of.js
blob: 6d414965ab7bff795453bbdd5ec503bee4e01949 (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
// 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);