Skip to content

Commit 6465541

Browse files
authored
Added support for some debugging APIs with the DDC library bundle format (#2541)
* Added support for getClassMetadata with the DDc library bundle format * Added support for some debugging APIs with the DDC library bundle format. * Update pattern test to account for new DDC JS variable naming * reverting change to pattern test * addressed comment
1 parent b685bb5 commit 6465541

9 files changed

+108
-19
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 24.2.1-wip
22

33
- Update to be forward compatible with changes to `package:shelf_web_socket`.
4+
- Added support for some debugging APIs with the DDC library bundle format. - [#2537](https://github.com/dart-lang/webdev/issues/2537)
45

56
## 24.2.0
67

dwds/lib/src/debugging/dart_runtime_debugger.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,57 @@ class DartRuntimeDebugger {
107107
// Use the helper method to wrap this in an IIFE
108108
return _wrapInIIFE(expression);
109109
}
110+
111+
/// Generates a JS expression for retrieving Dart Developer Extension Names.
112+
String getDartDeveloperExtensionNamesJsExpression() {
113+
return _generateJsExpression(
114+
"${_loadStrategy.loadModuleSnippet}('dart_sdk').developer._extensions.keys.toList();",
115+
'dartDevEmbedder.debugger.extensionNames',
116+
);
117+
}
118+
119+
/// Generates a JS expression for retrieving metadata of classes in a library.
120+
String getClassesInLibraryJsExpression(String libraryUri) {
121+
final expression = _buildExpression(
122+
'',
123+
"getLibraryMetadata('$libraryUri')",
124+
"getClassesInLibrary('$libraryUri')",
125+
);
126+
// Use the helper method to wrap this in an IIFE
127+
return _wrapInIIFE(expression);
128+
}
129+
130+
/// Generates a JS expression for retrieving map elements.
131+
String getMapElementsJsExpression() {
132+
return _buildExpression(
133+
'',
134+
'getMapElements(this)',
135+
'getMapElements(this)',
136+
);
137+
}
138+
139+
/// Generates a JS expression for getting a property from a JS object.
140+
String getPropertyJsExpression(String fieldName) {
141+
return _generateJsExpression(
142+
'''
143+
function() {
144+
return this["$fieldName"];
145+
}
146+
''',
147+
'''
148+
function() {
149+
return this["$fieldName"];
150+
}
151+
''',
152+
);
153+
}
154+
155+
/// Generates a JS expression for retrieving set elements.
156+
String getSetElementsJsExpression() {
157+
return _buildExpression(
158+
'',
159+
'getSetElements(this)',
160+
'getSetElements(this)',
161+
);
162+
}
110163
}

dwds/lib/src/debugging/inspector.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,8 @@ class AppInspector implements AppInspectorInterface {
192192
/// Get the value of the field named [fieldName] from [receiver].
193193
@override
194194
Future<RemoteObject> loadField(RemoteObject receiver, String fieldName) {
195-
final load = '''
196-
function() {
197-
return ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").dart.dloadRepl(this, "$fieldName");
198-
}
199-
''';
195+
final load = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
196+
.getPropertyJsExpression(fieldName);
200197
return jsCallFunctionOn(receiver, load, []);
201198
}
202199

@@ -748,8 +745,8 @@ class AppInspector implements AppInspectorInterface {
748745

749746
/// Runs an eval on the page to compute all existing registered extensions.
750747
Future<List<String>> _getExtensionRpcs() async {
751-
final expression =
752-
"${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk').developer._extensions.keys.toList();";
748+
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
749+
.getDartDeveloperExtensionNamesJsExpression();
753750
final extensionRpcs = <String>[];
754751
final params = {
755752
'expression': expression,

dwds/lib/src/debugging/instance.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ class InstanceHelper extends Domain {
306306
// We do this in in awkward way because we want the keys and values, but we
307307
// can't return things by value or some Dart objects will come back as
308308
// values that we need to be RemoteObject, e.g. a List of int.
309-
final expression = _jsRuntimeFunctionCall('getMapElements(this)');
309+
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
310+
.getMapElementsJsExpression();
310311

311312
final keysAndValues = await inspector.jsCallFunctionOn(map, expression, []);
312313
final keys = await inspector.loadField(keysAndValues, 'keys');
@@ -674,8 +675,8 @@ class InstanceHelper extends Domain {
674675
final length = metaData.length;
675676
final objectId = remoteObject.objectId;
676677
if (objectId == null) return null;
677-
678-
final expression = _jsRuntimeFunctionCall('getSetElements(this)');
678+
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
679+
.getSetElementsJsExpression();
679680

680681
final result =
681682
await inspector.jsCallFunctionOn(remoteObject, expression, []);

dwds/lib/src/debugging/libraries.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,8 @@ class LibraryHelper extends Domain {
8282
final libraryUri = libraryRef.uri;
8383
if (libraryId == null || libraryUri == null) return null;
8484
// Fetch information about all the classes in this library.
85-
final expression = '''
86-
(function() {
87-
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk');
88-
const dart = sdk.dart;
89-
return dart.getLibraryMetadata('$libraryUri');
90-
})()
91-
''';
85+
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
86+
.getClassesInLibraryJsExpression(libraryUri);
9287

9388
RemoteObject? result;
9489
try {

dwds/test/instances/common/instance_inspection_common.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void runTests({
6262
verboseCompiler: debug,
6363
canaryFeatures: canaryFeatures,
6464
experiments: ['records'],
65+
moduleFormat: provider.ddcModuleFormat,
6566
),
6667
);
6768
service = context.debugConnection.vmService;

dwds/test/instances/instance_inspection_canary_test.dart renamed to dwds/test/instances/instance_inspection_amd_canary_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

@@ -7,6 +7,7 @@
77
@Timeout(Duration(minutes: 2))
88
library;
99

10+
import 'package:dwds/src/services/expression_compiler.dart';
1011
import 'package:test/test.dart';
1112
import 'package:test_common/test_sdk_configuration.dart';
1213

@@ -22,6 +23,7 @@ void main() {
2223
final provider = TestSdkConfigurationProvider(
2324
verbose: debug,
2425
canaryFeatures: canaryFeatures,
26+
ddcModuleFormat: ModuleFormat.amd,
2527
);
2628
tearDownAll(provider.dispose);
2729

dwds/test/instances/instance_inspection_test.dart renamed to dwds/test/instances/instance_inspection_amd_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

@@ -7,6 +7,7 @@
77
@Timeout(Duration(minutes: 2))
88
library;
99

10+
import 'package:dwds/src/services/expression_compiler.dart';
1011
import 'package:test/test.dart';
1112
import 'package:test_common/test_sdk_configuration.dart';
1213

@@ -22,6 +23,7 @@ void main() {
2223
final provider = TestSdkConfigurationProvider(
2324
verbose: debug,
2425
canaryFeatures: canaryFeatures,
26+
ddcModuleFormat: ModuleFormat.amd,
2527
);
2628
tearDownAll(provider.dispose);
2729

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
@Tags(['daily'])
6+
@TestOn('vm')
7+
@Timeout(Duration(minutes: 2))
8+
library;
9+
10+
import 'package:dwds/expression_compiler.dart';
11+
import 'package:test/test.dart';
12+
import 'package:test_common/test_sdk_configuration.dart';
13+
14+
import '../fixtures/context.dart';
15+
import 'common/instance_inspection_common.dart';
16+
17+
void main() {
18+
// Enable verbose logging for debugging.
19+
final debug = false;
20+
final canaryFeatures = true;
21+
final compilationMode = CompilationMode.frontendServer;
22+
23+
group('canary: $canaryFeatures |', () {
24+
final provider = TestSdkConfigurationProvider(
25+
verbose: debug,
26+
canaryFeatures: canaryFeatures,
27+
ddcModuleFormat: ModuleFormat.ddc,
28+
);
29+
tearDownAll(provider.dispose);
30+
runTests(
31+
provider: provider,
32+
compilationMode: compilationMode,
33+
canaryFeatures: canaryFeatures,
34+
debug: debug,
35+
);
36+
});
37+
}

0 commit comments

Comments
 (0)