Skip to content

Commit 809bfec

Browse files
author
Anna Gringauze
committed
Fix broken debugging caused by missing CallFrame.url
1 parent bd3ab2f commit 809bfec

File tree

9 files changed

+4242
-4286
lines changed

9 files changed

+4242
-4286
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Update error message on expression evaluation using unloaded libraries.
1717
- Add `screen` field to the `DebuggerReady` event.
1818
- Report `DebuggerReady` events for DevTools embedded into Chrome Devtools.
19+
- Fix missing `CallFrame.url` after update to Chrome 100.
1920

2021
**Breaking changes:**
2122
- `Dwds.start` and `ExpressionCompilerService` now take

dwds/debug_extension/web/background.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,6 @@ void _filterAndForwardToBackend(Debuggee source, String method, Object params) {
575575

576576
if (debugSession == null) return;
577577

578-
if (method == 'Debugger.scriptParsed') return;
579-
580578
var event = _extensionEventFor(method, params);
581579

582580
debugSession.socketClient.sink.add(jsonEncode(serializers.serialize(event)));

dwds/debug_extension/web/background.js

Lines changed: 4204 additions & 4239 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dwds/lib/src/debugging/debugger.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,21 @@ class Debugger extends Domain {
312312
}
313313
}
314314

315+
String urlForScriptId(String scriptId) =>
316+
_remoteDebugger.scripts[scriptId]?.url;
317+
315318
/// Returns source [Location] for the paused event.
316319
///
317320
/// If we do not have [Location] data for the embedded JS location, null is
318321
/// returned.
319322
Future<Location> _sourceLocation(DebuggerPausedEvent e) {
320323
var frame = e.params['callFrames'][0];
321324
var location = frame['location'];
322-
return _locations.locationForJs(
323-
frame['url'] as String, (location['lineNumber'] as int) + 1);
325+
var scriptId = location['scriptId'] as String;
326+
var lineNumber = location['lineNumber'] as int;
327+
328+
var url = urlForScriptId(scriptId);
329+
return _locations.locationForJs(url, lineNumber + 1);
324330
}
325331

