mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 13:48:23 +02:00
***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8
This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:
ChromeUtils.import("resource://gre/modules/Services.jsm");
is approximately the same as the following, in the new model:
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs
This was done using the followng script:
https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16750
--HG--
extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895
extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
147 lines
4 KiB
JavaScript
147 lines
4 KiB
JavaScript
var {XPCOMUtils} = ChromeUtils.import('resource://gre/modules/XPCOMUtils.jsm');
|
|
var {Services} = ChromeUtils.import('resource://gre/modules/Services.jsm');
|
|
|
|
var _CSvc;
|
|
function get_cache_service() {
|
|
if (_CSvc)
|
|
return _CSvc;
|
|
|
|
return _CSvc = Cc["@mozilla.org/netwerk/cache-storage-service;1"]
|
|
.getService(Ci.nsICacheStorageService);
|
|
}
|
|
|
|
function evict_cache_entries(where)
|
|
{
|
|
var clearDisk = (!where || where == "disk" || where == "all");
|
|
var clearMem = (!where || where == "memory" || where == "all");
|
|
var clearAppCache = (where == "appcache");
|
|
|
|
var svc = get_cache_service();
|
|
var storage;
|
|
|
|
if (clearMem) {
|
|
storage = svc.memoryCacheStorage(Services.loadContextInfo.default);
|
|
storage.asyncEvictStorage(null);
|
|
}
|
|
|
|
if (clearDisk) {
|
|
storage = svc.diskCacheStorage(Services.loadContextInfo.default, false);
|
|
storage.asyncEvictStorage(null);
|
|
}
|
|
|
|
if (clearAppCache) {
|
|
storage = svc.appCacheStorage(Services.loadContextInfo.default, null);
|
|
storage.asyncEvictStorage(null);
|
|
}
|
|
}
|
|
|
|
function createURI(urispec)
|
|
{
|
|
var ioServ = Cc["@mozilla.org/network/io-service;1"]
|
|
.getService(Ci.nsIIOService);
|
|
return ioServ.newURI(urispec);
|
|
}
|
|
|
|
function getCacheStorage(where, lci, appcache)
|
|
{
|
|
if (!lci) lci = Services.loadContextInfo.default;
|
|
var svc = get_cache_service();
|
|
switch (where) {
|
|
case "disk": return svc.diskCacheStorage(lci, false);
|
|
case "memory": return svc.memoryCacheStorage(lci);
|
|
case "appcache": return svc.appCacheStorage(lci, appcache);
|
|
case "pin": return svc.pinningCacheStorage(lci);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function asyncOpenCacheEntry(key, where, flags, lci, callback, appcache)
|
|
{
|
|
key = createURI(key);
|
|
|
|
function CacheListener() { }
|
|
CacheListener.prototype = {
|
|
_appCache: appcache,
|
|
|
|
QueryInterface: function (iid) {
|
|
if (iid.equals(Ci.nsICacheEntryOpenCallback) ||
|
|
iid.equals(Ci.nsISupports))
|
|
return this;
|
|
throw Cr.NS_ERROR_NO_INTERFACE;
|
|
},
|
|
|
|
onCacheEntryCheck: function(entry, appCache) {
|
|
if (typeof callback === "object")
|
|
return callback.onCacheEntryCheck(entry, appCache);
|
|
return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED;
|
|
},
|
|
|
|
onCacheEntryAvailable: function (entry, isnew, appCache, status) {
|
|
if (typeof callback === "object") {
|
|
// Root us at the callback
|
|
callback.__cache_listener_root = this;
|
|
callback.onCacheEntryAvailable(entry, isnew, appCache, status);
|
|
}
|
|
else
|
|
callback(status, entry, appCache);
|
|
},
|
|
|
|
run: function () {
|
|
var storage = getCacheStorage(where, lci, this._appCache);
|
|
storage.asyncOpenURI(key, "", flags, this);
|
|
}
|
|
};
|
|
|
|
(new CacheListener()).run();
|
|
}
|
|
|
|
function syncWithCacheIOThread(callback, force)
|
|
{
|
|
if (force) {
|
|
asyncOpenCacheEntry(
|
|
"http://nonexistententry/", "disk", Ci.nsICacheStorage.OPEN_READONLY, null,
|
|
function(status, entry) {
|
|
Assert.equal(status, Cr.NS_ERROR_CACHE_KEY_NOT_FOUND);
|
|
callback();
|
|
});
|
|
}
|
|
else {
|
|
callback();
|
|
}
|
|
}
|
|
|
|
function get_device_entry_count(where, lci, continuation) {
|
|
var storage = getCacheStorage(where, lci);
|
|
if (!storage) {
|
|
continuation(-1, 0);
|
|
return;
|
|
}
|
|
|
|
var visitor = {
|
|
onCacheStorageInfo: function (entryCount, consumption) {
|
|
executeSoon(function() {
|
|
continuation(entryCount, consumption);
|
|
});
|
|
},
|
|
};
|
|
|
|
// get the device entry count
|
|
storage.asyncVisitStorage(visitor, false);
|
|
}
|
|
|
|
function asyncCheckCacheEntryPresence(key, where, shouldExist, continuation, appCache)
|
|
{
|
|
asyncOpenCacheEntry(key, where, Ci.nsICacheStorage.OPEN_READONLY, null,
|
|
function(status, entry) {
|
|
if (shouldExist) {
|
|
dump("TEST-INFO | checking cache key " + key + " exists @ " + where);
|
|
Assert.equal(status, Cr.NS_OK);
|
|
Assert.ok(!!entry);
|
|
} else {
|
|
dump("TEST-INFO | checking cache key " + key + " doesn't exist @ " + where);
|
|
Assert.equal(status, Cr.NS_ERROR_CACHE_KEY_NOT_FOUND);
|
|
Assert.equal(null, entry);
|
|
}
|
|
continuation();
|
|
}, appCache);
|
|
}
|