|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 const Cu = Components.utils; |
|
6 const Ci = Components.interfaces; |
|
7 |
|
8 "use strict"; |
|
9 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
10 Cu.import("resource://gre/modules/Services.jsm"); |
|
11 |
|
12 var gGlobal = this; |
|
13 function checkGlobal(obj) { |
|
14 if (Object(obj) === obj && Cu.getGlobalForObject(obj) != gGlobal) { |
|
15 // This message may not make it to the caller in a useful form, so dump |
|
16 // as well. |
|
17 var msg = "TestInterfaceJS received an object from a different scope!"; |
|
18 dump(msg + "\n"); |
|
19 throw new Error(msg); |
|
20 } |
|
21 } |
|
22 |
|
23 function TestInterfaceJS(anyArg, objectArg) {} |
|
24 |
|
25 TestInterfaceJS.prototype = { |
|
26 classID: Components.ID("{2ac4e026-cf25-47d5-b067-78d553c3cad8}"), |
|
27 contractID: "@mozilla.org/dom/test-interface-js;1", |
|
28 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]), |
|
29 |
|
30 __init: function (anyArg, objectArg) { |
|
31 this._anyAttr = undefined; |
|
32 this._objectAttr = null; |
|
33 this._anyArg = anyArg; |
|
34 this._objectArg = objectArg; |
|
35 checkGlobal(anyArg); |
|
36 checkGlobal(objectArg); |
|
37 }, |
|
38 |
|
39 get anyArg() { return this._anyArg; }, |
|
40 get objectArg() { return this._objectArg; }, |
|
41 get anyAttr() { return this._anyAttr; }, |
|
42 set anyAttr(val) { checkGlobal(val); this._anyAttr = val; }, |
|
43 get objectAttr() { return this._objectAttr; }, |
|
44 set objectAttr(val) { checkGlobal(val); this._objectAttr = val; }, |
|
45 pingPongAny: function(any) { checkGlobal(any); return any; }, |
|
46 pingPongObject: function(obj) { checkGlobal(obj); return obj; }, |
|
47 |
|
48 getCallerPrincipal: function() { return Cu.getWebIDLCallerPrincipal().origin; } |
|
49 }; |
|
50 |
|
51 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestInterfaceJS]) |