From 5c0872d1b09440f729168503b799cddcc3befc49 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 21 Jun 2023 19:53:30 +0200 Subject: [PATCH] [Firefox] Avoid unnecessary string-parsing when reading preferences Note how the [`ChromeActions.getPreferences` method](https://searchfox.org/mozilla-central/rev/4e8f62a231e71dc53eb50b6d74afca21d6b254e9/toolkit/components/pdfjs/content/PdfStreamConverter.sys.mjs#497-530) returns the preferences as a string, which we then have to convert back into an Object in the viewer. Back when that code was originally written it wasn't possible to send Objects from the platform-code, however that's no longer the case and we should be able to (eventually) remove this unnecessary string-parsing now. *Please note that in order to prevent breakage we'll need to land these changes in stages:* - Land this patch in mozilla-central, as part of regular the PDF.js updates. - Change the return type in the `ChromeActions.getPreferences` method, in a mozilla-central patch. - Remove the string-handling from the `FirefoxPreferences._readFromStorage` method. --- web/firefoxcom.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/firefoxcom.js b/web/firefoxcom.js index 6d5401fc4..8673a3fd0 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -175,8 +175,8 @@ class DownloadManager { class FirefoxPreferences extends BasePreferences { async _readFromStorage(prefObj) { - const prefStr = await FirefoxCom.requestAsync("getPreferences", prefObj); - return JSON.parse(prefStr); + const prefs = await FirefoxCom.requestAsync("getPreferences", prefObj); + return typeof prefs === "string" ? JSON.parse(prefs) : prefs; } }