| 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/. */ |
| 6 |
|
| 7 |
/* JavaScript API. */ |
| 8 |
|
| 9 |
#ifndef js_ContextOptions_h |
| 10 |
#define js_ContextOptions_h |
| 11 |
|
| 12 |
#include "jstypes.h" // JS_PUBLIC_API |
| 13 |
|
| 14 |
#include "js/CompileOptions.h" // PrefableCompileOptions |
| 15 |
#include "js/WasmFeatures.h" |
| 16 |
|
| 17 |
struct JS_PUBLIC_API JSContext; |
| 18 |
|
| 19 |
namespace JS { |
| 20 |
|
| 21 |
class JS_PUBLIC_API ContextOptions { |
| 22 |
public: |
| 23 |
// clang-format off |
| 24 |
ContextOptions() |
| 25 |
: wasm_(true), |
| 26 |
wasmForTrustedPrinciples_(true), |
| 27 |
wasmBaseline_(true), |
| 28 |
wasmIon_(true), |
| 29 |
testWasmAwaitTier2_(false), |
| 30 |
disableIon_(false), |
| 31 |
disableEvalSecurityChecks_(false), |
| 32 |
asyncStack_(true), |
| 33 |
asyncStackCaptureDebuggeeOnly_(false), |
| 34 |
throwOnDebuggeeWouldRun_(true), |
| 35 |
dumpStackOnDebuggeeWouldRun_(false), |
| 36 |
fuzzing_(false) { |
| 37 |
} |
| 38 |
// clang-format on |
| 39 |
|
| 40 |
bool asmJS() const { |
| 41 |
return compileOptions_.asmJSOption() == AsmJSOption::Enabled; |
| 42 |
} |
| 43 |
AsmJSOption asmJSOption() const { return compileOptions_.asmJSOption(); } |
| 44 |
ContextOptions& setAsmJS(bool flag) { |
| 45 |
compileOptions_.setAsmJS(flag); |
| 46 |
return *this; |
| 47 |
} |
| 48 |
ContextOptions& setAsmJSOption(AsmJSOption option) { |
| 49 |
compileOptions_.setAsmJSOption(option); |
| 50 |
return *this; |
| 51 |
} |
| 52 |
|
| 53 |
bool wasm() const { return wasm_; } |
| 54 |
ContextOptions& setWasm(bool flag) { |
| 55 |
wasm_ = flag; |
| 56 |
return *this; |
| 57 |
} |
| 58 |
ContextOptions& toggleWasm() { |
| 59 |
wasm_ = !wasm_; |
| 60 |
return *this; |
| 61 |
} |
| 62 |
|
| 63 |
bool wasmForTrustedPrinciples() const { return wasmForTrustedPrinciples_; } |
| 64 |
ContextOptions& setWasmForTrustedPrinciples(bool flag) { |
| 65 |
wasmForTrustedPrinciples_ = flag; |
| 66 |
return *this; |
| 67 |
} |
| 68 |
|
| 69 |
bool wasmBaseline() const { return wasmBaseline_; } |
| 70 |
ContextOptions& setWasmBaseline(bool flag) { |
| 71 |
wasmBaseline_ = flag; |
| 72 |
return *this; |
| 73 |
} |
| 74 |
|
| 75 |
bool wasmIon() const { return wasmIon_; } |
| 76 |
ContextOptions& setWasmIon(bool flag) { |
| 77 |
wasmIon_ = flag; |
| 78 |
return *this; |
| 79 |
} |
| 80 |
|
| 81 |
bool testWasmAwaitTier2() const { return testWasmAwaitTier2_; } |
| 82 |
ContextOptions& setTestWasmAwaitTier2(bool flag) { |
| 83 |
testWasmAwaitTier2_ = flag; |
| 84 |
return *this; |
| 85 |
} |
| 86 |
|
| 87 |
bool throwOnAsmJSValidationFailure() const { |
| 88 |
return compileOptions_.throwOnAsmJSValidationFailure(); |
| 89 |
} |
| 90 |
ContextOptions& setThrowOnAsmJSValidationFailure(bool flag) { |
| 91 |
compileOptions_.setThrowOnAsmJSValidationFailure(flag); |
| 92 |
return *this; |
| 93 |
} |
| 94 |
ContextOptions& toggleThrowOnAsmJSValidationFailure() { |
| 95 |
compileOptions_.toggleThrowOnAsmJSValidationFailure(); |
| 96 |
return *this; |
| 97 |
} |
| 98 |
|
| 99 |
// Override to allow disabling Ion for this context irrespective of the |
| 100 |
// process-wide Ion-enabled setting. This must be set right after creating |
| 101 |
// the context. |
| 102 |
bool disableIon() const { return disableIon_; } |
| 103 |
ContextOptions& setDisableIon() { |
| 104 |
disableIon_ = true; |
| 105 |
return *this; |
| 106 |
} |
| 107 |
|
| 108 |
bool importAttributes() const { return compileOptions_.importAttributes(); } |
| 109 |
ContextOptions& setImportAttributes(bool enabled) { |
| 110 |
compileOptions_.setImportAttributes(enabled); |
| 111 |
return *this; |
| 112 |
} |
| 113 |
|
| 114 |
// Override to allow disabling the eval restriction security checks for |
| 115 |
// this context. |
| 116 |
bool disableEvalSecurityChecks() const { return disableEvalSecurityChecks_; } |
| 117 |
ContextOptions& setDisableEvalSecurityChecks() { |
| 118 |
disableEvalSecurityChecks_ = true; |
| 119 |
return *this; |
| 120 |
} |
| 121 |
|
| 122 |
bool asyncStack() const { return asyncStack_; } |
| 123 |
ContextOptions& setAsyncStack(bool flag) { |
| 124 |
asyncStack_ = flag; |
| 125 |
return *this; |
| 126 |
} |
| 127 |
|
| 128 |
bool asyncStackCaptureDebuggeeOnly() const { |
| 129 |
return asyncStackCaptureDebuggeeOnly_; |
| 130 |
} |
| 131 |
ContextOptions& setAsyncStackCaptureDebuggeeOnly(bool flag) { |
| 132 |
asyncStackCaptureDebuggeeOnly_ = flag; |
| 133 |
return *this; |
| 134 |
} |
| 135 |
|
| 136 |
// Enable/disable support for parsing '//(#@) source(Mapping)?URL=' pragmas. |
| 137 |
bool sourcePragmas() const { return compileOptions_.sourcePragmas(); } |
| 138 |
ContextOptions& setSourcePragmas(bool flag) { |
| 139 |
compileOptions_.setSourcePragmas(flag); |
| 140 |
return *this; |
| 141 |
} |
| 142 |
|
| 143 |
bool throwOnDebuggeeWouldRun() const { return throwOnDebuggeeWouldRun_; } |
| 144 |
ContextOptions& setThrowOnDebuggeeWouldRun(bool flag) { |
| 145 |
throwOnDebuggeeWouldRun_ = flag; |
| 146 |
return *this; |
| 147 |
} |
| 148 |
|
| 149 |
bool dumpStackOnDebuggeeWouldRun() const { |
| 150 |
return dumpStackOnDebuggeeWouldRun_; |
| 151 |
} |
| 152 |
ContextOptions& setDumpStackOnDebuggeeWouldRun(bool flag) { |
| 153 |
dumpStackOnDebuggeeWouldRun_ = flag; |
| 154 |
return *this; |
| 155 |
} |
| 156 |
|
| 157 |
bool fuzzing() const { return fuzzing_; } |
| 158 |
// Defined out-of-line because it depends on a compile-time option |
| 159 |
ContextOptions& setFuzzing(bool flag); |
| 160 |
|
| 161 |
void disableOptionsForSafeMode() { |
| 162 |
setAsmJSOption(AsmJSOption::DisabledByAsmJSPref); |
| 163 |
setWasmBaseline(false); |
| 164 |
} |
| 165 |
|
| 166 |
PrefableCompileOptions& compileOptions() { return compileOptions_; } |
| 167 |
const PrefableCompileOptions& compileOptions() const { |
| 168 |
return compileOptions_; |
| 169 |
} |
| 170 |
|
| 171 |
private: |
| 172 |
// WASM options. |
| 173 |
bool wasm_ : 1; |
| 174 |
bool wasmForTrustedPrinciples_ : 1; |
| 175 |
bool wasmBaseline_ : 1; |
| 176 |
bool wasmIon_ : 1; |
| 177 |
bool testWasmAwaitTier2_ : 1; |
| 178 |
|
| 179 |
// JIT options. |
| 180 |
bool disableIon_ : 1; |
| 181 |
bool disableEvalSecurityChecks_ : 1; |
| 182 |
|
| 183 |
// Runtime options. |
| 184 |
bool asyncStack_ : 1; |
| 185 |
bool asyncStackCaptureDebuggeeOnly_ : 1; |
| 186 |
bool throwOnDebuggeeWouldRun_ : 1; |
| 187 |
bool dumpStackOnDebuggeeWouldRun_ : 1; |
| 188 |
bool fuzzing_ : 1; |
| 189 |
|
| 190 |
// Compile options. |
| 191 |
PrefableCompileOptions compileOptions_; |
| 192 |
}; |
| 193 |
|
| 194 |
JS_PUBLIC_API ContextOptions& ContextOptionsRef(JSContext* cx); |
| 195 |
|
| 196 |
} // namespace JS |
| 197 |
|
| 198 |
#endif // js_ContextOptions_h |