From bc238a78dc66b12cdd89572d6c1d3528e80dca72 Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Tue, 1 Jun 2021 18:19:15 -0400 Subject: [PATCH 01/19] converted mono-config.js to mono-config.json --- .../Directory.Build.props | 1 + src/mono/sample/mbr/browser/index.html | 1 - src/mono/sample/mbr/browser/runtime.js | 27 +++++- src/mono/sample/wasm/browser-bench/index.html | 1 - src/mono/sample/wasm/browser-bench/runtime.js | 34 ++++++- .../sample/wasm/browser-profile/index.html | 59 ------------ .../sample/wasm/browser-profile/runtime.js | 93 +++++++++++++++++-- src/mono/sample/wasm/browser/index.html | 1 - src/mono/sample/wasm/browser/runtime.js | 26 +++++- src/mono/wasm/Makefile | 6 +- src/mono/wasm/build/WasmApp.targets | 2 +- .../tests/debugger-test/debugger-driver.html | 1 - .../tests/debugger-test/runtime-debugger.js | 25 ++++- src/mono/wasm/runtime-test.js | 28 ++++-- src/mono/wasm/runtime/js_support.js | 57 ++++++++++++ src/mono/wasm/wasm.proj | 2 +- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 6 +- .../Wasm.Build.Tests/BuildTestBase.cs | 2 +- .../WebAssembly/Browser/AOT/index.html | 1 - .../WebAssembly/Browser/AOT/runtime.js | 20 +++- .../Browser/NormalInterp/index.html | 1 - .../Browser/NormalInterp/runtime.js | 20 +++- 22 files changed, 302 insertions(+), 112 deletions(-) create mode 100644 src/mono/wasm/runtime/js_support.js diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index 834fa2bac988d6..4f2be71a46fd09 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -212,6 +212,7 @@ + diff --git a/src/mono/sample/mbr/browser/index.html b/src/mono/sample/mbr/browser/index.html index 472cf5f29ea053..eb19b7bb2f5954 100644 --- a/src/mono/sample/mbr/browser/index.html +++ b/src/mono/sample/mbr/browser/index.html @@ -29,7 +29,6 @@ }, }; - diff --git a/src/mono/sample/mbr/browser/runtime.js b/src/mono/sample/mbr/browser/runtime.js index 0856b8d0e03033..3a63c214f2ff65 100644 --- a/src/mono/sample/mbr/browser/runtime.js +++ b/src/mono/sample/mbr/browser/runtime.js @@ -2,17 +2,36 @@ // The .NET Foundation licenses this file to you under the MIT license. var Module = { + config: null, + + // Called once the config file is loaded. The contents of the config file + // are passed as a JS object within the config parameter + onConfigLoaded: function (config) { + if (!config || config.error){ + console.log("An error occured while loading the config file"); + return; + } + + Module.config = config; + }, + + // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { - config.loaded_cb = function () { + if (!Module.config || Module.config.error){ + alert("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); }, }; diff --git a/src/mono/sample/wasm/browser-bench/index.html b/src/mono/sample/wasm/browser-bench/index.html index eebbae65eb1052..658bfb573ddbfc 100644 --- a/src/mono/sample/wasm/browser-bench/index.html +++ b/src/mono/sample/wasm/browser-bench/index.html @@ -51,7 +51,6 @@ } }; - diff --git a/src/mono/sample/wasm/browser-bench/runtime.js b/src/mono/sample/wasm/browser-bench/runtime.js index a39b0b97b14901..cbebc617ba82d7 100644 --- a/src/mono/sample/wasm/browser-bench/runtime.js +++ b/src/mono/sample/wasm/browser-bench/runtime.js @@ -1,9 +1,27 @@ // 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, + + // Called once the config file is loaded. The contents of the config file + // are passed as a JS object within the config parameter + onConfigLoaded: function (config) { + if (!config || config.error){ + console.log("An error occured while loading the config file"); + return; + } + + Module.config = config; + }, + + // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { - config.loaded_cb = function () { + if (!Module.config || Module.config.error){ + alert("An error occured while loading the config file"); + return; + } + + Module.config.loaded_cb = function () { try { App.init (); } catch (error) { @@ -11,13 +29,21 @@ var Module = { 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); diff --git a/src/mono/sample/wasm/browser-profile/index.html b/src/mono/sample/wasm/browser-profile/index.html index 50eb0ff28c2efe..de4a5599e94ad0 100644 --- a/src/mono/sample/wasm/browser-profile/index.html +++ b/src/mono/sample/wasm/browser-profile/index.html @@ -10,67 +10,8 @@ Result from Sample.Test.TestMeaning: - - - diff --git a/src/mono/sample/wasm/browser-profile/runtime.js b/src/mono/sample/wasm/browser-profile/runtime.js index 1ce1c0b736034c..e385167eaec223 100644 --- a/src/mono/sample/wasm/browser-profile/runtime.js +++ b/src/mono/sample/wasm/browser-profile/runtime.js @@ -1,22 +1,42 @@ // 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, + + // Called once the config file is loaded. The contents of the config file + // are passed as a JS object within the config parameter + onConfigLoaded: function (config) { + if (!config || config.error){ + console.log("An error occured while loading the config file"); + return; + } + + Module.config = config; + }, + + // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { - config.loaded_cb = function () { + if (!Module.config || Module.config.error){ + alert("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" } @@ -24,10 +44,63 @@ var Module = { 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 +}; diff --git a/src/mono/sample/wasm/browser/index.html b/src/mono/sample/wasm/browser/index.html index bd8e5015a0ee5f..5f170bb38e7bcb 100644 --- a/src/mono/sample/wasm/browser/index.html +++ b/src/mono/sample/wasm/browser/index.html @@ -48,7 +48,6 @@ }, }; - diff --git a/src/mono/sample/wasm/browser/runtime.js b/src/mono/sample/wasm/browser/runtime.js index a39b0b97b14901..0a99c174a01f62 100644 --- a/src/mono/sample/wasm/browser/runtime.js +++ b/src/mono/sample/wasm/browser/runtime.js @@ -2,8 +2,28 @@ // The .NET Foundation licenses this file to you under the MIT license. var Module = { + + config: null, + + // Called once the config file is loaded. The contents of the config file + // are passed as a JS object within the config parameter + onConfigLoaded: function (config) { + if (!config || config.error){ + console.log("An error occured while loading the config file"); + return; + } + + Module.config = config; + }, + + // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { - config.loaded_cb = function () { + if (!Module.config || Module.config.error){ + alert("No config found"); + return; + } + + Module.config.loaded_cb = function () { try { App.init (); } catch (error) { @@ -11,13 +31,13 @@ var Module = { 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); diff --git a/src/mono/wasm/Makefile b/src/mono/wasm/Makefile index 8a69822976bfe4..95bb1c170f6ed0 100644 --- a/src/mono/wasm/Makefile +++ b/src/mono/wasm/Makefile @@ -92,8 +92,8 @@ $(NATIVE_BIN_DIR)/include/wasm: $(BUILDS_OBJ_DIR): mkdir -p $$@ -$(NATIVE_BIN_DIR)/dotnet.js: $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o runtime/library_mono.js runtime/binding_support.js runtime/dotnet_support.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js $(2) $(EMCC_DEFAULT_RSP) | $(NATIVE_BIN_DIR) - $(EMCC) @$(EMCC_DEFAULT_RSP) $(1) --js-library runtime/library_mono.js --js-library runtime/binding_support.js --js-library runtime/dotnet_support.js --js-library $(SYSTEM_NATIVE_LIBDIR)/pal_random.js $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o $(2) -o $(NATIVE_BIN_DIR)/dotnet.js $(3) +$(NATIVE_BIN_DIR)/dotnet.js: $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o runtime/library_mono.js runtime/binding_support.js runtime/dotnet_support.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js runtime/js_support.js $(2) $(EMCC_DEFAULT_RSP) | $(NATIVE_BIN_DIR) + $(EMCC) @$(EMCC_DEFAULT_RSP) $(1) --js-library runtime/library_mono.js --js-library runtime/binding_support.js --js-library runtime/dotnet_support.js --js-library $(SYSTEM_NATIVE_LIBDIR)/pal_random.js --pre-js runtime/js_support.js $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o $(2) -o $(NATIVE_BIN_DIR)/dotnet.js $(3) $(BUILDS_OBJ_DIR)/pinvoke-table.h: $(PINVOKE_TABLE) | $(BUILDS_OBJ_DIR) if cmp -s $(PINVOKE_TABLE) $$@ ; then : ; else cp $(PINVOKE_TABLE) $$@ ; fi @@ -132,7 +132,7 @@ clean: icu-files: $(wildcard $(ICU_LIBDIR)/*.dat) $(ICU_LIBDIR)/libicuuc.a $(ICU_LIBDIR)/libicui18n.a | $(NATIVE_BIN_DIR) cp $^ $(NATIVE_BIN_DIR) -source-files: runtime/driver.c runtime/pinvoke.c runtime/corebindings.c runtime/binding_support.js runtime/dotnet_support.js runtime/library_mono.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js | $(NATIVE_BIN_DIR)/src +source-files: runtime/driver.c runtime/pinvoke.c runtime/corebindings.c runtime/binding_support.js runtime/dotnet_support.js runtime/library_mono.js runtime/js_support.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js | $(NATIVE_BIN_DIR)/src cp $^ $(NATIVE_BIN_DIR)/src header-files: runtime/pinvoke.h | $(NATIVE_BIN_DIR)/include/wasm diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 2141cce41b69b2..b886f327d71626 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -65,7 +65,7 @@ - @(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. - Value attribute can have a number, bool, quoted string, or json string diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html b/src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html index 87ba804792ef39..b1bfcd859d0644 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html @@ -83,7 +83,6 @@ return App.int_add (a, b); } - diff --git a/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js b/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js index 4c641eb2c6a0d7..da8da61bd92fd3 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js +++ b/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js @@ -2,8 +2,27 @@ // The .NET Foundation licenses this file to you under the MIT license. var Module = { - onRuntimeInitialized: function () { - config.loaded_cb = function () { + config: null, + + // Called once the config file is loaded. The contents of the config file + // are passed as a JS object within the config parameter + onConfigLoaded: function (config) { + if (!config || config.error){ + console.log("An error occured while loading the config file"); + return; + } + + Module.config = config; + }, + + // 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 @@ -15,6 +34,6 @@ var Module = { 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) }, }; diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index 74aa1083c033d1..98a1470a0f9ef3 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -204,11 +204,10 @@ function loadScript (url) } } -loadScript ("mono-config.js"); - var Module = { mainScriptUrlOrBlob: "dotnet.js", + config: null, print, printErr, @@ -220,6 +219,21 @@ var Module = { test_exit (1); }, + onConfigLoaded: function (config) { + if (!config || config.error){ + console.log("An error occured while loading the config file"); + return; + } + + Module.config = config; + + if (is_node) { + eval (read ("dotnet.js").toString()); + } else { + loadScript ("dotnet.js"); + } + }, + onRuntimeInitialized: function () { // Have to set env vars here to enable setting MONO_LOG_LEVEL etc. for (var variable in setenv) { @@ -230,7 +244,7 @@ var Module = { 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}`); @@ -240,13 +254,13 @@ var Module = { 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); */ @@ -280,12 +294,10 @@ var Module = { } }; - 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; var App = { diff --git a/src/mono/wasm/runtime/js_support.js b/src/mono/wasm/runtime/js_support.js new file mode 100644 index 00000000000000..404084cd183910 --- /dev/null +++ b/src/mono/wasm/runtime/js_support.js @@ -0,0 +1,57 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// Loads the config file located in the root of the project +// Not meant to be used outside of this class (TODO make private to this file when project converted to TS) +function load_config() { + // since this file loads before emsdk we don't have environment vars yet, so we define them locally + var ENVIRONMENT_IS_NODE = typeof process === 'object'; + var ENVIRONMENT_IS_WEB = typeof window === 'object'; + // var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function'; + // var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER; + + callback = Module['onConfigLoaded']; + + if (ENVIRONMENT_IS_NODE){ + try { + var config = JSON.parse(require('./mono-config.json')); + callback(config); + } catch(e) { + callback({error: "Error loading mono-config.json file from current directory"}); + } + } else if (ENVIRONMENT_IS_WEB){ + var xobj = new XMLHttpRequest(); + xobj.overrideMimeType("application/json"); + xobj.open('GET', './mono-config.json', true); + xobj.onreadystatechange = function() { + if (xobj.readyState == XMLHttpRequest.DONE) { + if (xobj.status === 0 || (xobj.status >= 200 && xobj.status < 400)) { + var config = JSON.parse(xobj.responseText); + callback(config); + } else { + // error if the request to load the file was successful but loading failed + callback({error: "Error loading mono-config.json file from current directory"}); + } + } + }; + xobj.onerror = function() { + // error if the request failed + callback({error: "Error loading mono-config.json file from current directory"}); + } + + try { + xobj.send(); + } catch(e) { + // other kinds of errors + callback({error: "Error loading mono-config.json file from current directory"}); + } + } else { + try { + var config = JSON.parse(load("./mono-config.json")); + callback(config); + } catch(e) { + callback({error: "Error loading mono-config.json file from current directory"}); + } + } +} +load_config(); diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index 562091ed6a26d8..4f87ecdd931ab4 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -227,7 +227,7 @@ EmSdkPath="$(EMSDK_PATH)" IgnoreStandardErrorWarningFormat="true" /> - diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 9ef7679c292b66..49d984490a64b2 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -51,7 +51,7 @@ public class WasmAppBuilder : Task public ITaskItem[]? ExtraFilesToDeploy { get; set; } // - // 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 @@ -246,11 +246,11 @@ public override bool Execute () 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); diff --git a/src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs b/src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs index b5f1f7e0b95f73..99e721dfa65f78 100644 --- a/src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs @@ -347,7 +347,7 @@ protected static void AssertBasicAppBundle(string bundleDir, string projectName, "runtime.js", "dotnet.timezones.blat", "dotnet.wasm", - "mono-config.js", + "mono-config.json", "dotnet.js", "run-v8.sh" }); diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/index.html b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/index.html index efab9ac4324a21..642987d23c5e2b 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/index.html +++ b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/index.html @@ -47,7 +47,6 @@ }, }; - diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js index a39b0b97b14901..50858fc439a109 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js @@ -2,8 +2,22 @@ // The .NET Foundation licenses this file to you under the MIT license. var Module = { + + config: null, + + // Called once the config file is loaded. The contents of the config file + // are passed as a JS object within the config parameter + onConfigLoaded: function (config) { + if (!config || config.error){ + console.log("An error occured while loading the config file"); + return; + } + + Module.config = config; + }, + onRuntimeInitialized: function () { - config.loaded_cb = function () { + Module.config.loaded_cb = function () { try { App.init (); } catch (error) { @@ -11,13 +25,13 @@ var Module = { 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); diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/index.html b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/index.html index 03f68679a5b85c..9de05f5031b325 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/index.html +++ b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/index.html @@ -47,7 +47,6 @@ }, }; - diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js index a39b0b97b14901..50858fc439a109 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js @@ -2,8 +2,22 @@ // The .NET Foundation licenses this file to you under the MIT license. var Module = { + + config: null, + + // Called once the config file is loaded. The contents of the config file + // are passed as a JS object within the config parameter + onConfigLoaded: function (config) { + if (!config || config.error){ + console.log("An error occured while loading the config file"); + return; + } + + Module.config = config; + }, + onRuntimeInitialized: function () { - config.loaded_cb = function () { + Module.config.loaded_cb = function () { try { App.init (); } catch (error) { @@ -11,13 +25,13 @@ var Module = { 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); From 9698a93ec7d0f7758be00ae38863cc0e9dee3085 Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Wed, 2 Jun 2021 14:26:09 -0400 Subject: [PATCH 02/19] Fixed test --- src/mono/wasm/runtime/js_support.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/runtime/js_support.js b/src/mono/wasm/runtime/js_support.js index 404084cd183910..0d62cf9dabafab 100644 --- a/src/mono/wasm/runtime/js_support.js +++ b/src/mono/wasm/runtime/js_support.js @@ -7,10 +7,10 @@ function load_config() { // since this file loads before emsdk we don't have environment vars yet, so we define them locally var ENVIRONMENT_IS_NODE = typeof process === 'object'; var ENVIRONMENT_IS_WEB = typeof window === 'object'; - // var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function'; - // var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER; - callback = Module['onConfigLoaded']; + // In some cases there may be no Module object (such as in tests) + // so we no-op during the callback + let callback = Module ? Module['onConfigLoaded'] : (_) => {}; if (ENVIRONMENT_IS_NODE){ try { From b5ea3c3151b573a3b39c0d1432a5dd730e5625fb Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Wed, 2 Jun 2021 16:22:18 -0400 Subject: [PATCH 03/19] fixed handling of case where Module isn't defined --- src/mono/wasm/runtime/js_support.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mono/wasm/runtime/js_support.js b/src/mono/wasm/runtime/js_support.js index 0d62cf9dabafab..1c434a77aadf67 100644 --- a/src/mono/wasm/runtime/js_support.js +++ b/src/mono/wasm/runtime/js_support.js @@ -5,16 +5,16 @@ // Not meant to be used outside of this class (TODO make private to this file when project converted to TS) function load_config() { // since this file loads before emsdk we don't have environment vars yet, so we define them locally - var ENVIRONMENT_IS_NODE = typeof process === 'object'; - var ENVIRONMENT_IS_WEB = typeof window === 'object'; + var ENVIRONMENT_IS_NODE = typeof process === "object"; + var ENVIRONMENT_IS_WEB = typeof window === "object"; // In some cases there may be no Module object (such as in tests) // so we no-op during the callback - let callback = Module ? Module['onConfigLoaded'] : (_) => {}; + let callback = typeof Module !== "undefined" ? Module['onConfigLoaded'] : (_) => {}; if (ENVIRONMENT_IS_NODE){ try { - var config = JSON.parse(require('./mono-config.json')); + var config = JSON.parse(require("./mono-config.json")); callback(config); } catch(e) { callback({error: "Error loading mono-config.json file from current directory"}); @@ -22,7 +22,7 @@ function load_config() { } else if (ENVIRONMENT_IS_WEB){ var xobj = new XMLHttpRequest(); xobj.overrideMimeType("application/json"); - xobj.open('GET', './mono-config.json', true); + xobj.open("GET", "./mono-config.json", true); xobj.onreadystatechange = function() { if (xobj.readyState == XMLHttpRequest.DONE) { if (xobj.status === 0 || (xobj.status >= 200 && xobj.status < 400)) { From f02ebfbd8a39dc23db441e04571218fe5ffb2a7e Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Fri, 4 Jun 2021 12:41:28 -0400 Subject: [PATCH 04/19] Fixed remaining failing tests --- src/mono/wasm/runtime-test.js | 7 +------ src/mono/wasm/runtime/js_support.js | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index 98a1470a0f9ef3..d6deeaff6a5e33 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -226,12 +226,6 @@ var Module = { } Module.config = config; - - if (is_node) { - eval (read ("dotnet.js").toString()); - } else { - loadScript ("dotnet.js"); - } }, onRuntimeInitialized: function () { @@ -297,6 +291,7 @@ var Module = { MONO.mono_load_runtime_and_bcl_args (Module.config); }, }; +loadScript ("dotnet.js"); const IGNORE_PARAM_COUNT = -1; diff --git a/src/mono/wasm/runtime/js_support.js b/src/mono/wasm/runtime/js_support.js index 1c434a77aadf67..efd3676a1b10eb 100644 --- a/src/mono/wasm/runtime/js_support.js +++ b/src/mono/wasm/runtime/js_support.js @@ -45,9 +45,9 @@ function load_config() { // other kinds of errors callback({error: "Error loading mono-config.json file from current directory"}); } - } else { + } else { // shell or worker try { - var config = JSON.parse(load("./mono-config.json")); + var config = JSON.parse(read("./mono-config.json")); // read is a v8 debugger command callback(config); } catch(e) { callback({error: "Error loading mono-config.json file from current directory"}); From 2067b23fd021c722c2c72ee2132e3799238c4c85 Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Fri, 4 Jun 2021 15:20:18 -0400 Subject: [PATCH 05/19] Replaced alerts with console.log to fix Helix test --- src/mono/sample/mbr/browser/runtime.js | 2 +- src/mono/sample/wasm/browser-bench/runtime.js | 2 +- src/mono/sample/wasm/browser-profile/runtime.js | 2 +- src/mono/sample/wasm/browser/runtime.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mono/sample/mbr/browser/runtime.js b/src/mono/sample/mbr/browser/runtime.js index 3a63c214f2ff65..07a08779f3f961 100644 --- a/src/mono/sample/mbr/browser/runtime.js +++ b/src/mono/sample/mbr/browser/runtime.js @@ -18,7 +18,7 @@ var Module = { // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { if (!Module.config || Module.config.error){ - alert("An error occured while loading the config file"); + console.log("An error occured while loading the config file"); return; } diff --git a/src/mono/sample/wasm/browser-bench/runtime.js b/src/mono/sample/wasm/browser-bench/runtime.js index cbebc617ba82d7..7fe5d8bd62091a 100644 --- a/src/mono/sample/wasm/browser-bench/runtime.js +++ b/src/mono/sample/wasm/browser-bench/runtime.js @@ -17,7 +17,7 @@ var Module = { // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { if (!Module.config || Module.config.error){ - alert("An error occured while loading the config file"); + console.log("An error occured while loading the config file"); return; } diff --git a/src/mono/sample/wasm/browser-profile/runtime.js b/src/mono/sample/wasm/browser-profile/runtime.js index e385167eaec223..55ab008856ff52 100644 --- a/src/mono/sample/wasm/browser-profile/runtime.js +++ b/src/mono/sample/wasm/browser-profile/runtime.js @@ -18,7 +18,7 @@ var Module = { // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { if (!Module.config || Module.config.error){ - alert("An error occured while loading the config file"); + console.log("An error occured while loading the config file"); return; } diff --git a/src/mono/sample/wasm/browser/runtime.js b/src/mono/sample/wasm/browser/runtime.js index 0a99c174a01f62..00b1a0c48f3a6b 100644 --- a/src/mono/sample/wasm/browser/runtime.js +++ b/src/mono/sample/wasm/browser/runtime.js @@ -19,7 +19,7 @@ var Module = { // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { if (!Module.config || Module.config.error){ - alert("No config found"); + console.log("No config found"); return; } From a9a420ceb5f705275231d8f377b403fb87826b9d Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Mon, 7 Jun 2021 09:53:51 -0400 Subject: [PATCH 06/19] replaced all vars with consts --- src/mono/wasm/runtime/js_support.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mono/wasm/runtime/js_support.js b/src/mono/wasm/runtime/js_support.js index efd3676a1b10eb..3ff1224de4a988 100644 --- a/src/mono/wasm/runtime/js_support.js +++ b/src/mono/wasm/runtime/js_support.js @@ -5,28 +5,28 @@ // Not meant to be used outside of this class (TODO make private to this file when project converted to TS) function load_config() { // since this file loads before emsdk we don't have environment vars yet, so we define them locally - var ENVIRONMENT_IS_NODE = typeof process === "object"; - var ENVIRONMENT_IS_WEB = typeof window === "object"; + const ENVIRONMENT_IS_NODE = typeof process === "object"; + const ENVIRONMENT_IS_WEB = typeof window === "object"; // In some cases there may be no Module object (such as in tests) // so we no-op during the callback - let callback = typeof Module !== "undefined" ? Module['onConfigLoaded'] : (_) => {}; + const callback = typeof Module !== "undefined" ? Module['onConfigLoaded'] : (_) => {}; if (ENVIRONMENT_IS_NODE){ try { - var config = JSON.parse(require("./mono-config.json")); + const config = JSON.parse(require("./mono-config.json")); callback(config); } catch(e) { callback({error: "Error loading mono-config.json file from current directory"}); } } else if (ENVIRONMENT_IS_WEB){ - var xobj = new XMLHttpRequest(); + const xobj = new XMLHttpRequest(); xobj.overrideMimeType("application/json"); xobj.open("GET", "./mono-config.json", true); xobj.onreadystatechange = function() { if (xobj.readyState == XMLHttpRequest.DONE) { if (xobj.status === 0 || (xobj.status >= 200 && xobj.status < 400)) { - var config = JSON.parse(xobj.responseText); + const config = JSON.parse(xobj.responseText); callback(config); } else { // error if the request to load the file was successful but loading failed @@ -47,7 +47,7 @@ function load_config() { } } else { // shell or worker try { - var config = JSON.parse(read("./mono-config.json")); // read is a v8 debugger command + const config = JSON.parse(read("./mono-config.json")); // read is a v8 debugger command callback(config); } catch(e) { callback({error: "Error loading mono-config.json file from current directory"}); From 0a1a666ce9fb4f7a3234da84f78af672f0dc7760 Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Thu, 10 Jun 2021 10:46:02 -0400 Subject: [PATCH 07/19] use fetch --- src/mono/wasm/runtime/js_support.js | 73 ++++++++++------------------- 1 file changed, 26 insertions(+), 47 deletions(-) diff --git a/src/mono/wasm/runtime/js_support.js b/src/mono/wasm/runtime/js_support.js index 3ff1224de4a988..da1e5e9956052b 100644 --- a/src/mono/wasm/runtime/js_support.js +++ b/src/mono/wasm/runtime/js_support.js @@ -3,55 +3,34 @@ // Loads the config file located in the root of the project // Not meant to be used outside of this class (TODO make private to this file when project converted to TS) -function load_config() { - // since this file loads before emsdk we don't have environment vars yet, so we define them locally - const ENVIRONMENT_IS_NODE = typeof process === "object"; - const ENVIRONMENT_IS_WEB = typeof window === "object"; +async function load_config() { + // In some cases there may be no Module object (such as in some tests) + // so we no-op during the callback + const callback = typeof Module !== "undefined" ? Module['onConfigLoaded'] : (_) => {}; + const configFile = "./mono-config.json"; - // In some cases there may be no Module object (such as in tests) - // so we no-op during the callback - const callback = typeof Module !== "undefined" ? Module['onConfigLoaded'] : (_) => {}; + const ENVIRONMENT_IS_NODE = typeof process === "object"; + const ENVIRONMENT_IS_WEB = typeof window === "object"; - if (ENVIRONMENT_IS_NODE){ - try { - const config = JSON.parse(require("./mono-config.json")); - callback(config); - } catch(e) { - callback({error: "Error loading mono-config.json file from current directory"}); - } - } else if (ENVIRONMENT_IS_WEB){ - const xobj = new XMLHttpRequest(); - xobj.overrideMimeType("application/json"); - xobj.open("GET", "./mono-config.json", true); - xobj.onreadystatechange = function() { - if (xobj.readyState == XMLHttpRequest.DONE) { - if (xobj.status === 0 || (xobj.status >= 200 && xobj.status < 400)) { - const config = JSON.parse(xobj.responseText); - callback(config); - } else { - // error if the request to load the file was successful but loading failed - callback({error: "Error loading mono-config.json file from current directory"}); - } - } - }; - xobj.onerror = function() { - // error if the request failed - callback({error: "Error loading mono-config.json file from current directory"}); - } - - try { - xobj.send(); - } catch(e) { - // other kinds of errors - callback({error: "Error loading mono-config.json file from current directory"}); - } - } else { // shell or worker - try { - const config = JSON.parse(read("./mono-config.json")); // read is a v8 debugger command - callback(config); - } catch(e) { - callback({error: "Error loading mono-config.json file from current directory"}); - } + // NOTE: when we add nodejs make sure to include the nodejs fetch package + if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_NODE) { + try { + const configRaw = await fetch(configFile); + const config = await configRaw.json(); + console.log(config); + callback(config); + } catch(e) { + console.log(e) + callback({error: e}); } + + } else { // shell or worker + try { + const config = JSON.parse(read(configFile)); // read is a v8 debugger command + callback(config); + } catch(e) { + callback({error: `Error loading ${configFile} file`}); + } + } } load_config(); From bf1fd71c6422c72197a0d2bf030527e043a1fbb5 Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Thu, 10 Jun 2021 10:49:42 -0400 Subject: [PATCH 08/19] clean syntax --- src/mono/wasm/runtime/js_support.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/mono/wasm/runtime/js_support.js b/src/mono/wasm/runtime/js_support.js index da1e5e9956052b..415bab37d3bed3 100644 --- a/src/mono/wasm/runtime/js_support.js +++ b/src/mono/wasm/runtime/js_support.js @@ -15,22 +15,20 @@ async function load_config() { // NOTE: when we add nodejs make sure to include the nodejs fetch package if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_NODE) { try { - const configRaw = await fetch(configFile); - const config = await configRaw.json(); - console.log(config); - callback(config); + const configRaw = await fetch(configFile); + const config = await configRaw.json(); + callback(config); } catch(e) { - console.log(e) - callback({error: e}); + callback({error: e}); } } else { // shell or worker - try { - const config = JSON.parse(read(configFile)); // read is a v8 debugger command - callback(config); - } catch(e) { - callback({error: `Error loading ${configFile} file`}); - } + try { + const config = JSON.parse(read(configFile)); // read is a v8 debugger command + callback(config); + } catch(e) { + callback({error: `Error loading ${configFile} file`}); + } } } load_config(); From 64ab9b08640943b9008be8b6af717f768dd6e1f1 Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Fri, 11 Jun 2021 09:46:18 -0400 Subject: [PATCH 09/19] prevent timeouts when the mono-config file fails to load --- .../FunctionalTests/WebAssembly/Browser/AOT/runtime.js | 6 ++++++ .../WebAssembly/Browser/NormalInterp/runtime.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js index 50858fc439a109..af72f6f8051cb7 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js @@ -17,6 +17,12 @@ var Module = { }, onRuntimeInitialized: 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 (); diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js index 50858fc439a109..8743d14d28039a 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js @@ -17,6 +17,12 @@ var Module = { }, onRuntimeInitialized: 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 (); From e4676dc4b3a1968d33699da8cdd1b52961b4ad7c Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Fri, 11 Jun 2021 13:10:35 -0400 Subject: [PATCH 10/19] Moved config file loading to preInit --- src/mono/sample/mbr/browser/runtime.js | 4 ++++ src/mono/sample/wasm/browser-bench/runtime.js | 4 ++++ src/mono/sample/wasm/browser-profile/runtime.js | 4 ++++ src/mono/sample/wasm/browser/runtime.js | 4 ++++ .../wasm/debugger/tests/debugger-test/runtime-debugger.js | 4 ++++ src/mono/wasm/runtime-test.js | 5 ++++- src/mono/wasm/runtime/js_support.js | 7 ++----- .../FunctionalTests/WebAssembly/Browser/AOT/runtime.js | 4 ++++ .../WebAssembly/Browser/NormalInterp/runtime.js | 4 ++++ 9 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/mono/sample/mbr/browser/runtime.js b/src/mono/sample/mbr/browser/runtime.js index 07a08779f3f961..32d9306a6c534d 100644 --- a/src/mono/sample/mbr/browser/runtime.js +++ b/src/mono/sample/mbr/browser/runtime.js @@ -4,6 +4,10 @@ var Module = { config: null, + preInit: async function() { + await loadMonoConfig("./mono-config.json"); + }, + // Called once the config file is loaded. The contents of the config file // are passed as a JS object within the config parameter onConfigLoaded: function (config) { diff --git a/src/mono/sample/wasm/browser-bench/runtime.js b/src/mono/sample/wasm/browser-bench/runtime.js index 7fe5d8bd62091a..6322660963433f 100644 --- a/src/mono/sample/wasm/browser-bench/runtime.js +++ b/src/mono/sample/wasm/browser-bench/runtime.js @@ -3,6 +3,10 @@ var Module = { config: null, + preInit: async function() { + await loadMonoConfig("./mono-config.json"); + }, + // Called once the config file is loaded. The contents of the config file // are passed as a JS object within the config parameter onConfigLoaded: function (config) { diff --git a/src/mono/sample/wasm/browser-profile/runtime.js b/src/mono/sample/wasm/browser-profile/runtime.js index 55ab008856ff52..d33b646f58b4d8 100644 --- a/src/mono/sample/wasm/browser-profile/runtime.js +++ b/src/mono/sample/wasm/browser-profile/runtime.js @@ -4,6 +4,10 @@ var Module = { is_testing: false, config: null, + preInit: async function() { + await loadMonoConfig("./mono-config.json"); + }, + // Called once the config file is loaded. The contents of the config file // are passed as a JS object within the config parameter onConfigLoaded: function (config) { diff --git a/src/mono/sample/wasm/browser/runtime.js b/src/mono/sample/wasm/browser/runtime.js index 00b1a0c48f3a6b..2cfaa265bb3332 100644 --- a/src/mono/sample/wasm/browser/runtime.js +++ b/src/mono/sample/wasm/browser/runtime.js @@ -5,6 +5,10 @@ var Module = { config: null, + preInit: async function() { + await loadMonoConfig("./mono-config.json"); + }, + // Called once the config file is loaded. The contents of the config file // are passed as a JS object within the config parameter onConfigLoaded: function (config) { diff --git a/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js b/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js index da8da61bd92fd3..cf3fc1956f5122 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js +++ b/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js @@ -4,6 +4,10 @@ var Module = { config: null, + preInit: async function() { + await loadMonoConfig("./mono-config.json"); + }, + // Called once the config file is loaded. The contents of the config file // are passed as a JS object within the config parameter onConfigLoaded: function (config) { diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index d6deeaff6a5e33..6b2d49d1c86464 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -206,11 +206,14 @@ function loadScript (url) var Module = { mainScriptUrlOrBlob: "dotnet.js", - config: null, print, printErr, + preInit: async function() { + await loadMonoConfig("./mono-config.json"); + }, + onAbort: function(x) { print ("ABORT: " + x); var err = new Error(); diff --git a/src/mono/wasm/runtime/js_support.js b/src/mono/wasm/runtime/js_support.js index 415bab37d3bed3..4ad4714fba46a3 100644 --- a/src/mono/wasm/runtime/js_support.js +++ b/src/mono/wasm/runtime/js_support.js @@ -1,13 +1,11 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// Loads the config file located in the root of the project -// Not meant to be used outside of this class (TODO make private to this file when project converted to TS) -async function load_config() { +// Loads the config file +async function loadMonoConfig(configFile) { // In some cases there may be no Module object (such as in some tests) // so we no-op during the callback const callback = typeof Module !== "undefined" ? Module['onConfigLoaded'] : (_) => {}; - const configFile = "./mono-config.json"; const ENVIRONMENT_IS_NODE = typeof process === "object"; const ENVIRONMENT_IS_WEB = typeof window === "object"; @@ -31,4 +29,3 @@ async function load_config() { } } } -load_config(); diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js index af72f6f8051cb7..cd91002d745571 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js @@ -5,6 +5,10 @@ var Module = { config: null, + preInit: async function() { + await loadMonoConfig("./mono-config.json"); + }, + // Called once the config file is loaded. The contents of the config file // are passed as a JS object within the config parameter onConfigLoaded: function (config) { diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js index 8743d14d28039a..7375519f5dd941 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js @@ -5,6 +5,10 @@ var Module = { config: null, + preInit: async function() { + await loadMonoConfig("./mono-config.json"); + }, + // Called once the config file is loaded. The contents of the config file // are passed as a JS object within the config parameter onConfigLoaded: function (config) { From 08f7b12436a20aa247f532b24bdacb7552db0f0c Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Fri, 11 Jun 2021 14:12:06 -0400 Subject: [PATCH 11/19] Fixed tests --- src/mono/wasm/wasm.proj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index 4f87ecdd931ab4..302b13cf1f3110 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -248,6 +248,7 @@ runtime/binding_support.js; runtime/dotnet_support.js; runtime/library_mono.js; + runtime/js_support.js; $(SystemNativeDir)\pal_random.js;" DestinationFolder="$(NativeBinDir)src" SkipUnchangedFiles="true" /> From e6f724fbe961aeb87d2d9f36083353789fe964b4 Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Fri, 11 Jun 2021 15:29:11 -0400 Subject: [PATCH 12/19] Adjusted file linking --- .../pkg/sfx/Microsoft.NETCore.App/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index 4f2be71a46fd09..43820785b9a8ce 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -212,7 +212,7 @@ - + From 857f1dd4eb4d6e9c7774389802700f7dbf0f1e5f Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Mon, 14 Jun 2021 11:20:55 -0400 Subject: [PATCH 13/19] removed the unnecessary js_support.js --- .../Directory.Build.props | 1 - src/mono/sample/mbr/browser/runtime.js | 2 +- src/mono/sample/wasm/browser-bench/runtime.js | 2 +- .../sample/wasm/browser-profile/runtime.js | 2 +- src/mono/sample/wasm/browser/runtime.js | 2 +- src/mono/wasm/Makefile | 6 ++-- .../tests/debugger-test/runtime-debugger.js | 2 +- src/mono/wasm/runtime-test.js | 2 +- src/mono/wasm/runtime/js_support.js | 31 ------------------- src/mono/wasm/runtime/library_mono.js | 31 ++++++++++++++++++- src/mono/wasm/wasm.proj | 3 +- .../WebAssembly/Browser/AOT/runtime.js | 2 +- .../Browser/NormalInterp/runtime.js | 2 +- 13 files changed, 42 insertions(+), 46 deletions(-) delete mode 100644 src/mono/wasm/runtime/js_support.js diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index 43820785b9a8ce..834fa2bac988d6 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -212,7 +212,6 @@ - diff --git a/src/mono/sample/mbr/browser/runtime.js b/src/mono/sample/mbr/browser/runtime.js index 32d9306a6c534d..c982497956d2d4 100644 --- a/src/mono/sample/mbr/browser/runtime.js +++ b/src/mono/sample/mbr/browser/runtime.js @@ -5,7 +5,7 @@ var Module = { config: null, preInit: async function() { - await loadMonoConfig("./mono-config.json"); + await MONO.mono_wasm_load_config("./mono-config.json"); }, // Called once the config file is loaded. The contents of the config file diff --git a/src/mono/sample/wasm/browser-bench/runtime.js b/src/mono/sample/wasm/browser-bench/runtime.js index 6322660963433f..7d82e78513e330 100644 --- a/src/mono/sample/wasm/browser-bench/runtime.js +++ b/src/mono/sample/wasm/browser-bench/runtime.js @@ -4,7 +4,7 @@ var Module = { config: null, preInit: async function() { - await loadMonoConfig("./mono-config.json"); + await MONO.mono_wasm_load_config("./mono-config.json"); }, // Called once the config file is loaded. The contents of the config file diff --git a/src/mono/sample/wasm/browser-profile/runtime.js b/src/mono/sample/wasm/browser-profile/runtime.js index d33b646f58b4d8..ab6ff90e15479e 100644 --- a/src/mono/sample/wasm/browser-profile/runtime.js +++ b/src/mono/sample/wasm/browser-profile/runtime.js @@ -5,7 +5,7 @@ var Module = { config: null, preInit: async function() { - await loadMonoConfig("./mono-config.json"); + await MONO.mono_wasm_load_config("./mono-config.json"); }, // Called once the config file is loaded. The contents of the config file diff --git a/src/mono/sample/wasm/browser/runtime.js b/src/mono/sample/wasm/browser/runtime.js index 2cfaa265bb3332..5e37c2fdb49ec9 100644 --- a/src/mono/sample/wasm/browser/runtime.js +++ b/src/mono/sample/wasm/browser/runtime.js @@ -6,7 +6,7 @@ var Module = { config: null, preInit: async function() { - await loadMonoConfig("./mono-config.json"); + await MONO.mono_wasm_load_config("./mono-config.json"); }, // Called once the config file is loaded. The contents of the config file diff --git a/src/mono/wasm/Makefile b/src/mono/wasm/Makefile index 95bb1c170f6ed0..6ff877c5722e28 100644 --- a/src/mono/wasm/Makefile +++ b/src/mono/wasm/Makefile @@ -92,8 +92,8 @@ $(NATIVE_BIN_DIR)/include/wasm: $(BUILDS_OBJ_DIR): mkdir -p $$@ -$(NATIVE_BIN_DIR)/dotnet.js: $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o runtime/library_mono.js runtime/binding_support.js runtime/dotnet_support.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js runtime/js_support.js $(2) $(EMCC_DEFAULT_RSP) | $(NATIVE_BIN_DIR) - $(EMCC) @$(EMCC_DEFAULT_RSP) $(1) --js-library runtime/library_mono.js --js-library runtime/binding_support.js --js-library runtime/dotnet_support.js --js-library $(SYSTEM_NATIVE_LIBDIR)/pal_random.js --pre-js runtime/js_support.js $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o $(2) -o $(NATIVE_BIN_DIR)/dotnet.js $(3) +$(NATIVE_BIN_DIR)/dotnet.js: $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o runtime/library_mono.js runtime/binding_support.js runtime/dotnet_support.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js $(2) $(EMCC_DEFAULT_RSP) | $(NATIVE_BIN_DIR) + $(EMCC) @$(EMCC_DEFAULT_RSP) $(1) --js-library runtime/library_mono.js --js-library runtime/binding_support.js --js-library runtime/dotnet_support.js --js-library $(SYSTEM_NATIVE_LIBDIR)/pal_random.js --pre-js $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o $(2) -o $(NATIVE_BIN_DIR)/dotnet.js $(3) $(BUILDS_OBJ_DIR)/pinvoke-table.h: $(PINVOKE_TABLE) | $(BUILDS_OBJ_DIR) if cmp -s $(PINVOKE_TABLE) $$@ ; then : ; else cp $(PINVOKE_TABLE) $$@ ; fi @@ -132,7 +132,7 @@ clean: icu-files: $(wildcard $(ICU_LIBDIR)/*.dat) $(ICU_LIBDIR)/libicuuc.a $(ICU_LIBDIR)/libicui18n.a | $(NATIVE_BIN_DIR) cp $^ $(NATIVE_BIN_DIR) -source-files: runtime/driver.c runtime/pinvoke.c runtime/corebindings.c runtime/binding_support.js runtime/dotnet_support.js runtime/library_mono.js runtime/js_support.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js | $(NATIVE_BIN_DIR)/src +source-files: runtime/driver.c runtime/pinvoke.c runtime/corebindings.c runtime/binding_support.js runtime/dotnet_support.js runtime/library_mono.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js | $(NATIVE_BIN_DIR)/src cp $^ $(NATIVE_BIN_DIR)/src header-files: runtime/pinvoke.h | $(NATIVE_BIN_DIR)/include/wasm diff --git a/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js b/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js index cf3fc1956f5122..d20426219943b1 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js +++ b/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js @@ -5,7 +5,7 @@ var Module = { config: null, preInit: async function() { - await loadMonoConfig("./mono-config.json"); + await MONO.mono_wasm_load_config("./mono-config.json"); }, // Called once the config file is loaded. The contents of the config file diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index 6b2d49d1c86464..44c5341b3329e5 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -211,7 +211,7 @@ var Module = { printErr, preInit: async function() { - await loadMonoConfig("./mono-config.json"); + await MONO.mono_wasm_load_config("./mono-config.json"); }, onAbort: function(x) { diff --git a/src/mono/wasm/runtime/js_support.js b/src/mono/wasm/runtime/js_support.js deleted file mode 100644 index 4ad4714fba46a3..00000000000000 --- a/src/mono/wasm/runtime/js_support.js +++ /dev/null @@ -1,31 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Loads the config file -async function loadMonoConfig(configFile) { - // In some cases there may be no Module object (such as in some tests) - // so we no-op during the callback - const callback = typeof Module !== "undefined" ? Module['onConfigLoaded'] : (_) => {}; - - const ENVIRONMENT_IS_NODE = typeof process === "object"; - const ENVIRONMENT_IS_WEB = typeof window === "object"; - - // NOTE: when we add nodejs make sure to include the nodejs fetch package - if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_NODE) { - try { - const configRaw = await fetch(configFile); - const config = await configRaw.json(); - callback(config); - } catch(e) { - callback({error: e}); - } - - } else { // shell or worker - try { - const config = JSON.parse(read(configFile)); // read is a v8 debugger command - callback(config); - } catch(e) { - callback({error: `Error loading ${configFile} file`}); - } - } -} diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 685aaaf375d85e..bafa568421e119 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -86,6 +86,7 @@ var MonoSupportLib = { 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: { @@ -2323,6 +2324,34 @@ var MonoSupportLib = { 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 + */ + mono_wasm_load_config: async function (configFilePath) { + // In some cases there may be no Module object (such as in some tests) + // so we no-op during the callback + const callback = typeof Module !== "undefined" ? Module['onConfigLoaded'] : (_) => {}; + + const ENVIRONMENT_IS_NODE = typeof process === "object"; + const ENVIRONMENT_IS_WEB = typeof window === "object"; + + try { + let config = null; + // NOTE: when we add nodejs make sure to include the nodejs fetch package + if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_NODE) { + const configRaw = await fetch(configFilePath); + config = await configRaw.json(); + } else { // shell or worker + config = JSON.parse(read(configFilePath)); // read is a v8 debugger command + } + callback(config); + } catch(e) { + callback({error: e}); + } + } }, mono_wasm_add_typed_value: function (type, str_value, value) { @@ -2510,7 +2539,7 @@ var MonoSupportLib = { assembly_b64, pdb_b64 }); - }, + } }; autoAddDeps(MonoSupportLib, '$MONO') diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index 302b13cf1f3110..562091ed6a26d8 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -227,7 +227,7 @@ EmSdkPath="$(EMSDK_PATH)" IgnoreStandardErrorWarningFormat="true" /> - @@ -248,7 +248,6 @@ runtime/binding_support.js; runtime/dotnet_support.js; runtime/library_mono.js; - runtime/js_support.js; $(SystemNativeDir)\pal_random.js;" DestinationFolder="$(NativeBinDir)src" SkipUnchangedFiles="true" /> diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js index cd91002d745571..7b9a62f0dc4627 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js @@ -6,7 +6,7 @@ var Module = { config: null, preInit: async function() { - await loadMonoConfig("./mono-config.json"); + await MONO.mono_wasm_load_config("./mono-config.json"); }, // Called once the config file is loaded. The contents of the config file diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js index 7375519f5dd941..80263536e4829f 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js @@ -6,7 +6,7 @@ var Module = { config: null, preInit: async function() { - await loadMonoConfig("./mono-config.json"); + await MONO.mono_wasm_load_config("./mono-config.json"); }, // Called once the config file is loaded. The contents of the config file From b3143d6d5a66f351112c1dd9fd178362014afbe9 Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Mon, 14 Jun 2021 11:37:48 -0400 Subject: [PATCH 14/19] cleaned up function --- src/mono/wasm/runtime/library_mono.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index bafa568421e119..827fbe1b7ca864 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -2329,15 +2329,9 @@ var MonoSupportLib = { * 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) { - // In some cases there may be no Module object (such as in some tests) - // so we no-op during the callback - const callback = typeof Module !== "undefined" ? Module['onConfigLoaded'] : (_) => {}; - - const ENVIRONMENT_IS_NODE = typeof process === "object"; - const ENVIRONMENT_IS_WEB = typeof window === "object"; - + mono_wasm_load_config: async function (configFilePath) { try { let config = null; // NOTE: when we add nodejs make sure to include the nodejs fetch package @@ -2347,9 +2341,9 @@ var MonoSupportLib = { } else { // shell or worker config = JSON.parse(read(configFilePath)); // read is a v8 debugger command } - callback(config); + return config; } catch(e) { - callback({error: e}); + return {message: "failed to load config file", error: e}; } } }, From 61b6ca3ee75934c2e7d773736351ecd9a7626b2d Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Mon, 14 Jun 2021 11:59:54 -0400 Subject: [PATCH 15/19] updated samples --- src/mono/sample/mbr/browser/runtime.js | 13 +------------ src/mono/sample/wasm/browser-bench/runtime.js | 13 +------------ src/mono/sample/wasm/browser-profile/runtime.js | 13 +------------ src/mono/sample/wasm/browser/runtime.js | 13 +------------ .../tests/debugger-test/runtime-debugger.js | 13 +------------ .../WebAssembly/Browser/AOT/runtime.js | 13 +------------ .../WebAssembly/Browser/NormalInterp/runtime.js | 13 +------------ 7 files changed, 7 insertions(+), 84 deletions(-) diff --git a/src/mono/sample/mbr/browser/runtime.js b/src/mono/sample/mbr/browser/runtime.js index c982497956d2d4..5949c5edb4bd3b 100644 --- a/src/mono/sample/mbr/browser/runtime.js +++ b/src/mono/sample/mbr/browser/runtime.js @@ -5,18 +5,7 @@ var Module = { config: null, preInit: async function() { - await MONO.mono_wasm_load_config("./mono-config.json"); - }, - - // Called once the config file is loaded. The contents of the config file - // are passed as a JS object within the config parameter - onConfigLoaded: function (config) { - if (!config || config.error){ - console.log("An error occured while loading the config file"); - return; - } - - Module.config = config; + Module.config = await MONO.mono_wasm_load_config("./mono-config.json"); }, // Called when the runtime is initialized and wasm is ready diff --git a/src/mono/sample/wasm/browser-bench/runtime.js b/src/mono/sample/wasm/browser-bench/runtime.js index 7d82e78513e330..07b54173be0bc0 100644 --- a/src/mono/sample/wasm/browser-bench/runtime.js +++ b/src/mono/sample/wasm/browser-bench/runtime.js @@ -4,18 +4,7 @@ var Module = { config: null, preInit: async function() { - await MONO.mono_wasm_load_config("./mono-config.json"); - }, - - // Called once the config file is loaded. The contents of the config file - // are passed as a JS object within the config parameter - onConfigLoaded: function (config) { - if (!config || config.error){ - console.log("An error occured while loading the config file"); - return; - } - - Module.config = config; + Module.config = await MONO.mono_wasm_load_config("./mono-config.json"); }, // Called when the runtime is initialized and wasm is ready diff --git a/src/mono/sample/wasm/browser-profile/runtime.js b/src/mono/sample/wasm/browser-profile/runtime.js index ab6ff90e15479e..8b7ef3258c685d 100644 --- a/src/mono/sample/wasm/browser-profile/runtime.js +++ b/src/mono/sample/wasm/browser-profile/runtime.js @@ -5,18 +5,7 @@ var Module = { config: null, preInit: async function() { - await MONO.mono_wasm_load_config("./mono-config.json"); - }, - - // Called once the config file is loaded. The contents of the config file - // are passed as a JS object within the config parameter - onConfigLoaded: function (config) { - if (!config || config.error){ - console.log("An error occured while loading the config file"); - return; - } - - Module.config = config; + Module.config = await MONO.mono_wasm_load_config("./mono-config.json"); }, // Called when the runtime is initialized and wasm is ready diff --git a/src/mono/sample/wasm/browser/runtime.js b/src/mono/sample/wasm/browser/runtime.js index 5e37c2fdb49ec9..748138d8ebeb9c 100644 --- a/src/mono/sample/wasm/browser/runtime.js +++ b/src/mono/sample/wasm/browser/runtime.js @@ -6,18 +6,7 @@ var Module = { config: null, preInit: async function() { - await MONO.mono_wasm_load_config("./mono-config.json"); - }, - - // Called once the config file is loaded. The contents of the config file - // are passed as a JS object within the config parameter - onConfigLoaded: function (config) { - if (!config || config.error){ - console.log("An error occured while loading the config file"); - return; - } - - Module.config = config; + Module.config = await MONO.mono_wasm_load_config("./mono-config.json"); }, // Called when the runtime is initialized and wasm is ready diff --git a/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js b/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js index d20426219943b1..2980f060fee35c 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js +++ b/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js @@ -5,18 +5,7 @@ var Module = { config: null, preInit: async function() { - await MONO.mono_wasm_load_config("./mono-config.json"); - }, - - // Called once the config file is loaded. The contents of the config file - // are passed as a JS object within the config parameter - onConfigLoaded: function (config) { - if (!config || config.error){ - console.log("An error occured while loading the config file"); - return; - } - - Module.config = config; + Module.config = await MONO.mono_wasm_load_config("./mono-config.json"); }, // Called when the runtime is initialized and wasm is ready diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js index 7b9a62f0dc4627..a7b616b6e611e3 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js @@ -6,18 +6,7 @@ var Module = { config: null, preInit: async function() { - await MONO.mono_wasm_load_config("./mono-config.json"); - }, - - // Called once the config file is loaded. The contents of the config file - // are passed as a JS object within the config parameter - onConfigLoaded: function (config) { - if (!config || config.error){ - console.log("An error occured while loading the config file"); - return; - } - - Module.config = config; + Module.config = await MONO.mono_wasm_load_config("./mono-config.json"); }, onRuntimeInitialized: function () { diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js index 80263536e4829f..917f7b12447a32 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js @@ -6,18 +6,7 @@ var Module = { config: null, preInit: async function() { - await MONO.mono_wasm_load_config("./mono-config.json"); - }, - - // Called once the config file is loaded. The contents of the config file - // are passed as a JS object within the config parameter - onConfigLoaded: function (config) { - if (!config || config.error){ - console.log("An error occured while loading the config file"); - return; - } - - Module.config = config; + Module.config = await MONO.mono_wasm_load_config("./mono-config.json"); }, onRuntimeInitialized: function () { From 6c9030b41ae841680eb5b67718453628ce79b146 Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Mon, 14 Jun 2021 12:50:09 -0400 Subject: [PATCH 16/19] removed lingering pre-js flag --- src/mono/wasm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Makefile b/src/mono/wasm/Makefile index 6ff877c5722e28..8a69822976bfe4 100644 --- a/src/mono/wasm/Makefile +++ b/src/mono/wasm/Makefile @@ -93,7 +93,7 @@ $(BUILDS_OBJ_DIR): mkdir -p $$@ $(NATIVE_BIN_DIR)/dotnet.js: $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o runtime/library_mono.js runtime/binding_support.js runtime/dotnet_support.js $(SYSTEM_NATIVE_LIBDIR)/pal_random.js $(2) $(EMCC_DEFAULT_RSP) | $(NATIVE_BIN_DIR) - $(EMCC) @$(EMCC_DEFAULT_RSP) $(1) --js-library runtime/library_mono.js --js-library runtime/binding_support.js --js-library runtime/dotnet_support.js --js-library $(SYSTEM_NATIVE_LIBDIR)/pal_random.js --pre-js $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o $(2) -o $(NATIVE_BIN_DIR)/dotnet.js $(3) + $(EMCC) @$(EMCC_DEFAULT_RSP) $(1) --js-library runtime/library_mono.js --js-library runtime/binding_support.js --js-library runtime/dotnet_support.js --js-library $(SYSTEM_NATIVE_LIBDIR)/pal_random.js $(BUILDS_OBJ_DIR)/driver.o $(BUILDS_OBJ_DIR)/pinvoke.o $(BUILDS_OBJ_DIR)/corebindings.o $(2) -o $(NATIVE_BIN_DIR)/dotnet.js $(3) $(BUILDS_OBJ_DIR)/pinvoke-table.h: $(PINVOKE_TABLE) | $(BUILDS_OBJ_DIR) if cmp -s $(PINVOKE_TABLE) $$@ ; then : ; else cp $(PINVOKE_TABLE) $$@ ; fi From 8476110f516bf75a2ec363f8f4bd6005975e1fb9 Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Mon, 14 Jun 2021 14:02:36 -0400 Subject: [PATCH 17/19] Fixed trimming tests --- src/mono/wasm/runtime-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index 44c5341b3329e5..18a4b54417707d 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -211,7 +211,7 @@ var Module = { printErr, preInit: async function() { - await MONO.mono_wasm_load_config("./mono-config.json"); + Module.config = await MONO.mono_wasm_load_config("./mono-config.json"); }, onAbort: function(x) { From 3214abc575f0479d5b38b39335dc9e7a403f5d6b Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Sat, 19 Jun 2021 10:41:11 -0400 Subject: [PATCH 18/19] addressed PR comments --- src/mono/sample/mbr/browser/runtime.js | 2 +- src/mono/sample/wasm/browser-bench/runtime.js | 2 +- src/mono/sample/wasm/browser-profile/runtime.js | 2 +- src/mono/sample/wasm/browser/runtime.js | 2 +- .../wasm/debugger/tests/debugger-test/runtime-debugger.js | 2 +- src/mono/wasm/runtime/library_mono.js | 4 +++- src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js | 2 +- .../WebAssembly/Browser/NormalInterp/runtime.js | 2 +- 8 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/mono/sample/mbr/browser/runtime.js b/src/mono/sample/mbr/browser/runtime.js index 5949c5edb4bd3b..32918aa573a44a 100644 --- a/src/mono/sample/mbr/browser/runtime.js +++ b/src/mono/sample/mbr/browser/runtime.js @@ -10,7 +10,7 @@ var Module = { // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { - if (!Module.config || Module.config.error){ + if (!Module.config || Module.config.error) { console.log("An error occured while loading the config file"); return; } diff --git a/src/mono/sample/wasm/browser-bench/runtime.js b/src/mono/sample/wasm/browser-bench/runtime.js index 07b54173be0bc0..60c383d13cb524 100644 --- a/src/mono/sample/wasm/browser-bench/runtime.js +++ b/src/mono/sample/wasm/browser-bench/runtime.js @@ -9,7 +9,7 @@ var Module = { // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { - if (!Module.config || Module.config.error){ + if (!Module.config || Module.config.error) { console.log("An error occured while loading the config file"); return; } diff --git a/src/mono/sample/wasm/browser-profile/runtime.js b/src/mono/sample/wasm/browser-profile/runtime.js index 8b7ef3258c685d..2c83ff54ef93d0 100644 --- a/src/mono/sample/wasm/browser-profile/runtime.js +++ b/src/mono/sample/wasm/browser-profile/runtime.js @@ -10,7 +10,7 @@ var Module = { // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { - if (!Module.config || Module.config.error){ + if (!Module.config || Module.config.error) { console.log("An error occured while loading the config file"); return; } diff --git a/src/mono/sample/wasm/browser/runtime.js b/src/mono/sample/wasm/browser/runtime.js index 748138d8ebeb9c..e97feef745a95d 100644 --- a/src/mono/sample/wasm/browser/runtime.js +++ b/src/mono/sample/wasm/browser/runtime.js @@ -11,7 +11,7 @@ var Module = { // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { - if (!Module.config || Module.config.error){ + if (!Module.config || Module.config.error) { console.log("No config found"); return; } diff --git a/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js b/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js index 2980f060fee35c..360aa9b8b3036d 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js +++ b/src/mono/wasm/debugger/tests/debugger-test/runtime-debugger.js @@ -10,7 +10,7 @@ var Module = { // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { - if (!Module.config || Module.config.error){ + if (!Module.config || Module.config.error) { console.log("An error occured while loading the config file"); return; } diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 827fbe1b7ca864..fd638804230bf6 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -2335,9 +2335,11 @@ var MonoSupportLib = { try { let config = null; // NOTE: when we add nodejs make sure to include the nodejs fetch package - if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_NODE) { + 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 } diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js index a7b616b6e611e3..65cba13a9b126b 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/AOT/runtime.js @@ -10,7 +10,7 @@ var Module = { }, onRuntimeInitialized: function () { - if (!Module.config || Module.config.error){ + if (!Module.config || Module.config.error) { console.log("No config found"); test_exit(1); throw(Module.config.error); diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js index 917f7b12447a32..1a8abf503fb33f 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/NormalInterp/runtime.js @@ -10,7 +10,7 @@ var Module = { }, onRuntimeInitialized: function () { - if (!Module.config || Module.config.error){ + if (!Module.config || Module.config.error) { console.log("No config found"); test_exit(1); throw(Module.config.error); From 1a1e502d3de0f3dd0dc0089be1289c0db399af00 Mon Sep 17 00:00:00 2001 From: Daniel-Genkin Date: Sat, 19 Jun 2021 18:27:28 -0400 Subject: [PATCH 19/19] removed useless function --- src/mono/wasm/runtime-test.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index 18a4b54417707d..8b3395f4ec50e8 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -222,15 +222,6 @@ var Module = { test_exit (1); }, - onConfigLoaded: function (config) { - if (!config || config.error){ - console.log("An error occured while loading the config file"); - return; - } - - Module.config = config; - }, - onRuntimeInitialized: function () { // Have to set env vars here to enable setting MONO_LOG_LEVEL etc. for (var variable in setenv) {