LCOV - code coverage report

Current view
top level - src/_impl/xplat - _transferables.dart
Test
lcov.info
Date
2024-11-13
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines293387.9%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import '../../exceptions/squadron_error.dart';
2
3class Transferables {
4 const Transferables._();
5
69 static List<Object>? get(List args) {
79 final objects = _get(args, <Object>{}).toList();
89 return objects.isEmpty ? null : objects;
99 }
10
119 static bool _isBaseType(Object? data) =>
129 (data == null || data is String || data is num || data is bool);
13
14 static bool _isListOfBaseType(Object? data) =>
159 (data is List<String> || data is List<num> || data is List<bool>);
16
179 static bool _isSafeForTransfer(Object? data) {
189 if (_isBaseType(data)) return true;
190 if (_isListOfBaseType(data)) return true;
209 if (data is List && data.every(_isSafeForTransfer)) return true;
219 return false;
229 }
23
249 static bool _isNotSafeForTransfer(Object? data) => !_isSafeForTransfer(data);
25
26 /// Excludes base type values from [list].
279 static Iterable<Object> _getObjects(Iterable list, Set<Object> seen) sync* {
289 for (var o in list.where(_isNotSafeForTransfer)) {
299 if (!seen.contains(o)) {
309 seen.add(o);
319 yield o as Object;
32 }
33 }
349 }
35
36 static void _checkKeys(Map data) {
370 if (!data.keys.every(_isBaseType)) {
380 throw SquadronErrorExt.create(
39 'Map keys must be strings, numbers or booleans.');
40 }
41 }
42
43 /// Yields objects contained in [message]. Used to identify non-base type objects and provide
44 /// them to [Worker.postMessage]. [Worker.postMessage] will clone these objects. The code makes
45 /// no effort to ensure these objects really are transferable.
469 static Iterable<Object> _get(List message, Set<Object> seen) sync* {
479 if (_isSafeForTransfer(message)) return;
489 final toBeInspected = _getObjects(message, seen).toList();
49 var i = 0;
509 while (i < toBeInspected.length) {
519 final arg = toBeInspected[i++];
529 if (arg is Map) {
53 _checkKeys(arg);
540 toBeInspected.addAll(_getObjects(arg.values, seen));
559 } else if (arg is Iterable) {
564 toBeInspected.addAll(_getObjects(arg, seen));
57 } else {
589 yield arg;
59 }
60 }
619 }
62}
Choose Features