Skip to content

Commit 5dc7950

Browse files
authored
Added support for callLibraryMethod with the DDC library bundle format. (#2577)
* 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 * Added support for some debugging APIs with the DDC library bundle format * updated CHANGELOG * refactored test to use common file * delete main_ddc_library_bundle.dart * fixed broken test - decoded response body to match source and renamed stack property * updated changelog * updated dart_scope to not renamed wildcard and skipped related test case * formatted test/common/chrome_proxy_service_common.dart * WIP * Added support for callLibraryMethod with the DDC library bundle format. * revert changes to callFunction * updated function name and comments * updated CHANGELOG
1 parent 1d0b32c commit 5dc7950

File tree

4 files changed

+63
-30
lines changed

4 files changed

+63
-30
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## 24.3.4-wip
2+
- Added support for some debugging APIs with the DDC library bundle format. - [#2566](https://github.com/dart-lang/webdev/issues/2566)
23

34
## 24.3.3
45

dwds/lib/src/debugging/dart_runtime_debugger.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,38 @@ class DartRuntimeDebugger {
197197
);
198198
}
199199

200+
/// Generates a JS expression to invoke a Dart extension method.
200201
String invokeExtensionJsExpression(String methodName, String encodedJson) {
201202
return _generateJsExpression(
202203
"${_loadStrategy.loadModuleSnippet}('dart_sdk').developer.invokeExtension('$methodName', JSON.stringify($encodedJson));",
203204
"dartDevEmbedder.debugger.invokeExtension('$methodName', JSON.stringify($encodedJson));",
204205
);
205206
}
207+
208+
/// Generates a JS expression for calling a library method.
209+
String callLibraryMethodJsExpression(
210+
String libraryUri,
211+
String methodName,
212+
) {
213+
final findLibraryExpression = '''
214+
(function() {
215+
const sdk = ${_loadStrategy.loadModuleSnippet}('dart_sdk');
216+
const dart = sdk.dart;
217+
const library = dart.getLibrary('$libraryUri');
218+
if (!library) throw 'cannot find library for $libraryUri';
219+
return library;
220+
})();
221+
''';
222+
223+
// `callLibraryMethod` expects an array of arguments. Chrome DevTools spreads
224+
// arguments individually when calling functions. This code reconstructs the
225+
// expected argument array.
226+
return _generateJsExpression(
227+
findLibraryExpression,
228+
_wrapWithBundleLoader(
229+
'',
230+
'callLibraryMethod("$libraryUri", "$methodName", Array.from(arguments))',
231+
),
232+
);
233+
}
206234
}

dwds/lib/src/debugging/inspector.dart

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:dwds/src/debugging/instance.dart';
1414
import 'package:dwds/src/debugging/libraries.dart';
1515
import 'package:dwds/src/debugging/location.dart';
1616
import 'package:dwds/src/debugging/remote_debugger.dart';
17+
import 'package:dwds/src/loaders/ddc_library_bundle.dart';
1718
import 'package:dwds/src/readers/asset_reader.dart';
1819
import 'package:dwds/src/utilities/conversions.dart';
1920
import 'package:dwds/src/utilities/dart_uri.dart';
@@ -301,11 +302,17 @@ class AppInspector implements AppInspectorInterface {
301302
String selector,
302303
List<RemoteObject> arguments,
303304
) {
304-
return _evaluateInLibrary(
305-
library,
306-
'function () { return this.$selector.apply(this, arguments);}',
307-
arguments,
308-
);
305+
return globalToolConfiguration.loadStrategy is DdcLibraryBundleStrategy
306+
? _evaluateLibraryMethodWithDdcLibraryBundle(
307+
library,
308+
selector,
309+
arguments,
310+
)
311+
: _evaluateInLibrary(
312+
library,
313+
'function () { return this.$selector.apply(this, arguments); }',
314+
arguments,
315+
);
309316
}
310317

