Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/mono/wasm/runtime/cjs/dotnet.cjs.extpost.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ var require = require || undefined;
let ENVIRONMENT_IS_GLOBAL = typeof globalThis.Module === "object" && globalThis.__dotnet_runtime === __dotnet_runtime;
if (ENVIRONMENT_IS_GLOBAL) {
createDotnetRuntime(() => { return globalThis.Module; }).then((exports) => exports);
}
else if (typeof globalThis.__onDotnetRuntimeLoaded === "function") {
globalThis.__onDotnetRuntimeLoaded(createDotnetRuntime);
}
22 changes: 18 additions & 4 deletions src/mono/wasm/test-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,24 @@ async function loadDotnet(file) {
return require(file);
};
} else if (is_browser) { // vanila JS in browser
loadScript = async function (file) {
globalThis.exports = {}; // if we are loading cjs file
const createDotnetRuntime = await import(file);
return typeof createDotnetRuntime === "function" ? createDotnetRuntime : globalThis.exports.createDotnetRuntime;
loadScript = function (file) {
var loaded = new Promise((resolve, reject) => {
try {
globalThis.__onDotnetRuntimeLoaded = (createDotnetRuntime) => {
// this is callback we have in CJS version of the runtime
resolve(createDotnetRuntime);
};
import(file).then(({ default: createDotnetRuntime }) => {
// this would work with ES6 default export
if (createDotnetRuntime) {
resolve(createDotnetRuntime);
}
});
} catch (err) {
reject(err);
}
});
return loaded;
}
}
else if (typeof globalThis.load !== 'undefined') {
Expand Down