Bug 985742 - Construct the [[Prototype]] chain given to FUEL Application instances without using mutable __proto__. r=mak

This commit is contained in:
Szabolcs Hubai 2014-03-29 23:23:33 +01:00
parent fb7441e902
commit 90642fb45a

View File

@ -729,6 +729,8 @@ var ApplicationFactory = {
}; };
#include ../../../toolkit/components/exthelper/extApplication.js
//================================================= //=================================================
// Application constructor // Application constructor
function Application() { function Application() {
@ -737,60 +739,80 @@ function Application() {
//================================================= //=================================================
// Application implementation // Application implementation
Application.prototype = { function ApplicationPrototype() {
// for nsIClassInfo + XPCOMUtils // for nsIClassInfo + XPCOMUtils
classID: APPLICATION_CID, this.classID = APPLICATION_CID;
// redefine the default factory for XPCOMUtils // redefine the default factory for XPCOMUtils
_xpcom_factory: ApplicationFactory, this._xpcom_factory = ApplicationFactory;
// for nsISupports // for nsISupports
QueryInterface: XPCOMUtils.generateQI([Ci.fuelIApplication, Ci.extIApplication, this.QueryInterface = XPCOMUtils.generateQI([
Ci.nsIObserver, Ci.nsISupportsWeakReference]), Ci.fuelIApplication,
Ci.extIApplication,
Ci.nsIObserver,
Ci.nsISupportsWeakReference
]);
// for nsIClassInfo // for nsIClassInfo
classInfo: XPCOMUtils.generateCI({classID: APPLICATION_CID, this.classInfo = XPCOMUtils.generateCI({
contractID: APPLICATION_CONTRACTID, classID: APPLICATION_CID,
interfaces: [Ci.fuelIApplication, contractID: APPLICATION_CONTRACTID,
Ci.extIApplication, interfaces: [
Ci.nsIObserver], Ci.fuelIApplication,
flags: Ci.nsIClassInfo.SINGLETON}), Ci.extIApplication,
Ci.nsIObserver
],
flags: Ci.nsIClassInfo.SINGLETON
});
// for nsIObserver // for nsIObserver
observe: function app_observe(aSubject, aTopic, aData) { this.observe = function (aSubject, aTopic, aData) {
// Call the extApplication version of this function first // Call the extApplication version of this function first
this.__proto__.__proto__.observe.call(this, aSubject, aTopic, aData); var superPrototype = Object.getPrototypeOf(Object.getPrototypeOf(this));
superPrototype.observe.call(this, aSubject, aTopic, aData);
if (aTopic == "xpcom-shutdown") { if (aTopic == "xpcom-shutdown") {
this._obs.removeObserver(this, "xpcom-shutdown"); this._obs.removeObserver(this, "xpcom-shutdown");
Utilities.free(); Utilities.free();
} }
}, };
get bookmarks() { Object.defineProperty(this, "bookmarks", {
let bookmarks = new BookmarkRoots(); get: function bookmarks () {
this.__defineGetter__("bookmarks", function() bookmarks); let bookmarks = new BookmarkRoots();
return this.bookmarks; Object.defineProperty(this, "bookmarks", { value: bookmarks });
}, return this.bookmarks;
},
enumerable: true,
configurable: true
});
get windows() { Object.defineProperty(this, "windows", {
var win = []; get: function windows() {
var browserEnum = Utilities.windowMediator.getEnumerator("navigator:browser"); var win = [];
var browserEnum = Utilities.windowMediator.getEnumerator("navigator:browser");
while (browserEnum.hasMoreElements()) while (browserEnum.hasMoreElements())
win.push(getWindow(browserEnum.getNext())); win.push(getWindow(browserEnum.getNext()));
return win; return win;
}, },
enumerable: true,
configurable: true
});
Object.defineProperty(this, "activeWindow", {
get: () => getWindow(Utilities.windowMediator.getMostRecentWindow("navigator:browser")),
enumerable: true,
configurable: true
});
get activeWindow() {
return getWindow(Utilities.windowMediator.getMostRecentWindow("navigator:browser"));
}
}; };
#include ../../../toolkit/components/exthelper/extApplication.js
// set the proto, defined in extApplication.js // set the proto, defined in extApplication.js
Application.prototype.__proto__ = extApplication.prototype; ApplicationPrototype.prototype = extApplication.prototype;
Application.prototype = new ApplicationPrototype();
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Application]); this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Application]);