Skip to content

[browser] Marshalling of resolved Tasks/promises is not resolved in JS/C# #105464

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 3 commits into from
Aug 1, 2024
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 @@ -275,7 +275,7 @@ public void ToJS(Task? value)
}
else
{
slot.ElementType = slot.Type;
slot.ElementType = MarshalerType.Void;
slot.Type = MarshalerType.TaskResolved;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,5 +436,12 @@ public async Task InternalsVisibleToDoesntBreak()
{
Assert.Equal(JavaScriptLibrary.JavaScriptInterop.ValidationMethod(5, 6), await JavaScriptTestHelper.callJavaScriptLibrary(5, 6));
}

[Fact]
public async void JSExportCompletedTaskReturnsResolvedPromise()
{
string result = await JavaScriptTestHelper.InvokeReturnCompletedTask();
Assert.Equal("resolved", result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,17 @@ public async Task JsImportTaskAwait()
await task;
}

[Fact]
public async Task JsImportResolvedPromiseReturnsCompletedTask()
{
var promise = JavaScriptTestHelper.ReturnResolvedPromise();
#if !FEATURE_WASM_MANAGED_THREADS
Assert.False(promise.IsCompleted);
#endif
await promise;
Assert.True(promise.IsCompleted);
}

#endregion

#region Action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,18 @@ public static Exception EchoException([JSMarshalAs<JSType.Error>] Exception arg1
[JSImport("invoke1", "JavaScriptTestHelper")]
[return: JSMarshalAs<JSType.Promise<JSType.Number>>]
internal static partial Task<int> invoke1_TaskOfInt([JSMarshalAs<JSType.Promise<JSType.Number>>] Task<int> value, [JSMarshalAs<JSType.String>] string name);

[JSImport("returnResolvedPromise", "JavaScriptTestHelper")]
internal static partial Task ReturnResolvedPromise();

[JSImport("invokeReturnCompletedTask", "JavaScriptTestHelper")]
internal static partial Task<string> InvokeReturnCompletedTask();

[JSExport]
internal static Task ReturnCompletedTask()
{
return Task.CompletedTask;
}

[JSExport]
[return: JSMarshalAs<JSType.Promise<JSType.Any>>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ export function invoke2(arg1, name) {
return res;
}

export function returnResolvedPromise() {
return Promise.resolve();
}

export async function invokeReturnCompletedTask() {
await dllExports.System.Runtime.InteropServices.JavaScript.Tests.JavaScriptTestHelper.ReturnCompletedTask();
return "resolved";
}

export function invokeStructClassRecords(arg1) {
return [
dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.EchoString(arg1),
Expand Down
Loading