Skip to content

Commit 659e1df

Browse files
authored
Added support for some debugging APIs with the DDC library bundle format - part 5 (#2549)
* 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 * Added support for debugging API with the DDC library bundle format. * updated licenses * updated licenses and remove new line from changelog * Added support for some debugging APIs with the DDC library bundle format - getRecordTypeFieldsJsExpression, callInstanceMethodJsExpression
1 parent fcd906f commit 659e1df

8 files changed

+79
-19
lines changed

dwds/CHANGELOG.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
## 24.3.0
44

55
- Update to be forward compatible with changes to `package:shelf_web_socket`.
6-
- Added support for some debugging APIs with the DDC library bundle format. - [#2537](https://github.com/dart-lang/webdev/issues/2537)
7-
- 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)
6+
- 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),[#2548](https://github.com/dart-lang/webdev/issues/2548)
87
- Fix issue where batched expression evals were failing if any subexpression failed. - [#2551](https://github.com/dart-lang/webdev/issues/2551)
98
- Expose a partial implementation of
109
`FrontendServerDdcLibraryBundleStrategyProvider`.

dwds/lib/src/debugging/dart_runtime_debugger.dart

+30
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,34 @@ class DartRuntimeDebugger {
169169
'getRecordFields(this)',
170170
);
171171
}
172+
173+
/// Generates a JS expression for retrieving the fields of a record type.
174+
String getRecordTypeFieldsJsExpression() {
175+
return _buildExpression(
176+
'',
177+
'getRecordTypeFields(this)',
178+
'getRecordTypeFields(this)',
179+
);
180+
}
181+
182+
/// Generates a JS expression for calling an instance method on an object.
183+
String callInstanceMethodJsExpression(String methodName) {
184+
String generateInstanceMethodJsExpression(String functionCall) {
185+
return '''
186+
function () {
187+
if (!Object.getPrototypeOf(this)) { return 'Instance of PlainJavaScriptObject'; }
188+
return $functionCall;
189+
}
190+
''';
191+
}
192+
193+
return _generateJsExpression(
194+
generateInstanceMethodJsExpression(
195+
'${_loadStrategy.loadModuleSnippet}("dart_sdk").dart.dsendRepl(this, "$methodName", arguments)',
196+
),
197+
generateInstanceMethodJsExpression(
198+
'dartDevEmbedder.debugger.callInstanceMethod(this, "$methodName", arguments)',
199+
),
200+
);
201+
}
172202
}

dwds/lib/src/debugging/inspector.dart

+2-6
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,8 @@ class AppInspector implements AppInspectorInterface {
210210
throw UnsupportedError('Named arguments are not yet supported');
211211
}
212212
// We use the JS pseudo-variable 'arguments' to get the list of all arguments.
213-
final send = '''
214-
function () {
215-
if (!Object.getPrototypeOf(this)) { return 'Instance of PlainJavaScriptObject';}
216-
return ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").dart.dsendRepl(this, "$methodName", arguments);
217-
}
218-
''';
213+
final send = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
214+
.callInstanceMethodJsExpression(methodName);
219215
final remote = await jsCallFunctionOn(receiver, send, positionalArgs);
220216
return remote;
221217
}

dwds/lib/src/debugging/instance.dart

+2-9
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,8 @@ class InstanceHelper extends Domain {
653653
// We do this in in awkward way because we want the names and types, but we
654654
// can't return things by value or some Dart objects will come back as
655655
// values that we need to be RemoteObject, e.g. a List of int.
656-
final expression = _jsRuntimeFunctionCall('getRecordTypeFields(this)');
656+
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
657+
.getRecordTypeFieldsJsExpression();
657658

658659
final result = await inspector.jsCallFunctionOn(record, expression, []);
659660
final fieldNameElements =
@@ -887,11 +888,3 @@ class InstanceHelper extends Domain {
887888
}
888889
}
889890
}
890-
891-
String _jsRuntimeFunctionCall(String expression) => '''
892-
function() {
893-
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk');
894-
const dart = sdk.dart;
895-
return dart.$expression;
896-
}
897-
''';

dwds/test/instances/common/record_type_inspection_common.dart

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ void runTests({
6464
verboseCompiler: debug,
6565
experiments: ['records', 'patterns'],
6666
canaryFeatures: canaryFeatures,
67+
moduleFormat: provider.ddcModuleFormat,
6768
),
6869
);
6970
service = context.debugConnection.vmService;

dwds/test/instances/record_type_inspection_canary_test.dart renamed to dwds/test/instances/record_type_inspection_amd_canary_test.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2023, 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/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/record_type_inspection_test.dart renamed to dwds/test/instances/record_type_inspection_amd_test.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2023, 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/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

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/record_type_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)