diff --git a/src/mono/wasm/runtime/dotnet.d.ts b/src/mono/wasm/runtime/dotnet.d.ts index d6a86af0a3278dd833eea39bed48c756bd2c2702..617b572e7574287174aeb5af2044e7ff277831e5 100644 --- a/src/mono/wasm/runtime/dotnet.d.ts +++ b/src/mono/wasm/runtime/dotnet.d.ts @@ -197,6 +197,7 @@ declare type DotnetModuleConfig = { onConfigLoaded?: (config: MonoConfig) => Promise; onDotnetReady?: () => void; imports?: DotnetModuleConfigImports; + exports?: string[]; } & Partial; declare type DotnetModuleConfigImports = { require?: (name: string) => any; diff --git a/src/mono/wasm/runtime/startup.ts b/src/mono/wasm/runtime/startup.ts index 9112a35defbd8d35d8d88962a3533e80865f9f8b..aa10c2724965b441ffbae23c07aa7cadca2fe5cc 100644 --- a/src/mono/wasm/runtime/startup.ts +++ b/src/mono/wasm/runtime/startup.ts @@ -266,6 +266,8 @@ function _apply_configuration_from_args(config: MonoConfig) { } function finalize_startup(config: MonoConfig | MonoConfigError | undefined): void { + const globalThisAny = globalThis as any; + try { if (!config || config.isError) { return; @@ -276,6 +278,23 @@ function finalize_startup(config: MonoConfig | MonoConfigError | undefined): voi const moduleExt = Module as DotnetModule; + if(!Module.disableDotnet6Compatibility && Module.exports){ + // Export emscripten defined in module through EXPORTED_RUNTIME_METHODS + // Useful to export IDBFS or other similar types generally exposed as + // global types when emscripten is not modularized. + for (let i = 0; i < Module.exports.length; ++i) { + const exportName = Module.exports[i]; + const exportValue = (Module)[exportName]; + + if(exportValue) { + globalThisAny[exportName] = exportValue; + } + else{ + console.warn(`MONO_WASM: The exported symbol ${exportName} could not be found in the emscripten module`); + } + } + } + try { _apply_configuration_from_args(config); diff --git a/src/mono/wasm/runtime/types.ts b/src/mono/wasm/runtime/types.ts index cc0d1b24583e31b2f49732cf2391c6593f2b2507..aa7481fa076d432d59d011e18564718b9e5536a5 100644 --- a/src/mono/wasm/runtime/types.ts +++ b/src/mono/wasm/runtime/types.ts @@ -166,6 +166,7 @@ export type DotnetModuleConfig = { onDotnetReady?: () => void; imports?: DotnetModuleConfigImports; + exports?: string[]; } & Partial export type DotnetModuleConfigImports = {