Skip to content

Commit d968dc4

Browse files
authored
[browser][coreCLR] detect browser features and fail fast (#122799)
1 parent 04d7aeb commit d968dc4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/native/corehost/browserhost/loader/bootstrap.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import type { LoaderConfig, DotnetHostBuilder } from "./types";
55

6+
import { exceptions, simd } from "wasm-feature-detect";
7+
68
import { GlobalizationMode } from "./types";
79
import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL } from "./per-module";
810
import { nodeFs } from "./polyfills";
@@ -14,6 +16,11 @@ const modulesUniqueQuery = queryIndex > 0 ? scriptUrlQuery.substring(queryIndex)
1416
const scriptUrl = normalizeFileUrl(scriptUrlQuery);
1517
const scriptDirectory = normalizeDirectoryUrl(scriptUrl);
1618

19+
export async function validateWasmFeatures(): Promise<void> {
20+
dotnetAssert.check(await exceptions, "This browser/engine doesn't support WASM exception handling. Please use a modern version. See also https://aka.ms/dotnet-wasm-features");
21+
dotnetAssert.check(await simd, "This browser/engine doesn't support WASM SIMD. Please use a modern version. See also https://aka.ms/dotnet-wasm-features");
22+
}
23+
1724
export function locateFile(path: string, isModule = false): string {
1825
let res;
1926
if (isPathAbsolute(path)) {

src/native/corehost/browserhost/loader/run.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import type { DotnetHostBuilder, JsModuleExports, EmscriptenModuleInternal } from "./types";
55

66
import { dotnetAssert, dotnetGetInternals, dotnetBrowserHostExports, Module } from "./cross-module";
7-
import { findResources, isNodeHosted, isShellHosted } from "./bootstrap";
7+
import { findResources, isNodeHosted, isShellHosted, validateWasmFeatures } from "./bootstrap";
88
import { exit, runtimeState } from "./exit";
99
import { createPromiseCompletionSource } from "./promise-completion-source";
1010
import { getIcuResourceName } from "./icu";
@@ -30,11 +30,12 @@ export async function createRuntime(downloadOnly: boolean): Promise<any> {
3030
const config = getLoaderConfig();
3131
if (!config.resources || !config.resources.coreAssembly || !config.resources.coreAssembly.length) throw new Error("Invalid config, resources is not set");
3232

33-
3433
if (typeof Module.onConfigLoaded === "function") {
3534
await Module.onConfigLoaded(config);
3635
}
3736

37+
await validateWasmFeatures();
38+
3839
if (config.resources.jsModuleDiagnostics && config.resources.jsModuleDiagnostics.length > 0) {
3940
const diagnosticsModule = await loadJSModule(config.resources.jsModuleDiagnostics[0]);
4041
diagnosticsModule.dotnetInitializeModule<void>(dotnetGetInternals());

0 commit comments

Comments
 (0)