Skip to content

Commit

Permalink
Modified runtime to get the path starting from dotnet.js in shell env…
Browse files Browse the repository at this point in the history
…ironment and use that path in test
  • Loading branch information
yamachu committed Jun 27, 2022
1 parent 3e2476c commit f41fd42
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/mono/wasm/runtime/es6/dotnet.es6.lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ if (ENVIRONMENT_IS_NODE) {
return getBinary(wasmBinaryFile);
}
}
if (ENVIRONMENT_IS_SHELL) {
scriptDirectory = import.meta.url.slice(0, import.meta.url.lastIndexOf('/')) + '/';
}
let __dotnet_exportedAPI = __dotnet_runtime.__initializeImportsAndExports(
{ isESM:true, isGlobal:false, isNode:ENVIRONMENT_IS_NODE, isWorker:ENVIRONMENT_IS_WORKER, isShell:ENVIRONMENT_IS_SHELL, isWeb:ENVIRONMENT_IS_WEB, locateFile, quit_, ExitStatus, requirePromise:__dotnet_replacements.requirePromise },
{ mono:MONO, binding:BINDING, internal:INTERNAL, module:Module },
Expand Down
14 changes: 13 additions & 1 deletion src/mono/wasm/test-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//glue code to deal with the differences between chrome, ch, d8, jsc and sm.
const is_browser = typeof window != "undefined";
const is_node = !is_browser && typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string';
const is_shell = !is_browser && !is_node;

if (is_node && process.versions.node.split(".")[0] < 14) {
throw new Error(`NodeJS at '${process.execPath}' has too low version '${process.versions.node}'`);
Expand Down Expand Up @@ -345,6 +346,14 @@ if (typeof globalThis.crypto === 'undefined') {
}

let toAbsoluteUrl = function (path, prefix) {
if (is_shell) {
// **NOTE** when loading dotnet.wasm,
// it returns a test dependent relative path because scriptDirectory(prefix) is an empty string.
if (prefix === "" && runArgs.deepWorkDir) {
return "./AppBundle/" + path;
}
return prefix + path;
}
if (prefix.startsWith("/")) {
return path;
}
Expand Down Expand Up @@ -396,7 +405,10 @@ Promise.all([argsPromise, loadDotnetPromise]).then(async ([_, createDotnetRuntim
disableDotnet6Compatibility: true,
config: null,
configSrc: "./mono-config.json",
locateFile: toAbsoluteUrl,
// URL class is undefined on V8(is_shell)
// To bypass assigning wasmBinaryFile variable in https://github.com/emscripten-core/emscripten/blob/4b5c4f0694174e081661944ab3ffdb43dd1949b8/src/preamble.js#L792-L793 ,
// pass implementation of locateFile
locateFile: is_browser || is_shell ? toAbsoluteUrl : undefined,
onConfigLoaded: (config) => {
if (!Module.config) {
const err = new Error("Could not find ./mono-config.json. Cancelling run");
Expand Down

0 comments on commit f41fd42

Please sign in to comment.