tor-browser

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

invoke-resolve.js (1265B)


      1 // Copyright (C) 2015 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: >
      6    Invocation of the constructor's `resolve` method
      7 es6id: 25.4.4.3
      8 info: |
      9    11. Let result be PerformPromiseRace(iteratorRecord, C, promiseCapability).
     10 
     11    [...]
     12 
     13    25.4.4.3.1 Runtime Semantics: PerformPromiseRace
     14 
     15    1. Repeat
     16        [...]
     17        h. Let nextPromise be Invoke(C, "resolve", «nextValue»).
     18 ---*/
     19 
     20 var p1 = new Promise(function() {});
     21 var p2 = new Promise(function() {});
     22 var p3 = new Promise(function() {});
     23 var resolve = Promise.resolve;
     24 var callCount = 0;
     25 var current = p1;
     26 var next = p2;
     27 var afterNext = p3;
     28 
     29 Promise.resolve = function(nextValue) {
     30  assert.sameValue(
     31    nextValue, current, '`resolve` invoked with next iterated value'
     32  );
     33  assert.sameValue(
     34    arguments.length, 1, '`resolve` invoked with a single argument'
     35  );
     36  assert.sameValue(this, Promise, '`this` value set to the constructor');
     37 
     38  current = next;
     39  next = afterNext;
     40  afterNext = null;
     41 
     42  callCount += 1;
     43 
     44  return resolve.apply(Promise, arguments);
     45 };
     46 
     47 Promise.race([p1, p2, p3]);
     48 
     49 assert.sameValue(
     50  callCount, 3, '`resolve` invoked once for each iterated value'
     51 );
     52 
     53 reportCompare(0, 0);