Promise-race-dependent-promises.js (1452B)
1 // Promise.race(...) may add a dummy PromiseReaction which is only used for the 2 // debugger. 3 // 4 // See BlockOnPromise when called from PerformPromiseRace for when this dummy 5 // reaction is created. 6 7 var g = newGlobal({newCompartment: true}); 8 var dbg = new Debugger(); 9 var gw = dbg.addDebuggee(g); 10 11 function test(withFastPath) { 12 g.eval(` 13 function newPromiseCapability() { 14 var resolve, reject, promise = new Promise(function(r1, r2) { 15 resolve = r1; 16 reject = r2; 17 }); 18 return {promise, resolve, reject}; 19 } 20 21 var {promise: alwaysPending} = newPromiseCapability(); 22 23 if (!${withFastPath}) { 24 // Disable the BlockOnPromise fast path by giving |alwaysPending| a 25 // non-default "then" function property. This will ensure the dummy 26 // reaction is created. 27 alwaysPending.then = function() {}; 28 } 29 30 var result = Promise.race([alwaysPending]); 31 `); 32 33 var alwaysPending = gw.makeDebuggeeValue(g.alwaysPending); 34 var result = gw.makeDebuggeeValue(g.result); 35 36 assertEq(alwaysPending.promiseDependentPromises.length, 1); 37 assertEq(alwaysPending.promiseDependentPromises[0], result); 38 39 assertEq(result.promiseDependentPromises.length, 0); 40 } 41 42 // No dummy reaction created when the fast path is taken. 43 test(true); 44 45 // Dummy reaction is created when we can't take the fast path. 46 test(false);