js/xpconnect/tests/unit/test_bug872772.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 const Cu = Components.utils;
     2 function run_test() {
     4   // Make a content sandbox with an Xrayable object.
     5   // NB: We use an nsEP here so that we can have access to Components, but still
     6   // have Xray behavior from this scope.
     7   var contentSB = new Cu.Sandbox(['http://www.google.com'],
     8                                  { wantGlobalProperties: ["XMLHttpRequest"], wantComponents: true });
    10   // Make an XHR in the content sandbox.
    11   Cu.evalInSandbox('xhr = new XMLHttpRequest();', contentSB);
    13   // Make sure that waivers can be set as Xray expandos.
    14   var xhr = contentSB.xhr;
    15   do_check_true(Cu.isXrayWrapper(xhr));
    16   xhr.unwaivedExpando = xhr;
    17   do_check_true(Cu.isXrayWrapper(xhr.unwaivedExpando));
    18   var waived = xhr.wrappedJSObject;
    19   do_check_true(!Cu.isXrayWrapper(waived));
    20   xhr.waivedExpando = waived;
    21   do_check_true(!Cu.isXrayWrapper(xhr.waivedExpando));
    23   // Try the same thing for getters/setters, even though that's kind of
    24   // contrived.
    25   Cu.evalInSandbox('function f() {}', contentSB);
    26   var f = contentSB.f;
    27   var fWaiver = Cu.waiveXrays(f);
    28   do_check_true(f != fWaiver);
    29   do_check_true(Cu.unwaiveXrays(fWaiver) === f);
    30   Object.defineProperty(xhr, 'waivedAccessors', {get: fWaiver, set: fWaiver});
    31   var desc = Object.getOwnPropertyDescriptor(xhr, 'waivedAccessors');
    32   do_check_true(desc.get === fWaiver);
    33   do_check_true(desc.set === fWaiver);
    35   // Make sure we correctly handle same-compartment security wrappers.
    36   var unwaivedC = contentSB.Components;
    37   do_check_true(Cu.isXrayWrapper(unwaivedC));
    38   var waivedC = unwaivedC.wrappedJSObject;
    39   do_check_true(waivedC && unwaivedC && (waivedC != unwaivedC));
    40   xhr.waivedC = waivedC;
    41   do_check_true(xhr.waivedC === waivedC);
    42   do_check_true(Cu.unwaiveXrays(xhr.waivedC) === unwaivedC);
    43 }

mercurial