311318
/// Evaluate [expression] by calling Chrome's Runtime.evaluate.
@@ -340,19 +347,31 @@ class AppInspector implements AppInspectorInterface {
340347
if (libraryUri == null) {
341348
throwInvalidParam('invoke', 'library uri is null');
342349
}
343-
final findLibrary = '''
344-
(function() {
345-
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk');
346-
const dart = sdk.dart;
347-
const library = dart.getLibrary('$libraryUri');
348-
if (!library) throw 'cannot find library for $libraryUri';
349-
return library;
350-
})();
351-
''';
352-
final remoteLibrary = await jsEvaluate(findLibrary);
350+
final findLibraryJsExpression = globalToolConfiguration
351+
.loadStrategy.dartRuntimeDebugger
352+
.callLibraryMethodJsExpression(libraryUri, jsFunction);
353+
354+
final remoteLibrary = await jsEvaluate(findLibraryJsExpression);
353355
return jsCallFunctionOn(remoteLibrary, jsFunction, arguments);
354356
}
355357

358+
/// Evaluates the specified top-level method [methodName] within [library]
359+
/// using the Dart Development Compiler (DDC) library bundle strategy with
360+
/// the given [arguments].
361+
Future<RemoteObject> _evaluateLibraryMethodWithDdcLibraryBundle(
362+
Library library,
363+
String methodName,
364+
List<RemoteObject> arguments,
365+
) {
366+
final libraryUri = library.uri;
367+
if (libraryUri == null) {
368+
throwInvalidParam('invoke', 'library uri is null');
369+
}
370+
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
371+
.callLibraryMethodJsExpression(libraryUri, methodName);
372+
return _jsCallFunction(expression, arguments);
373+
}
374+
356375
/// Call [function] with objects referred by [argumentIds] as arguments.
357376
@override
358377
Future<RemoteObject> callFunction(

dwds/test/common/chrome_proxy_service_common.dart

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,9 +1733,6 @@ void runTests({
17331733
.having((instance) => instance.kind, 'kind', 'String'),
17341734
);
17351735
},
1736-
skip: moduleFormat == ModuleFormat.ddc && canaryFeatures == true
1737-
? 'https://github.com/dart-lang/webdev/issues/2566'
1738-
: null,
17391736
);
17401737

17411738
test(
@@ -1761,9 +1758,6 @@ void runTests({
17611758
.having((instance) => instance.kind, 'kind', 'Null'),
17621759
);
17631760
},
1764-
skip: moduleFormat == ModuleFormat.ddc && canaryFeatures == true
1765-
? 'https://github.com/dart-lang/webdev/issues/2566'
1766-
: null,
17671761
);
17681762

17691763
test(
@@ -1789,9 +1783,6 @@ void runTests({
17891783
.having((instance) => instance.kind, 'kind', 'Bool'),
17901784
);
17911785
},
1792-
skip: moduleFormat == ModuleFormat.ddc && canaryFeatures == true
1793-
? 'https://github.com/dart-lang/webdev/issues/2566'
1794-
: null,
17951786
);
17961787

17971788
test(
@@ -1817,9 +1808,6 @@ void runTests({
18171808
.having((instance) => instance.kind, 'kind', 'Double'),
18181809
);
18191810
},
1820-
skip: moduleFormat == ModuleFormat.ddc && canaryFeatures == true
1821-
? 'https://github.com/dart-lang/webdev/issues/2566'
1822-
: null,
18231811
);
18241812

18251813
test(
@@ -1845,9 +1833,6 @@ void runTests({
18451833
.having((instance) => instance.kind, 'kind', 'String'),
18461834
);
18471835
},
1848-
skip: moduleFormat == ModuleFormat.ddc && canaryFeatures == true
1849-
? 'https://github.com/dart-lang/webdev/issues/2566'
1850-
: null,
18511836
);
18521837
});
18531838

0 commit comments

Comments
 (0)