From 620bbb27eaca8ce70d402c296dd1e424bf23b561 Mon Sep 17 00:00:00 2001 From: Andreas Farre Date: Fri, 27 Jan 2023 09:17:17 +0000 Subject: [PATCH] Bug 1806501 - Start the JS Oracle process early. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D167230 --- browser/components/BrowserGlue.sys.mjs | 8 ++++++++ dom/base/ChromeUtils.cpp | 7 +++++++ dom/base/ChromeUtils.h | 2 ++ dom/chrome-webidl/ChromeUtils.webidl | 5 +++++ 4 files changed, 22 insertions(+) diff --git a/browser/components/BrowserGlue.sys.mjs b/browser/components/BrowserGlue.sys.mjs index 5c0e8b421d58..8af42d330f1a 100644 --- a/browser/components/BrowserGlue.sys.mjs +++ b/browser/components/BrowserGlue.sys.mjs @@ -2855,6 +2855,14 @@ BrowserGlue.prototype = { }, }, + { + // Starts the JSOracle process for ORB JavaScript validation, if it hasn't started already. + name: "start-orb-javascript-oracle", + task: () => { + ChromeUtils.ensureJSOracleStarted(); + }, + }, + { name: "browser-startup-idle-tasks-finished", task: () => { diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp index fffabcf6aa5d..7a0828a9b102 100644 --- a/dom/base/ChromeUtils.cpp +++ b/dom/base/ChromeUtils.cpp @@ -6,6 +6,7 @@ #include "ChromeUtils.h" +#include "JSOracleParent.h" #include "js/CharacterEncoding.h" #include "js/Object.h" // JS::GetClass #include "js/PropertyAndElement.h" // JS_DefineProperty, JS_DefinePropertyById, JS_Enumerate, JS_GetProperty, JS_GetPropertyById, JS_SetProperty, JS_SetPropertyById, JS::IdVector @@ -1762,6 +1763,12 @@ bool ChromeUtils::IsDarkBackground(GlobalObject&, Element& aElement) { double ChromeUtils::DateNow(GlobalObject&) { return JS_Now() / 1000.0; } +/* static */ +void ChromeUtils::EnsureJSOracleStarted(GlobalObject&) { + JSOracleParent::WithJSOracle( + [](JSOracleParent* aParent) { MOZ_DIAGNOSTIC_ASSERT(aParent); }); +} + /* static */ unsigned ChromeUtils::AliveUtilityProcesses(const GlobalObject&) { const auto& utilityProcessManager = diff --git a/dom/base/ChromeUtils.h b/dom/base/ChromeUtils.h index cd30c0e8ca77..9b570d9d92b4 100644 --- a/dom/base/ChromeUtils.h +++ b/dom/base/ChromeUtils.h @@ -285,6 +285,8 @@ class ChromeUtils { static double DateNow(GlobalObject&); + static void EnsureJSOracleStarted(GlobalObject&); + static unsigned AliveUtilityProcesses(const GlobalObject&); }; diff --git a/dom/chrome-webidl/ChromeUtils.webidl b/dom/chrome-webidl/ChromeUtils.webidl index 109d61bb5673..564a2d069c0c 100644 --- a/dom/chrome-webidl/ChromeUtils.webidl +++ b/dom/chrome-webidl/ChromeUtils.webidl @@ -654,6 +654,11 @@ partial namespace ChromeUtils { */ boolean isDarkBackground(Element element); + /** + * Starts the JSOracle process for ORB JavaScript validation, if it hasn't started already. + */ + undefined ensureJSOracleStarted(); + /** * The number of currently alive utility processes. */