mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-31 22:25:30 +00:00
30b2b7ce44
For simple rules like function spacing, we can auto-fix these across the code base so they are followed in a consistent way. To generate this patch, I ran: ./mach eslint devtools --no-ignore --fix After this, I reverted any changes to third party files that we really do want to ignore. MozReview-Commit-ID: 6Q8BApkAW20
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
"use strict";
|
|
|
|
const { Ci } = require("chrome");
|
|
const Services = require("Services");
|
|
|
|
var globalsCache = {};
|
|
|
|
exports.addContentGlobal = function (options) {
|
|
if (!options || !options.global || !options["inner-window-id"]) {
|
|
throw Error("Invalid arguments");
|
|
}
|
|
let cache = getGlobalCache(options["inner-window-id"]);
|
|
cache.push(options.global);
|
|
return undefined;
|
|
};
|
|
|
|
exports.getContentGlobals = function (options) {
|
|
if (!options || !options["inner-window-id"]) {
|
|
throw Error("Invalid arguments");
|
|
}
|
|
return Array.slice(globalsCache[options["inner-window-id"]] || []);
|
|
};
|
|
|
|
exports.removeContentGlobal = function (options) {
|
|
if (!options || !options.global || !options["inner-window-id"]) {
|
|
throw Error("Invalid arguments");
|
|
}
|
|
let cache = getGlobalCache(options["inner-window-id"]);
|
|
let index = cache.indexOf(options.global);
|
|
cache.splice(index, 1);
|
|
return undefined;
|
|
};
|
|
|
|
function getGlobalCache(aInnerWindowID) {
|
|
return globalsCache[aInnerWindowID] = globalsCache[aInnerWindowID] || [];
|
|
}
|
|
|
|
// when the window is destroyed, eliminate the associated globals cache
|
|
if (!isWorker) {
|
|
Services.obs.addObserver(function observer(subject, topic, data) {
|
|
let id = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
|
delete globalsCache[id];
|
|
}, "inner-window-destroyed", false);
|
|
}
|