tor-browser

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

await-non-promise-thenable.js (1284B)


      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 let thenCallCount = 0;
     17 
     18 const actual = [];
     19 const expected = [
     20  'Promise: 1',
     21  'Promise: 2',
     22  'Await: 1',
     23  'Promise: 3',
     24  'Promise: 4',
     25  'Await: 2',
     26 ];
     27 
     28 const patched = {};
     29 patched.then = function(fulfill, reject) {
     30  thenCallCount++;
     31  fulfill(thenCallCount);
     32 };
     33 
     34 async function trigger() {
     35  actual.push('Await: ' + await patched);
     36  actual.push('Await: ' + await patched);
     37 }
     38 
     39 function checkAssertions() {
     40  assert.compareArray(actual, expected,
     41    'Async/await and promises should be interleaved');
     42  assert.sameValue(thenCallCount, 2,
     43    '"then" on non-native promises should be called.');
     44 }
     45 
     46 trigger().then(checkAssertions).then($DONE, $DONE);
     47 
     48 new Promise(function (resolve) {
     49  actual.push('Promise: 1');
     50  resolve();
     51 }).then(function () {
     52  actual.push('Promise: 2');
     53 }).then(function () {
     54  actual.push('Promise: 3');
     55 }).then(function () {
     56  actual.push('Promise: 4');
     57 });