@@ -45,6 +45,9 @@ class AppInspector extends Domain {
45
45
/// Map of [ScriptRef] id to containing [LibraryRef] id.
46
46
final _scriptIdToLibraryId = < String , String > {};
47
47
48
+ /// Map of [Library] id to included [ScriptRef] s.
49
+ final _libraryIdToScriptRefs = < String , List <ScriptRef >> {};
50
+
48
51
final RemoteDebugger remoteDebugger;
49
52
final Debugger debugger;
50
53
final Isolate isolate;
@@ -232,7 +235,7 @@ class AppInspector extends Domain {
232
235
String isolateId, String targetId, String expression,
233
236
{Map <String , String > scope}) async {
234
237
scope ?? = {};
235
- var library = await _getLibrary (isolateId, targetId);
238
+ var library = await getLibrary (isolateId, targetId);
236
239
if (library == null ) {
237
240
throw UnsupportedError (
238
241
'Evaluate is only supported when `targetId` is a library.' );
@@ -341,10 +344,6 @@ function($argsString) {
341
344
}
342
345
343
346
Future <Library > getLibrary (String isolateId, String objectId) async {
344
- return await _getLibrary (isolateId, objectId);
345
- }
346
-
347
- Future <Library > _getLibrary (String isolateId, String objectId) async {
348
347
if (isolateId != isolate.id) return null ;
349
348
var libraryRef = await libraryHelper.libraryRefFor (objectId);
350
349
if (libraryRef == null ) return null ;
@@ -354,7 +353,7 @@ function($argsString) {
354
353
Future <Obj > getObject (String isolateId, String objectId,
355
354
{int offset, int count}) async {
356
355
try {
357
- var library = await _getLibrary (isolateId, objectId);
356
+ var library = await getLibrary (isolateId, objectId);
358
357
if (library != null ) {
359
358
return library;
360
359
}
@@ -410,13 +409,16 @@ function($argsString) {
410
409
411
410
/// Returns the [ScriptRef] for the provided Dart server path [uri] .
412
411
Future <ScriptRef > scriptRefFor (String uri) async {
413
- if (_serverPathToScriptRef.isEmpty) {
414
- // TODO(grouma) - populate the server path cache a better way.
415
- await getScripts (isolate.id);
416
- }
412
+ await _populateScriptCaches ();
417
413
return _serverPathToScriptRef[uri];
418
414
}
419
415
416
+ /// Returns the [ScriptRef] s in the library with [libraryId] .
417
+ Future <List <ScriptRef >> scriptRefsForLibrary (String libraryId) async {
418
+ await _populateScriptCaches ();
419
+ return _libraryIdToScriptRefs[libraryId];
420
+ }
421
+
420
422
/// Return the VM SourceReport for the given parameters.
421
423
///
422
424
/// Currently this implements the 'PossibleBreakpoints' report kind.
@@ -486,8 +488,10 @@ function($argsString) {
486
488
487
489
/// Request and cache <ScriptRef>s for all the scripts in the application.
488
490
///
489
- /// This populates [_scriptRefsById] , [_scriptIdToLibraryId] and
490
- /// [_serverPathToScriptRef] . It is a one-time operation, because if we do a
491
+ /// This populates [_scriptRefsById] , [_scriptIdToLibraryId] ,
492
+ /// [_libraryIdToScriptRefs] and [_serverPathToScriptRef] .
493
+ ///
494
+ /// It is a one-time operation, because if we do a
491
495
/// reload the inspector will get re-created.
492
496
///
493
497
/// Returns the list of scripts refs cached.
@@ -507,11 +511,13 @@ function($argsString) {
507
511
for (var part in parts) ScriptRef (uri: part, id: createId ())
508
512
];
509
513
var libraryRef = await libraryHelper.libraryRefFor (uri);
514
+ _libraryIdToScriptRefs.putIfAbsent (libraryRef.id, () => < ScriptRef > []);
510
515
for (var scriptRef in scriptRefs) {
511
516
_scriptRefsById[scriptRef.id] = scriptRef;
512
517
_scriptIdToLibraryId[scriptRef.id] = libraryRef.id;
513
518
_serverPathToScriptRef[DartUri (scriptRef.uri, _root).serverPath] =
514
519
scriptRef;
520
+ _libraryIdToScriptRefs[libraryRef.id].add (scriptRef);
515
521
}
516
522
}
517
523
return _scriptRefsById.values.toList ();
0 commit comments