Backed out changeset 50f86f169ee8 (bug 1889087) for causing talos performance test failures CLOSED TREE

This commit is contained in:
Sandor Molnar 2024-04-03 09:18:07 +03:00
parent b48495be08
commit e1e4a33e82
6 changed files with 69 additions and 6 deletions

View file

@ -2206,7 +2206,10 @@ module.exports = {
},
},
{
files: [
files: ["**"],
excludedFiles: [
// Devtools code, see bug 1525652.
"devtools/**",
// Tests specific to JSM
"dom/encoding/test/test_stringencoding.xhtml",
"dom/url/tests/test_bug883784.xhtml",
@ -2221,7 +2224,7 @@ module.exports = {
"js/xpconnect/loader/XPCOMUtils.sys.mjs",
],
rules: {
"mozilla/reject-chromeutils-import": "off",
"mozilla/reject-chromeutils-import": "error",
},
},
{

View file

@ -0,0 +1,55 @@
/* 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/. */
// @ts-check
"use strict";
/**
* TypeScript can't understand the lazyRequireGetter mechanism, due to how it defines
* properties as a getter. This function, instead provides lazy loading in a
* TypeScript-friendly manner. It applies the lazy load memoization to each property
* of the provided object.
*
* Example usage:
*
* const lazy = createLazyLoaders({
* moduleA: () => require("module/a"),
* moduleB: () => require("module/b"),
* });
*
* Later:
*
* const moduleA = lazy.moduleA();
* const { objectInModuleB } = lazy.moduleB();
*
* @template {{ [key: string]: () => any }} T
* @param {T} definition - An object where each property has a function that loads a module.
* @returns {T} - The load memoized version of T.
*/
function createLazyLoaders(definition) {
/** @type {any} */
const result = {};
for (const [key, callback] of Object.entries(definition)) {
/** @type {any} */
let cache;
result[key] = () => {
if (cache === undefined) {
cache = callback();
}
return cache;
};
}
return result;
}
// Provide an exports object for the JSM to be properly read by TypeScript.
/** @type {any} */
var module = {};
module.exports = {
createLazyLoaders,
};
// Object.keys() confuses the linting which expects a static array expression.
// eslint-disable-next-line
var EXPORTED_SYMBOLS = Object.keys(module.exports);

View file

@ -37,6 +37,9 @@ function* getOwnIdentifiers(x) {
function isJSONURI(uri) {
return uri.endsWith(".json");
}
function isJSMURI(uri) {
return uri.endsWith(".jsm");
}
function isSYSMJSURI(uri) {
return uri.endsWith(".sys.mjs");
}
@ -215,7 +218,7 @@ function load(loader, module) {
// Utility function to normalize module `uri`s so they have `.js` extension.
function normalizeExt(uri) {
if (isJSURI(uri) || isJSONURI(uri) || isSYSMJSURI(uri)) {
if (isJSURI(uri) || isJSONURI(uri) || isJSMURI(uri) || isSYSMJSURI(uri)) {
return uri;
}
return uri + ".js";
@ -333,6 +336,9 @@ export function Require(loader, requirer) {
// If module is already cached by loader then just use it.
if (uri in modules) {
module = modules[uri];
} else if (isJSMURI(uri)) {
module = modules[uri] = Module(requirement, uri);
module.exports = ChromeUtils.import(uri);
} else if (isSYSMJSURI(uri)) {
module = modules[uri] = Module(requirement, uri);
module.exports = ChromeUtils.importESModule(uri, {

View file

@ -55,7 +55,6 @@ module.exports = {
files: ["**/*.sys.mjs", "**/*.jsm"],
rules: {
"mozilla/lazy-getter-object-name": "error",
"mozilla/reject-chromeutils-import": "error",
"mozilla/reject-eager-module-in-lazy-getter": "error",
"mozilla/reject-global-this": "error",
"mozilla/reject-globalThis-modification": "error",

View file

@ -1,6 +1,6 @@
{
"name": "eslint-plugin-mozilla",
"version": "3.7.2",
"version": "3.7.1",
"lockfileVersion": 3,
"requires": true,
"packages": {

View file

@ -1,6 +1,6 @@
{
"name": "eslint-plugin-mozilla",
"version": "3.7.2",
"version": "3.7.1",
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
"keywords": [
"eslint",