From 754ebbc4d714968b9d35edcddf99649da865c7cf Mon Sep 17 00:00:00 2001 From: Tom Ritter Date: Fri, 4 Oct 2019 17:35:46 +0000 Subject: [PATCH] Bug 1576254 - Add a wasmForTrustedPrinciples bool onto ContextOptions that (currently) behaves the exact same as the wasm bool r=luke In a future commit we will tie this boolean to its own preference value, but here we initialize it with the same value as the wasm boolean. We also update wasm::HasSupport to check the to-be-added isSystemOrAddonPrincipal() method on JSPrincipals to determine which member (wasm or wasmForTrustedPrinciples) to consult. Differential Revision: https://phabricator.services.mozilla.com/D47472 --HG-- extra : moz-landing-system : lando --- dom/workers/RuntimeService.cpp | 2 ++ js/public/ContextOptions.h | 8 ++++++++ js/src/shell/js.cpp | 1 + js/src/wasm/WasmJS.cpp | 11 +++++++++-- js/xpconnect/src/XPCJSContext.cpp | 1 + 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index e0942eaf3fa5..e690eaa6fd15 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -286,6 +286,8 @@ void LoadContextOptions(const char* aPrefName, void* /* aClosure */) { JS::ContextOptions contextOptions; contextOptions.setAsmJS(GetWorkerPref(NS_LITERAL_CSTRING("asmjs"))) .setWasm(GetWorkerPref(NS_LITERAL_CSTRING("wasm"))) + .setWasmForTrustedPrinciples( + GetWorkerPref(NS_LITERAL_CSTRING("wasm"))) .setWasmBaseline( GetWorkerPref(NS_LITERAL_CSTRING("wasm_baselinejit"))) .setWasmIon(GetWorkerPref(NS_LITERAL_CSTRING("wasm_ionjit"))) diff --git a/js/public/ContextOptions.h b/js/public/ContextOptions.h index b562db836865..7845aa6f6e54 100644 --- a/js/public/ContextOptions.h +++ b/js/public/ContextOptions.h @@ -20,6 +20,7 @@ class JS_PUBLIC_API ContextOptions { ContextOptions() : asmJS_(true), wasm_(true), + wasmForTrustedPrinciples_(true), wasmVerbose_(false), wasmBaseline_(true), wasmIon_(true), @@ -64,6 +65,12 @@ class JS_PUBLIC_API ContextOptions { return *this; } + bool wasmForTrustedPrinciples() const { return wasmForTrustedPrinciples_; } + ContextOptions& setWasmForTrustedPrinciples(bool flag) { + wasmForTrustedPrinciples_ = flag; + return *this; + } + bool wasmVerbose() const { return wasmVerbose_; } ContextOptions& setWasmVerbose(bool flag) { wasmVerbose_ = flag; @@ -187,6 +194,7 @@ class JS_PUBLIC_API ContextOptions { private: bool asmJS_ : 1; bool wasm_ : 1; + bool wasmForTrustedPrinciples_ : 1; bool wasmVerbose_ : 1; bool wasmBaseline_ : 1; bool wasmIon_ : 1; diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index c73bbb902bc0..b0f6e8c55814 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -10327,6 +10327,7 @@ static bool SetContextOptions(JSContext* cx, const OptionParser& op) { JS::ContextOptionsRef(cx) .setAsmJS(enableAsmJS) .setWasm(enableWasm) + .setWasmForTrustedPrinciples(enableWasm) .setWasmBaseline(enableWasmBaseline) .setWasmIon(enableWasmIon) #ifdef ENABLE_WASM_CRANELIFT diff --git a/js/src/wasm/WasmJS.cpp b/js/src/wasm/WasmJS.cpp index 588a953044cc..7ec1f2e6904d 100644 --- a/js/src/wasm/WasmJS.cpp +++ b/js/src/wasm/WasmJS.cpp @@ -151,8 +151,15 @@ static bool HasAvailableCompilerTier(JSContext* cx) { } bool wasm::HasSupport(JSContext* cx) { - return cx->options().wasm() && HasCompilerSupport(cx) && - HasAvailableCompilerTier(cx); + // If the general wasm pref is on, it's on for everything. + bool prefEnabled = cx->options().wasm(); + // If the general pref is off, check trusted principals. + if (MOZ_UNLIKELY(!prefEnabled)) { + prefEnabled = cx->options().wasmForTrustedPrinciples() && cx->realm() && + cx->realm()->principals() && + cx->realm()->principals()->isSystemOrAddonPrincipal(); + } + return prefEnabled && HasCompilerSupport(cx) && HasAvailableCompilerTier(cx); } bool wasm::HasStreamingSupport(JSContext* cx) { diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index d64268c374b9..6cddfc9ac7ac 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -957,6 +957,7 @@ static void ReloadPrefsCallback(const char* pref, XPCJSContext* xpccx) { JS::ContextOptionsRef(cx) .setAsmJS(useAsmJS) .setWasm(useWasm) + .setWasmForTrustedPrinciples(useWasm) .setWasmIon(useWasmIon) .setWasmBaseline(useWasmBaseline) #ifdef ENABLE_WASM_CRANELIFT