Skip to content

Commit

Permalink
fix array conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Nov 16, 2023
1 parent 4501f85 commit 9ed06fe
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/PuppeteerSharp/ElementHandle.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -847,8 +848,17 @@ private async Task<T> BindIsolatedHandleAsync<T>(Func<ElementHandle, Task<T>> ac
if (typeof(T).IsArray)
{
var enumerable = result as IEnumerable<IJSHandle>;

if (typeof(T).GetElementType() == typeof(IElementHandle))
{
return (T)(object)await Task.WhenAll(
enumerable.Select(
async item => await Realm.TransferHandleAsync(item).ConfigureAwait(false) as IElementHandle)).ConfigureAwait(false);
}

return (T)(object)await Task.WhenAll(
enumerable.Select(item => item is IJSHandle ? Realm.TransferHandleAsync(item) : Task.FromResult(item))).ConfigureAwait(false);
enumerable.Select(
item => item is IJSHandle ? Realm.TransferHandleAsync(item) : Task.FromResult(item))).ConfigureAwait(false);
}

if (result is IDictionary<string, IJSHandle> dictionaryResult)
Expand Down

0 comments on commit 9ed06fe

Please sign in to comment.