tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

iteration-statement-for-await-of.js (893B)


      1 // |reftest| async
      2 // Copyright 2019 Google, LLC.  All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 /*---
      5 esid: prod-OptionalExpression
      6 description: >
      7  optional chain RHS of for await statement
      8 info: |
      9  IterationStatement
     10    for await (LeftHandSideExpression of AssignmentExpression) Statement
     11 features: [optional-chaining]
     12 flags: [async]
     13 includes: [asyncHelpers.js]
     14 ---*/
     15 const obj = {
     16  iterable: {
     17    [Symbol.asyncIterator]() {
     18      return {
     19        i: 0,
     20        next() {
     21          if (this.i < 3) {
     22            return Promise.resolve({ value: this.i++, done: false });
     23          }
     24          return Promise.resolve({ done: true });
     25        }
     26      };
     27    }
     28  }
     29 };
     30 async function checkAssertions() {
     31  let count = 0;
     32  for await (const num of obj?.iterable) {
     33    count += num;
     34  }
     35  assert.sameValue(3, count);
     36 }
     37 asyncTest(checkAssertions);