Skip to content

Commit

Permalink
[wasm] few JS interop tests (#77218)
Browse files Browse the repository at this point in the history
* new JS interop tests
Co-authored-by: Marek Fišera <mara@neptuo.com>
Co-authored-by: Ankit Jain <radical@gmail.com>
  • Loading branch information
pavelsavara authored Oct 20, 2022
1 parent 88aea31 commit 9674537
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,18 @@ public async Task JsImportSleep()
await JavaScriptTestHelper.sleep(100);
}

[Fact]
public async Task JsImportTaskTypes()
{
object a = new object();
Exception e = new Exception();
JSObject j = JSHost.GlobalThis;
Assert.Equal("test", await JavaScriptTestHelper.echopromise_String("test"));
Assert.Same(a, await JavaScriptTestHelper.echopromise_Object(a));
Assert.Same(e, await JavaScriptTestHelper.echopromise_Exception(e));
Assert.Same(j, await JavaScriptTestHelper.echopromise_JSObject(j));
}

[Fact]
public async Task JsImportThenVoid()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ public static string EchoString([JSMarshalAs<JSType.String>] string arg1)
{
return arg1;
}

[JSImport("echopromise", "JavaScriptTestHelper")]
[return: JSMarshalAs<JSType.Promise<JSType.String>>]
internal static partial Task<string> echopromise_String([JSMarshalAs<JSType.String>] string value);
#endregion String

#region Object
Expand All @@ -333,6 +337,10 @@ public static object EchoObject([JSMarshalAs<JSType.Any>] object arg1)
{
return arg1;
}

[JSImport("echopromise", "JavaScriptTestHelper")]
[return: JSMarshalAs<JSType.Promise<JSType.Any>>]
internal static partial Task<object> echopromise_Object([JSMarshalAs<JSType.Any>] object value);
#endregion Object

#region Exception
Expand All @@ -359,6 +367,9 @@ public static Exception EchoException([JSMarshalAs<JSType.Error>] Exception arg1
{
return arg1;
}
[JSImport("echopromise", "JavaScriptTestHelper")]
[return: JSMarshalAs<JSType.Promise<JSType.Error>>]
internal static partial Task<Exception> echopromise_Exception([JSMarshalAs<JSType.Error>] Exception value);
#endregion Exception

#region Task
Expand Down Expand Up @@ -967,6 +978,10 @@ public static JSObject EchoIJSObject([JSMarshalAs<JSType.Object>] JSObject arg1)
{
return arg1;
}

[JSImport("echopromise", "JavaScriptTestHelper")]
[return: JSMarshalAs<JSType.Promise<JSType.Object>>]
internal static partial Task<JSObject> echopromise_JSObject([JSMarshalAs<JSType.Object>] JSObject value);
#endregion JSObject

[JSImport("setup", "JavaScriptTestHelper")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ export function invokeStructClassRecords(arg1) {
];
}

export function echopromise(arg1) {
return new Promise(resolve => setTimeout(() => resolve(arg1), 0));
}

export async function awaitvoid(arg1) {
// console.log("awaitvoid:" + typeof arg1);
await arg1;
Expand Down

0 comments on commit 9674537

Please sign in to comment.