invoke-then.js (1526B)
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 instance's `then` method 7 es6id: 25.4.4.1 8 info: | 9 11. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability). 10 11 [...] 12 13 25.4.4.1.1 Runtime Semantics: PerformPromiseAll 14 15 [...] 16 6. Repeat 17 [...] 18 r. Let result be Invoke(nextPromise, "then", «resolveElement, 19 resultCapability.[[Reject]]»). 20 ---*/ 21 22 var p1 = new Promise(function() {}); 23 var p2 = new Promise(function() {}); 24 var p3 = new Promise(function() {}); 25 var callCount = 0; 26 var currentThis = p1; 27 var nextThis = p2; 28 var afterNextThis = p3; 29 30 p1.then = p2.then = p3.then = function(a, b) { 31 assert.sameValue(typeof a, 'function', 'type of first argument'); 32 assert.sameValue( 33 a.length, 34 1, 35 'ES6 25.4.1.3.2: The length property of a promise resolve function is 1.' 36 ); 37 assert.sameValue(typeof b, 'function', 'type of second argument'); 38 assert.sameValue( 39 b.length, 40 1, 41 'ES6 25.4.1.3.1: The length property of a promise reject function is 1.' 42 ); 43 assert.sameValue(arguments.length, 2, '`then` invoked with two arguments'); 44 assert.sameValue(this, currentThis, '`this` value'); 45 46 currentThis = nextThis; 47 nextThis = afterNextThis; 48 afterNextThis = null; 49 50 callCount += 1; 51 }; 52 53 Promise.all([p1, p2, p3]); 54 55 assert.sameValue(callCount, 3, '`then` invoked once for every iterated value'); 56 57 reportCompare(0, 0);