From 01a7f462fc11f1dda07b3abb0547683b344cc155 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 11 Jul 2022 23:33:21 +0200 Subject: [PATCH 1/2] protect class names from mangling --- src/mono/wasm/runtime/dotnet.d.ts | 2 +- src/mono/wasm/runtime/marshal.ts | 8 ++++---- src/mono/wasm/runtime/rollup.config.js | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mono/wasm/runtime/dotnet.d.ts b/src/mono/wasm/runtime/dotnet.d.ts index dd58eb3e3f29fd..4b0d7826fde5e3 100644 --- a/src/mono/wasm/runtime/dotnet.d.ts +++ b/src/mono/wasm/runtime/dotnet.d.ts @@ -392,7 +392,7 @@ declare class ManagedError extends Error implements IDisposable { get isDisposed(): boolean; toString(): string; } -declare enum MemoryViewType { +declare const enum MemoryViewType { Byte = 0, Int32 = 1, Double = 2 diff --git a/src/mono/wasm/runtime/marshal.ts b/src/mono/wasm/runtime/marshal.ts index 9a5e6a6dd63288..7df0c232693be9 100644 --- a/src/mono/wasm/runtime/marshal.ts +++ b/src/mono/wasm/runtime/marshal.ts @@ -364,10 +364,10 @@ export function array_element_size(element_type: MarshalerType): number { : -1; } -export enum MemoryViewType { - Byte, - Int32, - Double, +export const enum MemoryViewType { + Byte = 0, + Int32 = 1, + Double = 2, } abstract class MemoryView implements IMemoryView, IDisposable { diff --git a/src/mono/wasm/runtime/rollup.config.js b/src/mono/wasm/runtime/rollup.config.js index 10228fd3838c4b..d8721129c82412 100644 --- a/src/mono/wasm/runtime/rollup.config.js +++ b/src/mono/wasm/runtime/rollup.config.js @@ -40,6 +40,7 @@ const terserConfig = { // because of stack walk at src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs // and unit test at src\libraries\System.Private.Runtime.InteropServices.JavaScript\tests\timers.js keep_fnames: /(mono_wasm_runtime_ready|mono_wasm_fire_debugger_agent_message|mono_wasm_set_timeout_exec)/, + keep_classnames: /(ManagedObject|ManagedError|Span|ArraySegment|WasmRootBuffer|SessionOptionsBuilder)/, }, }; const plugins = isDebug ? [writeOnChangePlugin()] : [terser(terserConfig), writeOnChangePlugin()]; From c2493ee4ad737485e119e26dac38923cffbca3b9 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Mon, 11 Jul 2022 21:42:19 +0000 Subject: [PATCH 2/2] [wasm] Fix `JSImportExportTest.JsImportObjectArray` .. failing as: ``` [09:26:02] fail: [FAIL] System.Runtime.InteropServices.JavaScript.Tests.JSImportExportTest.JsImportObjectArray [09:26:02] info: System.Runtime.InteropServices.JavaScript.JSException : Error: Assert failed: ES6 module JavaScriptTestHelper was not imported yet, please call JSHost.Import() first. [09:26:02] info: at mono_wasm_lookup_function (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:3:131530) [09:26:02] info: at Object.mono_wasm_bind_js_function (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:3:129592) [09:26:02] info: at _mono_wasm_bind_js_function (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:12:103196) [09:26:02] info: at do_icall (do_icall (:wasm-function[320]):0x1d48)e [09:26:02] info: at do_icall_wrapper (do_icall_wrapper (:wasm-function[290]):0x1c89)3 [09:26:02] info: at interp_exec_method (interp_exec_method (:wasm-function[228]):0xe11)9 [09:26:02] info: at interp_runtime_invoke (interp_runtime_invoke (:wasm-function[227]):0xcfe)5 [09:26:02] info: at mono_jit_runtime_invoke (mono_jit_runtime_invoke (:wasm-function[8109]):0x1a141)9 [09:26:02] info: at do_runtime_invoke (do_runtime_invoke (:wasm-function[2050]):0x84c9)3 [09:26:02] info: at mono_runtime_try_invoke (mono_runtime_try_invoke (:wasm-function[2055]):0x852f)b [09:26:02] info: at mono_runtime_invoke (mono_runtime_invoke (:wasm-function[2082]):0x873b)a [09:26:02] info: at mono_wasm_invoke_method_ref (mono_wasm_invoke_method_ref (:wasm-function[121]):0x9ce0) [09:26:02] info: at Module._mono_wasm_invoke_method_ref (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:12:125660) [09:26:02] info: at Object.t. (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:3:5668) [09:26:02] info: at _call_method_with_converted_args (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:3:68736) [09:26:02] info: at call_method_ref (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:3:67909) [09:26:02] info: at /datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:3:69762 [09:26:02] info: at mono_call_assembly_entry_point (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:3:69894) [09:26:02] info: at Object.mono_run_main (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:3:78650) [09:26:02] info: at Object.init (test-main.js:495:47) [09:26:02] info: at Object.onDotnetReady (test-main.js:439:17) [09:26:02] info: at finalize_startup (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:3:120653) [09:26:02] info: at mono_wasm_after_runtime_initialized (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:3:116586) [09:26:02] info: at callRuntimeCallbacks (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:12:16200) [09:26:02] info: at postRun (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:12:12076) [09:26:02] info: at doRun (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:12:144539) [09:26:02] info: at run (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:12:144696) [09:26:02] info: at runCaller (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:12:144176) [09:26:02] info: at removeRunDependency (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:12:12868) [09:26:02] info: at receiveInstance (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:12:14757) [09:26:02] info: at receiveInstantiationResult (/datadisks/disk1/work/98BF08F2/w/A36B0892/e/dotnet.js:12:14878) [09:26:02] info: at System.Runtime.InteropServices.JavaScript.JSFunctionBinding.BindJSFunctionImpl(String functionName, String moduleName, ReadOnlySpan`1 signatures) [09:26:02] info: at System.Runtime.InteropServices.JavaScript.JSFunctionBinding.BindJSFunction(String functionName, String moduleName, ReadOnlySpan`1 signatures) [09:26:02] info: at System.Runtime.InteropServices.JavaScript.Tests.JavaScriptTestHelper.createData(String name) [09:26:02] info: at System.Runtime.InteropServices.JavaScript.Tests.JSImportExportTest.MarshalObjectArrayCases()+MoveNext() [09:26:02] info: at System.Linq.Enumerable.SelectEnumerableIterator`2[[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object[], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext() ``` This is because the xunit is enumerating the member data before the static `InitializeAsync` has completed. And this member data calls `JavaScriptTestHelper.createData("test")` before we are ready. Fixes https://github.com/dotnet/runtime/issues/71952 . --- .../JavaScript/JSImportExportTest.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs index b2595736311a48..e6de590b85e08b 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs @@ -253,7 +253,7 @@ public static IEnumerable MarshalObjectArrayCases() yield return new object[] { new object[] { 1.1d, new DateTime(2022, 5, 8, 14, 55, 01, DateTimeKind.Utc), false, true } }; yield return new object[] { new object[] { new double?(1.1d), new DateTime?(new DateTime(2022, 5, 8, 14, 55, 01, DateTimeKind.Utc)), new bool?(false), new bool?(true) } }; yield return new object[] { new object[] { null, new object(), new SomethingRef(), new SomethingStruct(), new Exception("test") } }; - yield return new object[] { new object[] { JavaScriptTestHelper.createData("test"), JavaScriptTestHelper.createException("test") } }; + yield return new object[] { new object[] { "JSData" } }; // special cased, so we call createData in the test itself yield return new object[] { new object[] { new byte[] { }, new int[] { }, new double[] { }, new string[] { }, new object[] { } } }; yield return new object[] { new object[] { new byte[] { 1, 2, 3 }, new int[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new string[] { "a", "b", "c" }, new object[] { } } }; yield return new object[] { new object[] { new object[] { new byte[] { 1, 2, 3 }, new int[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new string[] { "a", "b", "c" } , new object(), new SomethingRef(), new SomethingStruct(), new Exception("test") } } }; @@ -265,15 +265,18 @@ public static IEnumerable MarshalObjectArrayCases() [MemberData(nameof(MarshalObjectArrayCases))] public unsafe void JsImportObjectArray(object[]? expected) { + if (expected?.Length == 1 && expected[0] is string s && s == "JSData") + { + expected = new object[] { new object[] { JavaScriptTestHelper.createData("test"), JavaScriptTestHelper.createException("test") } }; + } var actual = JavaScriptTestHelper.echo1_ObjectArray(expected); Assert.Equal(expected, actual); - if (expected != null) for (int i = 0; i < expected.Length; i++) - { - var actualI = JavaScriptTestHelper.store_ObjectArray(expected, i); - Assert.Equal(expected[i], actualI); - } + { + var actualI = JavaScriptTestHelper.store_ObjectArray(expected, i); + Assert.Equal(expected[i], actualI); + } } public static IEnumerable MarshalObjectArrayCasesToDouble()