Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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);
}
21 changes: 15 additions & 6 deletions src/mono/wasm/test-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ loadDotnet("./dotnet.js").then((createDotnetRuntime) => {
}))
}).catch(function (err) {
console.error(err);
set_exit_code(1, "failed to load the dotnet.js file");
throw err;
set_exit_code(1, "failed to load the dotnet.js file.\n" + err);
});

const App = {
Expand Down Expand Up @@ -361,10 +360,20 @@ 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) => {
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);
}
}, reject);
});
return loaded;
}
}
else if (typeof globalThis.load !== 'undefined') {
Expand Down