Bug 1948498 - Split platform specific xpcom idls into separate typelibs r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D238386
This commit is contained in:
zombie
2025-02-24 16:03:20 +00:00
parent 6a340a96fc
commit ffbe673917
9 changed files with 12011 additions and 11815 deletions
+6
View File
@@ -8,6 +8,12 @@
/// <reference types="./lib.gecko.nsresult.d.ts" />
/// <reference types="./lib.gecko.services.d.ts" />
/// <reference types="./lib.gecko.xpcom.d.ts" />
/// <reference types="./lib.gecko.xpidl.d.ts" />
/// Platform specific XPCOM modules.
/// <reference types="./lib.gecko.darwin.d.ts" />
/// <reference types="./lib.gecko.linux.d.ts" />
/// <reference types="./lib.gecko.win32.d.ts" />
/// Order of references matters here, for overriding type signatures.
/// <reference types="./lib.gecko.tweaks.d.ts" />
+381
View File
@@ -0,0 +1,381 @@
/**
* NOTE: Do not modify this file by hand.
* Content was generated from source XPCOM .idl files.
* If you're updating some of the sources, see README for instructions.
*/
declare global {
// https://searchfox.org/mozilla-central/source/toolkit/components/aboutthirdparty/nsIAboutThirdParty.idl
interface nsIInstalledApplication extends nsISupports {
readonly name: string;
readonly publisher: string;
}
interface nsIAboutThirdParty extends nsISupports {
readonly ModuleType_Unknown: 1;
readonly ModuleType_IME: 2;
readonly ModuleType_ShellExtension: 4;
readonly ModuleType_BlockedByUser: 8;
readonly ModuleType_BlockedByUserAtLaunch: 16;
lookupModuleType(aLeafName: string): u32;
lookupApplication(aModulePath: string): nsIInstalledApplication;
readonly isDynamicBlocklistAvailable: boolean;
readonly isDynamicBlocklistDisabled: boolean;
updateBlocklist(aLeafName: string, aNewBlockStatus: boolean): Promise<any>;
collectSystemInfo(): Promise<any>;
loadModuleForTesting(aModulePath: string): void;
}
// https://searchfox.org/mozilla-central/source/toolkit/components/aboutwindowsmessages/nsIAboutWindowsMessages.idl
interface nsIAboutWindowsMessages extends nsISupports {
getMessages(currentWindow: mozIDOMWindowProxy, messages: OutParam<string[][]>, windowTitles: OutParam<string[]>): void;
}
// https://searchfox.org/mozilla-central/source/toolkit/components/alerts/nsIWindowsAlertsService.idl
} // global
declare namespace nsIWindowsAlertNotification {
enum ImagePlacement {
eInline = 0,
eHero = 1,
eIcon = 2,
}
}
declare global {
interface nsIWindowsAlertNotification extends nsIAlertNotification, Enums<typeof nsIWindowsAlertNotification.ImagePlacement> {
handleActions: boolean;
imagePlacement: nsIWindowsAlertNotification.ImagePlacement;
}
interface nsIWindowsAlertsService extends nsIAlertsService {
handleWindowsTag(aWindowsTag: string): Promise<any>;
getXmlStringForWindowsAlert(aAlert: nsIAlertNotification, aWindowsTag?: string): string;
removeAllNotificationsForInstall(): void;
}
// https://searchfox.org/mozilla-central/source/toolkit/mozapps/defaultagent/nsIDefaultAgent.idl
interface nsIDefaultAgent extends nsISupports {
registerTask(aUniqueToken: string): void;
updateTask(aUniqueToken: string): void;
unregisterTask(aUniqueToken: string): void;
uninstall(aUniqueToken: string): void;
secondsSinceLastAppRun(): i64;
getDefaultBrowser(): string;
getReplacePreviousDefaultBrowser(aCurrentBrowser: string): string;
getDefaultPdfHandler(): string;
sendPing(aCurrentBrowser: string, aPreviousBrowser: string, aPdfHandler: string, aNotificationShown: string, aNotificationAction: string, daysSinceLastAppLaunch: u32): void;
setDefaultBrowserUserChoice(aAumid: string, aExtraFileExtensions: string[]): void;
setDefaultBrowserUserChoiceAsync(aAumid: string, aExtraFileExtensions: string[]): Promise<any>;
setDefaultExtensionHandlersUserChoice(aAumid: string, aFileExtensions: string[]): void;
agentDisabled(): boolean;
}
// https://searchfox.org/mozilla-central/source/toolkit/mozapps/defaultagent/nsIWindowsMutex.idl
interface nsIWindowsMutex extends nsISupports {
tryLock(): void;
isLocked(): boolean;
unlock(): void;
}
interface nsIWindowsMutexFactory extends nsISupports {
createMutex(aName: string): nsIWindowsMutex;
}
// https://searchfox.org/mozilla-central/source/dom/geolocation/nsIGeolocationUIUtilsWin.idl
interface nsIGeolocationUIUtilsWin extends nsISupports {
dismissPrompts(aBC: BrowsingContext): void;
}
// https://searchfox.org/mozilla-central/source/netwerk/socket/nsINamedPipeService.idl
// https://searchfox.org/mozilla-central/source/browser/components/shell/nsIWindowsShellService.idl
} // global
declare namespace nsIWindowsShellService {
enum LaunchOnLoginEnabledEnumerator {
LAUNCH_ON_LOGIN_DISABLED_BY_SETTINGS = 0,
LAUNCH_ON_LOGIN_DISABLED = 1,
LAUNCH_ON_LOGIN_ENABLED = 2,
LAUNCH_ON_LOGIN_ENABLED_BY_POLICY = 3,
}
}
declare global {
interface nsIWindowsShellService extends nsIShellService, Enums<typeof nsIWindowsShellService.LaunchOnLoginEnabledEnumerator> {
createShortcut(aBinary: nsIFile, aArguments: string[], aDescription: string, aIconFile: nsIFile, aIconIndex: u16, aAppUserModelId: string, aShortcutFolder: string, aShortcutName: string): Promise<any>;
getLaunchOnLoginShortcuts(): string[];
pinCurrentAppToStartMenuAsync(aCheckOnly: boolean): Promise<any>;
isCurrentAppPinnedToStartMenuAsync(): Promise<any>;
enableLaunchOnLoginMSIXAsync(aTaskId: string): Promise<any>;
disableLaunchOnLoginMSIXAsync(aTaskId: string): Promise<any>;
getLaunchOnLoginEnabledMSIXAsync(aTaskId: string): Promise<any>;
pinCurrentAppToTaskbarAsync(aPrivateBrowsing: boolean): Promise<any>;
checkPinCurrentAppToTaskbarAsync(aPrivateBrowsing: boolean): Promise<any>;
isCurrentAppPinnedToTaskbarAsync(aumid: string): Promise<any>;
pinShortcutToTaskbar(aAppUserModelId: string, aShortcutPath: string): Promise<any>;
createWindowsIcon(aFile: nsIFile, aContainer: imgIContainer): Promise<any>;
unpinShortcutFromTaskbar(aShortcutPath: string): void;
getTaskbarTabShortcutPath(aShortcutName: string): string;
getTaskbarTabPins(): string[];
classifyShortcut(aPath: string): string;
hasPinnableShortcut(aAUMID: string, aPrivateBrowsing: boolean): Promise<any>;
canSetDefaultBrowserUserChoice(): boolean;
checkAllProgIDsExist(): boolean;
checkBrowserUserChoiceHashes(): boolean;
isDefaultHandlerFor(aFileExtensionOrProtocol: string): boolean;
queryCurrentDefaultHandlerFor(aFileExtensionOrProtocol: string): string;
}
// https://searchfox.org/mozilla-central/source/toolkit/components/taskscheduler/nsIWinTaskSchedulerService.idl
interface nsIWinTaskSchedulerService extends nsISupports {
registerTask(aFolderName: string, aTaskName: string, aDefinitionXML: string, aUpdateExisting?: boolean): void;
validateTaskDefinition(aDefinitionXML: string): i32;
getTaskXML(aFolderName: string, aTaskName: string): string;
getCurrentUserSid(): string;
deleteTask(aFolderName: string, aTaskName: string): void;
getFolderTasks(aFolderName: string): string[];
createFolder(aParentFolderName: string, aSubFolderName: string): void;
deleteFolder(aParentFolderName: string, aSubFolderName: string): void;
}
// https://searchfox.org/mozilla-central/source/widget/nsIJumpListBuilder.idl
interface nsIJumpListBuilder extends nsISupports {
obtainAndCacheFavicon(faviconURL: nsIURI): string;
obtainAndCacheFaviconAsync(faviconURL: nsIURI): Promise<any>;
isAvailable(): Promise<any>;
checkForRemovals(): Promise<any>;
populateJumpList(aTaskDescriptions: any, aCustomTitle: string, aCustomDescriptions: any): Promise<any>;
clearJumpList(): Promise<any>;
}
// https://searchfox.org/mozilla-central/source/widget/nsIPrintSettingsWin.idl
// https://searchfox.org/mozilla-central/source/widget/nsITaskbarOverlayIconController.idl
interface nsITaskbarOverlayIconController extends nsISupports {
setOverlayIcon(statusIcon: imgIContainer, statusDescription: string, paintContext?: nsISVGPaintContext): void;
}
// https://searchfox.org/mozilla-central/source/widget/nsITaskbarPreview.idl
interface nsITaskbarPreview extends nsISupports {
controller: nsITaskbarPreviewController;
tooltip: string;
visible: boolean;
active: boolean;
invalidate(): void;
}
// https://searchfox.org/mozilla-central/source/widget/nsITaskbarPreviewButton.idl
interface nsITaskbarPreviewButton extends nsISupports {
tooltip: string;
dismissOnClick: boolean;
hasBorder: boolean;
disabled: boolean;
image: imgIContainer;
visible: boolean;
}
// https://searchfox.org/mozilla-central/source/widget/nsITaskbarPreviewController.idl
type nsITaskbarPreviewCallback = Callable<{
done(aCanvas: nsISupports, aDrawBorder: boolean): void;
}>
interface nsITaskbarPreviewController extends nsISupports {
readonly width: u32;
readonly height: u32;
readonly thumbnailAspectRatio: float;
requestPreview(aCallback: nsITaskbarPreviewCallback): void;
requestThumbnail(aCallback: nsITaskbarPreviewCallback, width: u32, height: u32): void;
onClose(): void;
onActivate(): boolean;
onClick(button: nsITaskbarPreviewButton): void;
}
// https://searchfox.org/mozilla-central/source/widget/nsITaskbarProgress.idl
interface nsITaskbarProgress extends nsISupports {
readonly STATE_NO_PROGRESS: 0;
readonly STATE_INDETERMINATE: 1;
readonly STATE_NORMAL: 2;
readonly STATE_ERROR: 3;
readonly STATE_PAUSED: 4;
setProgressState(state: nsTaskbarProgressState, currentValue?: u64, maxValue?: u64): void;
}
// https://searchfox.org/mozilla-central/source/widget/nsITaskbarTabPreview.idl
interface nsITaskbarTabPreview extends nsITaskbarPreview {
title: string;
icon: imgIContainer;
move(aNext: nsITaskbarTabPreview): void;
}
// https://searchfox.org/mozilla-central/source/widget/nsITaskbarWindowPreview.idl
interface nsITaskbarWindowPreview extends nsITaskbarPreview {
readonly NUM_TOOLBAR_BUTTONS: 7;
getButton(index: u32): nsITaskbarPreviewButton;
enableCustomDrawing: boolean;
}
// https://searchfox.org/mozilla-central/source/widget/nsIWinTaskbar.idl
interface nsIWinTaskbar extends nsISupports {
readonly available: boolean;
readonly defaultGroupId: string;
readonly defaultPrivateGroupId: string;
createTaskbarTabPreview(shell: nsIDocShell, controller: nsITaskbarPreviewController): nsITaskbarTabPreview;
getTaskbarWindowPreview(shell: nsIDocShell): nsITaskbarWindowPreview;
getTaskbarProgress(shell: nsIDocShell): nsITaskbarProgress;
getOverlayIconController(shell: nsIDocShell): nsITaskbarOverlayIconController;
createJumpListBuilder(aPrivateBrowsing: boolean): nsIJumpListBuilder;
getGroupIdForWindow(aParent: mozIDOMWindow): string;
setGroupIdForWindow(aParent: mozIDOMWindow, aIdentifier: string): void;
}
// https://searchfox.org/mozilla-central/source/widget/nsIWindowsUIUtils.idl
interface nsIWindowsUIUtils extends nsISupports {
readonly systemSmallIconSize: i32;
readonly systemLargeIconSize: i32;
setWindowIcon(aWindow: mozIDOMWindowProxy, aSmallIcon: imgIContainer, aLargeIcon: imgIContainer): void;
setWindowIconFromExe(aWindow: mozIDOMWindowProxy, aExe: string, aIndex: u16): void;
setWindowIconNoData(aWindow: mozIDOMWindowProxy): void;
readonly inWin10TabletMode: boolean;
readonly inWin11TabletMode: boolean;
shareUrl(shareTitle: string, urlToShare: string): void;
}
// https://searchfox.org/mozilla-central/source/toolkit/system/windowsPackageManager/nsIWindowsPackageManager.idl
interface nsIWindowsPackageManager extends nsISupports {
findUserInstalledPackages(prefix: string[]): string[];
getInstalledDate(): u64;
campaignId(): Promise<any>;
}
// https://searchfox.org/mozilla-central/source/xpcom/ds/nsIWindowsRegKey.idl
interface nsIWindowsRegKey extends nsISupports {
readonly ROOT_KEY_CLASSES_ROOT: 2147483648;
readonly ROOT_KEY_CURRENT_USER: 2147483649;
readonly ROOT_KEY_LOCAL_MACHINE: 2147483650;
readonly ACCESS_BASIC: 131072;
readonly ACCESS_QUERY_VALUE: 1;
readonly ACCESS_SET_VALUE: 2;
readonly ACCESS_CREATE_SUB_KEY: 4;
readonly ACCESS_ENUMERATE_SUB_KEYS: 8;
readonly ACCESS_NOTIFY: 16;
readonly ACCESS_READ: 131097;
readonly ACCESS_WRITE: 131078;
readonly ACCESS_ALL: 131103;
readonly WOW64_32: 512;
readonly WOW64_64: 256;
readonly TYPE_NONE: 0;
readonly TYPE_STRING: 1;
readonly TYPE_BINARY: 3;
readonly TYPE_INT: 4;
readonly TYPE_INT64: 11;
close(): void;
open(rootKey: u32, relPath: string, mode: u32): void;
create(rootKey: u32, relPath: string, mode: u32): void;
openChild(relPath: string, mode: u32): nsIWindowsRegKey;
createChild(relPath: string, mode: u32): nsIWindowsRegKey;
readonly childCount: u32;
getChildName(index: u32): string;
hasChild(name: string): boolean;
readonly valueCount: u32;
getValueName(index: u32): string;
hasValue(name: string): boolean;
removeChild(relPath: string): void;
removeValue(name: string): void;
getValueType(name: string): u32;
readStringValue(name: string): string;
readIntValue(name: string): u32;
readInt64Value(name: string): u64;
readBinaryValue(name: string): string;
writeStringValue(name: string, data: string): void;
writeIntValue(name: string, data: u32): void;
writeInt64Value(name: string, data: u64): void;
writeBinaryValue(name: string, data: string): void;
}
// https://searchfox.org/mozilla-central/source/toolkit/xre/nsIWinAppHelper.idl
interface nsIWinAppHelper extends nsISupports {
readonly userCanElevate: boolean;
}
interface nsIXPCComponents_Interfaces {
nsIInstalledApplication: nsJSIID<nsIInstalledApplication>;
nsIAboutThirdParty: nsJSIID<nsIAboutThirdParty>;
nsIAboutWindowsMessages: nsJSIID<nsIAboutWindowsMessages>;
nsIWindowsAlertNotification: nsJSIID<nsIWindowsAlertNotification, typeof nsIWindowsAlertNotification.ImagePlacement>;
nsIWindowsAlertsService: nsJSIID<nsIWindowsAlertsService>;
nsIDefaultAgent: nsJSIID<nsIDefaultAgent>;
nsIWindowsMutex: nsJSIID<nsIWindowsMutex>;
nsIWindowsMutexFactory: nsJSIID<nsIWindowsMutexFactory>;
nsIGeolocationUIUtilsWin: nsJSIID<nsIGeolocationUIUtilsWin>;
nsIWindowsShellService: nsJSIID<nsIWindowsShellService, typeof nsIWindowsShellService.LaunchOnLoginEnabledEnumerator>;
nsIWinTaskSchedulerService: nsJSIID<nsIWinTaskSchedulerService>;
nsIJumpListBuilder: nsJSIID<nsIJumpListBuilder>;
nsITaskbarOverlayIconController: nsJSIID<nsITaskbarOverlayIconController>;
nsITaskbarPreview: nsJSIID<nsITaskbarPreview>;
nsITaskbarPreviewButton: nsJSIID<nsITaskbarPreviewButton>;
nsITaskbarPreviewCallback: nsJSIID<nsITaskbarPreviewCallback>;
nsITaskbarPreviewController: nsJSIID<nsITaskbarPreviewController>;
nsITaskbarProgress: nsJSIID<nsITaskbarProgress>;
nsITaskbarTabPreview: nsJSIID<nsITaskbarTabPreview>;
nsITaskbarWindowPreview: nsJSIID<nsITaskbarWindowPreview>;
nsIWinTaskbar: nsJSIID<nsIWinTaskbar>;
nsIWindowsUIUtils: nsJSIID<nsIWindowsUIUtils>;
nsIWindowsPackageManager: nsJSIID<nsIWindowsPackageManager>;
nsIWindowsRegKey: nsJSIID<nsIWindowsRegKey>;
nsIWinAppHelper: nsJSIID<nsIWinAppHelper>;
}
} // global
// Typedefs from xpidl.
type PRTime = i64;
type nsTaskbarProgressState = i32;
// XPCOM internal utility types.
/** XPCOM inout param is passed in as a js object with a value property. */
type InOutParam<T> = { value: T };
/** XPCOM out param is written to the passed in object's value property. */
type OutParam<T> = { value?: T };
/** A named type to enable interfaces to inherit from enums. */
type Enums<enums> = enums;
/** Callable accepts either form of a [function] interface. */
type Callable<iface> = iface | Extract<iface[keyof iface], Function>
export {};
+11495 -11684
View File
File diff suppressed because it is too large Load Diff
+47
View File
@@ -0,0 +1,47 @@
/**
* Gecko XPIDL base types.
*/
/**
* Generic IDs are created by most code which passes a nsID to js.
* https://searchfox.org/mozilla-central/source/js/xpconnect/src/XPCJSID.cpp#24
*/
interface nsID<uuid = string> {
readonly number: uuid;
}
/**
* In addition to nsID, interface IIDs support instanceof type guards,
* and expose constants defined on the class, including variants from enums.
* https://searchfox.org/mozilla-central/source/js/xpconnect/src/XPCJSID.cpp#45
*/
type nsJSIID<iface, enums = {}> = nsID & Constants<iface> & enums & {
new (_: never): void;
prototype: iface;
}
/** A union type of all known interface IIDs. */
type nsIID = nsIXPCComponents_Interfaces[keyof nsIXPCComponents_Interfaces];
/** A generic to resolve QueryInterface return type from a nsIID. */
type nsQIResult<iid> = iid extends { prototype: infer U } ? U : never;
/** Picks only const number properties from T. */
type Constants<T> = { [K in keyof T as IfConst<K, T[K]>]: T[K] };
/** Resolves only for keys K whose corresponding type T is a narrow number. */
type IfConst<K, T> = T extends number ? (number extends T ? never : K) : never;
/** u32 */
type nsresult = u32;
// Numeric typedefs, useful as a quick reference in method signatures.
type double = number;
type float = number;
type i16 = number;
type i32 = number;
type i64 = number;
type u16 = number;
type u32 = number;
type u64 = number;
type u8 = number;
+76 -11
View File
@@ -20,6 +20,68 @@ const HEADER = `/**
*/
`;
const FOOTER = `
// XPCOM internal utility types.
/** XPCOM inout param is passed in as a js object with a value property. */
type InOutParam<T> = { value: T };
/** XPCOM out param is written to the passed in object's value property. */
type OutParam<T> = { value?: T };
/** A named type to enable interfaces to inherit from enums. */
type Enums<enums> = enums;
/** Callable accepts either form of a [function] interface. */
type Callable<iface> = iface | Extract<iface[keyof iface], Function>
export {};
`;
const PLATFORM_SPECIFIC = new Set([
"nsIAboutThirdParty.idl",
"nsIAboutWindowsMessages.idl",
"nsIAccessibleMacInterface.idl",
"nsIApplicationChooser.idl",
"nsIDefaultAgent.idl",
"nsIGeolocationUIUtilsWin.idl",
"nsIGtkTaskbarProgress.idl",
"nsIGNOMEShellService.idl",
"nsIJumpListBuilder.idl",
"nsIKeychainMigrationUtils.idl",
"nsILocalFileMac.idl",
"nsIMacDockSupport.idl",
"nsIMacFinderProgress.idl",
"nsIMacPreferencesReader.idl",
"nsIMacSharingService.idl",
"nsIMacShellService.idl",
"nsIMacUserActivityUpdater.idl",
"nsIMacWebAppUtils.idl",
"nsINamedPipeService.idl",
"nsIOpenTabsProvider.idl",
"nsIPrintSettingsWin.idl",
"nsIStandaloneNativeMenu.idl",
"nsITaskbarOverlayIconController.idl",
"nsITaskbarPreview.idl",
"nsITaskbarPreviewButton.idl",
"nsITaskbarPreviewController.idl",
"nsITaskbarProgress.idl",
"nsITaskbarTabPreview.idl",
"nsITaskbarWindowPreview.idl",
"nsITouchBarHelper.idl",
"nsITouchBarInput.idl",
"nsITouchBarUpdater.idl",
"nsIWinAppHelper.idl",
"nsIWinTaskbar.idl",
"nsIWinTaskSchedulerService.idl",
"nsIWindowsAlertsService.idl",
"nsIWindowsMutex.idl",
"nsIWindowsPackageManager.idl",
"nsIWindowsRegKey.idl",
"nsIWindowsShellService.idl",
"nsIWindowsUIUtils.idl",
]);
// Emit a typescript interface, along with any related enums.
function ts_interface(iface) {
let lines = [];
@@ -88,15 +150,15 @@ function ts_interface(iface) {
}
// Link all generated .d.json files into a self-contained ts typelib.
function ts_link(dir, files) {
function ts_link(dir, files, filter) {
let lines = [HEADER, "declare global {\n"];
let typedefs = {};
let iids = [];
for (let djson of files) {
for (let djson of files.sort()) {
let modules = JSON.parse(fs.readFileSync(`${dir}/${djson}`, "utf8"));
for (let mod of modules) {
for (let mod of modules.filter(m => filter(m.path.split("/").at(-1)))) {
lines.push(`// ${URL}${mod.path}\n`);
Object.assign(typedefs, Object.fromEntries(mod.typedefs ?? []));
@@ -119,20 +181,23 @@ function ts_link(dir, files) {
for (let [id, type] of Object.entries(typedefs).sort()) {
lines.push(`type ${id} = ${type};`);
}
lines.push("");
lines.push(FOOTER);
// Include xpcom builtins.
lines.push(fs.readFileSync(`${__dirname}/config/intrinsics.d.ts`, "utf8"));
return lines;
return lines.join("\n");
}
// For testing.
module.exports = { ts_link };
function main(lib_dts, djson_dir, ...djson_files) {
let dts = ts_link(djson_dir, djson_files).join("\n");
console.log(`[INFO] ${lib_dts} (${dts.length.toLocaleString()} bytes)`);
fs.writeFileSync(lib_dts, dts);
function main(lib_xpcom, djson_dir, ...djson_files) {
let dts = ts_link(djson_dir, djson_files, m => !PLATFORM_SPECIFIC.has(m));
console.log(`[INFO] ${lib_xpcom} (${dts.length.toLocaleString()} bytes)`);
fs.writeFileSync(lib_xpcom, dts);
let lib_plat = lib_xpcom.replace("xpcom", process.platform);
let spec = ts_link(djson_dir, djson_files, m => PLATFORM_SPECIFIC.has(m));
console.log(`[INFO] ${lib_plat} (${spec.length.toLocaleString()} bytes)`);
fs.writeFileSync(lib_plat, spec);
}
if (require.main === module) {
-66
View File
@@ -1,66 +0,0 @@
/**
* Gecko XPCOM builtins.
*/
declare global {
/**
* Generic IDs are created by most code which passes a nsID to js.
* https://searchfox.org/mozilla-central/source/js/xpconnect/src/XPCJSID.cpp#24
*/
interface nsID<uuid = string> {
readonly number: uuid;
}
/**
* In addition to nsID, interface IIDs support instanceof type guards,
* and expose constants defined on the class, including variants from enums.
* https://searchfox.org/mozilla-central/source/js/xpconnect/src/XPCJSID.cpp#45
*/
type nsJSIID<iface, enums = {}> = nsID & Constants<iface> & enums & {
new (_: never): void;
prototype: iface;
}
/** A union type of all known interface IIDs. */
type nsIID = nsIXPCComponents_Interfaces[keyof nsIXPCComponents_Interfaces];
/** A generic to resolve QueryInterface return type from a nsIID. */
export type nsQIResult<iid> = iid extends { prototype: infer U } ? U : never;
/** u32 */
type nsresult = u32;
// Numeric typedefs, useful as a quick reference in method signatures.
type double = number;
type float = number;
type i16 = number;
type i32 = number;
type i64 = number;
type u16 = number;
type u32 = number;
type u64 = number;
type u8 = number;
}
/**
* XPCOM utility types.
*/
/** XPCOM inout param is passed in as a js object with a value property. */
type InOutParam<T> = { value: T };
/** XPCOM out param is written to the passed in object's value property. */
type OutParam<T> = { value?: T };
/** A named type to enable interfaces to inherit from enums. */
type Enums<enums> = enums;
/** Callable accepts either form of a [function] interface. */
type Callable<iface> = iface | Extract<iface[keyof iface], Function>
/** Picks only const number properties from T. */
type Constants<T> = { [K in keyof T as IfConst<K, T[K]>]: T[K] };
/** Resolves only for keys K whose corresponding type T is a narrow number. */
type IfConst<K, T> = T extends number ? (number extends T ? never : K) : never;
export {};
+4 -1
View File
@@ -99,11 +99,14 @@ def setup(ctx):
@SubCommand("ts", "update", description="Update tools/@types libraries.")
def update(ctx):
typelib_dir = mozpath.join(ctx.topsrcdir, "tools/@types")
platforms = ["darwin", "linux", "win32"]
for lib in targets:
for lib in targets + platforms:
file = f"lib.gecko.{lib}.d.ts"
path = mozpath.join(ctx.distdir, "@types", file)
if not os.path.exists(path):
if lib in platforms:
continue
print(f"[ERROR] {path} not found. Did you run `mach ts build`?")
return 1
+1 -52
View File
@@ -187,52 +187,7 @@ interface nsIXPCComponents_Interfaces {
// Typedefs from xpidl.
type PRTime = i64;
/**
* Gecko XPCOM builtins.
*/
declare global {
/**
* Generic IDs are created by most code which passes a nsID to js.
* https://searchfox.org/mozilla-central/source/js/xpconnect/src/XPCJSID.cpp#24
*/
interface nsID<uuid = string> {
readonly number: uuid;
}
/**
* In addition to nsID, interface IIDs support instanceof type guards,
* and expose constants defined on the class, including variants from enums.
* https://searchfox.org/mozilla-central/source/js/xpconnect/src/XPCJSID.cpp#45
*/
type nsJSIID<iface, enums = {}> = nsID & Constants<iface> & enums & {
new (_: never): void;
prototype: iface;
}
/** A union type of all known interface IIDs. */
type nsIID = nsIXPCComponents_Interfaces[keyof nsIXPCComponents_Interfaces];
/** A generic to resolve QueryInterface return type from a nsIID. */
export type nsQIResult<iid> = iid extends { prototype: infer U } ? U : never;
/** u32 */
type nsresult = u32;
// Numeric typedefs, useful as a quick reference in method signatures.
type double = number;
type float = number;
type i16 = number;
type i32 = number;
type i64 = number;
type u16 = number;
type u32 = number;
type u64 = number;
type u8 = number;
}
/**
* XPCOM utility types.
*/
// XPCOM internal utility types.
/** XPCOM inout param is passed in as a js object with a value property. */
type InOutParam<T> = { value: T };
@@ -246,10 +201,4 @@ type Enums<enums> = enums;
/** Callable accepts either form of a [function] interface. */
type Callable<iface> = iface | Extract<iface[keyof iface], Function>
/** Picks only const number properties from T. */
type Constants<T> = { [K in keyof T as IfConst<K, T[K]>]: T[K] };
/** Resolves only for keys K whose corresponding type T is a narrow number. */
type IfConst<K, T> = T extends number ? (number extends T ? never : K) : never;
export {};
+1 -1
View File
@@ -13,6 +13,6 @@ const dir = path.join(__dirname, "../../../xpcom/idl-parser/xpidl/fixtures/");
const files = ["xpctest.d.json"];
test("xpctest.d.json produces expected baseline d.ts", () => {
let dts = ts_link(dir, files).join("\n");
let dts = ts_link(dir, files, () => true);
expect(dts).toEqual(fs.readFileSync(test_dts, "utf8"));
});