test_private_field_xrays.js (1103B)
1 'use strict'; 2 3 add_task(async function () { 4 let webnav = Services.appShell.createWindowlessBrowser(false); 5 6 let docShell = webnav.docShell; 7 8 docShell.createAboutBlankDocumentViewer(null, null); 9 10 let window = webnav.document.defaultView; 11 12 let iframe = window.eval(` 13 iframe = document.createElement("iframe"); 14 iframe.id = "iframe" 15 document.body.appendChild(iframe) 16 iframe`); 17 18 19 let unwrapped = Cu.waiveXrays(iframe); 20 21 22 class Base { 23 constructor(o) { 24 return o; 25 } 26 }; 27 28 29 class A extends Base { 30 #x = 12; 31 static gx(o) { 32 return o.#x; 33 } 34 35 static sx(o, v) { 36 o.#x = v; 37 } 38 }; 39 40 new A(iframe); 41 Assert.equal(A.gx(iframe), 12); 42 A.sx(iframe, 'wrapped'); 43 44 // Shouldn't tunnel past xray. 45 Assert.throws(() => A.gx(unwrapped), TypeError); 46 Assert.throws(() => A.sx(unwrapped, 'unwrapped'), TypeError); 47 48 new A(unwrapped); 49 Assert.equal(A.gx(unwrapped), 12); 50 Assert.equal(A.gx(iframe), 'wrapped'); 51 52 A.sx(iframe, 'modified'); 53 Assert.equal(A.gx(unwrapped), 12); 54 A.sx(unwrapped, 16); 55 Assert.equal(A.gx(iframe), 'modified'); 56 });