},
};
</script>
- <script type="text/javascript" src="mono-config.js"></script>
<script type="text/javascript" src="runtime.js"></script>
<script defer src="dotnet.js"></script>
// The .NET Foundation licenses this file to you under the MIT license.
var Module = {
+ config: null,
+
+ preInit: async function() {
+ Module.config = await MONO.mono_wasm_load_config("./mono-config.json");
+ },
+
+ // Called when the runtime is initialized and wasm is ready
onRuntimeInitialized: function () {
- config.loaded_cb = function () {
+ if (!Module.config || Module.config.error) {
+ console.log("An error occured while loading the config file");
+ return;
+ }
+
+ Module.config.loaded_cb = function () {
App.init ();
};
- config.environment_variables = {
+ Module.config.environment_variables = {
"DOTNET_MODIFIABLE_ASSEMBLIES": "debug"
};
- config.fetch_file_cb = function (asset) {
+ Module.config.fetch_file_cb = function (asset) {
return fetch (asset, { credentials: 'same-origin' });
}
- MONO.mono_load_runtime_and_bcl_args (config);
+ MONO.mono_load_runtime_and_bcl_args (Module.config);
},
};
}
};
</script>
- <script type="text/javascript" src="mono-config.js"></script>
<script type="text/javascript" src="runtime.js"></script>
<script defer src="dotnet.js"></script>
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-
var Module = {
+ config: null,
+
+ preInit: async function() {
+ Module.config = await MONO.mono_wasm_load_config("./mono-config.json");
+ },
+
+ // Called when the runtime is initialized and wasm is ready
onRuntimeInitialized: function () {
- config.loaded_cb = function () {
+ if (!Module.config || Module.config.error) {
+ console.log("An error occured while loading the config file");
+ return;
+ }
+
+ Module.config.loaded_cb = function () {
try {
App.init ();
} catch (error) {
throw (error);
}
};
- config.fetch_file_cb = function (asset) {
+ Module.config.fetch_file_cb = function (asset) {
return fetch (asset, { credentials: 'same-origin' });
}
+ if (Module.config.enable_profiler)
+ {
+ Module.config.aot_profiler_options = {
+ write_at:"Sample.Test::StopProfile",
+ send_to: "System.Runtime.InteropServices.JavaScript.Runtime::DumpAotProfileData"
+ }
+ }
+
try
{
- MONO.mono_load_runtime_and_bcl_args (config);
+ MONO.mono_load_runtime_and_bcl_args (Module.config);
} catch (error) {
test_exit(1);
throw(error);
<body>
<h3 id="header">Wasm Browser Sample</h3>
Result from Sample.Test.TestMeaning: <span id="out"></span>
- <script type='text/javascript'>
- var is_testing = false;
- var onLoad = function() {
- var url = new URL(decodeURI(window.location));
- let args = url.searchParams.getAll('arg');
- is_testing = args !== undefined && (args.find(arg => arg == '--testing') !== undefined);
- };
- var test_exit = function(exit_code)
- {
- if (!is_testing) {
- console.log(`test_exit: ${exit_code}`);
- return;
- }
-
- /* Set result in a tests_done element, to be read by xharness */
- var tests_done_elem = document.createElement("label");
- tests_done_elem.id = "tests_done";
- tests_done_elem.innerHTML = exit_code.toString();
- document.body.appendChild(tests_done_elem);
-
- console.log(`WASM EXIT ${exit_code}`);
- };
-
- var App = {
- init: function () {
- var ret = BINDING.call_static_method("[Wasm.BrowserProfile.Sample] Sample.Test:TestMeaning", []);
- document.getElementById("out").innerHTML = ret;
- console.log ("ready");
-
- if (is_testing)
- {
- console.debug(`ret: ${ret}`);
- let exit_code = ret == 42 ? 0 : 1;
- test_exit(exit_code);
- }
-
- if (config.enable_profiler) {
- BINDING.call_static_method("[Wasm.BrowserProfile.Sample] Sample.Test:StopProfile", []);
- saveProfile();
- }
- },
- };
-
- function saveProfile() {
- var a = document.createElement('a');
- var blob = new Blob([Module.aot_profile_data]);
- a.href = URL.createObjectURL(blob);
- a.download = "data.aotprofile";
- // Append anchor to body.
- document.body.appendChild(a);
- a.click();
-
- // Remove anchor from body
- document.body.removeChild(a);
- }
-
- </script>
- <script type="text/javascript" src="mono-config.js"></script>
<script type="text/javascript" src="runtime.js"></script>
-
<script defer src="dotnet.js"></script>
</body>
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-var Module = {
+var Module = {
+ is_testing: false,
+ config: null,
+
+ preInit: async function() {
+ Module.config = await MONO.mono_wasm_load_config("./mono-config.json");
+ },
+
+ // Called when the runtime is initialized and wasm is ready
onRuntimeInitialized: function () {
- config.loaded_cb = function () {
+ if (!Module.config || Module.config.error) {
+ console.log("An error occured while loading the config file");
+ return;
+ }
+
+ Module.config.loaded_cb = function () {
try {
- App.init ();
+ Module.init();
} catch (error) {
- test_exit(1);
+ Module.test_exit(1);
throw (error);
}
};
- config.fetch_file_cb = function (asset) {
+ Module.config.fetch_file_cb = function (asset) {
return fetch (asset, { credentials: 'same-origin' });
}
- if (config.enable_profiler)
+ if (Module.config.enable_profiler)
{
- config.aot_profiler_options = {
+ Module.config.aot_profiler_options = {
write_at:"Sample.Test::StopProfile",
send_to: "System.Runtime.InteropServices.JavaScript.Runtime::DumpAotProfileData"
}
try
{
- MONO.mono_load_runtime_and_bcl_args (config);
+ MONO.mono_load_runtime_and_bcl_args (Module.config);
} catch (error) {
- test_exit(1);
+ Module.test_exit(1);
throw(error);
}
+ },
+
+ init: function () {
+ console.log("not ready yet")
+ var ret = BINDING.call_static_method("[Wasm.BrowserProfile.Sample] Sample.Test:TestMeaning", []);
+ document.getElementById("out").innerHTML = ret;
+ console.log ("ready");
+
+ if (Module.is_testing)
+ {
+ console.debug(`ret: ${ret}`);
+ let exit_code = ret == 42 ? 0 : 1;
+ Module.test_exit(exit_code);
+ }
+
+ if (Module.config.enable_profiler) {
+ BINDING.call_static_method("[Wasm.BrowserProfile.Sample] Sample.Test:StopProfile", []);
+ Module.saveProfile();
+ }
+ },
+
+ onLoad: function() {
+ var url = new URL(decodeURI(window.location));
+ let args = url.searchParams.getAll('arg');
+ Module.is_testing = args !== undefined && (args.find(arg => arg == '--testing') !== undefined);
+ },
+
+ test_exit: function(exit_code) {
+ if (!Module.is_testing) {
+ console.log(`test_exit: ${exit_code}`);
+ return;
+ }
+
+ /* Set result in a tests_done element, to be read by xharness */
+ var tests_done_elem = document.createElement("label");
+ tests_done_elem.id = "tests_done";
+ tests_done_elem.innerHTML = exit_code.toString();
+ document.body.appendChild(tests_done_elem);
+
+ console.log(`WASM EXIT ${exit_code}`);
+ },
+
+ saveProfile: function () {
+ var a = document.createElement('a');
+ var blob = new Blob([Module.aot_profile_data]);
+ a.href = URL.createObjectURL(blob);
+ a.download = "data.aotprofile";
+ // Append anchor to body.
+ document.body.appendChild(a);
+ a.click();
+
+ // Remove anchor from body
+ document.body.removeChild(a);
}
-};
\ No newline at end of file
+};
},
};
</script>
- <script type="text/javascript" src="mono-config.js"></script>
<script type="text/javascript" src="runtime.js"></script>
<script defer src="dotnet.js"></script>
// The .NET Foundation licenses this file to you under the MIT license.
var Module = {
+
+ config: null,
+
+ preInit: async function() {
+ Module.config = await MONO.mono_wasm_load_config("./mono-config.json");
+ },
+
+ // Called when the runtime is initialized and wasm is ready
onRuntimeInitialized: function () {
- config.loaded_cb = function () {
+ if (!Module.config || Module.config.error) {
+ console.log("No config found");
+ return;
+ }
+
+ Module.config.loaded_cb = function () {
try {
App.init ();
} catch (error) {
throw (error);
}
};
- config.fetch_file_cb = function (asset) {
+ Module.config.fetch_file_cb = function (asset) {
return fetch (asset, { credentials: 'same-origin' });
}
try
{
- MONO.mono_load_runtime_and_bcl_args (config);
+ MONO.mono_load_runtime_and_bcl_args (Module.config);
} catch (error) {
test_exit(1);
throw(error);
- @(WasmFilesToIncludeInFileSystem) - Files to include in the vfs
- @(WasmNativeAsset) - Native files to be added to `NativeAssets` in the bundle.
- - @(WasmExtraConfig) - json elements to add to `mono-config.js`
+ - @(WasmExtraConfig) - json elements to add to `mono-config.json`
Eg. <WasmExtraConfig Include="enable_profiler" Value="true" />
- Value attribute can have a number, bool, quoted string, or json string
return App.int_add (a, b);
}
</script>
- <script type="text/javascript" src="mono-config.js"></script>
<script type="text/javascript" src="runtime-debugger.js"></script>
<script type="text/javascript" src="other.js"></script>
<script async type="text/javascript" src="dotnet.js"></script>
// The .NET Foundation licenses this file to you under the MIT license.
var Module = {
- onRuntimeInitialized: function () {
- config.loaded_cb = function () {
+ config: null,
+
+ preInit: async function() {
+ Module.config = await MONO.mono_wasm_load_config("./mono-config.json");
+ },
+
+ // Called when the runtime is initialized and wasm is ready
+ onRuntimeInitialized: function () {
+ if (!Module.config || Module.config.error) {
+ console.log("An error occured while loading the config file");
+ return;
+ }
+
+ Module.config.loaded_cb = function () {
App.init ();
};
// For custom logging patch the functions below
MONO.mono_wasm_setenv ("MONO_LOG_LEVEL", "debug");
MONO.mono_wasm_setenv ("MONO_LOG_MASK", "all");
*/
- MONO.mono_load_runtime_and_bcl_args (config)
+ MONO.mono_load_runtime_and_bcl_args (Module.config)
},
};
}
}
-loadScript ("mono-config.js");
-
var Module = {
mainScriptUrlOrBlob: "dotnet.js",
-
+ config: null,
print,
printErr,
+ preInit: async function() {
+ Module.config = await MONO.mono_wasm_load_config("./mono-config.json");
+ },
+
onAbort: function(x) {
print ("ABORT: " + x);
var err = new Error();
Module.ccall ('mono_wasm_enable_on_demand_gc', 'void', ['number'], [0]);
}
- config.loaded_cb = function () {
+ Module.config.loaded_cb = function () {
let wds = FS.stat (working_dir);
if (wds === undefined || !FS.isDir (wds.mode)) {
fail_exec (`Could not find working directory ${working_dir}`);
FS.chdir (working_dir);
App.init ();
};
- config.fetch_file_cb = function (asset) {
+ Module.config.fetch_file_cb = function (asset) {
// console.log("fetch_file_cb('" + asset + "')");
// for testing purposes add BCL assets to VFS until we special case File.Open
// to identify when an assembly from the BCL is being open and resolve it correctly.
/*
var content = new Uint8Array (read (asset, 'binary'));
- var path = asset.substr(config.deploy_prefix.length);
+ var path = asset.substr(Module.config.deploy_prefix.length);
writeContentToFile(content, path);
*/
}
};
- MONO.mono_load_runtime_and_bcl_args (config);
+ MONO.mono_load_runtime_and_bcl_args (Module.config);
},
};
-
loadScript ("dotnet.js");
const IGNORE_PARAM_COUNT = -1;
module ["mono_wasm_new_root"] = MONO.mono_wasm_new_root.bind(MONO);
module ["mono_wasm_new_roots"] = MONO.mono_wasm_new_roots.bind(MONO);
module ["mono_wasm_release_roots"] = MONO.mono_wasm_release_roots.bind(MONO);
+ module ["mono_wasm_load_config"] = MONO.mono_wasm_load_config.bind(MONO);
},
_base64Converter: {
console.debug('mono_wasm_debug_event_raised:aef14bca-5519-4dfe-b35a-f867abc123ae', JSON.stringify(event), JSON.stringify(args));
},
+
+ /**
+ * Loads the mono config file (typically called mono-config.json)
+ *
+ * @param {string} configFilePath - relative path to the config file
+ * @throws Will throw an error if the config file loading fails
+ */
+ mono_wasm_load_config: async function (configFilePath) {
+ try {
+ let config = null;
+ // NOTE: when we add nodejs make sure to include the nodejs fetch package
+ if (ENVIRONMENT_IS_WEB) {
+ const configRaw = await fetch(configFilePath);
+ config = await configRaw.json();
+ }else if (ENVIRONMENT_IS_NODE) {
+ config = require(configFilePath);
+ } else { // shell or worker
+ config = JSON.parse(read(configFilePath)); // read is a v8 debugger command
+ }
+ return config;
+ } catch(e) {
+ return {message: "failed to load config file", error: e};
+ }
+ }
},
mono_wasm_add_typed_value: function (type, str_value, value) {
assembly_b64,
pdb_b64
});
- },
+ }
};
autoAddDeps(MonoSupportLib, '$MONO')
public ITaskItem[]? ExtraFilesToDeploy { get; set; }
// <summary>
- // Extra json elements to add to mono-config.js
+ // Extra json elements to add to mono-config.json
//
// Metadata:
// - Value: can be a number, bool, quoted string, or json string
config.Extra[name] = valueObject;
}
- string monoConfigPath = Path.Combine(AppDir, "mono-config.js");
+ string monoConfigPath = Path.Combine(AppDir, "mono-config.json");
using (var sw = File.CreateText(monoConfigPath))
{
var json = JsonSerializer.Serialize (config, new JsonSerializerOptions { WriteIndented = true });
- sw.Write($"config = {json};");
+ sw.Write(json);
}
_fileWrites.Add(monoConfigPath);
"runtime.js",
"dotnet.timezones.blat",
"dotnet.wasm",
- "mono-config.js",
+ "mono-config.json",
"dotnet.js",
"run-v8.sh"
});
},
};
</script>
- <script type="text/javascript" src="mono-config.js"></script>
<script type="text/javascript" src="runtime.js"></script>
<script defer src="dotnet.js"></script>
// The .NET Foundation licenses this file to you under the MIT license.
var Module = {
+
+ config: null,
+
+ preInit: async function() {
+ Module.config = await MONO.mono_wasm_load_config("./mono-config.json");
+ },
+
onRuntimeInitialized: function () {
- config.loaded_cb = function () {
+ if (!Module.config || Module.config.error) {
+ console.log("No config found");
+ test_exit(1);
+ throw(Module.config.error);
+ }
+
+ Module.config.loaded_cb = function () {
try {
App.init ();
} catch (error) {
throw (error);
}
};
- config.fetch_file_cb = function (asset) {
+ Module.config.fetch_file_cb = function (asset) {
return fetch (asset, { credentials: 'same-origin' });
}
try
{
- MONO.mono_load_runtime_and_bcl_args (config);
+ MONO.mono_load_runtime_and_bcl_args (Module.config);
} catch (error) {
test_exit(1);
throw(error);
},
};
</script>
- <script type="text/javascript" src="mono-config.js"></script>
<script type="text/javascript" src="runtime.js"></script>
<script defer src="dotnet.js"></script>
// The .NET Foundation licenses this file to you under the MIT license.
var Module = {
+
+ config: null,
+
+ preInit: async function() {
+ Module.config = await MONO.mono_wasm_load_config("./mono-config.json");
+ },
+
onRuntimeInitialized: function () {
- config.loaded_cb = function () {
+ if (!Module.config || Module.config.error) {
+ console.log("No config found");
+ test_exit(1);
+ throw(Module.config.error);
+ }
+
+ Module.config.loaded_cb = function () {
try {
App.init ();
} catch (error) {
throw (error);
}
};
- config.fetch_file_cb = function (asset) {
+ Module.config.fetch_file_cb = function (asset) {
return fetch (asset, { credentials: 'same-origin' });
}
try
{
- MONO.mono_load_runtime_and_bcl_args (config);
+ MONO.mono_load_runtime_and_bcl_args (Module.config);
} catch (error) {
test_exit(1);
throw(error);