Skip to content

Added support for callLibraryMethod with the DDC library bundle format. #2577

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 33 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7caa652
Added support for getClassMetadata with the DDc library bundle format
jyameo Dec 5, 2024
5f29674
Merge branch 'main' into yj-dartdevembedder-3
jyameo Dec 10, 2024
17a9775
Merge branch 'main' into yj-dartdevembedder-3
jyameo Dec 12, 2024
f3b2bd7
Added support for some debugging APIs with the DDC library bundle for…
jyameo Dec 12, 2024
a1f017c
Update pattern test to account for new DDC JS variable naming
jyameo Dec 13, 2024
58b8762
reverting change to pattern test
jyameo Dec 13, 2024
c781e5f
Added support for debugging API with the DDC library bundle format.
jyameo Dec 13, 2024
8a9006a
Merge branch 'main' into yj-dartdevembedder-4
jyameo Dec 17, 2024
0b235e6
updated licenses
jyameo Dec 17, 2024
607c7e4
updated licenses and remove new line from changelog
jyameo Dec 17, 2024
067ab27
Merge branch 'main' into yj-dartdevembedder-5
jyameo Dec 18, 2024
b9a8c2f
Added support for some debugging APIs with the DDC library bundle for…
jyameo Dec 18, 2024
b220536
Merge branch 'main' into yj-dartdevembedder-5
jyameo Dec 23, 2024
75f57a9
Merge branch 'main' into yj-dartdevembedder-5
jyameo Dec 23, 2024
3401d30
Merge branch 'main' into yj-dartdevembedder-5
jyameo Dec 23, 2024
1e44766
Added support for some debugging APIs with the DDC library bundle format
jyameo Jan 9, 2025
62c3cea
Merge branch 'main' into yj-dartdevembedder-6
jyameo Jan 9, 2025
c537b7b
updated CHANGELOG
jyameo Jan 9, 2025
0e35c5e
refactored test to use common file
jyameo Jan 10, 2025
344867d
delete main_ddc_library_bundle.dart
jyameo Jan 10, 2025
22cdf34
Merge branch 'main' into yj-dartdevembedder-6
jyameo Jan 10, 2025
db9abfb
fixed broken test - decoded response body to match source and renamed…
jyameo Jan 15, 2025
c7b0632
Merge branch 'main' into yj-dartdevembedder-6
jyameo Jan 15, 2025
1bc9d5c
updated changelog
jyameo Jan 15, 2025
32c12a5
updated dart_scope to not renamed wildcard and skipped related test case
jyameo Jan 16, 2025
aa38d3a
formatted test/common/chrome_proxy_service_common.dart
jyameo Jan 16, 2025
a551cb5
WIP
jyameo Jan 20, 2025
e81fa22
Added support for callLibraryMethod with the DDC library bundle format.
jyameo Jan 22, 2025
72d198a
updated DCM
jyameo Jan 22, 2025
951e72b
revert changes to callFunction
jyameo Jan 22, 2025
498184a
updated function name and comments
jyameo Jan 23, 2025
006322f
Merge branch 'main' into yj-dev-2566
jyameo Jan 24, 2025
c83a78c
updated CHANGELOG
jyameo Jan 24, 2025
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
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## 24.3.4-wip
- Added support for some debugging APIs with the DDC library bundle format. - [#2566](https://github.com/dart-lang/webdev/issues/2566)

## 24.3.3

Expand Down
28 changes: 28 additions & 0 deletions dwds/lib/src/debugging/dart_runtime_debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,38 @@ class DartRuntimeDebugger {
);
}

/// Generates a JS expression to invoke a Dart extension method.
String invokeExtensionJsExpression(String methodName, String encodedJson) {
return _generateJsExpression(
"${_loadStrategy.loadModuleSnippet}('dart_sdk').developer.invokeExtension('$methodName', JSON.stringify($encodedJson));",
"dartDevEmbedder.debugger.invokeExtension('$methodName', JSON.stringify($encodedJson));",
);
}

