Bug 1590907 - Remove preprocessor dependence from size of ContextOptions. r=sfink

Previously, if SpiderMonkey embedders linked to a copy of libmozjs built
with --enable-cranelift, --enable-wasm-gc, or --enable-fuzzing, then the
size of the ContextOptions data structure declared in the header file
would be different than the size of ContextOptions in the library,
likely leading to crashes. This makes all members of ContextOptions
independent of preprocessor macros. Any options not compiled into
SpiderMonkey will still be no-ops.

Differential Revision: https://phabricator.services.mozilla.com/D52460

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Philip Chimento 2019-11-26 02:01:46 +00:00
Родитель 20c2be51e8
Коммит 28a552a99b
2 изменённых файлов: 29 добавлений и 37 удалений

Просмотреть файл

@ -24,12 +24,8 @@ class JS_PUBLIC_API ContextOptions {
wasmVerbose_(false),
wasmBaseline_(true),
wasmIon_(true),
#ifdef ENABLE_WASM_CRANELIFT
wasmCranelift_(false),
#endif
#ifdef ENABLE_WASM_GC
wasmGc_(false),
#endif
testWasmAwaitTier2_(false),
throwOnAsmJSValidationFailure_(false),
asyncStack_(true),
@ -37,13 +33,8 @@ class JS_PUBLIC_API ContextOptions {
dumpStackOnDebuggeeWouldRun_(false),
werror_(false),
strictMode_(false),
extraWarnings_(false)
#ifdef FUZZING
,
fuzzing_(false)
#endif
{
}
extraWarnings_(false),
fuzzing_(false) {}
bool asmJS() const { return asmJS_; }
ContextOptions& setAsmJS(bool flag) {
@ -89,13 +80,9 @@ class JS_PUBLIC_API ContextOptions {
return *this;
}
#ifdef ENABLE_WASM_CRANELIFT
bool wasmCranelift() const { return wasmCranelift_; }
ContextOptions& setWasmCranelift(bool flag) {
wasmCranelift_ = flag;
return *this;
}
#endif
// Defined out-of-line because it depends on a compile-time option
ContextOptions& setWasmCranelift(bool flag);
bool testWasmAwaitTier2() const { return testWasmAwaitTier2_; }
ContextOptions& setTestWasmAwaitTier2(bool flag) {
@ -103,13 +90,9 @@ class JS_PUBLIC_API ContextOptions {
return *this;
}
#ifdef ENABLE_WASM_GC
bool wasmGc() const { return wasmGc_; }
ContextOptions& setWasmGc(bool flag) {
wasmGc_ = flag;
return *this;
}
#endif
// Defined out-of-line because it depends on a compile-time option
ContextOptions& setWasmGc(bool flag);
bool throwOnAsmJSValidationFailure() const {
return throwOnAsmJSValidationFailure_;
@ -173,22 +156,16 @@ class JS_PUBLIC_API ContextOptions {
return *this;
}
#ifdef FUZZING
bool fuzzing() const { return fuzzing_; }
ContextOptions& setFuzzing(bool flag) {
fuzzing_ = flag;
return *this;
}
#endif
// Defined out-of-line because it depends on a compile-time option
ContextOptions& setFuzzing(bool flag);
void disableOptionsForSafeMode() {
setAsmJS(false);
setWasm(false);
setWasmBaseline(false);
setWasmIon(false);
#ifdef ENABLE_WASM_GC
setWasmGc(false);
#endif
}
private:
@ -198,12 +175,8 @@ class JS_PUBLIC_API ContextOptions {
bool wasmVerbose_ : 1;
bool wasmBaseline_ : 1;
bool wasmIon_ : 1;
#ifdef ENABLE_WASM_CRANELIFT
bool wasmCranelift_ : 1;
#endif
#ifdef ENABLE_WASM_GC
bool wasmGc_ : 1;
#endif
bool testWasmAwaitTier2_ : 1;
bool throwOnAsmJSValidationFailure_ : 1;
bool asyncStack_ : 1;
@ -212,9 +185,7 @@ class JS_PUBLIC_API ContextOptions {
bool werror_ : 1;
bool strictMode_ : 1;
bool extraWarnings_ : 1;
#ifdef FUZZING
bool fuzzing_ : 1;
#endif
};
JS_PUBLIC_API ContextOptions& ContextOptionsRef(JSContext* cx);

Просмотреть файл

@ -401,6 +401,27 @@ JS_PUBLIC_API JS::ContextOptions& JS::ContextOptionsRef(JSContext* cx) {
return cx->options();
}
JS::ContextOptions& JS::ContextOptions::setWasmCranelift(bool flag) {
#ifdef ENABLE_WASM_CRANELIFT
wasmCranelift_ = flag;
#endif
return *this;
}
JS::ContextOptions& JS::ContextOptions::setWasmGc(bool flag) {
#ifdef ENABLE_WASM_GC
wasmGc_ = flag;
#endif
return *this;
}
JS::ContextOptions& JS::ContextOptions::setFuzzing(bool flag) {
#ifdef FUZZING
fuzzing_ = flag;
#endif
return *this;
}
JS_PUBLIC_API bool JS::InitSelfHostedCode(JSContext* cx) {
MOZ_RELEASE_ASSERT(!cx->runtime()->hasInitializedSelfHosting(),
"JS::InitSelfHostedCode() called more than once");