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)
|
if (succeeded)
|
||||||
{
|
{
|
||||||
var resultType = TaskGenericsUtil.GetTaskCompletionSourceResultType(tcs);
|
var resultType = TaskGenericsUtil.GetTaskCompletionSourceResultType(tcs);
|
||||||
var resultValue = resultOrException is SimpleJson.JsonObject
|
if (resultOrException is SimpleJson.JsonObject || resultOrException is SimpleJson.JsonArray)
|
||||||
? ArgSerializerStrategy.DeserializeObject(resultOrException, resultType)
|
{
|
||||||
: resultOrException;
|
resultOrException = ArgSerializerStrategy.DeserializeObject(resultOrException, resultType);
|
||||||
TaskGenericsUtil.SetTaskCompletionSourceResult(tcs, resultValue);
|
}
|
||||||
|
|
||||||
|
TaskGenericsUtil.SetTaskCompletionSourceResult(tcs, resultOrException);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -59,6 +59,7 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
|
||||||
["testDtoNonSerializedValueAsync"] = "99999",
|
["testDtoNonSerializedValueAsync"] = "99999",
|
||||||
["testDtoAsync"] = "Same",
|
["testDtoAsync"] = "Same",
|
||||||
["returnPrimitiveAsync"] = "123",
|
["returnPrimitiveAsync"] = "123",
|
||||||
|
["returnArrayAsync"] = "first,second",
|
||||||
};
|
};
|
||||||
|
|
||||||
var expectedSyncValues = new Dictionary<string, string>
|
var expectedSyncValues = new Dictionary<string, string>
|
||||||
|
@ -92,6 +93,7 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
|
||||||
["testDtoNonSerializedValueSync"] = "99999",
|
["testDtoNonSerializedValueSync"] = "99999",
|
||||||
["testDtoSync"] = "Same",
|
["testDtoSync"] = "Same",
|
||||||
["returnPrimitive"] = "123",
|
["returnPrimitive"] = "123",
|
||||||
|
["returnArray"] = "first,second",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Include the sync assertions only when running under WebAssembly
|
// Include the sync assertions only when running under WebAssembly
|
||||||
|
|
|
@ -122,9 +122,11 @@
|
||||||
ReceiveDotNetObjectByRefAsyncResult["testDto"] = ReceiveDotNetObjectByRefAsyncResult["testDto"] == passDotNetObjectByRef ? "Same" : "Different";
|
ReceiveDotNetObjectByRefAsyncResult["testDto"] = ReceiveDotNetObjectByRefAsyncResult["testDto"] == passDotNetObjectByRef ? "Same" : "Different";
|
||||||
|
|
||||||
ReturnValues["returnPrimitiveAsync"] = (await JSRuntime.Current.InvokeAsync<int>("returnPrimitiveAsync")).ToString();
|
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)
|
if (shouldSupportSyncInterop)
|
||||||
{
|
{
|
||||||
ReturnValues["returnPrimitive"] = ((IJSInProcessRuntime)JSRuntime.Current).Invoke<int>("returnPrimitive").ToString();
|
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;
|
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() {
|
function functionThrowsException() {
|
||||||
throw new Error('Function threw an exception!');
|
throw new Error('Function threw an exception!');
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче