[await] Add async iterator tests for await optimization

These tests make sure the ticks are correct when resolving against a
Promise.

Without the optimization, the result is:
"start,tick 1,tick 2,tick 3,tick 4,done,tick 5"

With the optimization, the result is:
"start,tick 1,tick 2,done,tick 3,tick 4,tick 5"

Bug: v8:8267
Change-Id: I6c6499c7c256927531a99bab4ae1c5bd5069ef7c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1534884
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60615}
This commit is contained in:
Sathya Gunasekaran 2019-03-21 18:30:53 -07:00 committed by Commit Bot
parent 1022396074
commit 46e944dbad
3 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,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; },
next() {
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.next();
p.then(_ => { actual.push("done"); } );
%PerformMicrotaskCheckpoint();
assertSame("start,tick 1,tick 2,done,tick 3,tick 4,tick 5", actual.join(","))

View File

@ -0,0 +1,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(","))

View File

@ -0,0 +1,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; },
throw() {
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.throw();
p.then(_ => { actual.push("done"); } );
%PerformMicrotaskCheckpoint();
assertSame("start,tick 1,tick 2,done,tick 3,tick 4,tick 5", actual.join(","))