зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1363215 - Replace calls to __define{Getter,Setter}__ on top-level this with Object.defineProperty. r=Gijs
__define{Getter,Setter}__ are deprecated, and are not defined on NonSyntacticVariablesObjects, so these calls get in the way of sharing globals between different .jsms. Probably only the DownloadUtils.jsm change is really needed for that. configurable and enumerable are both set to true to match the existing behavior. If enumerable is set to false, then tests fail, because some of the getters overwrite the getter with a regular property. MozReview-Commit-ID: 1OZF45fIAQ --HG-- extra : source : 96dd2e2d8d1677fb04c98bb3a063df32478fbc00
This commit is contained in:
Родитель
0a340a3e90
Коммит
e3a114f978
|
@ -224,38 +224,54 @@ if (AppConstants.platform != "macosx") {
|
|||
["gNavigatorBundle", "bundle_browser"]
|
||||
].forEach(function(elementGlobal) {
|
||||
var [name, id] = elementGlobal;
|
||||
window.__defineGetter__(name, function() {
|
||||
var element = document.getElementById(id);
|
||||
if (!element)
|
||||
return null;
|
||||
delete window[name];
|
||||
return window[name] = element;
|
||||
});
|
||||
window.__defineSetter__(name, function(val) {
|
||||
delete window[name];
|
||||
return window[name] = val;
|
||||
Object.defineProperty(window, name, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
var element = document.getElementById(id);
|
||||
if (!element)
|
||||
return null;
|
||||
delete window[name];
|
||||
return window[name] = element;
|
||||
},
|
||||
set(val) {
|
||||
delete window[name];
|
||||
return window[name] = val;
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// Smart getter for the findbar. If you don't wish to force the creation of
|
||||
// the findbar, check gFindBarInitialized first.
|
||||
|
||||
this.__defineGetter__("gFindBar", function() {
|
||||
return window.gBrowser.getFindBar();
|
||||
Object.defineProperty(this, "gFindBar", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
return window.gBrowser.getFindBar();
|
||||
},
|
||||
});
|
||||
|
||||
this.__defineGetter__("gFindBarInitialized", function() {
|
||||
return window.gBrowser.isFindBarInitialized();
|
||||
Object.defineProperty(this, "gFindBarInitialized", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
return window.gBrowser.isFindBarInitialized();
|
||||
},
|
||||
});
|
||||
|
||||
this.__defineGetter__("AddonManager", function() {
|
||||
let tmp = {};
|
||||
Cu.import("resource://gre/modules/AddonManager.jsm", tmp);
|
||||
return this.AddonManager = tmp.AddonManager;
|
||||
});
|
||||
this.__defineSetter__("AddonManager", function(val) {
|
||||
delete this.AddonManager;
|
||||
return this.AddonManager = val;
|
||||
Object.defineProperty(this, "AddonManager", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
let tmp = {};
|
||||
Cu.import("resource://gre/modules/AddonManager.jsm", tmp);
|
||||
return this.AddonManager = tmp.AddonManager;
|
||||
},
|
||||
set(val) {
|
||||
delete this.AddonManager;
|
||||
return this.AddonManager = val;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -18,13 +18,17 @@ XPCOMUtils.defineLazyServiceGetter(this, "aboutNewTabService",
|
|||
"@mozilla.org/browser/aboutnewtab-service;1",
|
||||
"nsIAboutNewTabService");
|
||||
|
||||
this.__defineGetter__("BROWSER_NEW_TAB_URL", () => {
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(window) &&
|
||||
!PrivateBrowsingUtils.permanentPrivateBrowsing &&
|
||||
!aboutNewTabService.overridden) {
|
||||
return "about:privatebrowsing";
|
||||
}
|
||||
return aboutNewTabService.newTabURL;
|
||||
Object.defineProperty(this, "BROWSER_NEW_TAB_URL", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(window) &&
|
||||
!PrivateBrowsingUtils.permanentPrivateBrowsing &&
|
||||
!aboutNewTabService.overridden) {
|
||||
return "about:privatebrowsing";
|
||||
}
|
||||
return aboutNewTabService.newTabURL;
|
||||
},
|
||||
});
|
||||
|
||||
var TAB_DROP_TYPE = "application/x-moz-tabbrowser-tab";
|
||||
|
|
|
@ -27,12 +27,16 @@ XPCOMUtils.defineLazyModuleGetter(this, "Deprecated",
|
|||
["gViewSourceBundle", "viewSourceBundle"],
|
||||
["gContextMenu", "viewSourceContextMenu"]
|
||||
].forEach(function([name, id]) {
|
||||
window.__defineGetter__(name, function() {
|
||||
var element = document.getElementById(id);
|
||||
if (!element)
|
||||
return null;
|
||||
delete window[name];
|
||||
return window[name] = element;
|
||||
Object.defineProperty(window, name, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
var element = document.getElementById(id);
|
||||
if (!element)
|
||||
return null;
|
||||
delete window[name];
|
||||
return window[name] = element;
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -779,14 +783,18 @@ function getBrowser() {
|
|||
return gBrowser;
|
||||
}
|
||||
|
||||
this.__defineGetter__("gPageLoader", function() {
|
||||
var webnav = viewSourceChrome.webNav;
|
||||
if (!webnav)
|
||||
return null;
|
||||
delete this.gPageLoader;
|
||||
this.gPageLoader = (webnav instanceof Ci.nsIWebPageDescriptor) ? webnav
|
||||
: null;
|
||||
return this.gPageLoader;
|
||||
Object.defineProperty(this, "gPageLoader", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
var webnav = viewSourceChrome.webNav;
|
||||
if (!webnav)
|
||||
return null;
|
||||
delete this.gPageLoader;
|
||||
this.gPageLoader = (webnav instanceof Ci.nsIWebPageDescriptor) ? webnav
|
||||
: null;
|
||||
return this.gPageLoader;
|
||||
},
|
||||
});
|
||||
|
||||
// Strips the |view-source:| for internalSave()
|
||||
|
@ -800,11 +808,15 @@ function ViewSourceSavePage() {
|
|||
// Below are old deprecated functions and variables left behind for
|
||||
// compatibility reasons. These will be removed soon via bug 1159293.
|
||||
|
||||
this.__defineGetter__("gLastLineFound", function() {
|
||||
Deprecated.warning("gLastLineFound is deprecated - please use " +
|
||||
"viewSourceChrome.lastLineFound instead.",
|
||||
"https://developer.mozilla.org/en-US/Add-ons/Code_snippets/View_Source_for_XUL_Applications");
|
||||
return viewSourceChrome.lastLineFound;
|
||||
Object.defineProperty(this, "gLastLineFound", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
Deprecated.warning("gLastLineFound is deprecated - please use " +
|
||||
"viewSourceChrome.lastLineFound instead.",
|
||||
"https://developer.mozilla.org/en-US/Add-ons/Code_snippets/View_Source_for_XUL_Applications");
|
||||
return viewSourceChrome.lastLineFound;
|
||||
},
|
||||
});
|
||||
|
||||
function onLoadViewSource() {
|
||||
|
|
|
@ -147,9 +147,13 @@ function setTooltipText(aID, aTooltipText) {
|
|||
element.setAttribute("tooltiptext", aTooltipText);
|
||||
}
|
||||
|
||||
this.__defineGetter__("NS_ASSERT", function() {
|
||||
delete this.NS_ASSERT;
|
||||
var tmpScope = {};
|
||||
Components.utils.import("resource://gre/modules/debug.js", tmpScope);
|
||||
return this.NS_ASSERT = tmpScope.NS_ASSERT;
|
||||
Object.defineProperty(this, "NS_ASSERT", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
delete this.NS_ASSERT;
|
||||
var tmpScope = {};
|
||||
Components.utils.import("resource://gre/modules/debug.js", tmpScope);
|
||||
return this.NS_ASSERT = tmpScope.NS_ASSERT;
|
||||
},
|
||||
});
|
||||
|
|
|
@ -49,9 +49,13 @@ XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
|
|||
|
||||
const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
||||
|
||||
this.__defineGetter__("gDecimalSymbol", function() {
|
||||
Object.defineProperty(this, "gDecimalSymbol", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
delete this.gDecimalSymbol;
|
||||
return this.gDecimalSymbol = Number(5.4).toLocaleString().match(/\D/);
|
||||
},
|
||||
});
|
||||
|
||||
var localeNumberFormatCache = new Map();
|
||||
|
@ -95,11 +99,15 @@ var gStr = {
|
|||
};
|
||||
|
||||
// This lazily initializes the string bundle upon first use.
|
||||
this.__defineGetter__("gBundle", function() {
|
||||
delete this.gBundle;
|
||||
return this.gBundle = Cc["@mozilla.org/intl/stringbundle;1"].
|
||||
getService(Ci.nsIStringBundleService).
|
||||
createBundle(kDownloadProperties);
|
||||
Object.defineProperty(this, "gBundle", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
delete this.gBundle;
|
||||
return this.gBundle = Cc["@mozilla.org/intl/stringbundle;1"].
|
||||
getService(Ci.nsIStringBundleService).
|
||||
createBundle(kDownloadProperties);
|
||||
},
|
||||
});
|
||||
|
||||
// Keep track of at most this many second/lastSec pairs so that multiple calls
|
||||
|
|
Загрузка…
Ссылка в новой задаче