From cac5de8b4078f696ed1a060a040ad0b8b9430484 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Wed, 7 Dec 2022 13:07:54 +0100 Subject: [PATCH] fix --- .../InteropServices/JavaScript/JSImportExportTest.cs | 8 ++++++++ .../InteropServices/JavaScript/JavaScriptTestHelper.cs | 4 ++++ .../InteropServices/JavaScript/JavaScriptTestHelper.mjs | 4 ++++ src/mono/wasm/runtime/marshal-to-cs.ts | 4 +--- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs index ace5417364514e..48f39d3254bc87 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs @@ -1390,6 +1390,14 @@ public void JsExportThrows() Assert.Contains("-t-e-s-t-", ex.Message); } + [Fact] + public void JSImportReturnError() + { + var err = JavaScriptTestHelper.returnError() as Exception; + Assert.NotNull(err); + Assert.Contains("this-is-error", err.Message); + } + [Fact] public void JsExportCatchToString() { diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs index 7847d75bfe3945..940c3a50ea6dd3 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs @@ -109,6 +109,10 @@ public static int Optimized2R(int a1, int a2) [return: JSMarshalAs] internal static partial void throw0(); + [JSImport("returnError", "JavaScriptTestHelper")] + [return: JSMarshalAs] + internal static partial object returnError(); + [JSImport("echo1", "JavaScriptTestHelper")] [return: JSMarshalAs>] internal static partial Task echo1_Task([JSMarshalAs>] Task arg1); diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs index 39248f53544f20..f6681f203b6409 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs @@ -110,6 +110,10 @@ export function throw0fn() { throw new Error('throw-0-msg'); } +export function returnError() { + return new Error('this-is-error'); +} + export function catch1toString(message, functionName) { const JavaScriptTestHelper = dllExports.System.Runtime.InteropServices.JavaScript.Tests.JavaScriptTestHelper; const fn = JavaScriptTestHelper[functionName]; diff --git a/src/mono/wasm/runtime/marshal-to-cs.ts b/src/mono/wasm/runtime/marshal-to-cs.ts index 9b3b05d8b558de..a3a3b9f232b46f 100644 --- a/src/mono/wasm/runtime/marshal-to-cs.ts +++ b/src/mono/wasm/runtime/marshal-to-cs.ts @@ -386,9 +386,7 @@ function _marshal_cs_object_to_cs(arg: JSMarshalerArgument, value: any): void { set_arg_date(arg, value); } else if (value instanceof Error) { - set_arg_type(arg, MarshalerType.JSException); - const js_handle = mono_wasm_get_js_handle(value); - set_js_handle(arg, js_handle); + marshal_exception_to_cs(arg, value); } else if (value instanceof Uint8Array) { marshal_array_to_cs_impl(arg, value, MarshalerType.Byte);