Skip to content

[wasm] fix marshaling Error to C# as JSType.Any #79340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ public static int Optimized2R(int a1, int a2)
[return: JSMarshalAs<JSType.Discard>]
internal static partial void throw0();

[JSImport("returnError", "JavaScriptTestHelper")]
[return: JSMarshalAs<JSType.Any>]
internal static partial object returnError();

[JSImport("echo1", "JavaScriptTestHelper")]
[return: JSMarshalAs<JSType.Promise<JSType.Void>>]
internal static partial Task echo1_Task([JSMarshalAs<JSType.Promise<JSType.Void>>] Task arg1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 1 addition & 3 deletions src/mono/wasm/runtime/marshal-to-cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down