diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index 72c5b9392df4..c09d581e54cd 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -670,23 +670,9 @@ static bool WasmBulkMemSupported(JSContext* cx, unsigned argc, Value* vp) { return true; } -static bool TestGCEnabled(JSContext* cx) { -#ifdef ENABLE_WASM_GC - bool isSupported = cx->options().wasmBaseline() && cx->options().wasmGc(); -#ifdef ENABLE_WASM_CRANELIFT - if (cx->options().wasmForceCranelift()) { - isSupported = false; - } -#endif - return isSupported; -#else - return false; -#endif -} - static bool WasmGcEnabled(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); - args.rval().setBoolean(TestGCEnabled(cx)); + args.rval().setBoolean(wasm::HasGcSupport(cx)); return true; } @@ -695,7 +681,7 @@ static bool WasmGeneralizedTables(JSContext* cx, unsigned argc, Value* vp) { #ifdef ENABLE_WASM_GENERALIZED_TABLES // Generalized tables depend on anyref, though not currently on (ref T) // types nor on structures or other GC-proposal features. - bool isSupported = TestGCEnabled(cx); + bool isSupported = wasm::HasGcSupport(cx); #else bool isSupported = false; #endif diff --git a/js/src/jit/CompileWrappers.cpp b/js/src/jit/CompileWrappers.cpp index 6b93078346de..7179701d41e3 100644 --- a/js/src/jit/CompileWrappers.cpp +++ b/js/src/jit/CompileWrappers.cpp @@ -225,6 +225,6 @@ JitCompileOptions::JitCompileOptions(JSContext* cx) { cx->runtime()->geckoProfiler().slowAssertionsEnabled(); offThreadCompilationAvailable_ = OffThreadCompilationAvailable(cx); #ifdef ENABLE_WASM_GC - wasmGcEnabled_ = cx->options().wasmGc(); + wasmGcEnabled_ = wasm::HasGcSupport(cx); #endif } diff --git a/js/src/wasm/WasmCompile.cpp b/js/src/wasm/WasmCompile.cpp index e57cc203edd6..3e4f7a417d25 100644 --- a/js/src/wasm/WasmCompile.cpp +++ b/js/src/wasm/WasmCompile.cpp @@ -75,7 +75,7 @@ uint32_t wasm::ObservedCPUFeatures() { CompileArgs::CompileArgs(JSContext* cx, ScriptedCaller&& scriptedCaller) : scriptedCaller(std::move(scriptedCaller)) { #ifdef ENABLE_WASM_GC - bool gcEnabled = cx->options().wasmGc(); + bool gcEnabled = HasGcSupport(cx); #else bool gcEnabled = false; #endif diff --git a/js/src/wasm/WasmJS.cpp b/js/src/wasm/WasmJS.cpp index 8277e725cdc9..d43e969c8735 100644 --- a/js/src/wasm/WasmJS.cpp +++ b/js/src/wasm/WasmJS.cpp @@ -57,6 +57,19 @@ using mozilla::RangedPtr; extern mozilla::Atomic fuzzingSafe; +bool wasm::HasGcSupport(JSContext* cx) { +#ifdef ENABLE_WASM_CRANELIFT + if (cx->options().wasmForceCranelift()) { + return false; + } +#endif +#ifdef ENABLE_WASM_GC + return cx->options().wasmGc() && cx->options().wasmBaseline(); +#else + return false; +#endif +} + bool wasm::HasCompilerSupport(JSContext* cx) { #if !MOZ_LITTLE_ENDIAN || defined(JS_CODEGEN_NONE) return false; @@ -2047,7 +2060,7 @@ bool WasmTableObject::isNewborn() const { tableKind = TableKind::AnyFunction; #ifdef ENABLE_WASM_GENERALIZED_TABLES } else if (StringEqualsAscii(elementLinearStr, "anyref")) { - if (!cx->options().wasmGc()) { + if (!HasGcSupport(cx)) { JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_WASM_BAD_ELEMENT); return false; @@ -2460,7 +2473,7 @@ const Class WasmGlobalObject::class_ = { } else if (StringEqualsAscii(typeLinearStr, "f64")) { globalType = ValType::F64; #ifdef ENABLE_WASM_GC - } else if (cx->options().wasmGc() && + } else if (HasGcSupport(cx) && StringEqualsAscii(typeLinearStr, "anyref")) { globalType = ValType::AnyRef; #endif diff --git a/js/src/wasm/WasmJS.h b/js/src/wasm/WasmJS.h index 9e36f08ac209..513fc6c7cd89 100644 --- a/js/src/wasm/WasmJS.h +++ b/js/src/wasm/WasmJS.h @@ -53,6 +53,11 @@ bool HasStreamingSupport(JSContext* cx); bool HasCachingSupport(JSContext* cx); +// Returns true if WebAssembly as configured by compile-time flags and run-time +// options can support reference types and stack walking. + +bool HasGcSupport(JSContext* cx); + // Compiles the given binary wasm module given the ArrayBufferObject // and links the module's imports with the given import object. diff --git a/js/src/wasm/WasmValidate.cpp b/js/src/wasm/WasmValidate.cpp index 670934b26de4..54e628c6816f 100644 --- a/js/src/wasm/WasmValidate.cpp +++ b/js/src/wasm/WasmValidate.cpp @@ -2792,7 +2792,7 @@ bool wasm::Validate(JSContext* cx, const ShareableBytes& bytecode, #ifdef ENABLE_WASM_GC HasGcTypes gcTypesConfigured = - cx->options().wasmGc() ? HasGcTypes::True : HasGcTypes::False; + HasGcSupport(cx) ? HasGcTypes::True : HasGcTypes::False; #else HasGcTypes gcTypesConfigured = HasGcTypes::False; #endif