resolve-prms-cstm-then.js (1531B)
1 // |reftest| async 2 // Copyright (C) 2016 the V8 project authors. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 /*--- 5 description: Resolving with a resolved Promise instance whose `then` method has been overridden 6 es6id: 25.4.4.3 7 info: | 8 [...] 9 6. Let promiseCapability be NewPromiseCapability(C). 10 [...] 11 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C). 12 [...] 13 14 25.4.4.3.1 Runtime Semantics: PerformPromiseRace 15 1. Repeat 16 [...] 17 j. Let result be Invoke(nextPromise, "then", 18 «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»). 19 20 25.4.1.3.2 Promise Resolve Functions 21 [...] 22 8. Let then be Get(resolution, "then"). 23 9. If then is an abrupt completion, then 24 [...] 25 10. Let thenAction be then.[[value]]. 26 11. If IsCallable(thenAction) is false, then 27 [...] 28 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob, 29 «promise, resolution, thenAction») 30 flags: [async] 31 ---*/ 32 33 var value = {}; 34 var thenableValue = { 35 then: function(resolve) { 36 resolve(value); 37 } 38 }; 39 var thenable = new Promise(function(resolve) { 40 resolve(); 41 }); 42 43 thenable.then = function(resolve) { 44 resolve(thenableValue); 45 }; 46 47 Promise.race([thenable]) 48 .then(function(val) { 49 if (val !== value) { 50 $DONE('The promise should be resolved with the correct value.'); 51 return; 52 } 53 $DONE(); 54 }, function() { 55 $DONE('The promise should not be rejected.'); 56 });