Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 11.3.1-dev
## 11.4.0

- Fix duplicated scripts returned by `VmService.getScripts` API.
- Encode extension url asynchronously.
- Use default constant port for debug service.
- If we fail binding to the port, fall back to previous strategy
Expand Down
57 changes: 28 additions & 29 deletions dwds/lib/src/debugging/inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// @dart = 2.9

import 'package:async/async.dart';
import 'package:logging/logging.dart';
import 'package:vm_service/vm_service.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
Expand All @@ -29,9 +30,9 @@ import 'libraries.dart';
/// Provides information about currently loaded scripts and objects and support
/// for eval.
class AppInspector extends Domain {
Future<List<ScriptRef>> _cachedScriptRefs;
final _scriptCacheMemoizer = AsyncMemoizer<List<ScriptRef>>();

Future<List<ScriptRef>> get scriptRefs => _cachedScriptRefs ??= _getScripts();
Future<List<ScriptRef>> get scriptRefs => _populateScriptCaches();

final _logger = Logger('AppInspector');

Expand Down Expand Up @@ -87,7 +88,7 @@ class AppInspector extends Domain {
isolate.libraries.addAll(libraries);
await DartUri.recordAbsoluteUris(libraries.map((lib) => lib.uri));

var scripts = await _getScripts();
var scripts = await scriptRefs;
await DartUri.recordAbsoluteUris(scripts.map((script) => script.uri));

isolate.extensionRPCs.addAll(await _getExtensionRpcs());
Expand Down Expand Up @@ -483,38 +484,36 @@ function($argsString) {
return ScriptList(scripts: await scriptRefs);
}

Future<List<ScriptRef>> _getScripts() async {
await _populateScriptCaches();
return _scriptRefsById.values.toList();
}

/// Request and cache <ScriptRef>s for all the scripts in the application.
///
/// This populates [_scriptRefsById], [_scriptIdToLibraryId] and
/// [_serverPathToScriptRef]. It is a one-time operation, because if we do a
/// reload the inspector will get re-created.
Future<void> _populateScriptCaches() async {
var libraryUris = [for (var library in isolate.libraries) library.uri];
var scripts = await globalLoadStrategy
.metadataProviderFor(appConnection.request.entrypointPath)
.scripts;
// For all the non-dart: libraries, find their parts and create scriptRefs
// for them.
var userLibraries = libraryUris.where((uri) => !uri.startsWith('dart:'));
for (var uri in userLibraries) {
var parts = scripts[uri];
var scriptRefs = [
ScriptRef(uri: uri, id: createId()),
for (var part in parts) ScriptRef(uri: part, id: createId())
];
var libraryRef = await libraryHelper.libraryRefFor(uri);
for (var scriptRef in scriptRefs) {
_scriptRefsById[scriptRef.id] = scriptRef;
_scriptIdToLibraryId[scriptRef.id] = libraryRef.id;
_serverPathToScriptRef[DartUri(scriptRef.uri, _root).serverPath] =
scriptRef;
Future<List<ScriptRef>> _populateScriptCaches() async {
return _scriptCacheMemoizer.runOnce(() async {
var libraryUris = [for (var library in isolate.libraries) library.uri];
var scripts = await globalLoadStrategy
.metadataProviderFor(appConnection.request.entrypointPath)
.scripts;
// For all the non-dart: libraries, find their parts and create scriptRefs
// for them.
var userLibraries = libraryUris.where((uri) => !uri.startsWith('dart:'));
for (var uri in userLibraries) {
var parts = scripts[uri];
var scriptRefs = [
ScriptRef(uri: uri, id: createId()),
for (var part in parts) ScriptRef(uri: part, id: createId())
];
var libraryRef = await libraryHelper.libraryRefFor(uri);
for (var scriptRef in scriptRefs) {
_scriptRefsById[scriptRef.id] = scriptRef;
_scriptIdToLibraryId[scriptRef.id] = libraryRef.id;
_serverPathToScriptRef[DartUri(scriptRef.uri, _root).serverPath] =
scriptRef;
}
}
}
return _scriptRefsById.values.toList();
});
}

/// Look up the script by id in an isolate.
Expand Down
Loading