resolve-prms-cstm-then.js (1153B)
1 // Copyright (C) 2016 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 description: Resolving with a resolved Promise instance whose `then` method has been overridden 5 es6id: 25.4.4.5 6 info: | 7 [...] 8 6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, 9 «x»). 10 [...] 11 12 25.4.1.3.2 Promise Resolve Functions 13 [...] 14 8. Let then be Get(resolution, "then"). 15 9. If then is an abrupt completion, then 16 [...] 17 10. Let thenAction be then.[[value]]. 18 11. If IsCallable(thenAction) is false, then 19 [...] 20 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob, 21 «promise, resolution, thenAction») 22 ---*/ 23 24 var value = {}; 25 var rejectCallCount = 0; 26 var thenable = new Promise(function(resolve) { 27 resolve(); 28 }); 29 var resolvedValue; 30 31 thenable.then = function(resolve) { 32 resolve(value); 33 }; 34 35 Promise.resolve(thenable).then(function(val) { 36 resolvedValue = val; 37 }, function() { 38 rejectCallCount += 1; 39 }); 40 41 assert.sameValue(resolvedValue, value); 42 assert.sameValue(rejectCallCount, 0); 43 44 reportCompare(0, 0);