tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug868675.js (1156B)


      1 function run_test() {
      2 
      3  // Make sure we don't throw for primitive values.
      4  var result = "threw";
      5  try { result = XPCNativeWrapper.unwrap(2); } catch (e) {}
      6  Assert.equal(result, 2);
      7  result = "threw";
      8  try { result = XPCNativeWrapper(2); } catch (e) {}
      9  Assert.equal(result, 2);
     10 
     11  // Make sure we throw when using `new` with primitives.
     12  result = null;
     13  try { result = new XPCNativeWrapper(2); } catch (e) { result = "catch"; }
     14  Assert.equal(result, "catch");
     15 
     16  // Make sure that we can waive on a non-Xrayable object, and that we preserve
     17  // transitive waiving behavior.
     18  var sb = new Cu.Sandbox('http://www.example.com', { wantGlobalProperties: ["XMLHttpRequest"] });
     19  Cu.evalInSandbox('this.xhr = new XMLHttpRequest();', sb);
     20  Cu.evalInSandbox('this.jsobj = {mynative: xhr};', sb);
     21  Assert.ok(!Cu.isXrayWrapper(XPCNativeWrapper.unwrap(sb.xhr)));
     22  Assert.ok(Cu.isXrayWrapper(sb.jsobj.mynative));
     23  Assert.ok(!Cu.isXrayWrapper(XPCNativeWrapper.unwrap(sb.jsobj).mynative));
     24 
     25  // Test the new Cu API.
     26  var waived = Cu.waiveXrays(sb.xhr);
     27  Assert.ok(!Cu.isXrayWrapper(waived));
     28  Assert.ok(Cu.isXrayWrapper(Cu.unwaiveXrays(waived)));
     29 }