Bug 1883023 [wpt PR 44879] - Avoid forced layout when finished parsing an empty subfr...
[gecko.git] / js / public / ContextOptions.h
blob0ac79c0ec70d3da86a1b43c72985e29be78f1c89
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 testWasmAwaitTier2_(false),
31 disableIon_(false),
32 disableEvalSecurityChecks_(false),
33 asyncStack_(true),
34 asyncStackCaptureDebuggeeOnly_(false),
35 throwOnDebuggeeWouldRun_(true),
36 dumpStackOnDebuggeeWouldRun_(false),
37 #ifdef JS_ENABLE_SMOOSH
38 trackNotImplemented_(false),
39 trySmoosh_(false),
40 #endif
41 fuzzing_(false) {
43 // clang-format on
45 bool asmJS() const {
46 return compileOptions_.asmJSOption() == AsmJSOption::Enabled;
48 AsmJSOption asmJSOption() const { return compileOptions_.asmJSOption(); }
49 ContextOptions& setAsmJS(bool flag) {
50 compileOptions_.setAsmJS(flag);
51 return *this;
53 ContextOptions& setAsmJSOption(AsmJSOption option) {
54 compileOptions_.setAsmJSOption(option);
55 return *this;
58 bool wasm() const { return wasm_; }
59 ContextOptions& setWasm(bool flag) {
60 wasm_ = flag;
61 return *this;
63 ContextOptions& toggleWasm() {
64 wasm_ = !wasm_;
65 return *this;
68 bool wasmForTrustedPrinciples() const { return wasmForTrustedPrinciples_; }
69 ContextOptions& setWasmForTrustedPrinciples(bool flag) {
70 wasmForTrustedPrinciples_ = flag;
71 return *this;
74 bool wasmVerbose() const { return wasmVerbose_; }
75 ContextOptions& setWasmVerbose(bool flag) {
76 wasmVerbose_ = flag;
77 return *this;
80 bool wasmBaseline() const { return wasmBaseline_; }
81 ContextOptions& setWasmBaseline(bool flag) {
82 wasmBaseline_ = flag;
83 return *this;
86 bool wasmIon() const { return wasmIon_; }
87 ContextOptions& setWasmIon(bool flag) {
88 wasmIon_ = flag;
89 return *this;
92 bool testWasmAwaitTier2() const { return testWasmAwaitTier2_; }
93 ContextOptions& setTestWasmAwaitTier2(bool flag) {
94 testWasmAwaitTier2_ = flag;
95 return *this;
98 bool throwOnAsmJSValidationFailure() const {
99 return compileOptions_.throwOnAsmJSValidationFailure();
101 ContextOptions& setThrowOnAsmJSValidationFailure(bool flag) {
102 compileOptions_.setThrowOnAsmJSValidationFailure(flag);
103 return *this;
105 ContextOptions& toggleThrowOnAsmJSValidationFailure() {
106 compileOptions_.toggleThrowOnAsmJSValidationFailure();
107 return *this;
110 // Override to allow disabling Ion for this context irrespective of the
111 // process-wide Ion-enabled setting. This must be set right after creating
112 // the context.
113 bool disableIon() const { return disableIon_; }
114 ContextOptions& setDisableIon() {
115 disableIon_ = true;
116 return *this;
119 bool importAttributes() const { return compileOptions_.importAttributes(); }
120 ContextOptions& setImportAttributes(bool enabled) {
121 compileOptions_.setImportAttributes(enabled);
122 return *this;
125 bool importAttributesAssertSyntax() const {
126 return compileOptions_.importAttributesAssertSyntax();
128 ContextOptions& setImportAttributesAssertSyntax(bool enabled) {
129 compileOptions_.setImportAttributesAssertSyntax(enabled);
130 return *this;
133 // Override to allow disabling the eval restriction security checks for
134 // this context.
135 bool disableEvalSecurityChecks() const { return disableEvalSecurityChecks_; }
136 ContextOptions& setDisableEvalSecurityChecks() {
137 disableEvalSecurityChecks_ = true;
138 return *this;
141 bool asyncStack() const { return asyncStack_; }
142 ContextOptions& setAsyncStack(bool flag) {
143 asyncStack_ = flag;
144 return *this;
147 bool asyncStackCaptureDebuggeeOnly() const {
148 return asyncStackCaptureDebuggeeOnly_;
150 ContextOptions& setAsyncStackCaptureDebuggeeOnly(bool flag) {
151 asyncStackCaptureDebuggeeOnly_ = flag;
152 return *this;
155 // Enable/disable support for parsing '//(#@) source(Mapping)?URL=' pragmas.
156 bool sourcePragmas() const { return compileOptions_.sourcePragmas(); }
157 ContextOptions& setSourcePragmas(bool flag) {
158 compileOptions_.setSourcePragmas(flag);
159 return *this;
162 bool throwOnDebuggeeWouldRun() const { return throwOnDebuggeeWouldRun_; }
163 ContextOptions& setThrowOnDebuggeeWouldRun(bool flag) {
164 throwOnDebuggeeWouldRun_ = flag;
165 return *this;
168 bool dumpStackOnDebuggeeWouldRun() const {
169 return dumpStackOnDebuggeeWouldRun_;
171 ContextOptions& setDumpStackOnDebuggeeWouldRun(bool flag) {
172 dumpStackOnDebuggeeWouldRun_ = flag;
173 return *this;
176 #ifdef JS_ENABLE_SMOOSH
177 // Track Number of Not Implemented Calls by writing to a file
178 bool trackNotImplemented() const { return trackNotImplemented_; }
179 ContextOptions& setTrackNotImplemented(bool flag) {
180 trackNotImplemented_ = flag;
181 return *this;
184 // Try compiling SmooshMonkey frontend first, and fallback to C++
185 // implementation when it fails.
186 bool trySmoosh() const { return trySmoosh_; }
187 ContextOptions& setTrySmoosh(bool flag) {
188 trySmoosh_ = flag;
189 return *this;
192 #endif // JS_ENABLE_SMOOSH
194 bool fuzzing() const { return fuzzing_; }
195 // Defined out-of-line because it depends on a compile-time option
196 ContextOptions& setFuzzing(bool flag);
198 void disableOptionsForSafeMode() {
199 setAsmJSOption(AsmJSOption::DisabledByAsmJSPref);
200 setWasmBaseline(false);
203 PrefableCompileOptions& compileOptions() { return compileOptions_; }
204 const PrefableCompileOptions& compileOptions() const {
205 return compileOptions_;
208 private:
209 // WASM options.
210 bool wasm_ : 1;
211 bool wasmForTrustedPrinciples_ : 1;
212 bool wasmVerbose_ : 1;
213 bool wasmBaseline_ : 1;
214 bool wasmIon_ : 1;
215 bool testWasmAwaitTier2_ : 1;
217 // JIT options.
218 bool disableIon_ : 1;
219 bool disableEvalSecurityChecks_ : 1;
221 // Runtime options.
222 bool asyncStack_ : 1;
223 bool asyncStackCaptureDebuggeeOnly_ : 1;
224 bool throwOnDebuggeeWouldRun_ : 1;
225 bool dumpStackOnDebuggeeWouldRun_ : 1;
226 #ifdef JS_ENABLE_SMOOSH
227 bool trackNotImplemented_ : 1;
228 bool trySmoosh_ : 1;
229 #endif
230 bool fuzzing_ : 1;
232 // Compile options.
233 PrefableCompileOptions compileOptions_;
236 JS_PUBLIC_API ContextOptions& ContextOptionsRef(JSContext* cx);
238 } // namespace JS
240 #endif // js_ContextOptions_h