Skip to content

Commit a045fe5

Browse files
committed
Use MessagePortSupportsTransferable to disable transferable checks when not supported
1 parent c3e3483 commit a045fe5

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

SpawnDev.BlazorJS.WebWorkers/ServiceCallDispatcher.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ async Task HandleCallMessage(Type serviceType, Array args, bool noReply, bool ke
393393
// Send notification of completion because there is a requestId
394394
var transferableList = new List<object>();
395395
// only check for transferables if transferables are supported and the return value is not null
396-
if (retValue != null && _port != null)
396+
if (retValue != null && MessagePortSupportsTransferable)
397397
{
398398
if (retValue is byte[] bytes)
399399
{
@@ -693,26 +693,25 @@ static bool IsAction(Type type)
693693
Type? genericType = null;
694694
if (methodParamType.IsGenericTypeDefinition) genericType = methodParamType;
695695
else if (methodParamType.IsGenericType) genericType = methodParamType.GetGenericTypeDefinition();
696-
#if DEBUG && false
697-
var genericTypeStr = genericType == null ? "NULL" : genericType.FullName;
698-
JS.Log($"genericTypeStr: {genericTypeStr}");
699-
#endif
700696
var coreType = genericType ?? methodParamType;
701697
//var methodParamTypeName = methodParamInfo.ParameterType.Name;
702698
var genericTypes = methodParamType.GenericTypeArguments;
703699
// check if it is a [TransferableList] object[] parameter
704700
if (transferableListAttributeParameter == methodParamInfo && arg is IEnumerable<object> objectArray)
705701
{
706-
transferableList.AddRange(objectArray);
702+
if (MessagePortSupportsTransferable)
703+
{
704+
transferableList.AddRange(objectArray);
705+
}
707706
// the parameter data is not actually passed, the parameter exists to tell the sender what data should be added to the transferables list
708-
// ret[i] = null;
707+
// ret[i] = null; (implicit)
709708
continue;
710709
}
711710
if (IsCallSideParameter(methodParamInfo))
712711
{
713712
// resolved on the other side
714713
// skip item ...
715-
// ret[i] = null;
714+
// ret[i] = null; (implicit)
716715
continue;
717716
}
718717
else if (arg is Delegate argDelegate && !string.IsNullOrEmpty(requestId))
@@ -758,15 +757,15 @@ static bool IsAction(Type type)
758757
ret[i] = null;
759758
}
760759
}
761-
else if (arg is byte[] bytes)
760+
else if (MessagePortSupportsTransferable && arg is byte[] bytes)
762761
{
763762
// to get better performance when sending byte arrays we convert it to a Uint8Array reference first, and add its array buffer to the transferables list.
764763
// it will still be read in on the other side as a byte array. this prevents 1 copying stage.
765764
var uint8Array = new Uint8Array(bytes);
766765
transferableList.Add(uint8Array.Buffer);
767766
ret[i] = uint8Array;
768767
}
769-
else if (!transferableListAttributeFound)
768+
else if (MessagePortSupportsTransferable && !transferableListAttributeFound)
770769
{
771770
// if a transfer list was not found...
772771
// Add required transferables like OffscreenCanvas

0 commit comments

Comments
 (0)