@@ -238,29 +238,49 @@ class InstanceHelper extends Domain {
238238 final objectId = remoteObject.objectId;
239239 if (objectId == null ) return null ;
240240
241+ final fields = await _getInstanceFields (
242+ metaData,
243+ remoteObject,
244+ offset: offset,
245+ count: count,
246+ );
247+
248+ final result = Instance (
249+ kind: InstanceKind .kPlainInstance,
250+ id: objectId,
251+ identityHashCode: remoteObject.objectId.hashCode,
252+ classRef: metaData.classRef,
253+ fields: fields,
254+ );
255+ return result;
256+ }
257+
258+ Future <List <BoundField >> _getInstanceFields (
259+ ClassMetaData metaData,
260+ RemoteObject remoteObject, {
261+ int ? offset,
262+ int ? count,
263+ }) async {
264+ final objectId = remoteObject.objectId;
265+ if (objectId == null ) throw StateError ('Object id is null for instance' );
266+
241267 final properties = await inspector.getProperties (
242268 objectId,
243269 offset: offset,
244270 count: count,
245271 length: metaData.length,
246272 );
273+
247274 final dartProperties = await _dartFieldsFor (properties, remoteObject);
248- var boundFields = await Future .wait (
275+ final boundFields = await Future .wait (
249276 dartProperties
250277 .map <Future <BoundField >>((p) => _fieldFor (p, metaData.classRef)),
251278 );
252- boundFields = boundFields
279+
280+ return boundFields
253281 .where ((bv) => inspector.isDisplayableObject (bv.value))
254282 .toList ()
255283 ..sort (_compareBoundFields);
256- final result = Instance (
257- kind: InstanceKind .kPlainInstance,
258- id: objectId,
259- identityHashCode: remoteObject.objectId.hashCode,
260- classRef: metaData.classRef,
261- fields: boundFields,
262- );
263- return result;
264284 }
265285
266286 int _compareBoundFields (BoundField a, BoundField b) {
@@ -700,7 +720,13 @@ class InstanceHelper extends Domain {
700720 final objectId = remoteObject.objectId;
701721 if (objectId == null ) return null ;
702722
703- final fields = await _typeFields (metaData.classRef, remoteObject);
723+ final fields = await _getInstanceFields (
724+ metaData,
725+ remoteObject,
726+ offset: offset,
727+ count: count,
728+ );
729+
704730 return Instance (
705731 identityHashCode: objectId.hashCode,
706732 kind: InstanceKind .kType,
@@ -714,36 +740,6 @@ class InstanceHelper extends Domain {
714740 );
715741 }
716742
717- /// The field types for a Dart RecordType.
718- ///
719- /// Returns a range of [count] field types, if available, starting from
720- /// the [offset] .
721- ///
722- /// If [offset] is `null` , assumes 0 offset.
723- /// If [count] is `null` , return all field types starting from the offset.
724- Future <List <BoundField >> _typeFields (
725- ClassRef classRef,
726- RemoteObject type,
727- ) async {
728- // Present the type as an instance of `core.Type` class and
729- // hide the internal implementation.
730- final expression = _jsRuntimeFunctionCall ('getTypeFields(this)' );
731-
732- final result = await inspector.jsCallFunctionOn (type, expression, []);
733- final hashCodeObject = await inspector.loadField (result, 'hashCode' );
734- final runtimeTypeObject = await inspector.loadField (result, 'runtimeType' );
735-
736- final properties = [
737- Property ({'name' : 'hashCode' , 'value' : hashCodeObject}),
738- Property ({'name' : 'runtimeType' , 'value' : runtimeTypeObject}),
739- ];
740-
741- final boundFields = await Future .wait (
742- properties.map <Future <BoundField >>((p) => _fieldFor (p, classRef)),
743- );
744- return boundFields;
745- }
746-
747743 /// Return the available count of elements in the requested range.
748744 /// Return `null` if the range includes the whole object.
749745 /// [count] is the range length requested by the `getObject` call.
0 commit comments