summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/harmony/async-from-sync-iterator-return-tick-count.js
blob: c4c5f8dc5209a6979eba747f29778f5b7bc18e21 (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
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --allow-natives-syntax

const actual = [];

function createIterator() {
  return {
    [Symbol.iterator]() { return this; },

    return() {
      return { value: Promise.resolve(1), done: true};
    }
  };
}

actual.push("start");
iter = %CreateAsyncFromSyncIterator(createIterator());

Promise.resolve(0)
  .then(() => actual.push("tick 1"))
  .then(() => actual.push("tick 2"))
  .then(() => actual.push("tick 3"))
  .then(() => actual.push("tick 4"))
  .then(() => actual.push("tick 5"));

let p = iter.return();
p.then(_ => { actual.push("done"); } );

%PerformMicrotaskCheckpoint();
assertSame("start,tick 1,tick 2,done,tick 3,tick 4,tick 5", actual.join(","))