Bug 1814798 - pt 1. Add bool to enable/disable PHC at runtime r=glandium
[gecko.git] / js / public / ContextOptions.h
bloba94ab13e3d0d57d684c4af64c2bb817115c0317c
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* JavaScript API. */
9 #ifndef js_ContextOptions_h
10 #define js_ContextOptions_h
12 #include "jstypes.h" // JS_PUBLIC_API
14 #include "js/CompileOptions.h" // PrefableCompileOptions
15 #include "js/WasmFeatures.h"
17 struct JS_PUBLIC_API JSContext;
19 namespace JS {
21 class JS_PUBLIC_API ContextOptions {
22 public:
23 // clang-format off
24 ContextOptions()
25 : wasm_(true),
26 wasmForTrustedPrinciples_(true),
27 wasmVerbose_(false),
28 wasmBaseline_(true),
29 wasmIon_(true),
30 #define WASM_FEATURE(NAME, LOWER_NAME, STAGE, ...) wasm##NAME##_(STAGE == WasmFeatureStage::Default),
31 JS_FOR_WASM_FEATURES(WASM_FEATURE)
32 #undef WASM_FEATURE
33 testWasmAwaitTier2_(false),
34 disableIon_(false),
35 disableEvalSecurityChecks_(false),
36 asyncStack_(true),
37 asyncStackCaptureDebuggeeOnly_(false),
38 throwOnDebuggeeWouldRun_(true),
39 dumpStackOnDebuggeeWouldRun_(false),
40 #ifdef JS_ENABLE_SMOOSH
41 trackNotImplemented_(false),
42 trySmoosh_(false),
43 #endif
44 fuzzing_(false) {
46 // clang-format on
48 bool asmJS() const {
49 return compileOptions_.asmJSOption() == AsmJSOption::Enabled;
51 AsmJSOption asmJSOption() const { return compileOptions_.asmJSOption(); }
52 ContextOptions& setAsmJS(bool flag) {
53 compileOptions_.setAsmJS(flag);
54 return *this;
56 ContextOptions& setAsmJSOption(AsmJSOption option) {
57 compileOptions_.setAsmJSOption(option);
58 return *this;
61 bool wasm() const { return wasm_; }
62 ContextOptions& setWasm(bool flag) {
63 wasm_ = flag;
64 return *this;
66 ContextOptions& toggleWasm() {
67 wasm_ = !wasm_;
68 return *this;
71 bool wasmForTrustedPrinciples() const { return wasmForTrustedPrinciples_; }
72 ContextOptions& setWasmForTrustedPrinciples(bool flag) {
73 wasmForTrustedPrinciples_ = flag;
74 return *this;
77 bool wasmVerbose() const { return wasmVerbose_; }
78 ContextOptions& setWasmVerbose(bool flag) {
79 wasmVerbose_ = flag;
80 return *this;
83 bool wasmBaseline() const { return wasmBaseline_; }
84 ContextOptions& setWasmBaseline(bool flag) {
85 wasmBaseline_ = flag;
86 return *this;
89 bool wasmIon() const { return wasmIon_; }
90 ContextOptions& setWasmIon(bool flag) {
91 wasmIon_ = flag;
92 return *this;
95 bool testWasmAwaitTier2() const { return testWasmAwaitTier2_; }
96 ContextOptions& setTestWasmAwaitTier2(bool flag) {
97 testWasmAwaitTier2_ = flag;
98 return *this;
101 #define WASM_FEATURE(NAME, ...) \
102 bool wasm##NAME() const { return wasm##NAME##_; } \
103 ContextOptions& setWasm##NAME(bool flag) { \
104 wasm##NAME##_ = flag; \
105 return *this; \
107 JS_FOR_WASM_FEATURES(WASM_FEATURE)
108 #undef WASM_FEATURE
110 bool throwOnAsmJSValidationFailure() const {
111 return compileOptions_.throwOnAsmJSValidationFailure();
113 ContextOptions& setThrowOnAsmJSValidationFailure(bool flag) {
114 compileOptions_.setThrowOnAsmJSValidationFailure(flag);
115 return *this;
117 ContextOptions& toggleThrowOnAsmJSValidationFailure() {
118 compileOptions_.toggleThrowOnAsmJSValidationFailure();
119 return *this;
122 // Override to allow disabling Ion for this context irrespective of the
123 // process-wide Ion-enabled setting. This must be set right after creating
124 // the context.
125 bool disableIon() const { return disableIon_; }
126 ContextOptions& setDisableIon() {
127 disableIon_ = true;
128 return *this;
131 bool importAssertions() const { return compileOptions_.importAssertions(); }
132 ContextOptions& setImportAssertions(bool enabled) {
133 compileOptions_.setImportAssertions(enabled);
134 return *this;
137 // Override to allow disabling the eval restriction security checks for
138 // this context.
139 bool disableEvalSecurityChecks() const { return disableEvalSecurityChecks_; }
140 ContextOptions& setDisableEvalSecurityChecks() {
141 disableEvalSecurityChecks_ = true;
142 return *this;
145 bool asyncStack() const { return asyncStack_; }
146 ContextOptions& setAsyncStack(bool flag) {
147 asyncStack_ = flag;
148 return *this;
151 bool asyncStackCaptureDebuggeeOnly() const {
152 return asyncStackCaptureDebuggeeOnly_;
154 ContextOptions& setAsyncStackCaptureDebuggeeOnly(bool flag) {
155 asyncStackCaptureDebuggeeOnly_ = flag;
156 return *this;
159 // Enable/disable support for parsing '//(#@) source(Mapping)?URL=' pragmas.
160 bool sourcePragmas() const { return compileOptions_.sourcePragmas(); }
161 ContextOptions& setSourcePragmas(bool flag) {
162 compileOptions_.setSourcePragmas(flag);
163 return *this;
166 bool throwOnDebuggeeWouldRun() const { return throwOnDebuggeeWouldRun_; }
167 ContextOptions& setThrowOnDebuggeeWouldRun(bool flag) {
168 throwOnDebuggeeWouldRun_ = flag;
169 return *this;
172 bool dumpStackOnDebuggeeWouldRun() const {
173 return dumpStackOnDebuggeeWouldRun_;
175 ContextOptions& setDumpStackOnDebuggeeWouldRun(bool flag) {
176 dumpStackOnDebuggeeWouldRun_ = flag;
177 return *this;
180 #ifdef JS_ENABLE_SMOOSH
181 // Track Number of Not Implemented Calls by writing to a file
182 bool trackNotImplemented() const { return trackNotImplemented_; }
183 ContextOptions& setTrackNotImplemented(bool flag) {
184 trackNotImplemented_ = flag;
185 return *this;
188 // Try compiling SmooshMonkey frontend first, and fallback to C++
189 // implementation when it fails.
190 bool trySmoosh() const { return trySmoosh_; }
191 ContextOptions& setTrySmoosh(bool flag) {
192 trySmoosh_ = flag;
193 return *this;
196 #endif // JS_ENABLE_SMOOSH
198 bool fuzzing() const { return fuzzing_; }
199 // Defined out-of-line because it depends on a compile-time option
200 ContextOptions& setFuzzing(bool flag);
202 void disableOptionsForSafeMode() {
203 setAsmJSOption(AsmJSOption::DisabledByAsmJSPref);
204 setWasmBaseline(false);
207 PrefableCompileOptions& compileOptions() { return compileOptions_; }
208 const PrefableCompileOptions& compileOptions() const {
209 return compileOptions_;
212 private:
213 // WASM options.
214 bool wasm_ : 1;
215 bool wasmForTrustedPrinciples_ : 1;
216 bool wasmVerbose_ : 1;
217 bool wasmBaseline_ : 1;
218 bool wasmIon_ : 1;
219 #define WASM_FEATURE(NAME, ...) bool wasm##NAME##_ : 1;
220 JS_FOR_WASM_FEATURES(WASM_FEATURE)
221 #undef WASM_FEATURE
222 bool testWasmAwaitTier2_ : 1;
224 // JIT options.
225 bool disableIon_ : 1;
226 bool disableEvalSecurityChecks_ : 1;
228 // Runtime options.
229 bool asyncStack_ : 1;
230 bool asyncStackCaptureDebuggeeOnly_ : 1;
231 bool throwOnDebuggeeWouldRun_ : 1;
232 bool dumpStackOnDebuggeeWouldRun_ : 1;
233 #ifdef JS_ENABLE_SMOOSH
234 bool trackNotImplemented_ : 1;
235 bool trySmoosh_ : 1;
236 #endif
237 bool fuzzing_ : 1;
239 // Compile options.
240 PrefableCompileOptions compileOptions_;
243 JS_PUBLIC_API ContextOptions& ContextOptionsRef(JSContext* cx);
245 } // namespace JS
247 #endif // js_ContextOptions_h