Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérôme Laban <jerome.laban@nventive.com>2022-03-29 17:57:42 +0300
committerGitHub <noreply@github.com>2022-03-29 17:57:42 +0300
commit5f3ae152140e626bc8535da34f3f5e148dd1fa24 (patch)
tree648997c9c032948c9980e3dde145f105a5f6b2de /src/mono/wasm/runtime
parent6f2d769ec11fb678b588af610cbadf169a18dc24 (diff)
feat: Add support for emscripten module exports (#66868)
Diffstat (limited to 'src/mono/wasm/runtime')
-rw-r--r--src/mono/wasm/runtime/dotnet.d.ts1
-rw-r--r--src/mono/wasm/runtime/startup.ts19
-rw-r--r--src/mono/wasm/runtime/types.ts1
3 files changed, 21 insertions, 0 deletions
diff --git a/src/mono/wasm/runtime/dotnet.d.ts b/src/mono/wasm/runtime/dotnet.d.ts
index d6a86af0a32..617b572e757 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<void>;
onDotnetReady?: () => void;
imports?: DotnetModuleConfigImports;
+ exports?: string[];
} & Partial<EmscriptenModule>;
declare type DotnetModuleConfigImports = {
require?: (name: string) => any;
diff --git a/src/mono/wasm/runtime/startup.ts b/src/mono/wasm/runtime/startup.ts
index 9112a35defb..aa10c272496 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 = (<any>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 cc0d1b24583..aa7481fa076 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<EmscriptenModule>
export type DotnetModuleConfigImports = {