From 3269d4c928ef0d8310c2f57634e9b6057aa636e9 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Wed, 6 Apr 2022 11:57:57 +0000 Subject: [PATCH] Bug 1703953 - Part 3: Apply mozilla/use-isInstance to devtools r=julienw Differential Revision: https://phabricator.services.mozilla.com/D142068 --- devtools/client/performance-new/@types/gecko.d.ts | 8 ++++++++ .../client/performance-new/symbolication.jsm.js | 13 +++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/devtools/client/performance-new/@types/gecko.d.ts b/devtools/client/performance-new/@types/gecko.d.ts index 5cded8f68b85..6bab9780b7f6 100644 --- a/devtools/client/performance-new/@types/gecko.d.ts +++ b/devtools/client/performance-new/@types/gecko.d.ts @@ -486,3 +486,11 @@ declare interface XULElementWithCommandHandler { } declare type nsIPrefBranch = MockedExports.nsIPrefBranch; + +// chrome context-only DOM isInstance method +// XXX: This hackishly extends Function because there is no way to extend DOM constructors. +// Callers should manually narrow the type when needed. +// See also https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/222 +interface Function { + isInstance(obj: any): boolean; +} diff --git a/devtools/client/performance-new/symbolication.jsm.js b/devtools/client/performance-new/symbolication.jsm.js index 9765835f99d8..b2535b484b71 100644 --- a/devtools/client/performance-new/symbolication.jsm.js +++ b/devtools/client/performance-new/symbolication.jsm.js @@ -139,7 +139,7 @@ async function getResultFromWorker(workerURL, initialMessageToWorker) { worker.onerror = errorEvent => { gActiveWorkers.delete(worker); worker.terminate(); - if (errorEvent instanceof ErrorEvent) { + if (ErrorEvent.isInstance(errorEvent)) { const { message, filename, lineno } = errorEvent; const error = new Error(`${message} at ${filename}:${lineno}`); error.name = "WorkerError"; @@ -152,17 +152,10 @@ async function getResultFromWorker(workerURL, initialMessageToWorker) { // Handle errors from messages that cannot be deserialized. I'm not sure // how to get into such a state, but having this handler seems like a good // idea. - worker.onmessageerror = errorEvent => { + worker.onmessageerror = () => { gActiveWorkers.delete(worker); worker.terminate(); - if (errorEvent instanceof ErrorEvent) { - const { message, filename, lineno } = errorEvent; - const error = new Error(`${message} at ${filename}:${lineno}`); - error.name = "WorkerMessageError"; - reject(error); - } else { - reject(new Error("Error in worker")); - } + reject(new Error("Error in worker")); }; worker.postMessage(initialMessageToWorker);