@@ -446,52 +446,32 @@ class InstanceHelper extends Domain {
446
446
.where ((p) => p.name != null && int .tryParse (p.name! ) != null )
447
447
.toList ();
448
448
449
- /// The fields for a Dart Record .
449
+ /// The field names for a Dart record shape .
450
450
///
451
451
/// Returns a range of [count] fields, if available, starting from
452
452
/// the [offset] .
453
453
///
454
454
/// If [offset] is `null` , assumes 0 offset.
455
455
/// If [count] is `null` , return all fields starting from the offset.
456
- Future <List <BoundField >> _recordFields (
457
- RemoteObject record, {
456
+ /// The [shape] object describes the shape using `positionalCount`
457
+ /// and `named` fields.
458
+ ///
459
+ /// Returns list of field names for the record shape.
460
+ Future <List <dynamic >> _recordShapeFields (
461
+ RemoteObject shape, {
458
462
int ? offset,
459
463
int ? count,
460
464
}) async {
461
- // We do this in in awkward way because we want the keys and values, but we
462
- // can't return things by value or some Dart objects will come back as
463
- // values that we need to be RemoteObject, e.g. a List of int.
464
- final expression = '''
465
- function() {
466
- var sdkUtils = ${globalLoadStrategy .loadModuleSnippet }('dart_sdk').dart;
467
- var shape = sdkUtils.dloadRepl(this, "shape");
468
- var positionalCount = sdkUtils.dloadRepl(shape, "positionals");
469
- var named = sdkUtils.dloadRepl(shape, "named");
470
- named = named == null? null: sdkUtils.dsendRepl(named, "toList", []);
471
- var values = sdkUtils.dloadRepl(this, "values");
472
- values = sdkUtils.dsendRepl(values, "toList", []);
473
-
474
- return {
475
- positionalCount: positionalCount,
476
- named: named,
477
- values: values
478
- };
479
- }
480
- ''' ;
481
- final result = await inspector.jsCallFunctionOn (record, expression, []);
482
465
final positionalCountObject =
483
- await inspector.loadField (result , 'positionalCount' );
466
+ await inspector.loadField (shape , 'positionalCount' );
484
467
if (positionalCountObject == null || positionalCountObject.value is ! int ) {
485
468
_logger.warning (
486
469
'Unexpected positional count from record: $positionalCountObject ' ,
487
470
);
488
471
return [];
489
472
}
490
473
491
- final namedObject = await inspector.loadField (result, 'named' );
492
- final valuesObject = await inspector.loadField (result, 'values' );
493
-
494
- // Collect positional fields in the requested range.
474
+ final namedObject = await inspector.loadField (shape, 'named' );
495
475
final positionalCount = positionalCountObject.value as int ;
496
476
final positionalOffset = offset ?? 0 ;
497
477
final positionalAvailable =
@@ -519,11 +499,49 @@ class InstanceHelper extends Domain {
519
499
final namedElements =
520
500
namedInstance? .elements? .map ((e) => e.valueAsString) ?? [];
521
501
522
- final fieldNameElements = [
502
+ return [
523
503
...positionalElements,
524
504
...namedElements,
525
505
];
506
+ }
507
+
508
+ /// The fields for a Dart Record.
509
+ ///
510
+ /// Returns a range of [count] fields, if available, starting from
511
+ /// the [offset] .
512
+ ///
513
+ /// If [offset] is `null` , assumes 0 offset.
514
+ /// If [count] is `null` , return all fields starting from the offset.
515
+ Future <List <BoundField >> _recordFields (
516
+ RemoteObject record, {
517
+ int ? offset,
518
+ int ? count,
519
+ }) async {
520
+ // We do this in in awkward way because we want the keys and values, but we
521
+ // can't return things by value or some Dart objects will come back as
522
+ // values that we need to be RemoteObject, e.g. a List of int.
523
+ final expression = '''
524
+ function() {
525
+ var sdkUtils = ${globalLoadStrategy .loadModuleSnippet }('dart_sdk').dart;
526
+ var shape = sdkUtils.dloadRepl(this, "shape");
527
+ var positionalCount = sdkUtils.dloadRepl(shape, "positionals");
528
+ var named = sdkUtils.dloadRepl(shape, "named");
529
+ named = named == null? null: sdkUtils.dsendRepl(named, "toList", []);
530
+ var values = sdkUtils.dloadRepl(this, "values");
531
+ values = sdkUtils.dsendRepl(values, "toList", []);
532
+
533
+ return {
534
+ positionalCount: positionalCount,
535
+ named: named,
536
+ values: values
537
+ };
538
+ }
539
+ ''' ;
540
+ final result = await inspector.jsCallFunctionOn (record, expression, []);
541
+ final fieldNameElements =
542
+ await _recordShapeFields (result, offset: offset, count: count);
526
543
544
+ final valuesObject = await inspector.loadField (result, 'values' );
527
545
final valuesInstance =
528
546
await instanceFor (valuesObject, offset: offset, count: count);
529
547
final valueElements = valuesInstance? .elements ?? [];
@@ -533,11 +551,19 @@ class InstanceHelper extends Domain {
533
551
return [];
534
552
}
535
553
536
- final fields = < BoundField > [];
537
- Map .fromIterables (fieldNameElements, valueElements).forEach ((key, value) {
538
- fields.add (BoundField (name: key, value: value));
554
+ return _elementsToBoundFields (fieldNameElements, valueElements);
555
+ }
556
+
557
+ /// Create a list of `BoundField` s from field [names] and [values] .
558
+ static List <BoundField > _elementsToBoundFields (
559
+ List <dynamic > names,
560
+ List <dynamic > values,
561
+ ) {
562
+ final boundFields = < BoundField > [];
563
+ Map .fromIterables (names, values).forEach ((name, value) {
564
+ boundFields.add (BoundField (name: name, value: value));
539
565
});
540
- return fields ;
566
+ return boundFields ;
541
567
}
542
568
543
569
static int _remainingCount (int collected, int requested) {
0 commit comments