未验证 提交 5f3ae152 编写于 作者: J Jérôme Laban 提交者: GitHub

feat: Add support for emscripten module exports (#66868)

上级 6f2d769e
......@@ -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;
......
......@@ -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);
......
......@@ -166,6 +166,7 @@ export type DotnetModuleConfig = {
onDotnetReady?: () => void;
imports?: DotnetModuleConfigImports;
exports?: string[];
} & Partial<EmscriptenModule>
export type DotnetModuleConfigImports = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册