/// Generates a JS expression for calling a library method.
String callLibraryMethodJsExpression(
String libraryUri,
String methodName,
) {
final findLibraryExpression = '''
(function() {
const sdk = ${_loadStrategy.loadModuleSnippet}('dart_sdk');
const dart = sdk.dart;
const library = dart.getLibrary('$libraryUri');
if (!library) throw 'cannot find library for $libraryUri';
return library;
})();
''';

// `callLibraryMethod` expects an array of arguments. Chrome DevTools spreads
// arguments individually when calling functions. This code reconstructs the
// expected argument array.
return _generateJsExpression(
findLibraryExpression,
_wrapWithBundleLoader(
'',
'callLibraryMethod("$libraryUri", "$methodName", Array.from(arguments))',
),
);
}
}
49 changes: 34 additions & 15 deletions dwds/lib/src/debugging/inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:dwds/src/debugging/instance.dart';
import 'package:dwds/src/debugging/libraries.dart';
import 'package:dwds/src/debugging/location.dart';
import 'package:dwds/src/debugging/remote_debugger.dart';
import 'package:dwds/src/loaders/ddc_library_bundle.dart';
import 'package:dwds/src/readers/asset_reader.dart';
import 'package:dwds/src/utilities/conversions.dart';
import 'package:dwds/src/utilities/dart_uri.dart';
Expand Down Expand Up @@ -301,11 +302,17 @@ class AppInspector implements AppInspectorInterface {
String selector,
List<RemoteObject> arguments,
) {
return _evaluateInLibrary(
library,
'function () { return this.$selector.apply(this, arguments);}',
arguments,
);
return globalToolConfiguration.loadStrategy is DdcLibraryBundleStrategy
? _evaluateLibraryMethodWithDdcLibraryBundle(
library,
selector,
arguments,
)
: _evaluateInLibrary(
library,
'function () { return this.$selector.apply(this, arguments); }',
arguments,
);
}

/// Evaluate [expression] by calling Chrome's Runtime.evaluate.
Expand Down Expand Up @@ -340,19 +347,31 @@ class AppInspector implements AppInspectorInterface {
if (libraryUri == null) {
throwInvalidParam('invoke', 'library uri is null');
}
final findLibrary = '''
(function() {
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk');
const dart = sdk.dart;
const library = dart.getLibrary('$libraryUri');
if (!library) throw 'cannot find library for $libraryUri';
return library;
})();
''';
final remoteLibrary = await jsEvaluate(findLibrary);
final findLibraryJsExpression = globalToolConfiguration
.loadStrategy.dartRuntimeDebugger
.callLibraryMethodJsExpression(libraryUri, jsFunction);

final remoteLibrary = await jsEvaluate(findLibraryJsExpression);
return jsCallFunctionOn(remoteLibrary, jsFunction, arguments);
}

/// Evaluates the specified top-level method [methodName] within [library]
/// using the Dart Development Compiler (DDC) library bundle strategy with
/// the given [arguments].
Future<RemoteObject> _evaluateLibraryMethodWithDdcLibraryBundle(
Library library,
String methodName,
List<RemoteObject> arguments,
) {
final libraryUri = library.uri;
if (libraryUri == null) {
throwInvalidParam('invoke', 'library uri is null');
}
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
.callLibraryMethodJsExpression(libraryUri, methodName);
return _jsCallFunction(expression, arguments);
}

/// Call [function] with objects referred by [argumentIds] as arguments.
@override
Future<RemoteObject> callFunction(
Expand Down
15 changes: 0 additions & 15 deletions dwds/test/common/chrome_proxy_service_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1733,9 +1733,6 @@ void runTests({
.having((instance) => instance.kind, 'kind', 'String'),
);
},
skip: moduleFormat == ModuleFormat.ddc && canaryFeatures == true
? 'https://github.com/dart-lang/webdev/issues/2566'
: null,
);

test(
Expand All @@ -1761,9 +1758,6 @@ void runTests({
.having((instance) => instance.kind, 'kind', 'Null'),
);
},
skip: moduleFormat == ModuleFormat.ddc && canaryFeatures == true
? 'https://github.com/dart-lang/webdev/issues/2566'
: null,
);

test(
Expand All @@ -1789,9 +1783,6 @@ void runTests({
.having((instance) => instance.kind, 'kind', 'Bool'),
);
},
skip: moduleFormat == ModuleFormat.ddc && canaryFeatures == true
? 'https://github.com/dart-lang/webdev/issues/2566'
: null,
);

test(
Expand All @@ -1817,9 +1808,6 @@ void runTests({
.having((instance) => instance.kind, 'kind', 'Double'),
);
},
skip: moduleFormat == ModuleFormat.ddc && canaryFeatures == true
? 'https://github.com/dart-lang/webdev/issues/2566'
: null,
);

test(
Expand All @@ -1845,9 +1833,6 @@ void runTests({
.having((instance) => instance.kind, 'kind', 'String'),
);
},
skip: moduleFormat == ModuleFormat.ddc && canaryFeatures == true
? 'https://github.com/dart-lang/webdev/issues/2566'
: null,
);
});

Expand Down
Loading