326332
/// The variables visible in a frame in Dart protocol [BoundVariable] form.
@@ -458,7 +464,8 @@ class Debugger extends Domain {
458464
// TODO(sdk/issues/37240) - ideally we look for an exact location instead
459465
// of the closest location on a given line.
460466
Location bestLocation;
461-
for (var location in await _locations.locationsForUrl(frame.url)) {
467+
var url = urlForScriptId(location.scriptId);
468+
for (var location in await _locations.locationsForUrl(url)) {
462469
if (location.jsLocation.line == line) {
463470
bestLocation ??= location;
464471
if ((location.jsLocation.column - column).abs() <
@@ -558,8 +565,9 @@ class Debugger extends Domain {
558565
// If we don't have source location continue stepping.
559566
if (_isStepping && (await _sourceLocation(e)) == null) {
560567
var frame = e.params['callFrames'][0];
561-
var url = '${frame["url"]}';
562568
var scriptId = '${frame["location"]["scriptId"]}';
569+
var url = urlForScriptId(scriptId);
570+
563571
// TODO(grouma) - In the future we should send all previously computed
564572
// skipLists.
565573
await _remoteDebugger.stepInto(params: {

dwds/lib/src/debugging/modules.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ class Modules {
2020
final _sourceToLibrary = <String, Uri>{};
2121
var _moduleMemoizer = AsyncMemoizer<void>();
2222

23-
// The Chrome script ID to corresponding module.
24-
final _scriptIdToModule = <String, String>{};
25-
2623
final Map<String, String> _libraryToModule = {};
2724

2825
String _entrypoint;
@@ -43,9 +40,6 @@ class Modules {
4340
_entrypoint = entrypoint;
4441
}
4542

46-
/// Returns the module for the Chrome script ID.
47-
String moduleForScriptId(String scriptId) => _scriptIdToModule[scriptId];
48-
4943
/// Returns the containing module for the provided Dart server path.
5044
Future<String> moduleForSource(String serverPath) async {
5145
await _moduleMemoizer.runOnce(_initializeMapping);

dwds/lib/src/injected/client.js

Lines changed: 2 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dwds/lib/src/services/expression_evaluator.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class ExpressionEvaluator {
160160

161161
var functionName = jsFrame.functionName;
162162
var jsLine = jsFrame.location.lineNumber + 1;
163+
var jsScriptId = jsFrame.location.scriptId;
163164
var jsScope = await _collectLocalJsScope(jsFrame);
164165

165166
// Find corresponding dart location and scope.
@@ -169,12 +170,13 @@ class ExpressionEvaluator {
169170
// so this will result in expressions not evaluated in some
170171
// cases. Invent location matching strategy for those cases.
171172
// [issue 890](https://github.com/dart-lang/webdev/issues/890)
172-
var locationMap = await _locations.locationForJs(jsFrame.url, jsLine);
173+
var url = urlForScriptId(jsScriptId);
174+
var locationMap = await _locations.locationForJs(url, jsLine);
173175
if (locationMap == null) {
174176
return _createError(
175177
ErrorKind.internal,
176178
'Cannot find Dart location for JS location: '
177-
'url: ${jsFrame.url}'
179+
'url: $url, '
178180
'function: $functionName, '
179181
'line: $jsLine');
180182
}
@@ -321,4 +323,7 @@ class ExpressionEvaluator {
321323

322324
return jsScope;
323325
}
326+
327+
String urlForScriptId(String scriptId) =>
328+
_inspector.remoteDebugger.scripts[scriptId]?.url;
324329
}

dwds/test/debugger_test.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import 'package:dwds/src/loaders/strategy.dart';
1717
import 'package:test/test.dart';
1818
import 'package:vm_service/vm_service.dart';
1919
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'
20-
show CallFrame, DebuggerPausedEvent, StackTrace, WipCallFrame;
20+
show CallFrame, DebuggerPausedEvent, StackTrace, WipCallFrame, WipScript;
2121

2222
import 'fixtures/context.dart';
2323
import 'fixtures/debugger_data.dart';
@@ -72,22 +72,31 @@ final sampleSyncFrame = WipCallFrame({
7272
'columnNumber': 72,
7373
},
7474
'location': {'scriptId': '69', 'lineNumber': 37, 'columnNumber': 0},
75-
'url': 'http://127.0.0.1:8081/foo.ddc.js',
75+
'url': '',
7676
'scopeChain': [],
7777
'this': {'type': 'undefined'},
7878
});
7979

8080
final sampleAsyncFrame = CallFrame({
8181
'functionName': 'myFunc',
82-
'url': 'http://127.0.0.1:8081/bar.ddc.js',
82+
'url': '',
8383
'scriptId': '71',
8484
'lineNumber': 40,
8585
'columnNumber': 1,
8686
});
8787

88+
final Map<String, WipScript> scripts = {
89+
'69': WipScript(<String, dynamic>{
90+
'url': 'http://127.0.0.1:8081/foo.ddc.js',
91+
}),
92+
'71': WipScript(<String, dynamic>{
93+
'url': 'http://127.0.0.1:8081/bar.ddc.js',
94+
}),
95+
};
96+
8897
void main() async {
8998
setUpAll(() async {
90-
webkitDebugger = FakeWebkitDebugger();
99+
webkitDebugger = FakeWebkitDebugger(scripts: scripts);
91100
pausedController = StreamController<DebuggerPausedEvent>();
92101
webkitDebugger.onPaused = pausedController.stream;
93102
globalLoadStrategy = TestStrategy();

dwds/test/fixtures/fakes.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ class FakeModules implements Modules {
115115
throw UnimplementedError();
116116
}
117117

118-
@override
119-
String moduleForScriptId(String serverId) => '';
120-
121118
@override
122119
Future<String> moduleForSource(String serverPath) {
123120
throw UnimplementedError();
@@ -135,13 +132,14 @@ class FakeModules implements Modules {
135132
}
136133

137134
class FakeWebkitDebugger implements WebkitDebugger {
135+
final Map<String, WipScript> _scripts;
138136
@override
139137
Future disable() => null;
140138

141139
@override
142140
Future enable() => null;
143141

144-
FakeWebkitDebugger() {
142+
FakeWebkitDebugger({Map<String, WipScript> scripts}) : _scripts = scripts {
145143
globalLoadStrategy = RequireStrategy(
146144
ReloadConfiguration.none,
147145
(_) async => {},
@@ -185,7 +183,7 @@ class FakeWebkitDebugger implements WebkitDebugger {
185183
Future<WipResponse> resume() => null;
186184

187185
@override
188-
Map<String, WipScript> get scripts => null;
186+
Map<String, WipScript> get scripts => _scripts;
189187

190188
List<WipResponse> results = variables1;
191189
int resultsReturned = 0;

0 commit comments

Comments
 (0)