Skip to content

Commit

Permalink
[wasm] fix marshaling Error to C# as JSType.Any (#79352)
Browse files Browse the repository at this point in the history
Co-authored-by: pavelsavara <pavel.savara@gmail.com>
  • Loading branch information
github-actions[bot] and pavelsavara committed Jan 4, 2023
1 parent d5f6805 commit b65e78a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,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 @@ -67,6 +67,10 @@ public static DateTime Now()
[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 @@ -449,9 +449,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

0 comments on commit b65e78a

Please sign in to comment.