Skip to content

Commit 49bf719

Browse files
authored
[browser][MT] fix feature detection on webworker (dotnet#107452)
1 parent aa418fc commit 49bf719

File tree

3 files changed

+6
-29
lines changed

3 files changed

+6
-29
lines changed

src/mono/browser/runtime/jiterpreter-jit-call.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ const maxJitQueueLength = 6,
6161

6262
let trampBuilder: WasmBuilder;
6363
let fnTable: WebAssembly.Table;
64-
let wasmEhSupported: boolean | undefined = undefined;
6564
let nextDisambiguateIndex = 0;
6665
const fnCache: Array<Function | undefined> = [];
6766
const targetCache: { [target: number]: TrampolineInfo } = {};
@@ -276,18 +275,6 @@ export function mono_interp_jit_wasm_jit_call_trampoline (
276275
mono_interp_flush_jitcall_queue();
277276
}
278277

279-
function getIsWasmEhSupported (): boolean {
280-
if (wasmEhSupported !== undefined)
281-
return wasmEhSupported;
282-
283-
// Probe whether the current environment can handle wasm exceptions
284-
wasmEhSupported = runtimeHelpers.featureWasmEh === true;
285-
if (!wasmEhSupported)
286-
mono_log_info("Disabling Jiterpreter Exception Handling");
287-
288-
return wasmEhSupported;
289-
}
290-
291278
export function mono_interp_flush_jitcall_queue (): void {
292279
const jitQueue: TrampolineInfo[] = [];
293280
let methodPtr = <MonoMethod><any>0;
@@ -336,7 +323,7 @@ export function mono_interp_flush_jitcall_queue (): void {
336323
}
337324

338325
if (builder.options.enableWasmEh) {
339-
if (!getIsWasmEhSupported()) {
326+
if (!runtimeHelpers.featureWasmEh) {
340327
// The user requested to enable wasm EH but it's not supported, so turn the option back off
341328
applyOptions(<any>{ enableWasmEh: false });
342329
builder.options.enableWasmEh = false;

src/mono/browser/runtime/jiterpreter-trace-generator.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,19 +3526,6 @@ function emit_arrayop (builder: WasmBuilder, frame: NativePointer, ip: MintOpcod
35263526
return true;
35273527
}
35283528

3529-
let wasmSimdSupported: boolean | undefined;
3530-
3531-
function getIsWasmSimdSupported (): boolean {
3532-
if (wasmSimdSupported !== undefined)
3533-
return wasmSimdSupported;
3534-
3535-
wasmSimdSupported = runtimeHelpers.featureWasmSimd === true;
3536-
if (!wasmSimdSupported)
3537-
mono_log_info("Disabling Jiterpreter SIMD");
3538-
3539-
return wasmSimdSupported;
3540-
}
3541-
35423529
function get_import_name (
35433530
builder: WasmBuilder, typeName: string,
35443531
functionPtr: number
@@ -3557,7 +3544,7 @@ function emit_simd (
35573544
): boolean {
35583545
// First, if compiling an intrinsic attempt to emit the special vectorized implementation
35593546
// We only do this if SIMD is enabled since we'll be using the v128 opcodes.
3560-
if (builder.options.enableSimd && getIsWasmSimdSupported()) {
3547+
if (builder.options.enableSimd && runtimeHelpers.featureWasmSimd) {
35613548
switch (argCount) {
35623549
case 2:
35633550
if (emit_simd_2(builder, ip, <SimdIntrinsic2>index))
@@ -3577,7 +3564,7 @@ function emit_simd (
35773564
// Fall back to a mix of non-vectorized wasm and the interpreter's implementation of the opcodes
35783565
switch (opcode) {
35793566
case MintOpcode.MINT_SIMD_V128_LDC: {
3580-
if (builder.options.enableSimd && getIsWasmSimdSupported()) {
3567+
if (builder.options.enableSimd && runtimeHelpers.featureWasmSimd) {
35813568
builder.local("pLocals");
35823569
const view = localHeapViewU8().slice(<any>ip + 4, <any>ip + 4 + sizeOfV128);
35833570
builder.v128_const(view);

src/mono/browser/runtime/startup.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ async function instantiateWasmWorker (
128128
successCallback: InstantiateWasmSuccessCallback
129129
): Promise<void> {
130130
if (!WasmEnableThreads) return;
131+
132+
await ensureUsedWasmFeatures();
133+
131134
// wait for the config to arrive by message from the main thread
132135
await loaderHelpers.afterConfigLoaded.promise;
133136

0 commit comments

Comments
 (0)