Skip to content

Commit 1337a21

Browse files
committed
Merge branch 'main' of github.com:dart-lang/webdev into dds_port
2 parents dd229b4 + edcfbf1 commit 1337a21

17 files changed

+186
-29
lines changed

dwds/CHANGELOG.md

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

33
- Update to be forward compatible with changes to `package:shelf_web_socket`.
44
- Add support for binding DDS to a custom port.
5+
- Added support for some debugging APIs with the DDC library bundle format. - [#2537](https://github.com/dart-lang/webdev/issues/2537),[#2544](https://github.com/dart-lang/webdev/issues/2544)
56

67
## 24.2.0
78

dwds/lib/src/debugging/dart_runtime_debugger.dart

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,66 @@ 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+
}
163+
164+
/// Generates a JS expression for retrieving the fields of a record.
165+
String getRecordFieldsJsExpression() {
166+
return _buildExpression(
167+
'',
168+
'getRecordFields(this)',
169+
'getRecordFields(this)',
170+
);
171+
}
110172
}

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: 6 additions & 4 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');
@@ -523,7 +524,8 @@ class InstanceHelper extends Domain {
523524
// We do this in in awkward way because we want the keys and values, but we
524525
// can't return things by value or some Dart objects will come back as
525526
// values that we need to be RemoteObject, e.g. a List of int.
526-
final expression = _jsRuntimeFunctionCall('getRecordFields(this)');
527+
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
528+
.getRecordFieldsJsExpression();
527529

528530
final result = await inspector.jsCallFunctionOn(record, expression, []);
529531
final fieldNameElements =
@@ -674,8 +676,8 @@ class InstanceHelper extends Domain {
674676
final length = metaData.length;
675677
final objectId = remoteObject.objectId;
676678
if (objectId == null) return null;
677-
678-
final expression = _jsRuntimeFunctionCall('getSetElements(this)');
679+
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
680+
.getSetElementsJsExpression();
679681

680682
final result =
681683
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/common/patterns_inspection_common.dart

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:test/test.dart';
66
import 'package:test_common/logging.dart';
77
import 'package:test_common/test_sdk_configuration.dart';
8+
import 'package:test_common/utilities.dart';
89
import 'package:vm_service/vm_service.dart';
910

1011
import '../../fixtures/context.dart';
@@ -96,11 +97,24 @@ void runTests({
9697
await onBreakPoint('testPatternCase2', (event) async {
9798
final frame = event.topFrame!;
9899

99-
expect(await getFrameVariables(frame), {
100-
'obj': matchListInstance(type: 'Object'),
101-
'a': matchPrimitiveInstance(kind: InstanceKind.kString, value: 'b'),
102-
'n': matchPrimitiveInstance(kind: InstanceKind.kDouble, value: 3.14),
103-
});
100+
if (dartSdkIsAtLeast('3.7.0-246.0.dev')) {
101+
expect(await getFrameVariables(frame), {
102+
'obj': matchListInstance(type: 'Object'),
103+
// Renamed to avoid shadowing variables from previous case.
104+
'a\$':
105+
matchPrimitiveInstance(kind: InstanceKind.kString, value: 'b'),
106+
'n\$':
107+
matchPrimitiveInstance(kind: InstanceKind.kDouble, value: 3.14),
108+
});
109+
} else {
110+
expect(await getFrameVariables(frame), {
111+
'obj': matchListInstance(type: 'Object'),
112+
// Renamed to avoid shadowing variables from previous case.
113+
'a': matchPrimitiveInstance(kind: InstanceKind.kString, value: 'b'),
114+
'n':
115+
matchPrimitiveInstance(kind: InstanceKind.kDouble, value: 3.14),
116+
});
117+
}
104118
});
105119
});
106120

dwds/test/instances/common/record_inspection_common.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void runTests({
6666
verboseCompiler: debug,
6767
experiments: ['records', 'patterns'],
6868
canaryFeatures: canaryFeatures,
69+
moduleFormat: provider.ddcModuleFormat,
6970
),
7071
);
7172
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

0 commit comments

Comments
 (0)