dom/bindings/test/TestInterfaceJS.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial