Skip to content

Commit 7d80a2c

Browse files
authored
Ignore offset / count if an instance has no length (#1972)
1 parent cd66172 commit 7d80a2c

File tree

2 files changed

+71
-12
lines changed

2 files changed

+71
-12
lines changed

dwds/lib/src/debugging/debugger.dart

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,21 @@ class Debugger extends Domain {
403403
return null;
404404
}
405405

406-
static bool _isEmptyRange({int? offset, int? count, int? length}) {
406+
static bool _isEmptyRange({
407+
required int length,
408+
int? offset,
409+
int? count,
410+
}) {
407411
if (count == 0) return true;
408-
if (length == null) return false;
409412
if (offset == null) return false;
410413
return offset >= length;
411414
}
412415

413-
static bool _isSubRange({int? offset, int? count, int? length}) {
414-
if (length == null) return false;
416+
static bool _isSubRange({
417+
required int length,
418+
int? offset,
419+
int? count,
420+
}) {
415421
if (offset == 0 && count == null) return false;
416422
return offset != null || count != null;
417423
}
@@ -502,13 +508,16 @@ class Debugger extends Domain {
502508
int? length,
503509
}) async {
504510
String rangeId = objectId;
505-
if (_isEmptyRange(offset: offset, count: count, length: length)) {
506-
return [];
507-
}
508-
if (_isSubRange(offset: offset, count: count, length: length)) {
509-
final range = await _subRange(objectId,
510-
offset: offset ?? 0, count: count, length: length!);
511-
rangeId = range.objectId ?? rangeId;
511+
// Ignore offset/count if there is no length:
512+
if (length != null) {
513+
if (_isEmptyRange(offset: offset, count: count, length: length)) {
514+
return [];
515+
}
516+
if (_isSubRange(offset: offset, count: count, length: length)) {
517+
final range = await _subRange(objectId,
518+
offset: offset ?? 0, count: count, length: length);
519+
rangeId = range.objectId ?? rangeId;
520+
}
512521
}
513522
final jsProperties = await sendCommandAndValidateResult<List>(
514523
_remoteDebugger,

dwds/test/chrome_proxy_service_test.dart

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,9 @@ void main() {
921921
expect(world.offset, 3);
922922
});
923923

924-
test('offset/count parameters are ignored for Classes', () async {
924+
test(
925+
'offset/count parameters greater than zero are ignored for Classes',
926+
() async {
925927
final testClass = await service.getObject(
926928
isolate.id!,
927929
rootLibrary!.classes!.first.id!,
@@ -968,6 +970,54 @@ void main() {
968970
]));
969971
});
970972

973+
test('offset/count parameters equal to zero are ignored for Classes',
974+
() async {
975+
final testClass = await service.getObject(
976+
isolate.id!,
977+
rootLibrary!.classes!.first.id!,
978+
offset: 0,
979+
count: 0,
980+
) as Class;
981+
expect(
982+
testClass.functions,
983+
unorderedEquals([
984+
predicate(
985+
(FuncRef f) => f.name == 'staticHello' && f.isStatic!),
986+
predicate((FuncRef f) => f.name == 'message' && !f.isStatic!),
987+
predicate((FuncRef f) => f.name == 'notFinal' && !f.isStatic!),
988+
predicate((FuncRef f) => f.name == 'hello' && !f.isStatic!),
989+
predicate((FuncRef f) => f.name == '_equals' && !f.isStatic!),
990+
predicate((FuncRef f) => f.name == 'hashCode' && !f.isStatic!),
991+
predicate((FuncRef f) => f.name == 'toString' && !f.isStatic!),
992+
predicate(
993+
(FuncRef f) => f.name == 'noSuchMethod' && !f.isStatic!),
994+
predicate(
995+
(FuncRef f) => f.name == 'runtimeType' && !f.isStatic!),
996+
]));
997+
expect(
998+
testClass.fields,
999+
unorderedEquals([
1000+
predicate((FieldRef f) =>
1001+
f.name == 'message' &&
1002+
f.declaredType != null &&
1003+
!f.isStatic! &&
1004+
!f.isConst! &&
1005+
f.isFinal!),
1006+
predicate((FieldRef f) =>
1007+
f.name == 'notFinal' &&
1008+
f.declaredType != null &&
1009+
!f.isStatic! &&
1010+
!f.isConst! &&
1011+
!f.isFinal!),
1012+
predicate((FieldRef f) =>
1013+
f.name == 'staticMessage' &&
1014+
f.declaredType != null &&
1015+
f.isStatic! &&
1016+
!f.isConst! &&
1017+
!f.isFinal!),
1018+
]));
1019+
});
1020+
9711021
test('offset/count parameters are ignored for bools', () async {
9721022
final ref = await service.evaluate(
9731023
isolate.id!, bootstrap!.id!, 'helloBool(true)') as InstanceRef;

0 commit comments

Comments
 (0)