From 812cb2ec35e3cb5dd1ac4bb16eec180c8be41787 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Tue, 12 Oct 2021 18:57:34 +0200 Subject: [PATCH] - introduce globalThis.INTERNAL and move all exported methods which we only use internally or for testing - reduce BINDING and MONO exports to minimal scope necessary - as used by Blazor - fix all internal usages in tests - produce dotnet.d.ts and include it in the workload - moved Module.config to MONO.config - added mono_load_runtime_and_bcl_args into MONO export - removed obsolete debugger test InvalidScopeId - introduced INTERNAL.mono_wasm_set_main_args --- .../Directory.Build.props | 1 + .../src/Interop/Browser/Interop.Runtime.cs | 2 +- .../Native/Unix/System.Native/pal_random.js | 8 +- .../JavaScript/MarshalTests.cs | 46 +- src/mono/mono/component/mini-wasm-debugger.c | 10 +- src/mono/sample/mbr/browser/index.html | 6 +- src/mono/sample/mbr/browser/runtime.js | 20 +- src/mono/sample/wasm/browser-bench/index.html | 4 +- src/mono/sample/wasm/browser-bench/runtime.js | 30 +- .../sample/wasm/browser-profile/README.md | 8 +- .../sample/wasm/browser-profile/runtime.js | 65 +- src/mono/sample/wasm/browser/index.html | 2 +- src/mono/sample/wasm/browser/runtime.js | 23 +- .../BrowserDebugProxy/DevToolsHelper.cs | 22 +- .../DebuggerTestSuite/BreakpointTests.cs | 12 +- .../DebuggerTestSuite/DebuggerTestBase.cs | 7 +- .../debugger/DebuggerTestSuite/MonoJsTests.cs | 38 +- .../tests/debugger-test/debugger-driver.html | 20 +- .../debugger/tests/debugger-test/other.js | 10 +- .../tests/debugger-test/runtime-debugger.js | 30 +- src/mono/wasm/runtime-test.js | 638 +++++++++--------- src/mono/wasm/runtime/CMakeLists.txt | 2 +- src/mono/wasm/runtime/buffers.ts | 2 +- src/mono/wasm/runtime/cancelable-promise.ts | 2 +- src/mono/wasm/runtime/corebindings.c | 2 +- src/mono/wasm/runtime/cs-to-js.ts | 2 +- src/mono/wasm/runtime/cwraps.ts | 17 +- src/mono/wasm/runtime/debug.ts | 1 + src/mono/wasm/runtime/driver.c | 21 +- src/mono/wasm/runtime/exports.ts | 140 ++-- src/mono/wasm/runtime/icu.ts | 2 +- src/mono/wasm/runtime/js-to-cs.ts | 2 +- src/mono/wasm/runtime/library-dotnet.js | 24 +- src/mono/wasm/runtime/method-binding.ts | 2 +- src/mono/wasm/runtime/method-calls.ts | 2 +- src/mono/wasm/runtime/modules.ts | 23 +- src/mono/wasm/runtime/package-lock.json | 25 + src/mono/wasm/runtime/package.json | 7 +- src/mono/wasm/runtime/profiler.ts | 4 +- src/mono/wasm/runtime/rollup.config.js | 41 +- src/mono/wasm/runtime/roots.ts | 1 + src/mono/wasm/runtime/startup.ts | 28 +- src/mono/wasm/runtime/strings.ts | 2 +- src/mono/wasm/runtime/tsconfig.json | 1 - src/mono/wasm/runtime/types.ts | 40 +- src/mono/wasm/runtime/types/emscripten.d.ts | 8 +- src/mono/wasm/runtime/web-socket.ts | 2 +- src/mono/wasm/wasm.proj | 2 +- .../WebAssembly/Browser/HotReload/index.html | 2 +- .../WebAssembly/Browser/HotReload/runtime.js | 33 +- .../Browser/RuntimeConfig/index.html | 2 +- .../Browser/RuntimeConfig/runtime.js | 27 +- 52 files changed, 752 insertions(+), 719 deletions(-) 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 3d070f437073b..12faf8e6f3f5f 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -218,6 +218,7 @@ + diff --git a/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs b/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs index d6ac21cf3219f..051b412b1199d 100644 --- a/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs +++ b/src/libraries/Common/src/Interop/Browser/Interop.Runtime.cs @@ -98,7 +98,7 @@ public static void StopProfile() { } - // Called by the AOT profiler to save profile data into Module.aot_profile_data + // Called by the AOT profiler to save profile data into INTERNAL.aot_profile_data [MethodImplAttribute(MethodImplOptions.NoInlining)] public static unsafe void DumpAotProfileData(ref byte buf, int len, string extraArg) { diff --git a/src/libraries/Native/Unix/System.Native/pal_random.js b/src/libraries/Native/Unix/System.Native/pal_random.js index 8e7c7af05f131..c0bbc9c9f0f9e 100644 --- a/src/libraries/Native/Unix/System.Native/pal_random.js +++ b/src/libraries/Native/Unix/System.Native/pal_random.js @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -var DotNetEntropyLib = { +const DotNetEntropyLib = { $DOTNETENTROPY: { // batchedQuotaMax is the max number of bytes as specified by the api spec. // If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm. @@ -10,13 +10,13 @@ var DotNetEntropyLib = { getBatchedRandomValues: function (buffer, bufferLength) { // for modern web browsers // map the work array to the memory buffer passed with the length - for (var i = 0; i < bufferLength; i += this.batchedQuotaMax) { - var view = new Uint8Array(Module.HEAPU8.buffer, buffer + i, Math.min(bufferLength - i, this.batchedQuotaMax)); + for (let i = 0; i < bufferLength; i += this.batchedQuotaMax) { + const view = new Uint8Array(Module.HEAPU8.buffer, buffer + i, Math.min(bufferLength - i, this.batchedQuotaMax)); crypto.getRandomValues(view) } } }, - dotnet_browser_entropy : function (buffer, bufferLength) { + dotnet_browser_entropy: function (buffer, bufferLength) { // check that we have crypto available if (typeof crypto === 'object' && typeof crypto['getRandomValues'] === 'function') { DOTNETENTROPY.getBatchedRandomValues(buffer, bufferLength) diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs index b70e07511c485..101ce90eaa272 100644 --- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs +++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs @@ -283,7 +283,7 @@ public static void BindStaticMethod() { HelperMarshal._intValue = 0; Runtime.InvokeJS(@$" - var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); + var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); invoke_int (200); "); @@ -295,7 +295,7 @@ public static void BindIntPtrStaticMethod() { HelperMarshal._intPtrValue = IntPtr.Zero; Runtime.InvokeJS(@$" - var invoke_int_ptr = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeIntPtr""); + var invoke_int_ptr = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeIntPtr""); invoke_int_ptr (42); "); Assert.Equal(42, (int)HelperMarshal._intPtrValue); @@ -306,7 +306,7 @@ public static void MarshalIntPtrToJS() { HelperMarshal._marshaledIntPtrValue = IntPtr.Zero; Runtime.InvokeJS(@$" - var invokeMarshalIntPtr = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeMarshalIntPtr""); + var invokeMarshalIntPtr = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeMarshalIntPtr""); var r = invokeMarshalIntPtr (); if (r != 42) throw `Invalid int_ptr value`; @@ -319,7 +319,7 @@ public static void InvokeStaticMethod() { HelperMarshal._intValue = 0; Runtime.InvokeJS(@$" - Module.mono_call_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"", [ 300 ]); + INTERNAL.call_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt"", [ 300 ]); "); Assert.Equal(300, HelperMarshal._intValue); @@ -330,7 +330,7 @@ public static void ResolveMethod() { HelperMarshal._intValue = 0; Runtime.InvokeJS(@$" - var invoke_int = Module.mono_method_resolve (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); + var invoke_int = INTERNAL.mono_method_resolve (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); App.call_test_method (""InvokeInt"", [ invoke_int ]); "); @@ -629,7 +629,7 @@ public static void BoundStaticMethodMissingArgs() HelperMarshal._intValue = 1; Runtime.InvokeJS(@$" - var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); + var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); invoke_int (); "); Assert.Equal(0, HelperMarshal._intValue); @@ -640,7 +640,7 @@ public static void BoundStaticMethodExtraArgs() { HelperMarshal._intValue = 0; Runtime.InvokeJS(@$" - var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); + var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); invoke_int (200, 400); "); Assert.Equal(200, HelperMarshal._intValue); @@ -654,13 +654,13 @@ public static void BoundStaticMethodArgumentTypeCoercion() HelperMarshal._intValue = 0; Runtime.InvokeJS(@$" - var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); + var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); invoke_int (""200""); "); Assert.Equal(200, HelperMarshal._intValue); Runtime.InvokeJS(@$" - var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); + var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); invoke_int (400.5); "); Assert.Equal(400, HelperMarshal._intValue); @@ -671,14 +671,14 @@ public static void BoundStaticMethodUnpleasantArgumentTypeCoercion() { HelperMarshal._intValue = 100; Runtime.InvokeJS(@$" - var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); + var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); invoke_int (""hello""); "); Assert.Equal(0, HelperMarshal._intValue); // In this case at the very least, the leading "7" is not turned into the number 7 Runtime.InvokeJS(@$" - var invoke_int = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); + var invoke_int = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeInt""); invoke_int (""7apples""); "); Assert.Equal(0, HelperMarshal._intValue); @@ -689,7 +689,7 @@ public static void PassUintArgument() { HelperMarshal._uintValue = 0; Runtime.InvokeJS(@$" - var invoke_uint = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeUInt""); + var invoke_uint = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeUInt""); invoke_uint (0xFFFFFFFE); "); @@ -702,9 +702,9 @@ public static void ReturnUintEnum () HelperMarshal._uintValue = 0; HelperMarshal._enumValue = TestEnum.BigValue; Runtime.InvokeJS(@$" - var get_value = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}GetEnumValue""); + var get_value = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}GetEnumValue""); var e = get_value (); - var invoke_uint = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeUInt""); + var invoke_uint = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}InvokeUInt""); invoke_uint (e); "); Assert.Equal((uint)TestEnum.BigValue, HelperMarshal._uintValue); @@ -715,7 +715,7 @@ public static void PassUintEnumByValue () { HelperMarshal._enumValue = TestEnum.Zero; Runtime.InvokeJS(@$" - var set_enum = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}SetEnumValue"", ""j""); + var set_enum = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}SetEnumValue"", ""j""); set_enum (0xFFFFFFFE); "); Assert.Equal(TestEnum.BigValue, HelperMarshal._enumValue); @@ -728,7 +728,7 @@ public static void PassUintEnumByValueMasqueradingAsInt () // HACK: We're explicitly telling the bindings layer to pass an int here, not an enum // Because we know the enum is : uint, this is compatible, so it works. Runtime.InvokeJS(@$" - var set_enum = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}SetEnumValue"", ""i""); + var set_enum = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}SetEnumValue"", ""i""); set_enum (0xFFFFFFFE); "); Assert.Equal(TestEnum.BigValue, HelperMarshal._enumValue); @@ -740,7 +740,7 @@ public static void PassUintEnumByNameIsNotImplemented () HelperMarshal._enumValue = TestEnum.Zero; var exc = Assert.Throws( () => Runtime.InvokeJS(@$" - var set_enum = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}SetEnumValue"", ""j""); + var set_enum = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}SetEnumValue"", ""j""); set_enum (""BigValue""); ") ); @@ -752,7 +752,7 @@ public static void CannotUnboxUint64 () { var exc = Assert.Throws( () => Runtime.InvokeJS(@$" - var get_u64 = Module.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}GetUInt64"", """"); + var get_u64 = INTERNAL.mono_bind_static_method (""{HelperMarshal.INTEROP_CLASS}GetUInt64"", """"); var u64 = get_u64(); ") ); @@ -806,7 +806,7 @@ public static void ManuallyInternString() { HelperMarshal._stringResource = HelperMarshal._stringResource2 = null; Runtime.InvokeJS(@" - var sym = BINDING.mono_intern_string(""interned string 3""); + var sym = INTERNAL.mono_intern_string(""interned string 3""); App.call_test_method (""InvokeString"", [ sym ], ""s""); App.call_test_method (""InvokeString2"", [ sym ], ""s""); "); @@ -823,7 +823,7 @@ public static void LargeStringsAreNotAutomaticallyLocatedInInternTable() var s = ""long interned string""; for (var i = 0; i < 1024; i++) s += String(i % 10); - var sym = BINDING.mono_intern_string(s); + var sym = INTERNAL.mono_intern_string(s); App.call_test_method (""InvokeString"", [ sym ], ""S""); App.call_test_method (""InvokeString2"", [ sym ], ""s""); "); @@ -837,7 +837,7 @@ public static void CanInternVeryManyStrings() HelperMarshal._stringResource = null; Runtime.InvokeJS(@" for (var i = 0; i < 10240; i++) - BINDING.mono_intern_string('s' + i); + INTERNAL.mono_intern_string('s' + i); App.call_test_method (""InvokeString"", [ 's5000' ], ""S""); "); Assert.Equal("s5000", HelperMarshal._stringResource); @@ -864,8 +864,8 @@ public static void InternedStringReturnValuesWork() HelperMarshal._stringResource = HelperMarshal._stringResource2 = null; var fqn = "[System.Private.Runtime.InteropServices.JavaScript.Tests]System.Runtime.InteropServices.JavaScript.Tests.HelperMarshal:StoreArgumentAndReturnLiteral"; Runtime.InvokeJS( - $"var a = BINDING.bind_static_method('{fqn}')('test');\r\n" + - $"var b = BINDING.bind_static_method('{fqn}')(a);\r\n" + + $"var a = INTERNAL.mono_bind_static_method('{fqn}')('test');\r\n" + + $"var b = INTERNAL.mono_bind_static_method('{fqn}')(a);\r\n" + "App.call_test_method ('InvokeString2', [ b ]);" ); Assert.Equal("s: 1 length: 1", HelperMarshal._stringResource); diff --git a/src/mono/mono/component/mini-wasm-debugger.c b/src/mono/mono/component/mini-wasm-debugger.c index f70738d7cb0c1..77ceed873a245 100644 --- a/src/mono/mono/component/mini-wasm-debugger.c +++ b/src/mono/mono/component/mini-wasm-debugger.c @@ -68,8 +68,8 @@ void wasm_debugger_log (int level, const gchar *format, ...) var message = Module.UTF8ToString ($1); var namespace = "Debugger.Debug"; - if (MONO["logging"] && MONO.logging["debugger"]) { - MONO.logging.debugger (level, message); + if (INTERNAL["logging"] && INTERNAL.logging["debugger"]) { + INTERNAL.logging.debugger (level, message); return; } @@ -375,7 +375,7 @@ mono_wasm_send_dbg_command_with_parms (int id, MdbgProtCommandSet command_set, i m_dbgprot_buffer_add_data (&bufWithParms, data, size); if (!write_value_to_buffer(&bufWithParms, valtype, newvalue)) { EM_ASM ({ - MONO.mono_wasm_add_dbg_command_received ($0, $1, $2, $3); + INTERNAL.mono_wasm_add_dbg_command_received ($0, $1, $2, $3); }, 0, id, 0, 0); return TRUE; } @@ -403,7 +403,7 @@ mono_wasm_send_dbg_command (int id, MdbgProtCommandSet command_set, int command, else error = mono_process_dbg_packet (id, command_set, command, &no_reply, data, data + size, &buf); EM_ASM ({ - MONO.mono_wasm_add_dbg_command_received ($0, $1, $2, $3); + INTERNAL.mono_wasm_add_dbg_command_received ($0, $1, $2, $3); }, error == MDBGPROT_ERR_NONE, id, buf.buf, buf.p-buf.buf); buffer_free (&buf); @@ -414,7 +414,7 @@ static gboolean receive_debugger_agent_message (void *data, int len) { EM_ASM ({ - MONO.mono_wasm_add_dbg_command_received (1, -1, $0, $1); + INTERNAL.mono_wasm_add_dbg_command_received (1, -1, $0, $1); }, data, len); mono_wasm_save_thread_context(); mono_wasm_fire_debugger_agent_message (); diff --git a/src/mono/sample/mbr/browser/index.html b/src/mono/sample/mbr/browser/index.html index eb19b7bb2f595..6122370dd9d65 100644 --- a/src/mono/sample/mbr/browser/index.html +++ b/src/mono/sample/mbr/browser/index.html @@ -18,12 +18,12 @@ init: function () { var outElement = document.getElementById("out"); document.getElementById("update").addEventListener("click", function () { - BINDING.call_static_method("[WasmDelta] Sample.Test:Update", []); + INTERNAL.call_static_method("[WasmDelta] Sample.Test:Update", []); console.log ("applied update"); - var ret = BINDING.call_static_method("[WasmDelta] Sample.Test:TestMeaning", []); + var ret = INTERNAL.call_static_method("[WasmDelta] Sample.Test:TestMeaning", []); outElement.innerHTML = ret; }) - var ret = BINDING.call_static_method("[WasmDelta] Sample.Test:TestMeaning", []); + var ret = INTERNAL.call_static_method("[WasmDelta] Sample.Test:TestMeaning", []); outElement.innerHTML = ret; console.log ("ready"); }, diff --git a/src/mono/sample/mbr/browser/runtime.js b/src/mono/sample/mbr/browser/runtime.js index 41989feb6a547..0252041eff5ac 100644 --- a/src/mono/sample/mbr/browser/runtime.js +++ b/src/mono/sample/mbr/browser/runtime.js @@ -2,30 +2,30 @@ // The .NET Foundation licenses this file to you under the MIT license. "use strict"; -var Module = { +var Module = { config: null, - preInit: async function() { - await MONO.mono_wasm_load_config("./mono-config.json"); // sets Module.config implicitly + preInit: async function () { + await MONO.mono_wasm_load_config("./mono-config.json"); // sets MONO.config implicitly }, // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { - if (!Module.config || Module.config.error) { + if (!MONO.config || MONO.config.error) { console.log("An error occured while loading the config file"); return; } - Module.config.loaded_cb = function () { - App.init (); + MONO.config.loaded_cb = function () { + App.init(); }; - Module.config.environment_variables = { + MONO.config.environment_variables = { "DOTNET_MODIFIABLE_ASSEMBLIES": "debug" }; - Module.config.fetch_file_cb = function (asset) { - return fetch (asset, { credentials: 'same-origin' }); + MONO.config.fetch_file_cb = function (asset) { + return fetch(asset, { credentials: 'same-origin' }); } - MONO.mono_load_runtime_and_bcl_args (Module.config); + MONO.mono_load_runtime_and_bcl_args(MONO.config); }, }; diff --git a/src/mono/sample/wasm/browser-bench/index.html b/src/mono/sample/wasm/browser-bench/index.html index 6b26090c6dddf..136e400e70c2a 100644 --- a/src/mono/sample/wasm/browser-bench/index.html +++ b/src/mono/sample/wasm/browser-bench/index.html @@ -37,7 +37,7 @@ }; function yieldBench () { - let promise = BINDING.call_static_method("[Wasm.Browser.Bench.Sample] Sample.Test:RunBenchmark", []); + let promise = INTERNAL.call_static_method("[Wasm.Browser.Bench.Sample] Sample.Test:RunBenchmark", []); promise.then(ret => { document.getElementById("out").innerHTML += ret; if (ret.length > 0) { @@ -52,7 +52,7 @@ var App = { init: function () { if (tasks != '') - BINDING.call_static_method("[Wasm.Browser.Bench.Sample] Sample.Test:SetTasks", tasks); + INTERNAL.call_static_method("[Wasm.Browser.Bench.Sample] Sample.Test:SetTasks", tasks); yieldBench (); } }; diff --git a/src/mono/sample/wasm/browser-bench/runtime.js b/src/mono/sample/wasm/browser-bench/runtime.js index 87fb6436dbc1d..2d934c659ea13 100644 --- a/src/mono/sample/wasm/browser-bench/runtime.js +++ b/src/mono/sample/wasm/browser-bench/runtime.js @@ -2,46 +2,44 @@ // The .NET Foundation licenses this file to you under the MIT license. "use strict"; -var Module = { +var Module = { config: null, - preInit: async function() { - await MONO.mono_wasm_load_config("./mono-config.json"); // sets Module.config implicitly + preInit: async function () { + await MONO.mono_wasm_load_config("./mono-config.json"); // sets MONO.config implicitly }, // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { - if (!Module.config || Module.config.error) { + if (!MONO.config || MONO.config.error) { console.log("An error occured while loading the config file"); return; } - Module.config.loaded_cb = function () { + MONO.config.loaded_cb = function () { try { - App.init (); + App.init(); } catch (error) { test_exit(1); throw (error); } }; - Module.config.fetch_file_cb = function (asset) { - return fetch (asset, { credentials: 'same-origin' }); + MONO.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", + if (MONO.config.enable_profiler) { + MONO.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 (Module.config); + try { + MONO.mono_load_runtime_and_bcl_args(MONO.config); } catch (error) { test_exit(1); - throw(error); + throw (error); } }, }; diff --git a/src/mono/sample/wasm/browser-profile/README.md b/src/mono/sample/wasm/browser-profile/README.md index 1e2981be112f7..26afb1386711b 100644 --- a/src/mono/sample/wasm/browser-profile/README.md +++ b/src/mono/sample/wasm/browser-profile/README.md @@ -27,16 +27,16 @@ var Module = { 3. Call the `write_at` method at the end of the app, either in C# or in JS. To call the `write_at` method in JS, make use of bindings: -`BINDING.call_static_method("<[ProjectName] Namespace.Class::StopProfile">, []);` +`INTERNAL.call_static_method("<[ProjectName] Namespace.Class::StopProfile">, []);` -When the `write_at` method is called, the `send_to` method `DumpAotProfileData` stores the profile data into `Module.aot_profile_data` +When the `write_at` method is called, the `send_to` method `DumpAotProfileData` stores the profile data into `INTERNAL.aot_profile_data` -4. Download `Module.aot_profile_data` in JS, using something similar to: +4. Download `INTERNAL.aot_profile_data` in JS, using something similar to: ``` function saveProfile() { var a = document.createElement('a'); - var blob = new Blob([Module.aot_profile_data]); + var blob = new Blob([INTERNAL.aot_profile_data]); a.href = URL.createObjectURL(blob); a.download = "data.aotprofile"; // Append anchor to body. diff --git a/src/mono/sample/wasm/browser-profile/runtime.js b/src/mono/sample/wasm/browser-profile/runtime.js index cd0dd0cb9ed32..69b84d002bb8d 100644 --- a/src/mono/sample/wasm/browser-profile/runtime.js +++ b/src/mono/sample/wasm/browser-profile/runtime.js @@ -2,22 +2,22 @@ // The .NET Foundation licenses this file to you under the MIT license. "use strict"; -var Module = { +var Module = { is_testing: false, config: null, - preInit: async function() { - await MONO.mono_wasm_load_config("./mono-config.json"); // sets Module.config implicitly + preInit: async function () { + await MONO.mono_wasm_load_config("./mono-config.json"); // sets MONO.config implicitly }, // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { - if (!Module.config || Module.config.error) { + if (!MONO.config || MONO.config.error) { console.log("An error occured while loading the config file"); return; } - Module.config.loaded_cb = function () { + MONO.config.loaded_cb = function () { try { Module.init(); } catch (error) { @@ -25,70 +25,67 @@ var Module = { throw (error); } }; - Module.config.fetch_file_cb = function (asset) { - return fetch (asset, { credentials: 'same-origin' }); + MONO.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", + if (MONO.config.enable_profiler) { + MONO.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 (Module.config); + try { + MONO.mono_load_runtime_and_bcl_args(MONO.config); } catch (error) { Module.test_exit(1); - throw(error); + throw (error); } }, init: function () { console.log("not ready yet") - var ret = BINDING.call_static_method("[Wasm.BrowserProfile.Sample] Sample.Test:TestMeaning", []); + const ret = INTERNAL.call_static_method("[Wasm.BrowserProfile.Sample] Sample.Test:TestMeaning", []); document.getElementById("out").innerHTML = ret; - console.log ("ready"); + 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.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(); + if (MONO.config.enable_profiler) { + INTERNAL.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'); + onLoad: function () { + const url = new URL(decodeURI(window.location)); + const args = url.searchParams.getAll('arg'); Module.is_testing = args !== undefined && (args.find(arg => arg == '--testing') !== undefined); }, - - test_exit: function(exit_code) { + + 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"); + const 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]); + const a = document.createElement('a'); + const blob = new Blob([INTERNAL.aot_profile_data]); a.href = URL.createObjectURL(blob); a.download = "data.aotprofile"; // Append anchor to body. diff --git a/src/mono/sample/wasm/browser/index.html b/src/mono/sample/wasm/browser/index.html index 5f170bb38e7bc..cedcae5715afb 100644 --- a/src/mono/sample/wasm/browser/index.html +++ b/src/mono/sample/wasm/browser/index.html @@ -36,7 +36,7 @@ var App = { init: function () { - var ret = BINDING.call_static_method("[Wasm.Browser.Sample] Sample.Test:TestMeaning", []); + var ret = INTERNAL.call_static_method("[Wasm.Browser.Sample] Sample.Test:TestMeaning", []); document.getElementById("out").innerHTML = ret; if (is_testing) diff --git a/src/mono/sample/wasm/browser/runtime.js b/src/mono/sample/wasm/browser/runtime.js index 904ca19958f76..8b14c3637e6b4 100644 --- a/src/mono/sample/wasm/browser/runtime.js +++ b/src/mono/sample/wasm/browser/runtime.js @@ -2,39 +2,38 @@ // The .NET Foundation licenses this file to you under the MIT license. "use strict"; -var Module = { +var Module = { config: null, - preInit: async function() { - await MONO.mono_wasm_load_config("./mono-config.json"); // sets Module.config implicitly + preInit: async function () { + await MONO.mono_wasm_load_config("./mono-config.json"); // sets MONO.config implicitly }, // Called when the runtime is initialized and wasm is ready onRuntimeInitialized: function () { - if (!Module.config || Module.config.error) { + if (!MONO.config || MONO.config.error) { console.log("No config found"); return; } - Module.config.loaded_cb = function () { + MONO.config.loaded_cb = function () { try { - App.init (); + App.init(); } catch (error) { test_exit(1); throw (error); } }; - Module.config.fetch_file_cb = function (asset) { - return fetch (asset, { credentials: 'same-origin' }); + MONO.config.fetch_file_cb = function (asset) { + return fetch(asset, { credentials: 'same-origin' }); } - try - { - MONO.mono_load_runtime_and_bcl_args (Module.config); + try { + MONO.mono_load_runtime_and_bcl_args(MONO.config); } catch (error) { test_exit(1); - throw(error); + throw (error); } }, }; diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs index 950acbb2dcf91..97acfe9517d4e 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs @@ -172,33 +172,31 @@ internal class MonoCommands public MonoCommands(string expression) => this.expression = expression; - public static MonoCommands GetExceptionObject() => new MonoCommands("MONO.mono_wasm_get_exception_object()"); + public static MonoCommands GetDebuggerAgentBufferReceived() => new MonoCommands("INTERNAL.mono_wasm_get_dbg_command_info()"); - public static MonoCommands GetDebuggerAgentBufferReceived() => new MonoCommands("MONO.mono_wasm_get_dbg_command_info()"); + public static MonoCommands IsRuntimeReady() => new MonoCommands("INTERNAL.mono_wasm_runtime_is_ready"); - public static MonoCommands IsRuntimeReady() => new MonoCommands("MONO.mono_wasm_runtime_is_ready"); - - public static MonoCommands GetLoadedFiles() => new MonoCommands("MONO.mono_wasm_get_loaded_files()"); + public static MonoCommands GetLoadedFiles() => new MonoCommands("INTERNAL.mono_wasm_get_loaded_files()"); public static MonoCommands SendDebuggerAgentCommand(int id, int command_set, int command, string command_parameters) { - return new MonoCommands($"MONO.mono_wasm_send_dbg_command ({id}, {command_set}, {command},'{command_parameters}')"); + return new MonoCommands($"INTERNAL.mono_wasm_send_dbg_command ({id}, {command_set}, {command},'{command_parameters}')"); } public static MonoCommands SendDebuggerAgentCommandWithParms(int id, int command_set, int command, string command_parameters, int len, int type, string parm) { - return new MonoCommands($"MONO.mono_wasm_send_dbg_command_with_parms ({id}, {command_set}, {command},'{command_parameters}', {len}, {type}, '{parm}')"); + return new MonoCommands($"INTERNAL.mono_wasm_send_dbg_command_with_parms ({id}, {command_set}, {command},'{command_parameters}', {len}, {type}, '{parm}')"); } - public static MonoCommands CallFunctionOn(JToken args) => new MonoCommands($"MONO.mono_wasm_call_function_on ({args.ToString()})"); + public static MonoCommands CallFunctionOn(JToken args) => new MonoCommands($"INTERNAL.mono_wasm_call_function_on ({args})"); - public static MonoCommands GetDetails(int objectId, JToken args = null) => new MonoCommands($"MONO.mono_wasm_get_details ({objectId}, {(args ?? "{ }")})"); + public static MonoCommands GetDetails(int objectId, JToken args = null) => new MonoCommands($"INTERNAL.mono_wasm_get_details ({objectId}, {(args ?? "{ }")})"); - public static MonoCommands Resume() => new MonoCommands($"MONO.mono_wasm_debugger_resume ()"); + public static MonoCommands Resume() => new MonoCommands($"INTERNAL.mono_wasm_debugger_resume ()"); - public static MonoCommands DetachDebugger() => new MonoCommands($"MONO.mono_wasm_detach_debugger()"); + public static MonoCommands DetachDebugger() => new MonoCommands($"INTERNAL.mono_wasm_detach_debugger()"); - public static MonoCommands ReleaseObject(DotnetObjectId objectId) => new MonoCommands($"MONO.mono_wasm_release_object('{objectId}')"); + public static MonoCommands ReleaseObject(DotnetObjectId objectId) => new MonoCommands($"INTERNAL.mono_wasm_release_object('{objectId}')"); } internal enum MonoErrorCodes diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs index 6e9d420801dd9..ecd9070a8e21d 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs @@ -35,7 +35,7 @@ public async Task CreateJSBreakpoint() { // Test that js breakpoints get set correctly // 13 24 - // 13 31 + // 13 33 var bp1_res = await SetBreakpoint("/debugger-driver.html", 13, 24); Assert.EndsWith("debugger-driver.html", bp1_res.Value["breakpointId"].ToString()); @@ -47,7 +47,7 @@ public async Task CreateJSBreakpoint() Assert.Equal(13, loc["lineNumber"]); Assert.Equal(24, loc["columnNumber"]); - var bp2_res = await SetBreakpoint("/debugger-driver.html", 13, 31); + var bp2_res = await SetBreakpoint("/debugger-driver.html", 13, 33); Assert.EndsWith("debugger-driver.html", bp2_res.Value["breakpointId"].ToString()); Assert.Equal(1, bp2_res.Value["locations"]?.Value()?.Count); @@ -56,14 +56,14 @@ public async Task CreateJSBreakpoint() Assert.NotNull(loc2["scriptId"]); Assert.Equal(13, loc2["lineNumber"]); - Assert.Equal(31, loc2["columnNumber"]); + Assert.Equal(33, loc2["columnNumber"]); } [Fact] public async Task CreateJS0Breakpoint() { // 13 24 - // 13 31 + // 13 33 var bp1_res = await SetBreakpoint("/debugger-driver.html", 13, 0); Assert.EndsWith("debugger-driver.html", bp1_res.Value["breakpointId"].ToString()); @@ -75,7 +75,7 @@ public async Task CreateJS0Breakpoint() Assert.Equal(13, loc["lineNumber"]); Assert.Equal(24, loc["columnNumber"]); - var bp2_res = await SetBreakpoint("/debugger-driver.html", 13, 31); + var bp2_res = await SetBreakpoint("/debugger-driver.html", 13, 33); Assert.EndsWith("debugger-driver.html", bp2_res.Value["breakpointId"].ToString()); Assert.Equal(1, bp2_res.Value["locations"]?.Value()?.Count); @@ -84,7 +84,7 @@ public async Task CreateJS0Breakpoint() Assert.NotNull(loc2["scriptId"]); Assert.Equal(13, loc2["lineNumber"]); - Assert.Equal(31, loc2["columnNumber"]); + Assert.Equal(33, loc2["columnNumber"]); } [Theory] diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs b/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs index 7e78bc0e2b64c..bd92af72637ad 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs @@ -41,7 +41,12 @@ protected static string DebuggerTestAppPath static protected string FindTestPath() { var asm_dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - var test_app_path = Path.Combine(asm_dir, "..", "..", "..", "debugger-test", "Debug", "publish"); +#if DEBUG + var config="Debug"; +#else + var config="Release"; +#endif + var test_app_path = Path.Combine(asm_dir, "..", "..", "..", "debugger-test", config, "publish"); if (File.Exists(Path.Combine(test_app_path, "debugger-driver.html"))) return test_app_path; diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/MonoJsTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/MonoJsTests.cs index b45825acfcbd8..38742d8d36330 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/MonoJsTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/MonoJsTests.cs @@ -13,41 +13,17 @@ namespace DebuggerTests { public class MonoJsTests : DebuggerTestBase { - [Fact] - public async Task InvalidScopeId() - { - var bp1_res = await SetBreakpointInMethod("debugger-test.dll", "Math", "IntAdd", 3); - await EvaluateAndCheck( - "window.setTimeout(function() { invoke_static_method('[debugger-test] Math:IntAdd', 1, 2); })", - null, -1, -1, "IntAdd"); - - var varIds = new[] - { - new { index = 0, name = "one" }, - }; - - var scopeId = "-12"; - var expression = $"MONO.mono_wasm_get_variables({scopeId}, {JsonConvert.SerializeObject(varIds)})"; - var res = await cli.SendCommand($"Runtime.evaluate", JObject.FromObject(new { expression, returnByValue = true }), token); - Assert.False(res.IsOk); - - scopeId = "30000"; - expression = $"MONO.mono_wasm_get_variables({scopeId}, {JsonConvert.SerializeObject(varIds)})"; - res = await cli.SendCommand($"Runtime.evaluate", JObject.FromObject(new { expression, returnByValue = true }), token); - Assert.False(res.IsOk); - } - [Fact] public async Task BadRaiseDebugEventsTest() { var bad_expressions = new[] { - "MONO.mono_wasm_raise_debug_event('')", - "MONO.mono_wasm_raise_debug_event(undefined)", - "MONO.mono_wasm_raise_debug_event({})", + "INTERNAL.mono_wasm_raise_debug_event('')", + "INTERNAL.mono_wasm_raise_debug_event(undefined)", + "INTERNAL.mono_wasm_raise_debug_event({})", - "MONO.mono_wasm_raise_debug_event({eventName:'foo'}, '')", - "MONO.mono_wasm_raise_debug_event({eventName:'foo'}, 12)" + "INTERNAL.mono_wasm_raise_debug_event({eventName:'foo'}, '')", + "INTERNAL.mono_wasm_raise_debug_event({eventName:'foo'}, 12)" }; foreach (var expression in bad_expressions) @@ -82,7 +58,7 @@ public async Task RaiseDebugEventTraceTest(bool? trace) }); var trace_str = trace.HasValue ? $"trace: {trace.ToString().ToLower()}" : String.Empty; - var expression = $"MONO.mono_wasm_raise_debug_event({{ eventName:'qwe' }}, {{ {trace_str} }})"; + var expression = $"INTERNAL.mono_wasm_raise_debug_event({{ eventName:'qwe' }}, {{ {trace_str} }})"; var res = await cli.SendCommand($"Runtime.evaluate", JObject.FromObject(new { expression }), token); Assert.True(res.IsOk, $"Expected to pass for {expression}"); @@ -163,7 +139,7 @@ async Task AssemblyLoadedEventTest(string asm_name, string asm_path, string pdb_ pdb_base64 = Convert.ToBase64String(bytes); } - var expression = $@"MONO.mono_wasm_raise_debug_event({{ + var expression = $@"INTERNAL.mono_wasm_raise_debug_event({{ eventName: 'AssemblyLoaded', assembly_name: '{asm_name}', assembly_b64: '{asm_base64}', 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 b1bfcd859d064..8f6902ca0f0de 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html @@ -6,14 +6,14 @@