michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Cu = Components.utils; michael@0: const Ci = Components.interfaces; michael@0: michael@0: "use strict"; michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: var gGlobal = this; michael@0: function checkGlobal(obj) { michael@0: if (Object(obj) === obj && Cu.getGlobalForObject(obj) != gGlobal) { michael@0: // This message may not make it to the caller in a useful form, so dump michael@0: // as well. michael@0: var msg = "TestInterfaceJS received an object from a different scope!"; michael@0: dump(msg + "\n"); michael@0: throw new Error(msg); michael@0: } michael@0: } michael@0: michael@0: function TestInterfaceJS(anyArg, objectArg) {} michael@0: michael@0: TestInterfaceJS.prototype = { michael@0: classID: Components.ID("{2ac4e026-cf25-47d5-b067-78d553c3cad8}"), michael@0: contractID: "@mozilla.org/dom/test-interface-js;1", michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]), michael@0: michael@0: __init: function (anyArg, objectArg) { michael@0: this._anyAttr = undefined; michael@0: this._objectAttr = null; michael@0: this._anyArg = anyArg; michael@0: this._objectArg = objectArg; michael@0: checkGlobal(anyArg); michael@0: checkGlobal(objectArg); michael@0: }, michael@0: michael@0: get anyArg() { return this._anyArg; }, michael@0: get objectArg() { return this._objectArg; }, michael@0: get anyAttr() { return this._anyAttr; }, michael@0: set anyAttr(val) { checkGlobal(val); this._anyAttr = val; }, michael@0: get objectAttr() { return this._objectAttr; }, michael@0: set objectAttr(val) { checkGlobal(val); this._objectAttr = val; }, michael@0: pingPongAny: function(any) { checkGlobal(any); return any; }, michael@0: pingPongObject: function(obj) { checkGlobal(obj); return obj; }, michael@0: michael@0: getCallerPrincipal: function() { return Cu.getWebIDLCallerPrincipal().origin; } michael@0: }; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestInterfaceJS])