Bug 1596918: Part 2 - Add ESLint support for SpecialPowers.spawn globals. r=Standard8

This patch updates the existing ContentTask.spawn rule to do similar things
for SpecialPowers.spawn calls, only with a slightly different set of globals.

Differential Revision: https://phabricator.services.mozilla.com/D53739

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kris Maglione 2019-12-07 18:44:33 +00:00
Родитель 7593e70946
Коммит 64dd29e2b8
2 изменённых файлов: 44 добавлений и 2 удалений

Просмотреть файл

@ -18,6 +18,9 @@ ChromeUtils.defineModuleGetter(
"resource://testing-common/Assert.jsm"
);
// Note: When updating the set of globals exposed to sandboxes by
// default, please also update the ESLint plugin rule defined in
// import-content-task-globals.js.
const SANDBOX_GLOBALS = [
"Blob",
"ChromeUtils",
@ -25,6 +28,10 @@ const SANDBOX_GLOBALS = [
"TextEncoder",
"URL",
];
const EXTRA_IMPORTS = {
EventUtils: "resource://specialpowers/SpecialPowersEventUtils.jsm",
Services: "resource://gre/modules/Services.jsm",
};
let expectFail = false;
function expectingFail(fn) {
@ -62,14 +69,16 @@ class SpecialPowersSandbox {
}
let imports = {
EventUtils: "resource://specialpowers/SpecialPowersEventUtils.jsm",
Services: "resource://gre/modules/Services.jsm",
...EXTRA_IMPORTS,
...opts.imports,
};
for (let [symbol, url] of Object.entries(imports)) {
ChromeUtils.defineModuleGetter(this.sandbox, symbol, url);
}
// Note: When updating the set of globals exposed to sandboxes by
// default, please also update the ESLint plugin rule defined in
// import-content-task-globals.js.
Object.assign(this.sandbox, {
BrowsingContext,
InspectorUtils,

Просмотреть файл

@ -36,5 +36,38 @@ module.exports = function(context) {
);
}
},
"CallExpression[callee.object.name='SpecialPowers'][callee.property.name='spawn']": function(
node
) {
// The global environment of SpecialPowers.spawn tasks is
// controlled by the Sandbox environment created by
// SpecialPowersSandbox.jsm. This list should be kept in sync with
// that module.
let globals = [
"Assert",
"Blob",
"BrowsingContext",
"ChromeUtils",
"ContentTaskUtils",
"EventUtils",
"Services",
"SpecialPowers",
"TextDecoder",
"TextEncoder",
"URL",
"assert",
"content",
"docShell",
"info",
"is",
"isnot",
"ok",
"todo",
"todo_is",
];
for (let global of globals) {
helpers.addVarToScope(global, context.getScope(), false);
}
},
};
};