Fix returning arrays in async JS interop calls. Fixes #1205
This commit is contained in:
Родитель
8c452ff71a
Коммит
f2232e0699
|
@ -100,10 +100,12 @@ namespace Microsoft.JSInterop
|
|||
if (succeeded)
|
||||
{
|
||||
var resultType = TaskGenericsUtil.GetTaskCompletionSourceResultType(tcs);
|
||||
var resultValue = resultOrException is SimpleJson.JsonObject
|
||||
? ArgSerializerStrategy.DeserializeObject(resultOrException, resultType)
|
||||
: resultOrException;
|
||||
TaskGenericsUtil.SetTaskCompletionSourceResult(tcs, resultValue);
|
||||
if (resultOrException is SimpleJson.JsonObject || resultOrException is SimpleJson.JsonArray)
|
||||
{
|
||||
resultOrException = ArgSerializerStrategy.DeserializeObject(resultOrException, resultType);
|
||||
}
|
||||
|
||||
TaskGenericsUtil.SetTaskCompletionSourceResult(tcs, resultOrException);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -59,6 +59,7 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
|
|||
["testDtoNonSerializedValueAsync"] = "99999",
|
||||
["testDtoAsync"] = "Same",
|
||||
["returnPrimitiveAsync"] = "123",
|
||||
["returnArrayAsync"] = "first,second",
|
||||
};
|
||||
|
||||
var expectedSyncValues = new Dictionary<string, string>
|
||||
|
@ -92,6 +93,7 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
|
|||
["testDtoNonSerializedValueSync"] = "99999",
|
||||
["testDtoSync"] = "Same",
|
||||
["returnPrimitive"] = "123",
|
||||
["returnArray"] = "first,second",
|
||||
};
|
||||
|
||||
// Include the sync assertions only when running under WebAssembly
|
||||
|
|
|
@ -122,9 +122,11 @@
|
|||
ReceiveDotNetObjectByRefAsyncResult["testDto"] = ReceiveDotNetObjectByRefAsyncResult["testDto"] == passDotNetObjectByRef ? "Same" : "Different";
|
||||
|
||||
ReturnValues["returnPrimitiveAsync"] = (await JSRuntime.Current.InvokeAsync<int>("returnPrimitiveAsync")).ToString();
|
||||
ReturnValues["returnArrayAsync"] = string.Join(",", (await JSRuntime.Current.InvokeAsync<Segment[]>("returnArrayAsync")).Select(x => x.Source).ToArray());
|
||||
if (shouldSupportSyncInterop)
|
||||
{
|
||||
ReturnValues["returnPrimitive"] = ((IJSInProcessRuntime)JSRuntime.Current).Invoke<int>("returnPrimitive").ToString();
|
||||
ReturnValues["returnArray"] = string.Join(",", ((IJSInProcessRuntime)JSRuntime.Current).Invoke<Segment[]>("returnArray").Select(x => x.Source).ToArray());
|
||||
}
|
||||
|
||||
Invocations = invocations;
|
||||
|
|
|
@ -186,6 +186,18 @@ function returnPrimitiveAsync() {
|
|||
});
|
||||
}
|
||||
|
||||
function returnArray() {
|
||||
return [{ source: 'first' }, { source: 'second' }];
|
||||
}
|
||||
|
||||
function returnArrayAsync() {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(function () {
|
||||
resolve(returnArray());
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
|
||||
function functionThrowsException() {
|
||||
throw new Error('Function threw an exception!');
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче