michael@0: const Cu = Components.utils; michael@0: function run_test() { michael@0: michael@0: // Make sure we don't throw for primitive values. michael@0: var result = "threw"; michael@0: try { result = XPCNativeWrapper.unwrap(2); } catch (e) {} michael@0: do_check_eq(result, 2); michael@0: result = "threw"; michael@0: try { result = XPCNativeWrapper(2); } catch (e) {} michael@0: do_check_eq(result, 2); michael@0: michael@0: // Make sure that we can waive on a non-Xrayable object, and that we preserve michael@0: // transitive waiving behavior. michael@0: var sb = new Cu.Sandbox('http://www.example.com', { wantGlobalProperties: ["XMLHttpRequest"] }); michael@0: Cu.evalInSandbox('this.xhr = new XMLHttpRequest();', sb); michael@0: Cu.evalInSandbox('this.jsobj = {mynative: xhr};', sb); michael@0: do_check_true(!Cu.isXrayWrapper(XPCNativeWrapper.unwrap(sb.xhr))); michael@0: do_check_true(Cu.isXrayWrapper(sb.jsobj.mynative)); michael@0: do_check_true(!Cu.isXrayWrapper(XPCNativeWrapper.unwrap(sb.jsobj).mynative)); michael@0: michael@0: // Test the new Cu API. michael@0: var waived = Cu.waiveXrays(sb.xhr); michael@0: do_check_true(!Cu.isXrayWrapper(waived)); michael@0: do_check_true(Cu.isXrayWrapper(Cu.unwaiveXrays(waived))); michael@0: }