зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1626873 - Load xpcshell-test globals from the xpcshell head.js file rather than hard-code them. r=mossop
Differential Revision: https://phabricator.services.mozilla.com/D69612 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
feed464a5d
Коммит
7d3f1f3447
|
@ -1,5 +1,4 @@
|
|||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
||||
/* global _XPCSHELL_PROCESS */
|
||||
|
||||
"use strict";
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
* by discarding app1 (non-pinned)
|
||||
*
|
||||
*/
|
||||
/* global _XPCSHELL_PROCESS */
|
||||
"use strict";
|
||||
|
||||
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
|
||||
|
|
|
@ -2,68 +2,8 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
// All globals made available in the test environment.
|
||||
globals: {
|
||||
Assert: false,
|
||||
PromiseDebugging: false,
|
||||
_TEST_FILE: false,
|
||||
add_task: false,
|
||||
add_test: false,
|
||||
// Test-only function.
|
||||
allocationMarker: false,
|
||||
byteSize: false,
|
||||
deepEqual: false,
|
||||
do_await_remote_message: false,
|
||||
do_check_instanceof: false,
|
||||
do_check_throws_nsIException: false,
|
||||
do_get_cwd: false,
|
||||
do_get_file: false,
|
||||
do_get_idle: false,
|
||||
do_get_profile: false,
|
||||
do_get_tempdir: false,
|
||||
do_load_child_test_harness: false,
|
||||
do_load_manifest: false,
|
||||
do_load_module: false,
|
||||
do_note_exception: false,
|
||||
do_parse_document: false,
|
||||
do_report_result: false,
|
||||
do_report_unexpected_exception: false,
|
||||
do_send_remote_message: false,
|
||||
do_test_finished: false,
|
||||
do_test_pending: false,
|
||||
do_throw: false,
|
||||
do_timeout: false,
|
||||
equal: false,
|
||||
executeSoon: false,
|
||||
gc: false,
|
||||
// XPCShell specific function, see XPCShellEnvironment.cpp
|
||||
gczeal: false,
|
||||
greater: false,
|
||||
greaterOrEqual: false,
|
||||
info: false,
|
||||
less: false,
|
||||
lessOrEqual: false,
|
||||
load: false,
|
||||
mozinfo: false,
|
||||
notDeepEqual: false,
|
||||
notEqual: false,
|
||||
notStrictEqual: false,
|
||||
ok: false,
|
||||
registerCleanupFunction: false,
|
||||
run_next_test: false,
|
||||
run_test: false,
|
||||
run_test_in_child: false,
|
||||
runningInParent: false,
|
||||
// Defined in XPCShellImpl.
|
||||
sendCommand: false,
|
||||
strictEqual: false,
|
||||
throws: false,
|
||||
todo: false,
|
||||
todo_check_false: false,
|
||||
todo_check_true: false,
|
||||
// Firefox specific function.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/uneval
|
||||
uneval: false,
|
||||
env: {
|
||||
"mozilla/xpcshell": true,
|
||||
},
|
||||
|
||||
overrides: [
|
||||
|
|
|
@ -14,11 +14,8 @@
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var helpers = require("../helpers");
|
||||
var globals = require("../globals");
|
||||
|
||||
const rootDir = helpers.rootDir;
|
||||
var { getScriptGlobals } = require("./utils");
|
||||
|
||||
// When updating EXTRA_SCRIPTS or MAPPINGS, be sure to also update the
|
||||
// 'support-files' config in `tools/lint/eslint.yml`.
|
||||
|
@ -101,44 +98,11 @@ function getGlobalScripts() {
|
|||
return results;
|
||||
}
|
||||
|
||||
function getScriptGlobals() {
|
||||
let fileGlobals = [];
|
||||
let scripts = getGlobalScripts();
|
||||
if (!scripts) {
|
||||
return [];
|
||||
}
|
||||
|
||||
for (let script of scripts.concat(EXTRA_SCRIPTS)) {
|
||||
let fileName = path.join(rootDir, script);
|
||||
try {
|
||||
fileGlobals = fileGlobals.concat(globals.getGlobalsForFile(fileName));
|
||||
} catch (e) {
|
||||
console.error(`Could not load globals from file ${fileName}: ${e}`);
|
||||
console.error(
|
||||
`You may need to update the mappings in ${module.filename}`
|
||||
);
|
||||
throw new Error(`Could not load globals from file ${fileName}: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
return fileGlobals.concat(extraDefinitions);
|
||||
}
|
||||
|
||||
function mapGlobals(fileGlobals) {
|
||||
let globalObjects = {};
|
||||
for (let global of fileGlobals) {
|
||||
globalObjects[global.name] = global.writable;
|
||||
}
|
||||
return globalObjects;
|
||||
}
|
||||
|
||||
function getMozillaCentralItems() {
|
||||
return {
|
||||
globals: mapGlobals(getScriptGlobals()),
|
||||
module.exports = getScriptGlobals(
|
||||
"browser-window",
|
||||
getGlobalScripts().concat(EXTRA_SCRIPTS),
|
||||
extraDefinitions,
|
||||
{
|
||||
browserjsScripts: getGlobalScripts().concat(EXTRA_SCRIPTS),
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = helpers.isMozillaCentralBased()
|
||||
? getMozillaCentralItems()
|
||||
: helpers.getSavedEnvironmentItems("browser-window");
|
||||
}
|
||||
);
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
var path = require("path");
|
||||
var helpers = require("../helpers");
|
||||
var globals = require("../globals");
|
||||
var { getScriptGlobals } = require("./utils");
|
||||
|
||||
// When updating this list, be sure to also update the 'support-files' config
|
||||
// in `tools/lint/eslint.yml`.
|
||||
|
@ -29,32 +28,7 @@ const simpleTestFiles = [
|
|||
];
|
||||
const simpleTestPath = "testing/mochitest/tests/SimpleTest";
|
||||
|
||||
function getScriptGlobals() {
|
||||
let fileGlobals = [];
|
||||
let root = helpers.rootDir;
|
||||
for (let file of simpleTestFiles) {
|
||||
let fileName = path.join(root, simpleTestPath, file);
|
||||
try {
|
||||
fileGlobals = fileGlobals.concat(globals.getGlobalsForFile(fileName));
|
||||
} catch (e) {
|
||||
// The files may not be available in non-m-c repositories.
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
return fileGlobals;
|
||||
}
|
||||
|
||||
function mapGlobals(fileGlobals) {
|
||||
var globalObjects = {};
|
||||
for (let global of fileGlobals) {
|
||||
globalObjects[global.name] = global.writable;
|
||||
}
|
||||
return globalObjects;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
globals: helpers.isMozillaCentralBased()
|
||||
? mapGlobals(getScriptGlobals())
|
||||
: helpers.getSavedEnvironmentItems("simpletest").globals,
|
||||
};
|
||||
module.exports = getScriptGlobals(
|
||||
"simpletest",
|
||||
simpleTestFiles.map(file => path.join(simpleTestPath, file))
|
||||
);
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* @fileoverview Provides utilities for setting up environments.
|
||||
*
|
||||
* 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";
|
||||
|
||||
var path = require("path");
|
||||
var helpers = require("../helpers");
|
||||
var globals = require("../globals");
|
||||
|
||||
/**
|
||||
* Obtains the globals for a list of files.
|
||||
*
|
||||
* @param {Array.<String>} files
|
||||
* The array of files to get globals for. The paths are relative to the topsrcdir.
|
||||
* @returns {Object}
|
||||
* Returns an object with keys of the global names and values of if they are
|
||||
* writable or not.
|
||||
*/
|
||||
function getGlobalsForScripts(environmentName, files, extraDefinitions) {
|
||||
let fileGlobals = extraDefinitions;
|
||||
const root = helpers.rootDir;
|
||||
for (const file of files) {
|
||||
const fileName = path.join(root, file);
|
||||
try {
|
||||
fileGlobals = fileGlobals.concat(globals.getGlobalsForFile(fileName));
|
||||
} catch (e) {
|
||||
console.error(`Could not load globals from file ${fileName}: ${e}`);
|
||||
console.error(
|
||||
`You may need to update the mappings for the ${environmentName} environment`
|
||||
);
|
||||
throw new Error(`Could not load globals from file ${fileName}: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
var globalObjects = {};
|
||||
for (let global of fileGlobals) {
|
||||
globalObjects[global.name] = global.writable;
|
||||
}
|
||||
return globalObjects;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getScriptGlobals(
|
||||
environmentName,
|
||||
files,
|
||||
extraDefinitions = [],
|
||||
extraEnv = {}
|
||||
) {
|
||||
if (helpers.isMozillaCentralBased()) {
|
||||
return {
|
||||
globals: getGlobalsForScripts(environmentName, files, extraDefinitions),
|
||||
...extraEnv,
|
||||
};
|
||||
}
|
||||
return helpers.getSavedEnvironmentItems(environmentName);
|
||||
},
|
||||
};
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* @fileoverview Defines the environment for frame scripts.
|
||||
*
|
||||
* 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";
|
||||
|
||||
var { getScriptGlobals } = require("./utils");
|
||||
|
||||
const extraGlobals = [
|
||||
// Assert.jsm globals.
|
||||
"setReporter",
|
||||
"report",
|
||||
"ok",
|
||||
"equal",
|
||||
"notEqual",
|
||||
"deepEqual",
|
||||
"notDeepEqual",
|
||||
"strictEqual",
|
||||
"notStrictEqual",
|
||||
"throws",
|
||||
"rejects",
|
||||
"greater",
|
||||
"greaterOrEqual",
|
||||
"less",
|
||||
"lessOrEqual",
|
||||
// TestingFunctions.cpp globals
|
||||
"allocationMarker",
|
||||
"byteSize",
|
||||
"gc",
|
||||
"gczeal",
|
||||
];
|
||||
|
||||
module.exports = getScriptGlobals(
|
||||
"xpcshell",
|
||||
["testing/xpcshell/head.js"],
|
||||
extraGlobals.map(g => {
|
||||
return { name: g, writable: false };
|
||||
})
|
||||
);
|
|
@ -26,6 +26,7 @@ module.exports = {
|
|||
jsm: require("../lib/environments/jsm.js"),
|
||||
simpletest: require("../lib/environments/simpletest.js"),
|
||||
privileged: require("../lib/environments/privileged.js"),
|
||||
xpcshell: require("../lib/environments/xpcshell.js"),
|
||||
},
|
||||
processors: {
|
||||
".xul": require("../lib/processors/xul"),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "eslint-plugin-mozilla",
|
||||
"version": "2.4.0",
|
||||
"version": "2.5.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "eslint-plugin-mozilla",
|
||||
"version": "2.4.0",
|
||||
"version": "2.5.0",
|
||||
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
|
||||
"keywords": [
|
||||
"eslint",
|
||||
|
|
Загрузка…
Ссылка в новой задаче