test_objectgrips-nested-promise.js (1958B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true); 7 registerCleanupFunction(() => { 8 Services.prefs.clearUserPref("security.allow_eval_with_system_principal"); 9 }); 10 11 add_task( 12 threadFrontTest(async ({ threadFront, debuggee }) => { 13 const packet = await executeOnNextTickAndWaitForPause( 14 () => evalCode(debuggee), 15 threadFront 16 ); 17 18 const [grip1, grip2] = packet.frame.arguments; 19 strictEqual(grip1.class, "Promise", "promise1 has a promise grip."); 20 strictEqual(grip2.class, "Promise", "promise2 has a promise grip."); 21 22 const objClient1 = threadFront.pauseGrip(grip1); 23 const objClient2 = threadFront.pauseGrip(grip2); 24 const { promiseState: state1 } = await objClient1.getPromiseState(); 25 const { promiseState: state2 } = await objClient2.getPromiseState(); 26 27 strictEqual(state1.state, "fulfilled", "promise1 was fulfilled."); 28 strictEqual(state1.value, objClient2, "promise1 fulfilled with promise2."); 29 ok(!state1.hasOwnProperty("reason"), "promise1 has no rejection reason."); 30 31 strictEqual(state2.state, "rejected", "promise2 was rejected."); 32 strictEqual(state2.reason, objClient1, "promise2 rejected with promise1."); 33 ok(!state2.hasOwnProperty("value"), "promise2 has no resolution value."); 34 35 await threadFront.resume(); 36 }) 37 ); 38 39 function evalCode(debuggee) { 40 debuggee.eval( 41 // These arguments are tested. 42 // eslint-disable-next-line no-unused-vars 43 function stopMe(arg) { 44 debugger; 45 }.toString() 46 ); 47 48 debuggee.eval(` 49 var resolve; 50 var promise1 = new Promise(r => {resolve = r}); 51 Object.setPrototypeOf(promise1, null); 52 var promise2 = Promise.reject(promise1); 53 promise2.catch(() => {}); 54 Object.setPrototypeOf(promise2, null); 55 resolve(promise2); 56 stopMe(promise1, promise2); 57 `); 58 }