Skip to content

Commit 81b9915

Browse files
committed
Merge branch 'yj-dev-2566' into yj-2573
2 parents e35ac5e + 498184a commit 81b9915

File tree

10 files changed

+293
-146
lines changed

10 files changed

+293
-146
lines changed

.github/workflows/dcm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
wget -qO- https://dcm.dev/pgp-key.public | sudo gpg --dearmor -o /usr/share/keyrings/dcm.gpg
2020
echo 'deb [signed-by=/usr/share/keyrings/dcm.gpg arch=amd64] https://dcm.dev/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list
2121
sudo apt-get update
22-
sudo apt-get install dcm=1.16.2-1 # To avoid errors add `-1` (build number) to the version
22+
sudo apt-get install dcm=1.26.0-1 # To avoid errors add `-1` (build number) to the version
2323
sudo chmod +x /usr/bin/dcm
2424
- name: Setup Dart SDK
2525
uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94

dwds/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 24.3.3-wip
22

3+
- Added support for some debugging APIs with the DDC library bundle format. - [#2563](https://github.com/dart-lang/webdev/issues/2563),[#2566](https://github.com/dart-lang/webdev/issues/2566)
4+
- Update `DCM` version to `1.26.0-1`
5+
36
## 24.3.2
47

58
- Bump `package:dds` to `>=4.2.5 <6.0.0`.

dwds/lib/src/debugging/dart_runtime_debugger.dart

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ class DartRuntimeDebugger {
1818
String _generateJsExpression(
1919
String ddcExpression,
2020
String libraryBundleExpression,
21-
) {
22-
return _useLibraryBundleExpression
23-
? libraryBundleExpression
24-
: ddcExpression;
25-
}
21+
) =>
22+
_useLibraryBundleExpression ? libraryBundleExpression : ddcExpression;
2623

2724
/// Wraps a JS function call with SDK loader logic.
2825
String _wrapWithSdkLoader(String args, String functionCall) {
@@ -200,14 +197,38 @@ class DartRuntimeDebugger {
200197
);
201198
}
202199

203-
String getVariableJsExpression(
204-
String libraryName,
205-
String url,
206-
String variable,
200+
/// Generates a JS expression to invoke a Dart extension method.
201+
String invokeExtensionJsExpression(String methodName, String encodedJson) {
202+
return _generateJsExpression(
203+
"${_loadStrategy.loadModuleSnippet}('dart_sdk').developer.invokeExtension('$methodName', JSON.stringify($encodedJson));",
204+
"dartDevEmbedder.debugger.invokeExtension('$methodName', JSON.stringify($encodedJson));",
205+
);
206+
}
207+
208+
/// Generates a JS expression for calling a library method.
209+
String callLibraryMethodJsExpression(
210+
String libraryUri,
211+
String methodName,
207212
) {
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.
208226
return _generateJsExpression(
209-
"${_loadStrategy.loadModuleSnippet}('dart_sdk').dart.getModuleLibraries('$libraryName')['$url']['$variable'];",
210-
'dartDevEmbedder.dart.getModuleLibraries("$libraryName")["$url"]["$variable"]',
227+
findLibraryExpression,
228+
_wrapWithBundleLoader(
229+
'',
230+
'callLibraryMethod("$libraryUri", "$methodName", Array.from(arguments))',
231+
),
211232
);
212233
}
213234
}

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/lib/src/services/chrome_proxy_service.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,8 @@ class ChromeProxyService implements VmServiceInterface {
518518
v is String ? v : jsonEncode(v),
519519
),
520520
);
521-
final expression = '''
522-
${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
523-
"$method", JSON.stringify(${jsonEncode(stringArgs)}));
524-
''';
521+
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
522+
.invokeExtensionJsExpression(method, jsonEncode(stringArgs));
525523
final result = await inspector.jsEvaluate(expression, awaitPromise: true);
526524
final decodedResponse =
527525
jsonDecode(result.value as String) as Map<String, dynamic>;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2025, 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+
@TestOn('vm')
6+
@Tags(['daily'])
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 'common/chrome_proxy_service_common.dart';
15+
import 'fixtures/context.dart';
16+
17+
void main() {
18+
// Enable verbose logging for debugging.
19+
final debug = false;
20+
final canaryFeatures = false;
21+
final moduleFormat = ModuleFormat.amd;
22+
final compilationMode = CompilationMode.buildDaemon;
23+
24+
group('canary: $canaryFeatures |', () {
25+
final provider = TestSdkConfigurationProvider(
26+
verbose: debug,
27+
canaryFeatures: canaryFeatures,
28+
ddcModuleFormat: moduleFormat,
29+
);
30+
tearDownAll(provider.dispose);
31+
32+
runTests(
33+
provider: provider,
34+
moduleFormat: moduleFormat,
35+
compilationMode: compilationMode,
36+
canaryFeatures: canaryFeatures,
37+
debug: debug,
38+
);
39+
});
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2025, 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+
@TestOn('vm')
6+
@Tags(['daily'])
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 'common/chrome_proxy_service_common.dart';
15+
import 'fixtures/context.dart';
16+
17+
void main() {
18+
// Enable verbose logging for debugging.
19+
final debug = false;
20+
final canaryFeatures = true;
21+
final moduleFormat = ModuleFormat.ddc;
22+
final compilationMode = CompilationMode.frontendServer;
23+
24+
group('canary: $canaryFeatures |', () {
25+
final provider = TestSdkConfigurationProvider(
26+
verbose: debug,
27+
canaryFeatures: canaryFeatures,
28+
ddcModuleFormat: moduleFormat,
29+
);
30+
tearDownAll(provider.dispose);
31+
32+
runTests(
33+
provider: provider,
34+
moduleFormat: moduleFormat,
35+
compilationMode: compilationMode,
36+
canaryFeatures: canaryFeatures,
37+
debug: debug,
38+
);
39+
});
40+
}

0 commit comments

Comments
 (0)