await-non-promise.js (940B)
1 // |reftest| async 2 // Copyright 2018 the V8 project authors. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 author: Maya Lekova <mslekova@chromium.org> 7 esid: await 8 description: > 9 This test demonstrates that "then" on a non-native promise 10 will still get called. 11 flags: [async] 12 features: [async-functions] 13 includes: [compareArray.js] 14 ---*/ 15 16 const value = 1; 17 18 const actual = []; 19 const expected = [ 20 'Await: 1', 21 'Promise: 1', 22 'Promise: 2', 23 ]; 24 25 function pushAwaitSync(value) { 26 actual.push('Await: ' + value); 27 } 28 29 async function trigger() { 30 await pushAwaitSync(value); 31 } 32 33 function checkAssertions() { 34 assert.compareArray(actual, expected, 35 'Async/await and promises should be interleaved'); 36 } 37 38 trigger().then(checkAssertions).then($DONE, $DONE); 39 40 new Promise(function (resolve) { 41 actual.push('Promise: 1'); 42 resolve(); 43 }).then(function () { 44 actual.push('Promise: 2'); 45 });