js/xpconnect/tests/unit/test_bug868675.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/unit/test_bug868675.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,25 @@
     1.4 +const Cu = Components.utils;
     1.5 +function run_test() {
     1.6 +
     1.7 +  // Make sure we don't throw for primitive values.
     1.8 +  var result = "threw";
     1.9 +  try { result = XPCNativeWrapper.unwrap(2); } catch (e) {}
    1.10 +  do_check_eq(result, 2);
    1.11 +  result = "threw";
    1.12 +  try { result = XPCNativeWrapper(2); } catch (e) {}
    1.13 +  do_check_eq(result, 2);
    1.14 +
    1.15 +  // Make sure that we can waive on a non-Xrayable object, and that we preserve
    1.16 +  // transitive waiving behavior.
    1.17 +  var sb = new Cu.Sandbox('http://www.example.com', { wantGlobalProperties: ["XMLHttpRequest"] });
    1.18 +  Cu.evalInSandbox('this.xhr = new XMLHttpRequest();', sb);
    1.19 +  Cu.evalInSandbox('this.jsobj = {mynative: xhr};', sb);
    1.20 +  do_check_true(!Cu.isXrayWrapper(XPCNativeWrapper.unwrap(sb.xhr)));
    1.21 +  do_check_true(Cu.isXrayWrapper(sb.jsobj.mynative));
    1.22 +  do_check_true(!Cu.isXrayWrapper(XPCNativeWrapper.unwrap(sb.jsobj).mynative));
    1.23 +
    1.24 +  // Test the new Cu API.
    1.25 +  var waived = Cu.waiveXrays(sb.xhr);
    1.26 +  do_check_true(!Cu.isXrayWrapper(waived));
    1.27 +  do_check_true(Cu.isXrayWrapper(Cu.unwaiveXrays(waived)));
    1.28 +}

mercurial