dom/bindings/test/TestInterfaceJS.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/bindings/test/TestInterfaceJS.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +const Cu = Components.utils;
     1.9 +const Ci = Components.interfaces;
    1.10 +
    1.11 +"use strict";
    1.12 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    1.13 +Cu.import("resource://gre/modules/Services.jsm");
    1.14 +
    1.15 +var gGlobal = this;
    1.16 +function checkGlobal(obj) {
    1.17 +  if (Object(obj) === obj && Cu.getGlobalForObject(obj) != gGlobal) {
    1.18 +    // This message may not make it to the caller in a useful form, so dump
    1.19 +    // as well.
    1.20 +    var msg = "TestInterfaceJS received an object from a different scope!";
    1.21 +    dump(msg + "\n");
    1.22 +    throw new Error(msg);
    1.23 +  }
    1.24 +}
    1.25 +
    1.26 +function TestInterfaceJS(anyArg, objectArg) {}
    1.27 +
    1.28 +TestInterfaceJS.prototype = {
    1.29 +  classID: Components.ID("{2ac4e026-cf25-47d5-b067-78d553c3cad8}"),
    1.30 +  contractID: "@mozilla.org/dom/test-interface-js;1",
    1.31 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
    1.32 +
    1.33 +  __init: function (anyArg, objectArg) {
    1.34 +    this._anyAttr = undefined;
    1.35 +    this._objectAttr = null;
    1.36 +    this._anyArg = anyArg;
    1.37 +    this._objectArg = objectArg;
    1.38 +    checkGlobal(anyArg);
    1.39 +    checkGlobal(objectArg);
    1.40 +  },
    1.41 +
    1.42 +  get anyArg() { return this._anyArg; },
    1.43 +  get objectArg() { return this._objectArg; },
    1.44 +  get anyAttr() { return this._anyAttr; },
    1.45 +  set anyAttr(val) { checkGlobal(val); this._anyAttr = val; },
    1.46 +  get objectAttr() { return this._objectAttr; },
    1.47 +  set objectAttr(val) { checkGlobal(val); this._objectAttr = val; },
    1.48 +  pingPongAny: function(any) { checkGlobal(any); return any; },
    1.49 +  pingPongObject: function(obj) { checkGlobal(obj); return obj; },
    1.50 +
    1.51 +  getCallerPrincipal: function() { return Cu.getWebIDLCallerPrincipal().origin; }
    1.52 +};
    1.53 +
    1.54 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestInterfaceJS])

mercurial