Bug 1965726 - Fixup type issues raised from all modules being fully typed r=robwu

Differential Revision: https://phabricator.services.mozilla.com/D248719
This commit is contained in:
Tomislav Jovanovic
2025-05-13 23:17:04 +00:00
committed by tjovanovic@mozilla.com
parent b73a14ef05
commit 3d16884db5
17 changed files with 96 additions and 78 deletions

View File

@@ -12,14 +12,14 @@ export var Observers = {
/** /**
* Register the given callback as an observer of the given topic. * Register the given callback as an observer of the given topic.
* *
* @param topic {String} * @param {string} topic
* the topic to observe * the topic to observe
* *
* @param callback {Object} * @param {object} callback
* the callback; an Object that implements nsIObserver or a Function * the callback; an Object that implements nsIObserver or a Function
* that gets called when the notification occurs * that gets called when the notification occurs
* *
* @param thisObject {Object} [optional] * @param {object} [thisObject]
* the object to use as |this| when calling a Function callback * the object to use as |this| when calling a Function callback
* *
* @returns the observer * @returns the observer
@@ -35,13 +35,13 @@ export var Observers = {
/** /**
* Unregister the given callback as an observer of the given topic. * Unregister the given callback as an observer of the given topic.
* *
* @param topic {String} * @param {string} topic
* the topic being observed * the topic being observed
* *
* @param callback {Object} * @param {object} callback
* the callback doing the observing * the callback doing the observing
* *
* @param thisObject {Object} [optional] * @param {object} [thisObject]
* the object being used as |this| when calling a Function callback * the object being used as |this| when calling a Function callback
*/ */
remove(topic, callback, thisObject) { remove(topic, callback, thisObject) {
@@ -64,13 +64,13 @@ export var Observers = {
/** /**
* Notify observers about something. * Notify observers about something.
* *
* @param topic {String} * @param {string} topic
* the topic to notify observers about * the topic to notify observers about
* *
* @param subject {Object} [optional] * @param {object} [subject]
* some information about the topic; can be any JS object or primitive * some information about the topic; can be any JS object or primitive
* *
* @param data {String} [optional] [deprecated] * @param {string} [data] [deprecated]
* some more information about the topic; deprecated as the subject * some more information about the topic; deprecated as the subject
* is sufficient to pass all needed information to the JS observers * is sufficient to pass all needed information to the JS observers
* that this module targets; if you have multiple values to pass to * that this module targets; if you have multiple values to pass to

View File

@@ -134,11 +134,10 @@ export var CryptoUtils = {
}, },
/** /**
* @param {String} alg Hash algorithm (common values are SHA-1 or SHA-256) * @param {string} alg Hash algorithm (common values are SHA-1 or SHA-256)
* @param {ArrayBuffer} key * @param {BufferSource} key
* @param {ArrayBuffer} data * @param {BufferSource} data
* @param {Number} len Desired output length in bytes. * @returns {Promise<Uint8Array>}
* @returns {Uint8Array}
*/ */
async hmac(alg, key, data) { async hmac(alg, key, data) {
const hmacKey = await crypto.subtle.importKey( const hmacKey = await crypto.subtle.importKey(

View File

@@ -3091,7 +3091,7 @@ export class ExtensionData {
/** /**
* @param {Array<string>} dataPermissions An array of data collection permissions. * @param {Array<string>} dataPermissions An array of data collection permissions.
* *
* @returns {{msg: string, collectsTechnicalAndInteractionData: boolean, hasNone: boolean}} An * @returns {{msg?: string, collectsTechnicalAndInteractionData?: boolean, hasNone: boolean}} An
* object with information about data collection permissions for the UI. * object with information about data collection permissions for the UI.
*/ */
static _formatDataCollectionPermissions(dataPermissions, type) { static _formatDataCollectionPermissions(dataPermissions, type) {
@@ -3158,10 +3158,11 @@ export class ExtensionData {
* @param {Array<string>} permissions A list of optional data collection * @param {Array<string>} permissions A list of optional data collection
* permissions. * permissions.
* *
* @returns {Record<string, string>} A map of permission names to localized * Returns an object mapping permission names to localized
* strings representing the optional data collection permissions. * strings representing the optional data collection permissions.
*/ */
static _formatOptionalDataCollectionPermissions(permissions) { static _formatOptionalDataCollectionPermissions(permissions) {
/** @type {Record<string, string>} */
const optionalDataCollectionPermissions = {}; const optionalDataCollectionPermissions = {};
const odcKeys = []; const odcKeys = [];

View File

@@ -362,6 +362,7 @@ const ProxyMessenger = {
async recvPortConnect(arg, { sender }) { async recvPortConnect(arg, { sender }) {
if (arg.native) { if (arg.native) {
/** @type {ParentPort} */
let port = this.openNative(arg.name, sender).onConnect(arg.portId, this); let port = this.openNative(arg.name, sender).onConnect(arg.portId, this);
port.senderChildId = sender.childId; port.senderChildId = sender.childId;
port.native = true; port.native = true;

View File

@@ -367,7 +367,7 @@ export var ExtensionPermissions = {
* @typedef {object} Perms * @typedef {object} Perms
* @property {string[]} origins * @property {string[]} origins
* @property {string[]} permissions * @property {string[]} permissions
* @property {string[]} data_collection * @property {string[]} [data_collection]
* *
* @param {Perms} perms api permissions and origins to be added/removed. * @param {Perms} perms api permissions and origins to be added/removed.
* @param {Perms} optional permissions and origins from the manifest. * @param {Perms} optional permissions and origins from the manifest.

View File

@@ -545,7 +545,7 @@ export var ExtensionSettingsStore = {
* *
* @param {string} type The type of setting to be returned. * @param {string} type The type of setting to be returned.
* @param {string} key A string that uniquely identifies the setting. * @param {string} key A string that uniquely identifies the setting.
* @param {string} id * @param {string} [id]
* The id of the extension for which the setting is being retrieved. * The id of the extension for which the setting is being retrieved.
* Defaults to undefined, in which case the top setting is returned. * Defaults to undefined, in which case the top setting is returned.
* *

View File

@@ -92,8 +92,10 @@ function serialize(name, anonymizedName, value) {
return value; return value;
} }
/** @import {JSONFile} from "resource://gre/modules/JSONFile.sys.mjs" */
export var ExtensionStorage = { export var ExtensionStorage = {
/** @type {Map<string, Promise<typeof lazy.JSONFile>>} */ /** @type {Map<string, Promise<JSONFile>>} */
jsonFilePromises: new Map(), jsonFilePromises: new Map(),
listeners: new Map(), listeners: new Map(),
@@ -104,7 +106,7 @@ export var ExtensionStorage = {
* *
* @param {string} extensionId * @param {string} extensionId
* The ID of the extension for which to return a file. * The ID of the extension for which to return a file.
* @returns {Promise<InstanceType<Lazy['JSONFile']>>} * @returns {Promise<JSONFile>}
*/ */
async _readFile(extensionId) { async _readFile(extensionId) {
await IOUtils.makeDirectory(this.getExtensionDir(extensionId)); await IOUtils.makeDirectory(this.getExtensionDir(extensionId));
@@ -128,7 +130,7 @@ export var ExtensionStorage = {
* *
* @param {string} extensionId * @param {string} extensionId
* The ID of the extension for which to return a file. * The ID of the extension for which to return a file.
* @returns {Promise<InstanceType<Lazy['JSONFile']>>} * @returns {Promise<JSONFile>}
*/ */
getFile(extensionId) { getFile(extensionId) {
let promise = this.jsonFilePromises.get(extensionId); let promise = this.jsonFilePromises.get(extensionId);

View File

@@ -1,14 +1,12 @@
/* This Source Code Form is subject to the terms of the Mozilla Public /* 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 * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* eslint-disable mozilla/valid-lazy */
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
import { IndexedDB } from "resource://gre/modules/IndexedDB.sys.mjs"; import { IndexedDB } from "resource://gre/modules/IndexedDB.sys.mjs";
/** @type {Lazy} */ const lazy = XPCOMUtils.declareLazy({
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
ExtensionStorage: "resource://gre/modules/ExtensionStorage.sys.mjs", ExtensionStorage: "resource://gre/modules/ExtensionStorage.sys.mjs",
ExtensionUtils: "resource://gre/modules/ExtensionUtils.sys.mjs", ExtensionUtils: "resource://gre/modules/ExtensionUtils.sys.mjs",
getTrimmedString: "resource://gre/modules/ExtensionTelemetry.sys.mjs", getTrimmedString: "resource://gre/modules/ExtensionTelemetry.sys.mjs",
@@ -170,7 +168,11 @@ class ExtensionStorageLocalIDB extends IndexedDB {
static openForPrincipal(storagePrincipal) { static openForPrincipal(storagePrincipal) {
// The db is opened using an extension principal isolated in a reserved user context id. // The db is opened using an extension principal isolated in a reserved user context id.
return super.openForPrincipal(storagePrincipal, IDB_NAME, IDB_VERSION); return /** @type {Promise<ExtensionStorageLocalIDB>} */ (
super.openForPrincipal(storagePrincipal, IDB_NAME, {
version: IDB_VERSION,
})
);
} }
async isEmpty() { async isEmpty() {

View File

@@ -579,6 +579,7 @@ class CryptoCollection {
*/ */
async getKeyRing() { async getKeyRing() {
const cryptoKeyRecord = await this.getKeyRingRecord(); const cryptoKeyRecord = await this.getKeyRingRecord();
/** @type {CollectionKeyManager & {uuid?}} */
const collectionKeys = new lazy.CollectionKeyManager(); const collectionKeys = new lazy.CollectionKeyManager();
if (cryptoKeyRecord.keys) { if (cryptoKeyRecord.keys) {
collectionKeys.setContents( collectionKeys.setContents(

View File

@@ -337,7 +337,7 @@ export class ProxyChannelFilter {
let wrapper = ChannelWrapper.get(channel); let wrapper = ChannelWrapper.get(channel);
let browserData = { tabId: -1, windowId: -1 }; let browserData = { tabId: -1, windowId: -1 };
if (wrapper.browserElement) { if (XULElement.isInstance(wrapper.browserElement)) {
browserData = lazy.tabTracker.getBrowserData(wrapper.browserElement); browserData = lazy.tabTracker.getBrowserData(wrapper.browserElement);
} }

View File

@@ -127,9 +127,9 @@ export var WebNavigationManager = {
* The data for the autocompleted item. * The data for the autocompleted item.
* @param {object} [acData.result] * @param {object} [acData.result]
* The result information associated with the navigation action. * The result information associated with the navigation action.
* @param {typeof lazy.UrlbarUtils.RESULT_TYPE} [acData.result.type] * @param {Items<typeof lazy.UrlbarUtils.RESULT_TYPE>} [acData.result.type]
* The result type associated with the navigation action. * The result type associated with the navigation action.
* @param {typeof lazy.UrlbarUtils.RESULT_SOURCE} [acData.result.source] * @param {Items<typeof lazy.UrlbarUtils.RESULT_SOURCE>} [acData.result.source]
* The result source associated with the navigation action. * The result source associated with the navigation action.
*/ */
onURLBarUserStartNavigation(acData) { onURLBarUserStartNavigation(acData) {

View File

@@ -2,10 +2,11 @@
* Types specific to toolkit/extensions code. * Types specific to toolkit/extensions code.
*/ */
declare global { declare global {
type BaseContext = import("ExtensionCommon.sys.mjs").BaseContext; type BaseContext = import("../ExtensionCommon.sys.mjs").BaseContext;
type ExtensionChild = import("ExtensionChild.sys.mjs").ExtensionChild; type ExtensionChild = import("../ExtensionChild.sys.mjs").ExtensionChild;
type Extension = import("Extension.sys.mjs").Extension; type Extension = import("../Extension.sys.mjs").Extension;
type callback = (...any) => any; type callback = (...any) => any;
type DOMWindow = Window;
interface nsIDOMProcessChild { interface nsIDOMProcessChild {
getActor(name: "ProcessConduits"): ProcessConduitsChild; getActor(name: "ProcessConduits"): ProcessConduitsChild;
@@ -33,3 +34,46 @@ import { ConduitAddress } from "ConduitsParent.sys.mjs";
type Conduit<Send> = PointConduit & { [s in `send${Items<Send>}`]: callback }; type Conduit<Send> = PointConduit & { [s in `send${Items<Send>}`]: callback };
type Init<Send> = ConduitAddress & { send: Send }; type Init<Send> = ConduitAddress & { send: Send };
type PreferencesNS =
typeof import("resource://gre/modules/Preferences.sys.mjs").Preferences;
declare module "resource://gre/modules/Preferences.sys.mjs" {
class Preferences {
get: PreferencesNS["get"];
}
}
declare module "resource://testing-common/Assert.sys.mjs" {
namespace Assert {
var equal: Assert["equal"];
var ok: Assert["ok"];
}
}
declare module "resource://gre/modules/addons/XPIDatabase.sys.mjs" {
interface AddonWrapper {
id: string;
version: string;
}
}
declare module "resource://gre/modules/IndexedDB.sys.mjs" {
interface Cursor extends IDBCursor {}
interface CursorWithValue {
value: IDBCursorWithValue["value"];
}
interface ObjectStore {
clear: IDBObjectStore["clear"];
delete: IDBObjectStore["delete"];
get: IDBObjectStore["get"];
getKey: (...args: Parameters<IDBObjectStore["getKey"]>) => Promise<any>;
put: IDBObjectStore["put"];
}
interface Transaction {
abort: IDBTransaction["abort"];
}
}

View File

@@ -1,32 +0,0 @@
// Exports for all modules redirected here by a catch-all rule in tsconfig.json.
export var AddonManager,
AddonManagerPrivate,
AddonSettings,
AddonWrapper,
AsyncShutdown,
ExtensionMenus,
ExtensionProcessScript,
ExtensionScriptingStore,
ExtensionUserScripts,
NetUtil,
E10SUtils,
LightweightThemeManager,
ServiceWorkerCleanUp,
GeckoViewConnection,
GeckoViewWebExtension,
IndexedDB,
JSONFile,
Log,
UrlbarUtils,
WebExtensionDescriptorActor;
/**
* A stub type for the "class" from EventEmitter.sys.mjs.
* TODO: Convert EventEmitter.sys.mjs into a proper class.
*/
export declare class EventEmitter {
emit(event: string, ...args: any[]): void;
on(event: string, listener: callback): void;
once(event: string, listener: callback): Promise<any>;
off(event: string, listener: callback): void;
}

View File

@@ -249,11 +249,11 @@ FinderHighlighter.prototype = {
* Toggle highlighting all occurrences of a word in a page. This method will * Toggle highlighting all occurrences of a word in a page. This method will
* be called recursively for each (i)frame inside a page. * be called recursively for each (i)frame inside a page.
* *
* @param {Booolean} highlight Whether highlighting should be turned on * @param {Booolean} highlight Whether highlighting should be turned on
* @param {String} word Needle to search for and highlight when found * @param {String} [word] Needle to search for and highlight when found
* @param {Boolean} linksOnly Only consider nodes that are links for the search * @param {Boolean} [linksOnly] Only consider nodes that are links for the search
* @param {Boolean} drawOutline Whether found links should be outlined. * @param {Boolean} [drawOutline] Whether found links should be outlined.
* @param {Boolean} useSubFrames Whether to iterate over subframes. * @param {Boolean} [useSubFrames] Whether to iterate over subframes.
* @yield {Promise} that resolves once the operation has finished * @yield {Promise} that resolves once the operation has finished
*/ */
async highlight(highlight, word, linksOnly, drawOutline, useSubFrames) { async highlight(highlight, word, linksOnly, drawOutline, useSubFrames) {

View File

@@ -62,6 +62,7 @@ export class FinderIterator {
* The returned promise is resolved when 1) the limit is reached, 2) when all * The returned promise is resolved when 1) the limit is reached, 2) when all
* the ranges have been found or 3) when `stop()` is called whilst iterating. * the ranges have been found or 3) when `stop()` is called whilst iterating.
* *
* @param {object} options
* @param {Number} [options.allowDistance] Allowed edit distance between the * @param {Number} [options.allowDistance] Allowed edit distance between the
* current word and `options.word` * current word and `options.word`
* when the iterator is already running * when the iterator is already running

View File

@@ -116,7 +116,7 @@ function forwardMethods(cls, target, methods) {
} }
} }
class Cursor { export class Cursor {
constructor(cursorRequest, source) { constructor(cursorRequest, source) {
this.cursorRequest = cursorRequest; this.cursorRequest = cursorRequest;
this.source = source; this.source = source;
@@ -166,7 +166,7 @@ defineCursorUpdateMethods(Cursor, [
forwardGetters(Cursor, "cursor", ["direction", "key", "primaryKey"]); forwardGetters(Cursor, "cursor", ["direction", "key", "primaryKey"]);
wrapMethods(Cursor, "cursor", ["delete", "update"]); wrapMethods(Cursor, "cursor", ["delete", "update"]);
class CursorWithValue extends Cursor {} export class CursorWithValue extends Cursor {}
forwardGetters(CursorWithValue, "cursor", ["value"]); forwardGetters(CursorWithValue, "cursor", ["value"]);
@@ -212,7 +212,7 @@ forwardGetters(Index, "index", [
"unique", "unique",
]); ]);
class ObjectStore extends Cursed { export class ObjectStore extends Cursed {
constructor(store) { constructor(store) {
super(store); super(store);
@@ -232,7 +232,7 @@ wrapMethods(ObjectStore, "store", ["add", "clear", "delete", "put"]);
forwardMethods(ObjectStore, "store", ["deleteIndex"]); forwardMethods(ObjectStore, "store", ["deleteIndex"]);
class Transaction { export class Transaction {
constructor(transaction) { constructor(transaction) {
this.transaction = transaction; this.transaction = transaction;
@@ -339,6 +339,7 @@ export class IndexedDB {
} }
constructor(db) { constructor(db) {
/** @type {IDBDatabase} */
this.db = db; this.db = db;
} }
@@ -347,7 +348,7 @@ export class IndexedDB {
/** /**
* Opens a transaction for the given object stores. * Opens a transaction for the given object stores.
* *
* @param {Array<string>} storeNames * @param {string | string[]} storeNames
* The names of the object stores for which to open a transaction. * The names of the object stores for which to open a transaction.
* @param {string} [mode = "readonly"] * @param {string} [mode = "readonly"]
* The mode in which to open the transaction. * The mode in which to open the transaction.

View File

@@ -249,8 +249,6 @@ let addonFor = wrapper => wrapperMap.get(wrapper);
const EMPTY_ARRAY = Object.freeze([]); const EMPTY_ARRAY = Object.freeze([]);
let AddonWrapper;
/** /**
* The AddonInternal is an internal only representation of add-ons. It * The AddonInternal is an internal only representation of add-ons. It
* may have come from the database or an extension manifest. * may have come from the database or an extension manifest.
@@ -882,7 +880,7 @@ export class AddonInternal {
* @param {AddonInternal} aAddon * @param {AddonInternal} aAddon
* The add-on object to wrap. * The add-on object to wrap.
*/ */
AddonWrapper = class { export class AddonWrapper {
constructor(aAddon) { constructor(aAddon) {
wrapperMap.set(this, aAddon); wrapperMap.set(this, aAddon);
} }
@@ -1525,7 +1523,7 @@ AddonWrapper = class {
} }
return url; return url;
} }
}; }
function chooseValue(aAddon, aObj, aProp) { function chooseValue(aAddon, aObj, aProp) {
let repositoryAddon = aAddon._repositoryAddon; let repositoryAddon = aAddon._repositoryAddon;