michael@0: const Cu = Components.utils; michael@0: function run_test() { michael@0: michael@0: // Make a content sandbox with an Xrayable object. michael@0: // NB: We use an nsEP here so that we can have access to Components, but still michael@0: // have Xray behavior from this scope. michael@0: var contentSB = new Cu.Sandbox(['http://www.google.com'], michael@0: { wantGlobalProperties: ["XMLHttpRequest"], wantComponents: true }); michael@0: michael@0: // Make an XHR in the content sandbox. michael@0: Cu.evalInSandbox('xhr = new XMLHttpRequest();', contentSB); michael@0: michael@0: // Make sure that waivers can be set as Xray expandos. michael@0: var xhr = contentSB.xhr; michael@0: do_check_true(Cu.isXrayWrapper(xhr)); michael@0: xhr.unwaivedExpando = xhr; michael@0: do_check_true(Cu.isXrayWrapper(xhr.unwaivedExpando)); michael@0: var waived = xhr.wrappedJSObject; michael@0: do_check_true(!Cu.isXrayWrapper(waived)); michael@0: xhr.waivedExpando = waived; michael@0: do_check_true(!Cu.isXrayWrapper(xhr.waivedExpando)); michael@0: michael@0: // Try the same thing for getters/setters, even though that's kind of michael@0: // contrived. michael@0: Cu.evalInSandbox('function f() {}', contentSB); michael@0: var f = contentSB.f; michael@0: var fWaiver = Cu.waiveXrays(f); michael@0: do_check_true(f != fWaiver); michael@0: do_check_true(Cu.unwaiveXrays(fWaiver) === f); michael@0: Object.defineProperty(xhr, 'waivedAccessors', {get: fWaiver, set: fWaiver}); michael@0: var desc = Object.getOwnPropertyDescriptor(xhr, 'waivedAccessors'); michael@0: do_check_true(desc.get === fWaiver); michael@0: do_check_true(desc.set === fWaiver); michael@0: michael@0: // Make sure we correctly handle same-compartment security wrappers. michael@0: var unwaivedC = contentSB.Components; michael@0: do_check_true(Cu.isXrayWrapper(unwaivedC)); michael@0: var waivedC = unwaivedC.wrappedJSObject; michael@0: do_check_true(waivedC && unwaivedC && (waivedC != unwaivedC)); michael@0: xhr.waivedC = waivedC; michael@0: do_check_true(xhr.waivedC === waivedC); michael@0: do_check_true(Cu.unwaiveXrays(xhr.waivedC) === unwaivedC); michael@0: }