Skip to content

Added support for getClassMetadata with the DDc library bundle format #2535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
to use the provided `name` in a `ModuleMetadata`. Metadata provided by DDC
when using the library bundle format does not provide a useful bundle name.
- Migrate to `package:web` v1.1.0.
- Added support for some debugging APIs with the DDC library bundle format. - [#2488](https://github.com/dart-lang/webdev/issues/2488)
- 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)
- Update `package:vm_service` to '>=14.2.4 <16.0.0'.
- Update `package:vm_service_interface` to '2.0.1'.

Expand Down
10 changes: 2 additions & 8 deletions dwds/lib/src/debugging/classes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,8 @@ class ClassHelper extends Domain {

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

final expression = '''
(function() {
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk');
const dart = sdk.dart;
return dart.getClassMetadata('$libraryUri', '$className');
})()
''';

final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
.getClassMetadataJsExpression(libraryUri, className);
RemoteObject result;
try {
result = await inspector.remoteDebugger.evaluate(
Expand Down
26 changes: 25 additions & 1 deletion dwds/lib/src/debugging/dart_runtime_debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class DartRuntimeDebugger {
}) : _loadStrategy = loadStrategy,
_useLibraryBundleExpression = useLibraryBundleExpression;

/// Generates a JS expression based on DDC module format.
String _generateJsExpression(
String ddcExpression,
String libraryBundleExpression,
Expand All @@ -23,16 +24,18 @@ class DartRuntimeDebugger {
: ddcExpression;
}

/// Wraps a JS function call with SDK loader logic.
String _wrapWithSdkLoader(String args, String functionCall) {
return '''
function($args) {
const sdk = ${_loadStrategy.loadModuleSnippet}("dart_sdk");
const sdk = ${_loadStrategy.loadModuleSnippet}('dart_sdk');
const dart = sdk.dart;
return dart.$functionCall;
}
''';
}

/// Wraps a JS function call with DDC library bundle loader logic.
String _wrapWithBundleLoader(String args, String functionCall) {
return '''
function($args) {
Expand All @@ -41,6 +44,12 @@ class DartRuntimeDebugger {
''';
}

/// Wraps an expression in an Immediately Invoked Function Expression (IIFE).
String _wrapInIIFE(String expression) {
return '($expression)()';
}

/// Builds a JS expression based on the loading strategy.
String _buildExpression(
String args,
String ddcFunction,
Expand All @@ -52,6 +61,7 @@ class DartRuntimeDebugger {
);
}

/// Generates a JS expression for retrieving object metadata.
String getObjectMetadataJsExpression() {
return _buildExpression(
'arg',
Expand All @@ -60,6 +70,7 @@ class DartRuntimeDebugger {
);
}

/// Generates a JS expression for retrieving object field names.
String getObjectFieldNamesJsExpression() {
return _buildExpression(
'',
Expand All @@ -68,6 +79,7 @@ class DartRuntimeDebugger {
);
}

/// Generates a JS expression for retrieving function metadata.
String getFunctionMetadataJsExpression() {
return _buildExpression(
'',
Expand All @@ -76,11 +88,23 @@ class DartRuntimeDebugger {
);
}

/// Generates a JS expression for retrieving a subrange of elements.
String getSubRangeJsExpression() {
return _buildExpression(
'offset, count',
'getSubRange(this, offset, count)',
'getSubRange(this, offset, count)',
);
}

/// Generates a JS expression for retrieving class metadata.
String getClassMetadataJsExpression(String libraryUri, String className) {
final expression = _buildExpression(
'',
"getClassMetadata('$libraryUri', '$className')",
"getClassMetadata('$libraryUri', '$className')",
);
// Use the helper method to wrap this in an IIFE
return _wrapInIIFE(expression);
}
}
37 changes: 37 additions & 0 deletions dwds/test/instances/class_inspection_amd_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@Tags(['daily'])
@TestOn('vm')
@Timeout(Duration(minutes: 2))
library;

import 'package:dwds/expression_compiler.dart';
import 'package:test/test.dart';
import 'package:test_common/test_sdk_configuration.dart';

import '../fixtures/context.dart';
import 'common/class_inspection_common.dart';

void main() {
// Enable verbose logging for debugging.
final debug = false;
final canaryFeatures = false;

group('Class |', () {
final provider = TestSdkConfigurationProvider(
verbose: debug,
ddcModuleFormat: ModuleFormat.amd,
);
tearDownAll(provider.dispose);
for (final compilationMode in CompilationMode.values) {
runTests(
provider: provider,
compilationMode: compilationMode,
canaryFeatures: canaryFeatures,
debug: debug,
);
}
});
}
37 changes: 37 additions & 0 deletions dwds/test/instances/class_inspection_ddc_library_bundle_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@Tags(['daily'])
@TestOn('vm')
@Timeout(Duration(minutes: 2))
library;

import 'package:dwds/expression_compiler.dart';
import 'package:test/test.dart';
import 'package:test_common/test_sdk_configuration.dart';

import '../fixtures/context.dart';
import 'common/class_inspection_common.dart';

void main() {
// Enable verbose logging for debugging.
final debug = false;
final canaryFeatures = true;
final compilationMode = CompilationMode.frontendServer;
final provider = TestSdkConfigurationProvider(
verbose: debug,
canaryFeatures: canaryFeatures,
ddcModuleFormat: ModuleFormat.ddc,
);

group('Class |', () {
tearDownAll(provider.dispose);
runTests(
provider: provider,
compilationMode: compilationMode,
canaryFeatures: canaryFeatures,
debug: debug,
);
});
}
127 changes: 0 additions & 127 deletions dwds/test/instances/class_inspection_test.dart

This file was deleted.

Loading
Loading