resolve-self.js (1497B)
1 // |reftest| async 2 // Copyright (C) 2015 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.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 6. If SameValue(resolution, promise) is true, then 23 a. Let selfResolutionError be a newly created TypeError object. 24 b. Return RejectPromise(promise, selfResolutionError). 25 flags: [async] 26 ---*/ 27 28 var self, resolve; 29 var builtinResolve = Promise.resolve; 30 var thenable = { 31 then: function(r) { 32 resolve = r; 33 } 34 }; 35 36 try { 37 Promise.resolve = function(v) { 38 return v; 39 }; 40 self = Promise.race([thenable]); 41 } finally { 42 Promise.resolve = builtinResolve; 43 } 44 45 resolve(self); 46 47 self.then(function() { 48 $DONE('The promise should not be fulfilled.'); 49 }, function(value) { 50 if (!value) { 51 $DONE('The promise should be rejected with a value.'); 52 return; 53 } 54 if (value.constructor !== TypeError) { 55 $DONE('The promise should be rejected with a TypeError instance.'); 56 return; 57 } 58 $DONE(); 59 });