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 testWasmAwaitTier2_(false),
32 disableEvalSecurityChecks_(false),
34 asyncStackCaptureDebuggeeOnly_(false),
35 throwOnDebuggeeWouldRun_(true),
36 dumpStackOnDebuggeeWouldRun_(false),
37 #ifdef JS_ENABLE_SMOOSH
38 trackNotImplemented_(false),
46 return compileOptions_
.asmJSOption() == AsmJSOption::Enabled
;
48 AsmJSOption
asmJSOption() const { return compileOptions_
.asmJSOption(); }
49 ContextOptions
& setAsmJS(bool flag
) {
50 compileOptions_
.setAsmJS(flag
);
53 ContextOptions
& setAsmJSOption(AsmJSOption option
) {
54 compileOptions_
.setAsmJSOption(option
);
58 bool wasm() const { return wasm_
; }
59 ContextOptions
& setWasm(bool flag
) {
63 ContextOptions
& toggleWasm() {
68 bool wasmForTrustedPrinciples() const { return wasmForTrustedPrinciples_
; }
69 ContextOptions
& setWasmForTrustedPrinciples(bool flag
) {
70 wasmForTrustedPrinciples_
= flag
;
74 bool wasmVerbose() const { return wasmVerbose_
; }
75 ContextOptions
& setWasmVerbose(bool flag
) {
80 bool wasmBaseline() const { return wasmBaseline_
; }
81 ContextOptions
& setWasmBaseline(bool flag
) {
86 bool wasmIon() const { return wasmIon_
; }
87 ContextOptions
& setWasmIon(bool flag
) {
92 bool testWasmAwaitTier2() const { return testWasmAwaitTier2_
; }
93 ContextOptions
& setTestWasmAwaitTier2(bool flag
) {
94 testWasmAwaitTier2_
= flag
;
98 bool throwOnAsmJSValidationFailure() const {
99 return compileOptions_
.throwOnAsmJSValidationFailure();
101 ContextOptions
& setThrowOnAsmJSValidationFailure(bool flag
) {
102 compileOptions_
.setThrowOnAsmJSValidationFailure(flag
);
105 ContextOptions
& toggleThrowOnAsmJSValidationFailure() {
106 compileOptions_
.toggleThrowOnAsmJSValidationFailure();
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
113 bool disableIon() const { return disableIon_
; }
114 ContextOptions
& setDisableIon() {
119 bool importAttributes() const { return compileOptions_
.importAttributes(); }
120 ContextOptions
& setImportAttributes(bool enabled
) {
121 compileOptions_
.setImportAttributes(enabled
);
125 bool importAttributesAssertSyntax() const {
126 return compileOptions_
.importAttributesAssertSyntax();
128 ContextOptions
& setImportAttributesAssertSyntax(bool enabled
) {
129 compileOptions_
.setImportAttributesAssertSyntax(enabled
);
133 // Override to allow disabling the eval restriction security checks for
135 bool disableEvalSecurityChecks() const { return disableEvalSecurityChecks_
; }
136 ContextOptions
& setDisableEvalSecurityChecks() {
137 disableEvalSecurityChecks_
= true;
141 bool asyncStack() const { return asyncStack_
; }
142 ContextOptions
& setAsyncStack(bool flag
) {
147 bool asyncStackCaptureDebuggeeOnly() const {
148 return asyncStackCaptureDebuggeeOnly_
;
150 ContextOptions
& setAsyncStackCaptureDebuggeeOnly(bool flag
) {
151 asyncStackCaptureDebuggeeOnly_
= flag
;
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
);
162 bool throwOnDebuggeeWouldRun() const { return throwOnDebuggeeWouldRun_
; }
163 ContextOptions
& setThrowOnDebuggeeWouldRun(bool flag
) {
164 throwOnDebuggeeWouldRun_
= flag
;
168 bool dumpStackOnDebuggeeWouldRun() const {
169 return dumpStackOnDebuggeeWouldRun_
;
171 ContextOptions
& setDumpStackOnDebuggeeWouldRun(bool flag
) {
172 dumpStackOnDebuggeeWouldRun_
= flag
;
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
;
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
) {
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_
;
211 bool wasmForTrustedPrinciples_
: 1;
212 bool wasmVerbose_
: 1;
213 bool wasmBaseline_
: 1;
215 bool testWasmAwaitTier2_
: 1;
218 bool disableIon_
: 1;
219 bool disableEvalSecurityChecks_
: 1;
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;
233 PrefableCompileOptions compileOptions_
;
236 JS_PUBLIC_API ContextOptions
& ContextOptionsRef(JSContext
* cx
);
240 #endif // js_ContextOptions_h