resolve-self.js (1307B)
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 reference to the promise itself 6 es6id: 25.4.4.5 7 info: | 8 1. Let C be the this value. 9 [...] 10 4. Let promiseCapability be NewPromiseCapability(C). 11 [...] 12 6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, 13 «x»). 14 [...] 15 16 25.4.1.3.2 Promise Resolve Functions 17 [...] 18 6. If SameValue(resolution, promise) is true, then 19 a. Let selfResolutionError be a newly created TypeError object. 20 b. Return RejectPromise(promise, selfResolutionError). 21 flags: [async] 22 ---*/ 23 24 var resolve, reject; 25 var promise = new Promise(function(_resolve, _reject) { 26 resolve = _resolve; 27 reject = _reject; 28 }); 29 var P = function(executor) { 30 executor(resolve, reject); 31 return promise; 32 }; 33 34 Promise.resolve.call(P, promise) 35 .then(function() { 36 $DONE('The promise should not be fulfilled.'); 37 }, function(value) { 38 if (!value) { 39 $DONE('The promise should be rejected with a value.'); 40 return; 41 } 42 if (value.constructor !== TypeError) { 43 $DONE('The promise should be rejected with a TypeError instance.'); 44 return; 45 } 46 47 $DONE(); 48 });