Bug 1703953 - Part 2: Apply mozilla/use-isInstance rules for .jsm files r=webdriver-reviewers,pip-reviewers,mhowell,Gijs,whimboo

This replaces all `instanceof` uses for DOM interfaces, since the operator in priviliged context works same as .isInstance().

Differential Revision: https://phabricator.services.mozilla.com/D141785
This commit is contained in:
Kagami Sascha Rosylight 2022-03-29 13:11:00 +00:00
parent cbfca993e7
commit c8f12f94dc
58 changed files with 178 additions and 170 deletions

View File

@ -173,7 +173,7 @@ class AboutReaderChild extends JSWindowActorChild {
!this.isAboutReader &&
this.contentWindow &&
this.contentWindow.windowRoot &&
this.document instanceof this.contentWindow.HTMLDocument &&
this.contentWindow.HTMLDocument.isInstance(this.document) &&
!this.document.mozSyntheticDocument
);
}

View File

@ -395,7 +395,7 @@ class ContextMenuChild extends JSWindowActorChild {
if (node.nodeType == node.TEXT_NODE) {
// Add this text to our collection.
text += " " + node.data;
} else if (node instanceof this.contentWindow.HTMLImageElement) {
} else if (this.contentWindow.HTMLImageElement.isInstance(node)) {
// If it has an "alt" attribute, add that.
let altText = node.getAttribute("alt");
if (altText && altText != "") {
@ -463,11 +463,11 @@ class ContextMenuChild extends JSWindowActorChild {
}
_isTargetATextBox(node) {
if (node instanceof this.contentWindow.HTMLInputElement) {
if (this.contentWindow.HTMLInputElement.isInstance(node)) {
return node.mozIsTextField(false);
}
return node instanceof this.contentWindow.HTMLTextAreaElement;
return this.contentWindow.HTMLTextAreaElement.isInstance(node);
}
/**
@ -800,9 +800,9 @@ class ContextMenuChild extends JSWindowActorChild {
if (node.containingShadowRoot?.isUAWidget()) {
const host = node.containingShadowRoot.host;
if (
host instanceof this.contentWindow.HTMLMediaElement ||
host instanceof this.contentWindow.HTMLEmbedElement ||
host instanceof this.contentWindow.HTMLObjectElement
this.contentWindow.HTMLMediaElement.isInstance(host) ||
this.contentWindow.HTMLEmbedElement.isInstance(host) ||
this.contentWindow.HTMLObjectElement.isInstance(host)
) {
node = host;
}
@ -973,10 +973,10 @@ class ContextMenuChild extends JSWindowActorChild {
imageText: context.target.title || context.target.alt,
};
const { SVGAnimatedLength } = context.target.ownerGlobal;
if (context.imageInfo.height instanceof SVGAnimatedLength) {
if (SVGAnimatedLength.isInstance(context.imageInfo.height)) {
context.imageInfo.height = context.imageInfo.height.animVal.value;
}
if (context.imageInfo.width instanceof SVGAnimatedLength) {
if (SVGAnimatedLength.isInstance(context.imageInfo.width)) {
context.imageInfo.width = context.imageInfo.width.animVal.value;
}
@ -1033,9 +1033,11 @@ class ContextMenuChild extends JSWindowActorChild {
descURL
);
}
} else if (context.target instanceof this.contentWindow.HTMLCanvasElement) {
} else if (
this.contentWindow.HTMLCanvasElement.isInstance(context.target)
) {
context.onCanvas = true;
} else if (context.target instanceof this.contentWindow.HTMLVideoElement) {
} else if (this.contentWindow.HTMLVideoElement.isInstance(context.target)) {
const mediaURL = context.target.currentSrc || context.target.src;
if (this._isMediaURLReusable(mediaURL)) {
@ -1061,7 +1063,7 @@ class ContextMenuChild extends JSWindowActorChild {
} else {
context.onVideo = true;
}
} else if (context.target instanceof this.contentWindow.HTMLAudioElement) {
} else if (this.contentWindow.HTMLAudioElement.isInstance(context.target)) {
context.onAudio = true;
const mediaURL = context.target.currentSrc || context.target.src;
@ -1092,7 +1094,7 @@ class ContextMenuChild extends JSWindowActorChild {
}
context.onKeywordField = editFlags & SpellCheckHelper.KEYWORD;
} else if (context.target instanceof this.contentWindow.HTMLHtmlElement) {
} else if (this.contentWindow.HTMLHtmlElement.isInstance(context.target)) {
const bodyElt = context.target.ownerDocument.body;
if (bodyElt) {
@ -1141,12 +1143,13 @@ class ContextMenuChild extends JSWindowActorChild {
// Be consistent with what hrefAndLinkNodeForClickEvent
// does in browser.js
(this._isXULTextLinkLabel(elem) ||
(elem instanceof this.contentWindow.HTMLAnchorElement &&
(this.contentWindow.HTMLAnchorElement.isInstance(elem) &&
elem.href) ||
(elem instanceof this.contentWindow.SVGAElement &&
(this.contentWindow.SVGAElement.isInstance(elem) &&
(elem.href || elem.hasAttributeNS(XLINK_NS, "href"))) ||
(elem instanceof this.contentWindow.HTMLAreaElement && elem.href) ||
elem instanceof this.contentWindow.HTMLLinkElement ||
(this.contentWindow.HTMLAreaElement.isInstance(elem) &&
elem.href) ||
this.contentWindow.HTMLLinkElement.isInstance(elem) ||
elem.getAttributeNS(XLINK_NS, "type") == "simple")
) {
// Target is a link or a descendant of a link.

View File

@ -175,7 +175,7 @@ class PageInfoChild extends JSWindowActorChild {
}
// One swi^H^H^Hif-else to rule them all.
if (elem instanceof content.HTMLImageElement) {
if (content.HTMLImageElement.isInstance(elem)) {
addMedia(
elem.src,
"img",
@ -184,7 +184,7 @@ class PageInfoChild extends JSWindowActorChild {
false,
!elem.hasAttribute("alt")
);
} else if (elem instanceof content.SVGImageElement) {
} else if (content.SVGImageElement.isInstance(elem)) {
try {
// Note: makeURLAbsolute will throw if either the baseURI is not a valid URI
// or the URI formed from the baseURI and the URL is not a valid URI.
@ -197,17 +197,17 @@ class PageInfoChild extends JSWindowActorChild {
addMedia(href, "img", "", elem, false);
}
} catch (e) {}
} else if (elem instanceof content.HTMLVideoElement) {
} else if (content.HTMLVideoElement.isInstance(elem)) {
addMedia(elem.currentSrc, "video", "", elem, false);
} else if (elem instanceof content.HTMLAudioElement) {
} else if (content.HTMLAudioElement.isInstance(elem)) {
addMedia(elem.currentSrc, "audio", "", elem, false);
} else if (elem instanceof content.HTMLLinkElement) {
} else if (content.HTMLLinkElement.isInstance(elem)) {
if (elem.rel && /\bicon\b/i.test(elem.rel)) {
addMedia(elem.href, "link", "", elem, false);
}
} else if (
elem instanceof content.HTMLInputElement ||
elem instanceof content.HTMLButtonElement
content.HTMLInputElement.isInstance(elem) ||
content.HTMLButtonElement.isInstance(elem)
) {
if (elem.type.toLowerCase() == "image") {
addMedia(
@ -219,9 +219,9 @@ class PageInfoChild extends JSWindowActorChild {
!elem.hasAttribute("alt")
);
}
} else if (elem instanceof content.HTMLObjectElement) {
} else if (content.HTMLObjectElement.isInstance(elem)) {
addMedia(elem.data, "object", this.getValueText(elem), elem, false);
} else if (elem instanceof content.HTMLEmbedElement) {
} else if (content.HTMLEmbedElement.isInstance(elem)) {
addMedia(elem.src, "embed", "", elem, false);
}
@ -240,12 +240,12 @@ class PageInfoChild extends JSWindowActorChild {
let imageText;
if (
!isBG &&
!(item instanceof content.SVGImageElement) &&
!(document instanceof content.ImageDocument)
!content.SVGImageElement.isInstance(item) &&
!content.ImageDocument.isInstance(document)
) {
imageText = item.title || item.alt;
if (!imageText && !(item instanceof content.HTMLImageElement)) {
if (!imageText && !content.HTMLImageElement.isInstance(item)) {
imageText = this.getValueText(item);
}
}
@ -255,9 +255,9 @@ class PageInfoChild extends JSWindowActorChild {
result.numFrames = 1;
if (
item instanceof content.HTMLObjectElement ||
item instanceof content.HTMLEmbedElement ||
item instanceof content.HTMLLinkElement
content.HTMLObjectElement.isInstance(item) ||
content.HTMLEmbedElement.isInstance(item) ||
content.HTMLLinkElement.isInstance(item)
) {
result.mimeType = item.type;
}
@ -290,13 +290,13 @@ class PageInfoChild extends JSWindowActorChild {
}
}
result.HTMLLinkElement = item instanceof content.HTMLLinkElement;
result.HTMLInputElement = item instanceof content.HTMLInputElement;
result.HTMLImageElement = item instanceof content.HTMLImageElement;
result.HTMLObjectElement = item instanceof content.HTMLObjectElement;
result.SVGImageElement = item instanceof content.SVGImageElement;
result.HTMLVideoElement = item instanceof content.HTMLVideoElement;
result.HTMLAudioElement = item instanceof content.HTMLAudioElement;
result.HTMLLinkElement = content.HTMLLinkElement.isInstance(item);
result.HTMLInputElement = content.HTMLInputElement.isInstance(item);
result.HTMLImageElement = content.HTMLImageElement.isInstance(item);
result.HTMLObjectElement = content.HTMLObjectElement.isInstance(item);
result.SVGImageElement = content.SVGImageElement.isInstance(item);
result.HTMLVideoElement = content.HTMLVideoElement.isInstance(item);
result.HTMLAudioElement = content.HTMLAudioElement.isInstance(item);
if (isBG) {
// Items that are showing this image as a background
@ -307,7 +307,7 @@ class PageInfoChild extends JSWindowActorChild {
img.src = url;
result.naturalWidth = img.naturalWidth;
result.naturalHeight = img.naturalHeight;
} else if (!(item instanceof content.SVGImageElement)) {
} else if (!content.SVGImageElement.isInstance(item)) {
// SVG items do not have integer values for height or width,
// so we must handle them differently in order to correctly
// serialize
@ -318,7 +318,7 @@ class PageInfoChild extends JSWindowActorChild {
result.height = item.height;
}
if (item instanceof content.SVGImageElement) {
if (content.SVGImageElement.isInstance(item)) {
result.SVGImageElementWidth = item.width.baseVal.value;
result.SVGImageElementHeight = item.height.baseVal.value;
}
@ -337,9 +337,9 @@ class PageInfoChild extends JSWindowActorChild {
// Form input elements don't generally contain information that is useful to our callers, so return nothing.
if (
node instanceof content.HTMLInputElement ||
node instanceof content.HTMLSelectElement ||
node instanceof content.HTMLTextAreaElement
content.HTMLInputElement.isInstance(node) ||
content.HTMLSelectElement.isInstance(node) ||
content.HTMLTextAreaElement.isInstance(node)
) {
return valueText;
}
@ -357,7 +357,7 @@ class PageInfoChild extends JSWindowActorChild {
} else if (nodeType == content.Node.ELEMENT_NODE) {
// And elements can have more text inside them.
// Images are special, we want to capture the alt text as if the image weren't there.
if (childNode instanceof content.HTMLImageElement) {
if (content.HTMLImageElement.isInstance(childNode)) {
valueText += " " + this.getAltText(childNode);
} else {
valueText += " " + this.getValueText(childNode);

View File

@ -71,7 +71,7 @@ class PluginChild extends JSWindowActorChild {
* document that GMP is being used in.
*/
async onPluginCrashed(aEvent) {
if (!(aEvent instanceof this.contentWindow.PluginCrashedEvent)) {
if (!this.contentWindow.PluginCrashedEvent.isInstance(aEvent)) {
return;
}

View File

@ -316,7 +316,7 @@ var AttributionCode = {
try {
bytes = await AttributionIOUtils.read(attributionFile.path);
} catch (ex) {
if (ex instanceof DOMException && ex.name == "NotFoundError") {
if (DOMException.isInstance(ex) && ex.name == "NotFoundError") {
log.debug(
`getAttrDataAsync: !exists("${
attributionFile.path

View File

@ -1784,7 +1784,7 @@ var CustomizableUIInternal = {
if (aWidget.onBuild) {
node = aWidget.onBuild(aDocument);
}
if (!node || !(node instanceof aDocument.defaultView.XULElement)) {
if (!node || !aDocument.defaultView.XULElement.isInstance(node)) {
log.error(
"Custom widget with id " +
aWidget.id +

View File

@ -65,7 +65,7 @@ this.PersistentCache = class PersistentCache {
data = await IOUtils.readJSON(filepath);
} catch (error) {
if (
!(error instanceof DOMException) ||
!DOMException.isInstance(error) ||
error.name !== "NotFoundError"
) {
Cu.reportError(

View File

@ -597,13 +597,13 @@ class SearchOneOffs {
} else {
let newTabPref = Services.prefs.getBoolPref("browser.search.openintab");
if (
(aEvent instanceof KeyboardEvent && aEvent.altKey) ^ newTabPref &&
(KeyboardEvent.isInstance(aEvent) && aEvent.altKey) ^ newTabPref &&
!this.window.gBrowser.selectedTab.isEmpty
) {
where = "tab";
}
if (
aEvent instanceof MouseEvent &&
MouseEvent.isInstance(aEvent) &&
(aEvent.button == 1 || aEvent.getModifierState("Accel"))
) {
where = "tab";
@ -903,17 +903,17 @@ class SearchOneOffs {
let target = event.originalTarget;
if (event instanceof KeyboardEvent && this.selectedButton) {
if (KeyboardEvent.isInstance(event) && this.selectedButton) {
return true;
}
if (
event instanceof MouseEvent &&
MouseEvent.isInstance(event) &&
target.classList.contains("searchbar-engine-one-off-item")
) {
return true;
}
if (
event instanceof this.window.XULCommandEvent &&
this.window.XULCommandEvent.isInstance(event) &&
target.classList.contains("search-one-offs-context-open-in-new-tab")
) {
return true;

View File

@ -276,9 +276,12 @@ var SessionFileInternal = {
.add(Date.now() - startMs);
break;
} catch (ex) {
if (ex instanceof DOMException && ex.name == "NotFoundError") {
if (DOMException.isInstance(ex) && ex.name == "NotFoundError") {
exists = false;
} else if (ex instanceof DOMException && ex.name == "NotAllowedError") {
} else if (
DOMException.isInstance(ex) &&
ex.name == "NotAllowedError"
) {
// The file might be inaccessible due to wrong permissions
// or similar failures. We'll just count it as "corrupted".
console.error("Could not read session file ", ex);

View File

@ -143,7 +143,7 @@ BingTranslator.prototype = {
*/
_chunkFailed(aError) {
if (
aError instanceof XMLHttpRequest &&
XMLHttpRequest.isInstance(aError) &&
[400, 401].includes(aError.status)
) {
let body = aError.responseText;

View File

@ -149,7 +149,7 @@ YandexTranslator.prototype = {
* @param aError [optional] The XHR object of the request that failed.
*/
_chunkFailed(aError) {
if (aError instanceof XMLHttpRequest) {
if (XMLHttpRequest.isInstance(aError)) {
let body = aError.responseText;
let json = { code: 0 };
try {

View File

@ -866,7 +866,7 @@ class TelemetryEvent {
} else if (event.type == "blur") {
action = "blur";
} else {
action = event instanceof MouseEvent ? "click" : "enter";
action = MouseEvent.isInstance(event) ? "click" : "enter";
}
let method = action == "blur" ? "abandonment" : "engagement";
let value = this._startEventInfo.interactionType;

View File

@ -436,7 +436,7 @@ class UrlbarInput {
* @param {Event} [event] The event triggering the open.
*/
handleCommand(event = null) {
let isMouseEvent = event instanceof this.window.MouseEvent;
let isMouseEvent = this.window.MouseEvent.isInstance(event);
if (isMouseEvent && event.button == 2) {
// Do nothing for right clicks.
return;
@ -2322,7 +2322,7 @@ class UrlbarInput {
// Only add the suffix when the URL bar value isn't already "URL-like",
// and only if we get a keyboard event, to match user expectations.
if (
!(event instanceof KeyboardEvent) ||
!KeyboardEvent.isInstance(event) ||
event._disableCanonization ||
!event.ctrlKey ||
!UrlbarPrefs.get("ctrlCanonizesURLs") ||
@ -2529,7 +2529,7 @@ class UrlbarInput {
* @returns {"current" | "tabshifted" | "tab" | "save" | "window"}
*/
_whereToOpen(event) {
let isKeyboardEvent = event instanceof KeyboardEvent;
let isKeyboardEvent = KeyboardEvent.isInstance(event);
let reuseEmpty = isKeyboardEvent;
let where = undefined;
if (
@ -3390,8 +3390,9 @@ class UrlbarInput {
_on_drop(event) {
let droppedItem = getDroppableData(event);
let droppedURL =
droppedItem instanceof URL ? droppedItem.href : droppedItem;
let droppedURL = URL.isInstance(droppedItem)
? droppedItem.href
: droppedItem;
if (droppedURL && droppedURL !== this.window.gBrowser.currentURI.spec) {
let principal = Services.droppedLinkHandler.getTriggeringPrincipal(event);
this.value = droppedURL;

View File

@ -684,7 +684,7 @@ var UrlbarUtils = {
: UrlbarUtils.ICON.DEFAULT;
}
if (
url instanceof URL &&
URL.isInstance(url) &&
UrlbarUtils.PROTOCOLS_WITH_ICONS.includes(url.protocol)
) {
return "page-icon:" + url.href;
@ -742,7 +742,7 @@ var UrlbarUtils = {
return;
}
if (urlOrEngine instanceof URL) {
if (URL.isInstance(urlOrEngine)) {
urlOrEngine = urlOrEngine.href;
}

View File

@ -90,7 +90,7 @@ function isBrowsingContextPartOfContext(
//
// Such project would be about applying "EFT" to the browser toolbox and non-content documents
if (
browsingContext instanceof CanonicalBrowsingContext &&
CanonicalBrowsingContext.isInstance(browsingContext) &&
!browsingContext.isContent
) {
return false;
@ -99,7 +99,7 @@ function isBrowsingContextPartOfContext(
if (!windowGlobal) {
// When we are in the parent process, WindowGlobal can be retrieved from the BrowsingContext,
// while in the content process, the callsites have to pass it manually as an argument
if (browsingContext instanceof CanonicalBrowsingContext) {
if (CanonicalBrowsingContext.isInstance(browsingContext)) {
windowGlobal = browsingContext.currentWindowGlobal;
} else if (!windowGlobal && !acceptNoWindowGlobal) {
throw new Error(

View File

@ -319,7 +319,7 @@ DOMRequestIpcHelper.prototype = {
}
Object.keys(this._requests).forEach(aKey => {
if (this.getRequest(aKey) instanceof this._window.DOMRequest) {
if (this._window.DOMRequest.isInstance(this.getRequest(aKey))) {
aCallback(aKey);
}
});

View File

@ -49,13 +49,13 @@ class GeckoViewAutoFillChild extends GeckoViewActorChild {
break;
}
case "focusin": {
if (aEvent.composedTarget instanceof contentWindow.HTMLInputElement) {
if (contentWindow.HTMLInputElement.isInstance(aEvent.composedTarget)) {
this._autofill.onFocus(aEvent.composedTarget);
}
break;
}
case "focusout": {
if (aEvent.composedTarget instanceof contentWindow.HTMLInputElement) {
if (contentWindow.HTMLInputElement.isInstance(aEvent.composedTarget)) {
this._autofill.onFocus(null);
}
break;

View File

@ -128,7 +128,7 @@ class SelectionActionDelegateChild extends GeckoViewActorChild {
return (
win &&
win.HTMLInputElement &&
focus instanceof win.HTMLInputElement &&
win.HTMLInputElement.isInstance(focus) &&
!focus.mozIsTextField(/* excludePassword */ true)
);
}
@ -149,8 +149,8 @@ class SelectionActionDelegateChild extends GeckoViewActorChild {
win &&
win.HTMLInputElement &&
win.HTMLTextAreaElement &&
!(focus instanceof win.HTMLInputElement) &&
!(focus instanceof win.HTMLTextAreaElement)
!win.HTMLInputElement.isInstance(focus) &&
!win.HTMLTextAreaElement.isInstance(focus)
);
}

View File

@ -102,10 +102,10 @@ class PromptFactory {
id: String(id),
disabled: disabled || child.disabled,
};
if (child instanceof win.HTMLOptGroupElement) {
if (win.HTMLOptGroupElement.isInstance(child)) {
item.label = child.label;
item.items = enumList(child, item.disabled);
} else if (child instanceof win.HTMLOptionElement) {
} else if (win.HTMLOptionElement.isInstance(child)) {
item.label = child.label || child.text;
item.selected = child.selected;
} else {
@ -140,7 +140,7 @@ class PromptFactory {
let dispatchEvents = false;
if (!aElement.multiple) {
const elem = map[result.choices[0]];
if (elem && elem instanceof win.HTMLOptionElement) {
if (elem && win.HTMLOptionElement.isInstance(elem)) {
dispatchEvents = !elem.selected;
elem.selected = true;
} else {
@ -153,7 +153,7 @@ class PromptFactory {
const elem = map[i];
const index = result.choices.indexOf(String(i));
if (
elem instanceof win.HTMLOptionElement &&
win.HTMLOptionElement.isInstance(elem) &&
elem.selected !== index >= 0
) {
// Current selected is not the same as the new selected state.
@ -386,7 +386,7 @@ class PromptFactory {
callProxy(aMethod, aArguments) {
const prompt = new PromptDelegate(aArguments[0]);
let promptArgs;
if (aArguments[0] instanceof BrowsingContext) {
if (BrowsingContext.isInstance(aArguments[0])) {
// Called by BrowsingContext prompt method, strip modalType.
[, , /*browsingContext*/ /*modalType*/ ...promptArgs] = aArguments;
} else {

View File

@ -24,7 +24,7 @@ class GeckoViewPrompter {
.slice(1, -1); // Discard surrounding braces
if (aParent) {
if (aParent instanceof Window) {
if (Window.isInstance(aParent)) {
this._domWin = aParent;
} else if (aParent.window) {
this._domWin = aParent.window;

View File

@ -57,7 +57,7 @@ class GeckoViewAutofill {
const window = aElement.ownerGlobal;
const bounds = aElement.getBoundingClientRect();
const isInputElement = aElement instanceof window.HTMLInputElement;
const isInputElement = window.HTMLInputElement.isInstance(aElement);
info = {
isInputElement,
@ -238,7 +238,7 @@ class GeckoViewAutofill {
const value = responses[uuid] || "";
if (
element instanceof window.HTMLInputElement &&
window.HTMLInputElement.isInstance(element) &&
!element.disabled &&
element.parentElement
) {

View File

@ -43,7 +43,7 @@ class StreamRegistry {
}
async _discard(stream) {
if (stream instanceof OS.File) {
if (OS.File.isInstance(stream)) {
let fileInfo;
// Also remove the temporary file
@ -70,7 +70,7 @@ class StreamRegistry {
add(stream) {
let handle;
if (stream instanceof OS.File) {
if (OS.File.isInstance(stream)) {
handle = Services.uuid
.generateUUID()
.toString()

View File

@ -84,7 +84,7 @@ class DOM extends ContentProcessDomain {
}
let context = this.docShell.browsingContext;
if (unsafeObj instanceof HTMLIFrameElement) {
if (HTMLIFrameElement.isInstance(unsafeObj)) {
context = unsafeObj.contentWindow.docShell.browsingContext;
}

View File

@ -108,7 +108,7 @@ class WindowManager {
* @return {WindowProperties} A window properties object.
*/
getWindowProperties(win, options = {}) {
if (!(win instanceof Window)) {
if (!Window.isInstance(win)) {
throw new TypeError("Invalid argument, expected a Window object");
}

View File

@ -8,7 +8,7 @@ const EXPORTED_SYMBOLS = ["isBrowsingContextCompatible"];
function isExtensionContext(browsingContext) {
let principal;
if (browsingContext instanceof CanonicalBrowsingContext) {
if (CanonicalBrowsingContext.isInstance(browsingContext)) {
principal = browsingContext.currentWindowGlobal.documentPrincipal;
} else {
principal = browsingContext.window.document.nodePrincipal;
@ -22,7 +22,7 @@ function isExtensionContext(browsingContext) {
}
function isParentProcess(browsingContext) {
if (browsingContext instanceof CanonicalBrowsingContext) {
if (CanonicalBrowsingContext.isInstance(browsingContext)) {
return browsingContext.currentWindowGlobal.osPid === -1;
}

View File

@ -148,7 +148,7 @@ var MockFilePicker = {
this.pendingPromises = [];
for (let file of files) {
if (file instanceof this.window.File) {
if (this.window.File.isInstance(file)) {
this.returnData.push(this.internalFileData({ domFile: file }));
} else {
let promise = this.window.File.createFromNsIFile(file, {

View File

@ -69,8 +69,10 @@ class AutoScrollChild extends JSWindowActorChild {
// Or if we're on a scrollbar or XUL <tree>
if (
(mmScrollbarPosition &&
node.closest("scrollbar,scrollcorner") instanceof content.XULElement) ||
node.closest("treechildren") instanceof content.XULElement
content.XULElement.isInstance(
node.closest("scrollbar,scrollcorner")
)) ||
content.XULElement.isInstance(node.closest("treechildren"))
) {
return true;
}
@ -79,11 +81,11 @@ class AutoScrollChild extends JSWindowActorChild {
isScrollableElement(aNode) {
let content = aNode.ownerGlobal;
if (aNode instanceof content.HTMLElement) {
return !(aNode instanceof content.HTMLSelectElement) || aNode.multiple;
if (content.HTMLElement.isInstance(aNode)) {
return !content.HTMLSelectElement.isInstance(aNode) || aNode.multiple;
}
return aNode instanceof content.XULElement;
return content.XULElement.isInstance(aNode);
}
computeWindowScrollDirection(global) {
@ -117,13 +119,13 @@ class AutoScrollChild extends JSWindowActorChild {
// overflow property
let scrollVert =
node.scrollTopMax &&
(node instanceof global.HTMLSelectElement ||
(global.HTMLSelectElement.isInstance(node) ||
scrollingAllowed.includes(overflowy));
// do not allow horizontal scrolling for select elements, it leads
// to visual artifacts and is not the expected behavior anyway
if (
!(node instanceof global.HTMLSelectElement) &&
!global.HTMLSelectElement.isInstance(node) &&
node.scrollLeftMin != node.scrollLeftMax &&
scrollingAllowed.includes(overflowx)
) {

View File

@ -26,7 +26,7 @@ class BackgroundThumbnailsChild extends JSWindowActorChild {
case "Browser:Thumbnail:ContentInfo": {
if (
message.data.isImage ||
this.document instanceof this.contentWindow.ImageDocument
this.contentWindow.ImageDocument.isInstance(this.document)
) {
// To avoid sending additional messages between processes, we return
// the image data directly with the size info.

View File

@ -131,9 +131,8 @@ class DateTimePickerChild extends JSWindowActorChild {
case "MozOpenDateTimePicker": {
// Time picker is disabled when preffed off
if (
!(
aEvent.originalTarget instanceof
aEvent.originalTarget.ownerGlobal.HTMLInputElement
!aEvent.originalTarget.ownerGlobal.HTMLInputElement.isInstance(
aEvent.originalTarget
) ||
(aEvent.originalTarget.type == "time" && !this.getTimePickerPref())
) {

View File

@ -119,7 +119,7 @@ class FindBarChild extends JSWindowActorChild {
shouldFastFind(elt) {
if (elt) {
let win = elt.ownerGlobal;
if (elt instanceof win.HTMLInputElement && elt.mozIsTextField(false)) {
if (win.HTMLInputElement.isInstance(elt) && elt.mozIsTextField(false)) {
return false;
}
@ -128,15 +128,15 @@ class FindBarChild extends JSWindowActorChild {
}
if (
elt instanceof win.HTMLTextAreaElement ||
elt instanceof win.HTMLSelectElement ||
elt instanceof win.HTMLObjectElement ||
elt instanceof win.HTMLEmbedElement
win.HTMLTextAreaElement.isInstance(elt) ||
win.HTMLSelectElement.isInstance(elt) ||
win.HTMLObjectElement.isInstance(elt) ||
win.HTMLEmbedElement.isInstance(elt)
) {
return false;
}
if (elt instanceof win.HTMLIFrameElement && elt.mozbrowser) {
if (win.HTMLIFrameElement.isInstance(elt) && elt.mozbrowser) {
// If we're targeting a mozbrowser iframe, it should be allowed to
// handle FastFind itself.
return false;

View File

@ -211,7 +211,7 @@ class PictureInPictureLauncherChild extends JSWindowActorChild {
let doc = this.document;
if (doc) {
let video = doc.activeElement;
if (!(video instanceof HTMLVideoElement)) {
if (!HTMLVideoElement.isInstance(video)) {
let listOfVideos = [...doc.querySelectorAll("video")].filter(
video => !isNaN(video.duration)
);
@ -407,7 +407,7 @@ class PictureInPictureToggleChild extends JSWindowActorChild {
case "UAWidgetSetupOrChange": {
if (
this.toggleEnabled &&
event.target instanceof this.contentWindow.HTMLVideoElement &&
this.contentWindow.HTMLVideoElement.isInstance(event.target) &&
event.target.ownerDocument == this.document
) {
this.registerVideo(event.target);
@ -1678,7 +1678,7 @@ class PictureInPictureChild extends JSWindowActorChild {
// can be either a MediaStream, MediaSource or Blob. In case of future changes
// we do not want to pause MediaStream srcObjects and we want to maintain current
// behavior for non-MediaStream srcObjects.
if (video && video.srcObject instanceof MediaStream) {
if (video && MediaStream.isInstance(video.srcObject)) {
break;
}
}

View File

@ -629,7 +629,7 @@ var DownloadIntegration = {
);
} catch (ex) {
// If writing to the file fails, we ignore the error and continue.
if (!(ex instanceof DOMException)) {
if (!DOMException.isInstance(ex)) {
Cu.reportError(ex);
}
}
@ -669,7 +669,7 @@ var DownloadIntegration = {
// We should report errors with making the permissions less restrictive
// or marking the file as read-only on Unix and Mac, but this should not
// prevent the download from completing.
if (!(ex instanceof DOMException)) {
if (!DOMException.isInstance(ex)) {
Cu.reportError(ex);
}
}

View File

@ -182,7 +182,7 @@ const Hub = {
fillInAddress(address, actor) {
address.actor = actor;
address.verified = this.verifyEnv(address);
if (actor instanceof JSWindowActorParent) {
if (JSWindowActorParent.isInstance(actor)) {
address.frameId = WebNavigationFrames.getFrameId(actor.browsingContext);
address.url = actor.manager.documentURI?.spec;
} else {

View File

@ -94,12 +94,12 @@ let StartupCache;
const global = this;
function verifyActorForContext(actor, context) {
if (actor instanceof JSWindowActorParent) {
if (JSWindowActorParent.isInstance(actor)) {
let target = actor.browsingContext.top.embedderElement;
if (context.parentMessageManager !== target.messageManager) {
throw new Error("Got message on unexpected message manager");
}
} else if (actor instanceof JSProcessActorParent) {
} else if (JSProcessActorParent.isInstance(actor)) {
if (actor.manager.remoteType !== context.extension.remoteType) {
throw new Error("Got message from unexpected process");
}
@ -301,7 +301,7 @@ const ProxyMessenger = {
url: source.url,
};
if (source.actor instanceof JSWindowActorParent) {
if (JSWindowActorParent.isInstance(source.actor)) {
let browser = source.actor.browsingContext.top.embedderElement;
let data =
browser && apiManager.global.tabTracker.getBrowserData(browser);
@ -836,7 +836,7 @@ ParentAPIManager = {
throw new Error(`Bad sender context envType: ${sender.envType}`);
}
if (actor instanceof JSWindowActorParent) {
if (JSWindowActorParent.isInstance(actor)) {
let processMessageManager =
target.messageManager.processMessageManager ||
Services.ppmm.getChildAt(0);
@ -852,7 +852,7 @@ ParentAPIManager = {
"Attempt to create privileged extension parent from incorrect child process"
);
}
} else if (actor instanceof JSProcessActorParent) {
} else if (JSProcessActorParent.isInstance(actor)) {
if (actor.manager.remoteType !== extension.remoteType) {
throw new Error(
"Attempt to create privileged extension parent from incorrect child process"
@ -1934,7 +1934,7 @@ StartupCache = {
result = aomStartup.decodeBlob(buffer);
} catch (e) {
if (!(e instanceof DOMException) || e.name !== "NotFoundError") {
if (!DOMException.isInstance(e) || e.name !== "NotFoundError") {
Cu.reportError(e);
}
}

View File

@ -82,7 +82,7 @@ class LegacyPermissionStore {
try {
prefs.data = await IOUtils.readJSON(path);
} catch (e) {
if (!(e instanceof DOMException && e.name == "NotFoundError")) {
if (!(DOMException.isInstance(e) && e.name == "NotFoundError")) {
Cu.reportError(e);
}
}
@ -178,7 +178,7 @@ class PermissionStore {
await this.migrateFrom(oldStore);
migrationWasSuccessful = true;
} catch (e) {
if (!(e instanceof DOMException && e.name == "NotFoundError")) {
if (!(DOMException.isInstance(e) && e.name == "NotFoundError")) {
Cu.reportError(e);
}
}

View File

@ -78,7 +78,7 @@ var ErrorsTelemetry = {
}
if (
error instanceof DOMException ||
DOMException.isInstance(error) ||
error instanceof DataMigrationAbortedError
) {
if (error.name.length > 80) {
@ -809,7 +809,7 @@ this.ExtensionStorageIDB = {
let errorMessage;
if (error instanceof DOMException) {
if (DOMException.isInstance(error)) {
switch (error.name) {
case "DataCloneError":
errorMessage = String(error);

View File

@ -59,7 +59,7 @@ class ExtensionError extends DOMException {
}
// Custom JS classes can't survive IPC, so need to check error name.
static [Symbol.hasInstance](e) {
return e instanceof DOMException && e.name === "ExtensionError";
return DOMException.isInstance(e) && e.name === "ExtensionError";
}
}

View File

@ -87,7 +87,7 @@ var WebNavigationFrames = {
},
getFromWindow(target) {
if (target instanceof Window) {
if (Window.isInstance(target)) {
return getFrameId(BrowsingContext.getFromWindow(target));
}
return -1;

View File

@ -380,7 +380,7 @@ this.LoginRecipesContent = {
// ownerGlobal doesn't exist in content privileged windows.
if (
// eslint-disable-next-line mozilla/use-ownerGlobal
!(field instanceof aParent.ownerDocument.defaultView.HTMLInputElement)
!aParent.ownerDocument.defaultView.HTMLInputElement.isInstance(field)
) {
log.warn("Login field isn't an <input> so ignoring it:", aSelector);
return null;

View File

@ -633,7 +633,7 @@ var Bookmarks = Object.freeze({
let url = "";
if (item.type == Bookmarks.TYPE_BOOKMARK) {
url = item.url instanceof URL ? item.url.href : item.url;
url = URL.isInstance(item.url) ? item.url.href : item.url;
}
notifications.push(
@ -1844,7 +1844,7 @@ var Bookmarks = Object.freeze({
}
if (query.url) {
if (typeof query.url === "string" || query.url instanceof URL) {
if (typeof query.url === "string" || URL.isInstance(query.url)) {
query.url = new URL(query.url).href;
} else if (query.url instanceof Ci.nsIURI) {
query.url = query.url.spec;

View File

@ -511,7 +511,7 @@ var History = Object.freeze({
if (
hasURL &&
!(filter.url instanceof URL) &&
!URL.isInstance(filter.url) &&
typeof filter.url != "string" &&
!(filter.url instanceof Ci.nsIURI)
) {
@ -1147,7 +1147,7 @@ var notifyOnResult = async function(data, onResult) {
var fetch = async function(db, guidOrURL, options) {
let whereClauseFragment = "";
let params = {};
if (guidOrURL instanceof URL) {
if (URL.isInstance(guidOrURL)) {
whereClauseFragment = "WHERE h.url_hash = hash(:url) AND h.url = :url";
params.url = guidOrURL.href;
} else {
@ -1274,7 +1274,7 @@ var fetchMany = async function(db, guidOrURLs) {
let urls = [];
let guids = [];
for (let v of chunk) {
if (v instanceof URL) {
if (URL.isInstance(v)) {
urls.push(v);
} else {
guids.push(v);

View File

@ -162,7 +162,7 @@ class DeletionHandler {
PlacesPreviews.onDelete(filePath);
deleted.push(hash);
} catch (ex) {
if (ex instanceof DOMException && ex.name == "NotFoundError") {
if (DOMException.isInstance(ex) && ex.name == "NotFoundError") {
deleted.push(hash);
} else {
logConsole.error("Unable to delete file: " + filePath);
@ -335,7 +335,7 @@ const PlacesPreviews = new (class extends EventEmitter {
}
} catch (ex) {
// If the file doesn't exist, we always update it.
if (!(ex instanceof DOMException) || ex.name != "NotFoundError") {
if (!DOMException.isInstance(ex) || ex.name != "NotFoundError") {
logConsole.error("Error while trying to stat() preview" + ex);
return false;
}

View File

@ -233,7 +233,7 @@ const BOOKMARK_VALIDATORS = Object.freeze({
val =>
(typeof val == "string" && val.length <= DB_URL_LENGTH_MAX) ||
(val instanceof Ci.nsIURI && val.spec.length <= DB_URL_LENGTH_MAX) ||
(val instanceof URL && val.href.length <= DB_URL_LENGTH_MAX)
(URL.isInstance(val) && val.href.length <= DB_URL_LENGTH_MAX)
).call(this, v);
if (typeof v === "string") {
return new URL(v);
@ -533,7 +533,7 @@ var PlacesUtils = {
* @return nsIURI for the given URL.
*/
toURI(url) {
url = url instanceof URL ? url.href : url;
url = URL.isInstance(url) ? url.href : url;
return NetUtil.newURI(url);
},
@ -597,7 +597,7 @@ var PlacesUtils = {
parseActionUrl(url) {
if (url instanceof Ci.nsIURI) {
url = url.spec;
} else if (url instanceof URL) {
} else if (URL.isInstance(url)) {
url = url.href;
}
// Faster bailout.
@ -1233,7 +1233,7 @@ var PlacesUtils = {
}
return new URL(key);
}
if (key instanceof URL) {
if (URL.isInstance(key)) {
return key;
}
if (key instanceof Ci.nsIURI) {

View File

@ -51,7 +51,7 @@ var PlacesTestUtils = Object.freeze({
let place;
if (
obj instanceof Ci.nsIURI ||
obj instanceof URL ||
URL.isInstance(obj) ||
typeof obj == "string"
) {
place = { uri: obj };
@ -67,7 +67,7 @@ var PlacesTestUtils = Object.freeze({
info.title = "title" in place ? place.title : "test visit for " + spec;
if (typeof place.referrer == "string") {
place.referrer = Services.io.newURI(place.referrer);
} else if (place.referrer && place.referrer instanceof URL) {
} else if (place.referrer && URL.isInstance(place.referrer)) {
place.referrer = Services.io.newURI(place.referrer.href);
}
let visitDate = place.visitDate;

View File

@ -342,7 +342,7 @@ BasePromiseWorker.prototype = {
throw this.ExceptionHandlers[error.data.exn](error.data);
}
if (error instanceof ErrorEvent) {
if (ErrorEvent.isInstance(error)) {
// Other errors get propagated as instances of ErrorEvent
this.log(
"Error serialized by DOM",

View File

@ -207,7 +207,7 @@ var ClientIDImpl = {
});
this._saveClientIdTask = null;
} catch (ex) {
if (!(ex instanceof DOMException) || ex.name !== "AbortError") {
if (!DOMException.isInstance(ex) || ex.name !== "AbortError") {
throw ex;
}
}

View File

@ -70,7 +70,7 @@ nsTerminatorTelemetry.prototype = {
try {
data = await IOUtils.readJSON(PATH);
} catch (ex) {
if (ex instanceof DOMException && ex.name == "NotFoundError") {
if (DOMException.isInstance(ex) && ex.name == "NotFoundError") {
return;
}
// Let other errors be reported by Promise's error-reporting.

View File

@ -746,7 +746,7 @@ var PageThumbsStorage = {
return function onError(err) {
if (
!aNoOverwrite ||
!(err instanceof DOMException) ||
!DOMException.isInstance(err) ||
err.name !== "TypeMismatchError"
) {
throw err;

View File

@ -39,10 +39,10 @@ TooltipTextProvider.prototype = {
// If the element is invalid per HTML5 Forms specifications and has no title,
// show the constraint validation error message.
if (
(tipElement instanceof defView.HTMLInputElement ||
tipElement instanceof defView.HTMLTextAreaElement ||
tipElement instanceof defView.HTMLSelectElement ||
tipElement instanceof defView.HTMLButtonElement) &&
(defView.HTMLInputElement.isInstance(tipElement) ||
defView.HTMLTextAreaElement.isInstance(tipElement) ||
defView.HTMLSelectElement.isInstance(tipElement) ||
defView.HTMLButtonElement.isInstance(tipElement)) &&
!tipElement.hasAttribute("title") &&
(!tipElement.form || !tipElement.form.noValidate)
) {
@ -55,7 +55,7 @@ TooltipTextProvider.prototype = {
// the current file selection.
if (
!titleText &&
tipElement instanceof defView.HTMLInputElement &&
defView.HTMLInputElement.isInstance(tipElement) &&
tipElement.type == "file" &&
!tipElement.hasAttribute("title")
) {
@ -114,29 +114,29 @@ TooltipTextProvider.prototype = {
XULtooltiptextText = tipElement.hasAttribute("tooltiptext")
? tipElement.getAttribute("tooltiptext")
: null;
} else if (!(tipElement instanceof defView.SVGElement)) {
} else if (!defView.SVGElement.isInstance(tipElement)) {
titleText = tipElement.getAttribute("title");
}
if (
(tipElement instanceof defView.HTMLAnchorElement ||
tipElement instanceof defView.HTMLAreaElement ||
tipElement instanceof defView.HTMLLinkElement ||
tipElement instanceof defView.SVGAElement) &&
(defView.HTMLAnchorElement.isInstance(tipElement) ||
defView.HTMLAreaElement.isInstance(tipElement) ||
defView.HTMLLinkElement.isInstance(tipElement) ||
defView.SVGAElement.isInstance(tipElement)) &&
tipElement.href
) {
XLinkTitleText = tipElement.getAttributeNS(XLinkNS, "title");
}
if (
lookingForSVGTitle &&
(!(tipElement instanceof defView.SVGElement) ||
(!defView.SVGElement.isInstance(tipElement) ||
tipElement.parentNode.nodeType == defView.Node.DOCUMENT_NODE)
) {
lookingForSVGTitle = false;
}
if (lookingForSVGTitle) {
for (let childNode of tipElement.childNodes) {
if (childNode instanceof defView.SVGTitleElement) {
if (defView.SVGTitleElement.isInstance(childNode)) {
SVGTitleText = childNode.textContent;
break;
}

View File

@ -179,9 +179,9 @@ var BrowserUtils = {
function isHTMLLink(aNode) {
// Be consistent with what nsContextMenu.js does.
return (
(aNode instanceof content.HTMLAnchorElement && aNode.href) ||
(aNode instanceof content.HTMLAreaElement && aNode.href) ||
aNode instanceof content.HTMLLinkElement
(content.HTMLAnchorElement.isInstance(aNode) && aNode.href) ||
(content.HTMLAreaElement.isInstance(aNode) && aNode.href) ||
content.HTMLLinkElement.isInstance(aNode)
);
}

View File

@ -405,7 +405,7 @@ Finder.prototype = {
if (
focusedElement &&
"frameLoader" in focusedElement &&
focusedElement.browsingContext instanceof BrowsingContext
BrowsingContext.isInstance(focusedElement.browsingContext)
) {
return {
focusedChildBrowserContextId: focusedElement.browsingContext.id,

View File

@ -758,7 +758,7 @@ FinderIterator.prototype = {
const HTMLAnchorElement = (node.ownerDocument || node).defaultView
.HTMLAnchorElement;
do {
if (node instanceof HTMLAnchorElement) {
if (HTMLAnchorElement.isInstance(node)) {
isInsideLink = node.hasAttribute("href");
break;
} else if (

View File

@ -425,7 +425,7 @@ var SpellCheckHelper = {
SPELLCHECKABLE: 0x100,
isTargetAKeywordField(aNode, window) {
if (!(aNode instanceof window.HTMLInputElement)) {
if (!window.HTMLInputElement.isInstance(aNode)) {
return false;
}
@ -460,7 +460,7 @@ var SpellCheckHelper = {
isEditable(element, window) {
var flags = 0;
if (element instanceof window.HTMLInputElement) {
if (window.HTMLInputElement.isInstance(element)) {
flags |= this.INPUT;
if (element.mozIsTextField(false) || element.type == "number") {
flags |= this.TEXTINPUT;
@ -486,7 +486,7 @@ var SpellCheckHelper = {
flags |= this.PASSWORD;
}
}
} else if (element instanceof window.HTMLTextAreaElement) {
} else if (window.HTMLTextAreaElement.isInstance(element)) {
flags |= this.TEXTINPUT | this.TEXTAREA;
if (!element.readOnly) {
flags |= this.SPELLCHECKABLE | this.EDITABLE;

View File

@ -240,7 +240,7 @@ JSONFile.prototype = {
cleansedBasename,
errorNo ? errorNo.toString() : ""
);
if (!(ex instanceof DOMException && ex.name == "NotFoundError")) {
if (!(DOMException.isInstance(ex) && ex.name == "NotFoundError")) {
Cu.reportError(ex);
// Move the original file to a backup location, ignoring errors.
@ -264,7 +264,7 @@ JSONFile.prototype = {
try {
await IOUtils.copy(this._options.backupFile, this.path);
} catch (e) {
if (!(e instanceof DOMException && e.name == "NotFoundError")) {
if (!(DOMException.isInstance(e) && e.name == "NotFoundError")) {
Cu.reportError(e);
}
}
@ -283,7 +283,7 @@ JSONFile.prototype = {
}
this._recordTelemetry("load", cleansedBasename, "used_backup");
} catch (e3) {
if (!(e3 instanceof DOMException && e3.name == "NotFoundError")) {
if (!(DOMException.isInstance(e3) && e3.name == "NotFoundError")) {
Cu.reportError(e3);
}
}

View File

@ -124,7 +124,7 @@ class ProfileAgeImpl {
);
} catch (e) {
if (
!(e instanceof DOMException) ||
!DOMException.isInstance(e) ||
e.name !== "AbortError" ||
e.message !== "IOUtils: Shutting down and refusing additional I/O tasks"
) {

View File

@ -88,7 +88,7 @@ var PropertyListUtils = Object.freeze({
* The reaon for failure is reported to the Error Console.
*/
read: function PLU_read(aFile, aCallback) {
if (!(aFile instanceof Ci.nsIFile || aFile instanceof File)) {
if (!(aFile instanceof Ci.nsIFile || File.isInstance(aFile))) {
throw new Error("aFile is not a file object");
}
if (typeof aCallback != "function") {

View File

@ -842,7 +842,7 @@ async function readUpdateConfig() {
return config;
} catch (e) {
if (e instanceof DOMException && e.name == "NotFoundError") {
if (DOMException.isInstance(e) && e.name == "NotFoundError") {
if (updateConfigNeedsMigration()) {
const migrationConfig = makeMigrationUpdateConfig();
setUpdateConfigMigrationDone();

View File

@ -1703,7 +1703,7 @@ this.XPIDatabase = {
logger.warn("Failed to save XPI database", error);
this._saveError = error;
if (!(error instanceof DOMException) || error.name !== "AbortError") {
if (!DOMException.isInstance(error) || error.name !== "AbortError") {
throw error;
}
}
@ -1913,7 +1913,7 @@ this.XPIDatabase = {
await this.maybeIdleDispatch();
await this.parseDB(json, true);
} catch (error) {
if (error instanceof DOMException && error.name === "NotFoundError") {
if (DOMException.isInstance(error) && error.name === "NotFoundError") {
if (Services.prefs.getIntPref(PREF_DB_SCHEMA, 0)) {
this._recordStartupError("dbMissing");
}