Skip to content

Commit cf1fa44

Browse files
authored
Added support for getClassMetadata with the DDc library bundle format (#2535)
* Added support for getClassMetadata with the DDc library bundle format * addressing comment - updated copyright and explicitly provided ddcModuleFormat
1 parent ba4851f commit cf1fa44

7 files changed

+223
-137
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
to use the provided `name` in a `ModuleMetadata`. Metadata provided by DDC
1212
when using the library bundle format does not provide a useful bundle name.
1313
- Migrate to `package:web` v1.1.0.
14-
- Added support for some debugging APIs with the DDC library bundle format. - [#2488](https://github.com/dart-lang/webdev/issues/2488)
14+
- Added support for some debugging APIs with the DDC library bundle format. - [#2488](https://github.com/dart-lang/webdev/issues/2488), [#2534](https://github.com/dart-lang/webdev/issues/2534)
1515
- Update `package:vm_service` to '>=14.2.4 <16.0.0'.
1616
- Update `package:vm_service_interface` to '2.0.1'.
1717

dwds/lib/src/debugging/classes.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,8 @@ class ClassHelper extends Domain {
7777

7878
if (libraryUri == null || classId == null || className == null) return null;
7979

80-
final expression = '''
81-
(function() {
82-
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk');
83-
const dart = sdk.dart;
84-
return dart.getClassMetadata('$libraryUri', '$className');
85-
})()
86-
''';
87-
80+
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
81+
.getClassMetadataJsExpression(libraryUri, className);
8882
RemoteObject result;
8983
try {
9084
result = await inspector.remoteDebugger.evaluate(

dwds/lib/src/debugging/dart_runtime_debugger.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class DartRuntimeDebugger {
1414
}) : _loadStrategy = loadStrategy,
1515
_useLibraryBundleExpression = useLibraryBundleExpression;
1616

17+
/// Generates a JS expression based on DDC module format.
1718
String _generateJsExpression(
1819
String ddcExpression,
1920
String libraryBundleExpression,
@@ -23,16 +24,18 @@ class DartRuntimeDebugger {
2324
: ddcExpression;
2425
}
2526

27+
/// Wraps a JS function call with SDK loader logic.
2628
String _wrapWithSdkLoader(String args, String functionCall) {
2729
return '''
2830
function($args) {
29-
const sdk = ${_loadStrategy.loadModuleSnippet}("dart_sdk");
31+
const sdk = ${_loadStrategy.loadModuleSnippet}('dart_sdk');
3032
const dart = sdk.dart;
3133
return dart.$functionCall;
3234
}
3335
''';
3436
}
3537

38+
/// Wraps a JS function call with DDC library bundle loader logic.
3639
String _wrapWithBundleLoader(String args, String functionCall) {
3740
return '''
3841
function($args) {
@@ -41,6 +44,12 @@ class DartRuntimeDebugger {
4144
''';
4245
}
4346

47+
/// Wraps an expression in an Immediately Invoked Function Expression (IIFE).
48+
String _wrapInIIFE(String expression) {
49+
return '($expression)()';
50+
}
51+
52+
/// Builds a JS expression based on the loading strategy.
4453
String _buildExpression(
4554
String args,
4655
String ddcFunction,
@@ -52,6 +61,7 @@ class DartRuntimeDebugger {
5261
);
5362
}
5463

64+
/// Generates a JS expression for retrieving object metadata.
5565
String getObjectMetadataJsExpression() {
5666
return _buildExpression(
5767
'arg',
@@ -60,6 +70,7 @@ class DartRuntimeDebugger {
6070
);
6171
}
6272

73+
/// Generates a JS expression for retrieving object field names.
6374
String getObjectFieldNamesJsExpression() {
6475
return _buildExpression(
6576
'',
@@ -68,6 +79,7 @@ class DartRuntimeDebugger {
6879
);
6980
}
7081

82+
/// Generates a JS expression for retrieving function metadata.
7183
String getFunctionMetadataJsExpression() {
7284
return _buildExpression(
7385
'',
@@ -76,11 +88,23 @@ class DartRuntimeDebugger {
7688
);
7789
}
7890

91+
/// Generates a JS expression for retrieving a subrange of elements.
7992
String getSubRangeJsExpression() {
8093
return _buildExpression(
8194
'offset, count',
8295
'getSubRange(this, offset, count)',
8396
'getSubRange(this, offset, count)',
8497
);
8598
}
99+
100+
/// Generates a JS expression for retrieving class metadata.
101+
String getClassMetadataJsExpression(String libraryUri, String className) {
102+
final expression = _buildExpression(
103+
'',
104+
"getClassMetadata('$libraryUri', '$className')",
105+
"getClassMetadata('$libraryUri', '$className')",
106+
);
107+
// Use the helper method to wrap this in an IIFE
108+
return _wrapInIIFE(expression);
109+
}
86110
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2023, 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/class_inspection_common.dart';
16+
17+
void main() {
18+
// Enable verbose logging for debugging.
19+
final debug = false;
20+
final canaryFeatures = false;
21+
22+
group('Class |', () {
23+
final provider = TestSdkConfigurationProvider(
24+
verbose: debug,
25+
ddcModuleFormat: ModuleFormat.amd,
26+
);
27+
tearDownAll(provider.dispose);
28+
for (final compilationMode in CompilationMode.values) {
29+
runTests(
30+
provider: provider,
31+
compilationMode: compilationMode,
32+
canaryFeatures: canaryFeatures,
33+
debug: debug,
34+
);
35+
}
36+
});
37+
}
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/class_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+
final provider = TestSdkConfigurationProvider(
23+
verbose: debug,
24+
canaryFeatures: canaryFeatures,
25+
ddcModuleFormat: ModuleFormat.ddc,
26+
);
27+
28+
group('Class |', () {
29+
tearDownAll(provider.dispose);
30+
runTests(
31+
provider: provider,
32+
compilationMode: compilationMode,
33+
canaryFeatures: canaryFeatures,
34+
debug: debug,
35+
);
36+
});
37+
}

dwds/test/instances/class_inspection_test.dart

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)