am {TranslationsParent} [translationsParent] */ startTranslation(languagePair, port, translationsParent) { const innerWindowId = translationsParent?.innerWindowId; if (translationsParent) { this.#translationsParents.set(innerWindowId, translationsParent); } if (this.#isDestroyed) { throw new Error("The translation engine process was already destroyed."); } const transferables = [port]; this.sendAsyncMessage( "TranslationsEngine:StartTranslation", { languagePair, innerWindowId, port, }, transferables ); } /** * Remove all the translations that are currently queued, and remove * the communication port. * * @param {number} innerWindowId */ discardTranslations(innerWindowId) { this.#translationsParents.delete(innerWindowId); if (this.#isDestroyed) { return; } this.sendAsyncMessage("TranslationsEngine:DiscardTranslations", { innerWindowId, }); } /** * Manually shut down the engines, typically for testing purposes. */ forceShutdown() { return this.sendQuery("TranslationsEngine:ForceShutdown"); } #isDestroyed = false; didDestroy() { this.#isDestroyed = true; } } PK