diff options
author | Michaël Zasso <targos@protonmail.com> | 2018-12-04 08:20:37 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2018-12-06 15:23:33 +0100 |
commit | 9b4bf7de6c9a7c25f116c7a502384c20b5cfaea3 (patch) | |
tree | 2b0c843168dafb939d8df8a15b2aa72b76dee51d /deps/v8/test/mjsunit/harmony/async-await-optimization.js | |
parent | b8fbe69db1292307adb2c2b2e0d5ef48c4ab2faf (diff) | |
download | android-node-v8-9b4bf7de6c9a7c25f116c7a502384c20b5cfaea3.tar.gz android-node-v8-9b4bf7de6c9a7c25f116c7a502384c20b5cfaea3.tar.bz2 android-node-v8-9b4bf7de6c9a7c25f116c7a502384c20b5cfaea3.zip |
deps: update V8 to 7.1.302.28
PR-URL: https://github.com/nodejs/node/pull/23423
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'deps/v8/test/mjsunit/harmony/async-await-optimization.js')
-rw-r--r-- | deps/v8/test/mjsunit/harmony/async-await-optimization.js | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/deps/v8/test/mjsunit/harmony/async-await-optimization.js b/deps/v8/test/mjsunit/harmony/async-await-optimization.js new file mode 100644 index 0000000000..b24e541916 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/async-await-optimization.js @@ -0,0 +1,124 @@ +// Copyright 2018 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: --harmony-await-optimization + +// test basic interleaving +(function () { + const actual = []; + const expected = [ 'await', 1, 'await', 2 ]; + const iterations = 2; + + async function pushAwait() { + actual.push('await'); + } + + async function callAsync() { + for (let i = 0; i < iterations; i++) { + await pushAwait(); + } + return 0; + } + + function checkAssertions() { + assertArrayEquals(expected, actual, + 'Async/await and promises should be interleaved.'); + } + + assertPromiseResult((async() => { + callAsync(); + + return new Promise(function (resolve) { + actual.push(1); + resolve(); + }).then(function () { + actual.push(2); + }).then(checkAssertions); + })()); +})(); + +// test async generators +(function () { + const actual = []; + const expected = [ 'await', 1, 'await', 2 ]; + const iterations = 2; + + async function pushAwait() { + actual.push('await'); + } + + async function* callAsync() { + for (let i = 0; i < iterations; i++) { + await pushAwait(); + } + return 0; + } + + function checkAssertions() { + assertArrayEquals(expected, actual, + 'Async/await and promises should be interleaved when using async generators.'); + } + + assertPromiseResult((async() => { + callAsync().next(); + + return new Promise(function (resolve) { + actual.push(1); + resolve(); + }).then(function () { + actual.push(2); + }).then(checkAssertions); + })()); +})(); + +// test yielding from async generators +(function () { + const actual = []; + const expected = [ + 'Promise: 6', + 'Promise: 5', + 'Await: 3', + 'Promise: 4', + 'Promise: 3', + 'Await: 2', + 'Promise: 2', + 'Promise: 1', + 'Await: 1', + 'Promise: 0' + ]; + const iterations = 3; + + async function* naturalNumbers(start) { + let current = start; + while (current > 0) { + yield Promise.resolve(current--); + } + } + + async function trigger() { + for await (const num of naturalNumbers(iterations)) { + actual.push('Await: ' + num); + } + } + + async function checkAssertions() { + assertArrayEquals(expected, actual, + 'Async/await and promises should be interleaved when yielding.'); + } + + async function countdown(counter) { + actual.push('Promise: ' + counter); + if (counter > 0) { + return Promise.resolve(counter - 1).then(countdown); + } else { + await checkAssertions(); + } + } + + assertPromiseResult((async() => { + trigger(); + + return countdown(iterations * 2); + })()); +})(); |