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/. */
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
;
21 class JS_PUBLIC_API ContextOptions
{
26 wasmForTrustedPrinciples_(true),
30 #define WASM_FEATURE(NAME, LOWER_NAME, STAGE, ...) wasm##NAME##_(STAGE == WasmFeatureStage::Default),
31 JS_FOR_WASM_FEATURES(WASM_FEATURE
)
33 testWasmAwaitTier2_(false),
35 disableEvalSecurityChecks_(false),
37 asyncStackCaptureDebuggeeOnly_(false),
38 throwOnDebuggeeWouldRun_(true),
39 dumpStackOnDebuggeeWouldRun_(false),
40 #ifdef JS_ENABLE_SMOOSH
41 trackNotImplemented_(false),
49 return compileOptions_
.asmJSOption() == AsmJSOption::Enabled
;
51 AsmJSOption
asmJSOption() const { return compileOptions_
.asmJSOption(); }
52 ContextOptions
& setAsmJS(bool flag
) {
53 compileOptions_
.setAsmJS(flag
);
56 ContextOptions
& setAsmJSOption(AsmJSOption option
) {
57 compileOptions_
.setAsmJSOption(option
);
61 bool wasm() const { return wasm_
; }
62 ContextOptions
& setWasm(bool flag
) {
66 ContextOptions
& toggleWasm() {
71 bool wasmForTrustedPrinciples() const { return wasmForTrustedPrinciples_
; }
72 ContextOptions
& setWasmForTrustedPrinciples(bool flag
) {
73 wasmForTrustedPrinciples_
= flag
;
77 bool wasmVerbose() const { return wasmVerbose_
; }
78 ContextOptions
& setWasmVerbose(bool flag
) {
83 bool wasmBaseline() const { return wasmBaseline_
; }
84 ContextOptions
& setWasmBaseline(bool flag
) {
89 bool wasmIon() const { return wasmIon_
; }
90 ContextOptions
& setWasmIon(bool flag
) {
95 bool testWasmAwaitTier2() const { return testWasmAwaitTier2_
; }
96 ContextOptions
& setTestWasmAwaitTier2(bool flag
) {
97 testWasmAwaitTier2_
= flag
;
101 #define WASM_FEATURE(NAME, ...) \
102 bool wasm##NAME() const { return wasm##NAME##_; } \
103 ContextOptions& setWasm##NAME(bool flag) { \
104 wasm##NAME##_ = flag; \
107 JS_FOR_WASM_FEATURES(WASM_FEATURE
)
110 bool throwOnAsmJSValidationFailure() const {
111 return compileOptions_
.throwOnAsmJSValidationFailure();
113 ContextOptions
& setThrowOnAsmJSValidationFailure(bool flag
) {
114 compileOptions_
.setThrowOnAsmJSValidationFailure(flag
);
117 ContextOptions
& toggleThrowOnAsmJSValidationFailure() {
118 compileOptions_
.toggleThrowOnAsmJSValidationFailure();
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
125 bool disableIon() const { return disableIon_
; }
126 ContextOptions
& setDisableIon() {
131 bool importAssertions() const { return compileOptions_
.importAssertions(); }
132 ContextOptions
& setImportAssertions(bool enabled
) {
133 compileOptions_
.setImportAssertions(enabled
);
137 // Override to allow disabling the eval restriction security checks for
139 bool disableEvalSecurityChecks() const { return disableEvalSecurityChecks_
; }
140 ContextOptions
& setDisableEvalSecurityChecks() {
141 disableEvalSecurityChecks_
= true;
145 bool asyncStack() const { return asyncStack_
; }
146 ContextOptions
& setAsyncStack(bool flag
) {
151 bool asyncStackCaptureDebuggeeOnly() const {
152 return asyncStackCaptureDebuggeeOnly_
;
154 ContextOptions
& setAsyncStackCaptureDebuggeeOnly(bool flag
) {
155 asyncStackCaptureDebuggeeOnly_
= flag
;
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
);
166 bool throwOnDebuggeeWouldRun() const { return throwOnDebuggeeWouldRun_
; }
167 ContextOptions
& setThrowOnDebuggeeWouldRun(bool flag
) {
168 throwOnDebuggeeWouldRun_
= flag
;
172 bool dumpStackOnDebuggeeWouldRun() const {
173 return dumpStackOnDebuggeeWouldRun_
;
175 ContextOptions
& setDumpStackOnDebuggeeWouldRun(bool flag
) {
176 dumpStackOnDebuggeeWouldRun_
= flag
;
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
;
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
) {
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_
;
215 bool wasmForTrustedPrinciples_
: 1;
216 bool wasmVerbose_
: 1;
217 bool wasmBaseline_
: 1;
219 #define WASM_FEATURE(NAME, ...) bool wasm##NAME##_ : 1;
220 JS_FOR_WASM_FEATURES(WASM_FEATURE
)
222 bool testWasmAwaitTier2_
: 1;
225 bool disableIon_
: 1;
226 bool disableEvalSecurityChecks_
: 1;
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;
240 PrefableCompileOptions compileOptions_
;
243 JS_PUBLIC_API ContextOptions
& ContextOptionsRef(JSContext
* cx
);
247 #endif // js_ContextOptions_h