test_makeGlobalObjectReference.html (3642B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=914405 5 6 Debugger.prototype.makeGlobalObjectReference should dereference WindowProxy 7 (outer window) objects. 8 --> 9 <head> 10 <meta charset="utf-8"> 11 <title>Mozilla Bug 914405</title> 12 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 13 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 14 </head> 15 <body> 16 <pre id="test"> 17 <script> 18 "use strict"; 19 20 const {addSandboxedDebuggerToGlobal} = ChromeUtils.importESModule("resource://gre/modules/jsdebugger.sys.mjs"); 21 addSandboxedDebuggerToGlobal(globalThis); 22 23 window.onload = function() { 24 SimpleTest.waitForExplicitFinish(); 25 26 // Load one of our iframes over http to force it in a different compartment 27 // from the current window and the other iframe. 28 const iframe = document.createElement("iframe"); 29 const baseURL = "http://mochi.test:8888/chrome/devtools/server/tests/chrome/"; 30 iframe.src = baseURL + "iframe1_makeGlobalObjectReference.html"; 31 iframe.onload = iframeOnLoad; 32 document.body.appendChild(iframe); 33 34 function iframeOnLoad() { 35 const dbg = new Debugger(); 36 37 // 'o' for 'outer window' 38 const g1o = iframe.contentWindow; 39 ok(!dbg.hasDebuggee(g1o), "iframe is not initially a debuggee"); 40 41 // Like addDebuggee, makeGlobalObjectReference innerizes. 42 // 'i' stands for 'inner window'. 43 // 'DO' stands for 'Debugger.Object'. 44 const g1iDO = dbg.makeGlobalObjectReference(g1o); 45 ok(!dbg.hasDebuggee(g1o), 46 "makeGlobalObjectReference does not add g1 as debuggee, designated via outer"); 47 ok(!dbg.hasDebuggee(g1iDO), 48 "makeGlobalObjectReference does not add g1 as debuggee, designated via D.O "); 49 50 // Wrapping an object automatically outerizes it, so dereferencing an 51 // inner object D.O gets you an outer object. 52 // ('===' does distinguish inner and outer objects.) 53 // (That's a capital '=', if you must know.) 54 ok(g1iDO.unsafeDereference() === g1o, "g1iDO has the right referent"); 55 56 // However, Debugger.Objects do distinguish inner and outer windows. 57 const g1oDO = g1iDO.makeDebuggeeValue(g1o); 58 ok(g1iDO !== g1oDO, "makeDebuggeeValue doesn't innerize"); 59 ok(g1iDO.unsafeDereference() === g1oDO.unsafeDereference(), 60 "unsafeDereference() outerizes," + 61 " so inner and outer window D.Os both dereference to outer"); 62 63 ok(dbg.addDebuggee(g1o) === g1iDO, "addDebuggee returns the inner window's D.O"); 64 ok(dbg.hasDebuggee(g1o), "addDebuggee adds the correct global"); 65 ok(dbg.hasDebuggee(g1iDO), 66 "hasDebuggee can take a D.O referring to the inner window"); 67 ok(dbg.hasDebuggee(g1oDO), 68 "hasDebuggee can take a D.O referring to the outer window"); 69 70 const iframe2 = document.createElement("iframe"); 71 iframe2.src = "iframe2_makeGlobalObjectReference.html"; 72 iframe2.onload = iframe2OnLoad; 73 document.body.appendChild(iframe2); 74 75 function iframe2OnLoad() { 76 // makeGlobalObjectReference dereferences CCWs. 77 const g2o = iframe2.contentWindow; 78 g2o.g1o = g1o; 79 80 const g2iDO = dbg.addDebuggee(g2o); 81 const g2g1oDO = g2iDO.getOwnPropertyDescriptor("g1o").value; 82 ok(g2g1oDO !== g1oDO, "g2's cross-compartment wrapper for g1o gets its own D.O"); 83 ok(g2g1oDO.unwrap() === g1oDO, 84 "unwrapping g2's cross-compartment wrapper for g1o gets the right D.O"); 85 ok(dbg.makeGlobalObjectReference(g2g1oDO) === g1iDO, 86 "makeGlobalObjectReference unwraps cross-compartment wrappers, and innerizes"); 87 88 SimpleTest.finish(); 89 } 90 } 91 }; 92 93 </script> 94 </pre> 95 </body> 96 </html>