Bug 1770727 - Fix ESLint rule mozilla/use-services on sjs files and expose Services to sjs files. r=Gijs

Depends on D147080

Differential Revision: https://phabricator.services.mozilla.com/D147081
This commit is contained in:
Mark Banner 2022-05-24 12:59:09 +00:00
Родитель ef5633d319
Коммит dac6401c3b
24 изменённых файлов: 23 добавлений и 65 удалений

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

@ -101,7 +101,6 @@ module.exports = {
"no-control-regex": "warn",
"no-throw-literal": "warn",
"no-useless-concat": "warn",
"mozilla/use-services": "warn",
"mozilla/use-includes-instead-of-indexOf": "warn",
"mozilla/no-compare-against-boolean-literals": "warn",
},

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

@ -114,9 +114,7 @@ function parseXml(body) {
}
function getInputStream(path) {
let file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
let file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
for (let part of path.split("/")) {
file.append(part);
}

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

@ -122,9 +122,7 @@ function getRequestBody(req) {
}
function getInputStream(path) {
let file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
let file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
for (let part of path.split("/")) {
file.append(part);
}

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

@ -6,9 +6,7 @@ function loadHTMLFromFile(path) {
// Load the HTML to return in the response from file.
// Since it's relative to the cwd of the test runner, we start there and
// append to get to the actual path of the file.
const testHTMLFile = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
const testHTMLFile = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
const testHTMLFileStream = Cc[
"@mozilla.org/network/file-input-stream;1"

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

@ -31,9 +31,7 @@ var types = {
function handleRequest(request, response) {
var resource = parseQuery(request, "");
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
Ci.nsIFileInputStream
);

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

@ -22,9 +22,7 @@ function handleRequest(request, response) {
// Get the filename to send back.
var filename = parseQuery(request, "file");
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
Ci.nsIFileInputStream
);

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

@ -64,9 +64,7 @@ function handleRequest(request, response) {
}
var startOffset = parseInt(offsets[0]);
var endOffset = parseInt(offsets[1]);
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
Ci.nsIFileInputStream
);

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

@ -25,9 +25,7 @@ function handleRequest(request, response) {
var resource = getState(key) == "2" ? resource2 : resource1;
setState(key, "2");
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
Ci.nsIFileInputStream
);

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

@ -20,9 +20,7 @@ function handleRequest(request, response) {
var redirected = parseQuery(query, "redirected") || false;
var useCors = parseQuery(query, "cors") || false;
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
Ci.nsIFileInputStream
);

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

@ -24,9 +24,7 @@ function handleRequest(request, response) {
) {
var name = parseQuery(request, "name");
var type = parseQuery(request, "type");
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
Ci.nsIFileInputStream
);

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

@ -1,7 +1,5 @@
function handleRequest(request, response) {
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
Ci.nsIFileInputStream
);

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

@ -7,9 +7,7 @@ var timer = Cc["@mozilla.org/timer;1"];
var partTimer = timer.createInstance(Ci.nsITimer);
function getFileAsInputStream(aFilename) {
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
file.append("tests");
file.append("image");

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

@ -1,7 +1,5 @@
function handleRequest(request, response) {
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
file.append("tests");
file.append("image");

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

@ -1,7 +1,5 @@
function handleRequest(request, response) {
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
file.append("tests");
file.append("image");

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

@ -1,7 +1,5 @@
function handleRequest(request, response) {
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
file.append("tests");
file.append("image");

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

@ -1,7 +1,5 @@
function handleRequest(request, response) {
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
file.append("tests");
file.append("image");

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

@ -1,7 +1,5 @@
function handleRequest(request, response) {
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
file.append("tests");
file.append("image");

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

@ -1,7 +1,5 @@
function handleRequest(request, response) {
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
file.append("tests");
file.append("image");

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

@ -28,9 +28,7 @@ var timer = Cc["@mozilla.org/timer;1"];
var partTimer = timer.createInstance(Ci.nsITimer);
function getFileAsInputStream(aFilename) {
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
file.append("tests");
file.append("image");

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

@ -6,9 +6,7 @@ var timer = Cc["@mozilla.org/timer;1"];
var partTimer = timer.createInstance(Ci.nsITimer);
function getFileAsInputStream(aFilename) {
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
file.append("tests");
file.append("image");

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

@ -8,9 +8,7 @@ var timer = Cc["@mozilla.org/timer;1"];
var partTimer = timer.createInstance(Ci.nsITimer);
function getFileAsInputStream(aFilename) {
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
file.append("tests");
file.append("image");

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

@ -2882,6 +2882,7 @@ ServerHandler.prototype = {
s.importFunction(atob, "atob");
s.importFunction(btoa, "btoa");
s.importFunction(ChromeUtils, "ChromeUtils");
s.importFunction(Services, "Services");
// Define a basic key-value state-preservation API across requests, with
// keys initially corresponding to the empty string.

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

@ -155,10 +155,7 @@ function handleRequest(request, response) {
if (formData && "upload_file_minidump" in formData) {
response.setHeader("Content-Type", "text/plain", false);
let uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(
Ci.nsIUUIDGenerator
);
let uuid = uuidGenerator.generateUUID().toString();
let uuid = Services.uuid.generateUUID().toString();
// ditch the {}, add bp- prefix
uuid = "bp-" + uuid.substring(1, uuid.length - 1);

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

@ -23,6 +23,7 @@ module.exports = {
getObjectState: false,
setObjectState: false,
registerPathHandler: false,
Services: false,
// importScripts is also available.
importScripts: false,
},