Skip to content

Commit c49579d

Browse files
authored
Merge branch 'main' into fix/upcoming-lint-fixes
2 parents 5f1b751 + 846608d commit c49579d

File tree

19 files changed

+150
-45
lines changed

19 files changed

+150
-45
lines changed

.github/workflows/dart.yml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Dart](https://github.com/dart-lang/webdev/workflows/Dart%20CI/badge.svg)](https://github.com/dart-lang/webdev/actions?query=workflow%3A%22Dart+CI%22+branch%3Amaster)
1+
[![Dart](https://github.com/dart-lang/webdev/workflows/Dart%20CI/badge.svg)](https://github.com/dart-lang/webdev/actions?query=workflow%3A%22Dart+CI%22+branch%3Amain)
22

33
## Packages
44

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +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)
1415

1516
## 24.1.0
1617

dwds/CONTRIBUTING.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ alias flutter_tools='/YOUR_PATH/flutter/bin/dart /YOUR_PATH/flutter/packages/flu
3434

3535
Note: This is even easier if you create a `pubspec_overrides.yaml` file in the `flutter_tools` directory, and then git-ignore it. This way you don't have to worry about committing your DWDS override.
3636

37-
4. Choose a Flutter app to run (eg, the
38-
[old](https://github.com/flutter/flutter/tree/master/dev/integration_tests/flutter_gallery)
39-
or [new](https://github.com/flutter/gallery) Flutter Gallery apps).
37+
4. Choose a Flutter app to run (such as the
38+
[Flutter Gallery app](https://github.com/flutter/flutter/tree/master/dev/integration_tests/flutter_gallery).
4039
1. From the Flutter app repo, run your local Flutter Tools with alias you
4140
defined in step #2:
4241

@@ -146,15 +145,15 @@ you need to:
146145
Sometimes you might need to do a hotfix release of DWDS. An example of why this
147146
might be necessary is if you need to do a hotfix of DWDS into Flutter, but don't
148147
want to release a new version of DWDS with the current untested changes on the
149-
master branch. Instead you only want to apply a fix to the current version of
148+
`main` branch. Instead you only want to apply a fix to the current version of
150149
DWDS in Flutter.
151150

152151
### Instructions:
153152

154153
1. Create a branch off the release that needs a hotfix:
155154

156155
a. In the GitHub UI's
157-
[commit history view](https://github.com/dart-lang/webdev/commits/master),
156+
[commit history view](https://github.com/dart-lang/webdev/commits/main),
158157
find the commit that prepared the release of DWDS that you would like to
159158
hotfix.
160159

@@ -180,18 +179,18 @@ DWDS in Flutter.
180179

181180
a. Make the appropriate changes to DWDS' `mono_pkg.yaml` then run
182181
`mono_repo generate`. Submit this change to the branch you created in step
183-
#3, **not** `master`.
182+
#3, **not** `main`.
184183

185184
1. Make the fix:
186185

187186
a. You can now make the change you would like to hotfix. From the GitHub UI,
188187
open a PR to merge your change into the branch you created in step #3,
189-
**not** `master`. See https://github.com/dart-lang/webdev/pull/1867 as an
188+
**not** `main`. See https://github.com/dart-lang/webdev/pull/1867 as an
190189
example.
191190

192191
1. Once it's merged, you can follow the instructions to
193192
[publish DWDS to pub](#step-2-publish-dwds-to-pub), except instead of pulling
194-
from `master`, pull from the branch your created in step #3.
193+
from `main`, pull from the branch your created in step #3.
195194

196195
1. If necessary, open a cherry-pick request in Flutter to update the version.
197196
See https://github.com/flutter/flutter/issues/118122 for an example.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
import 'package:dwds/src/loaders/strategy.dart';
6+
7+
class DartRuntimeDebugger {
8+
final LoadStrategy _loadStrategy;
9+
final bool _useLibraryBundleExpression;
10+
11+
DartRuntimeDebugger({
12+
required LoadStrategy loadStrategy,
13+
required bool useLibraryBundleExpression,
14+
}) : _loadStrategy = loadStrategy,
15+
_useLibraryBundleExpression = useLibraryBundleExpression;
16+
17+
String _generateJsExpression(
18+
String ddcExpression,
19+
String libraryBundleExpression,
20+
) {
21+
return _useLibraryBundleExpression
22+
? libraryBundleExpression
23+
: ddcExpression;
24+
}
25+
26+
String _wrapWithSdkLoader(String args, String functionCall) {
27+
return '''
28+
function($args) {
29+
const sdk = ${_loadStrategy.loadModuleSnippet}("dart_sdk");
30+
const dart = sdk.dart;
31+
return dart.$functionCall;
32+
}
33+
''';
34+
}
35+
36+
String _wrapWithBundleLoader(String args, String functionCall) {
37+
return '''
38+
function($args) {
39+
return dartDevEmbedder.debugger.$functionCall;
40+
}
41+
''';
42+
}
43+
44+
String _buildExpression(
45+
String args,
46+
String ddcFunction,
47+
String libraryBundleFunction,
48+
) {
49+
return _generateJsExpression(
50+
_wrapWithSdkLoader(args, ddcFunction),
51+
_wrapWithBundleLoader(args, libraryBundleFunction),
52+
);
53+
}
54+
55+
String getObjectMetadataJsExpression() {
56+
return _buildExpression(
57+
'arg',
58+
'getObjectMetadata(arg)',
59+
'getObjectMetadata(arg)',
60+
);
61+
}
62+
63+
String getObjectFieldNamesJsExpression() {
64+
return _buildExpression(
65+
'',
66+
'getObjectFieldNames(this)',
67+
'getObjectFieldNames(this)',
68+
);
69+
}
70+
71+
String getFunctionMetadataJsExpression() {
72+
return _buildExpression(
73+
'',
74+
'getFunctionMetadata(this)',
75+
'getFunctionName(this)',
76+
);
77+
}
78+
79+
String getSubRangeJsExpression() {
80+
return _buildExpression(
81+
'offset, count',
82+
'getSubRange(this, offset, count)',
83+
'getSubRange(this, offset, count)',
84+
);
85+
}
86+
}

dwds/lib/src/debugging/inspector.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -643,13 +643,8 @@ class AppInspector implements AppInspectorInterface {
643643
// If this is a List, just call sublist. If it's a Map, get the entries, but
644644
// avoid doing a toList on a large map using skip/take to get the section we
645645
// want. To make those alternatives easier in JS, pass both count and end.
646-
final expression = '''
647-
function (offset, count) {
648-
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk");
649-
const dart = sdk.dart;
650-
return dart.getSubRange(this, offset, count);
651-
}
652-
''';
646+
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
647+
.getSubRangeJsExpression();
653648

654649
return await jsCallFunctionOn(receiver, expression, args);
655650
}

dwds/lib/src/debugging/instance.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,9 @@ class InstanceHelper extends Domain {
772772
//
773773
// For maps and lists it's more complicated. Treat the actual SDK versions
774774
// of these as special.
775-
final fieldNameExpression =
776-
_jsRuntimeFunctionCall('getObjectFieldNames(this)');
777-
775+
final fieldNameExpression = globalToolConfiguration
776+
.loadStrategy.dartRuntimeDebugger
777+
.getObjectFieldNamesJsExpression();
778778
final result = await inspector.jsCallFunctionOn(
779779
remoteObject,
780780
fieldNameExpression,

dwds/lib/src/debugging/metadata/class.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,9 @@ class ClassMetaDataHelper {
152152
/// Returns null if the [remoteObject] is not a Dart class.
153153
Future<ClassMetaData?> metaDataFor(RemoteObject remoteObject) async {
154154
try {
155-
final evalExpression = '''
156-
function(arg) {
157-
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk');
158-
const dart = sdk.dart;
159-
return dart.getObjectMetadata(arg);
160-
}
161-
''';
155+
final evalExpression = globalToolConfiguration
156+
.loadStrategy.dartRuntimeDebugger
157+
.getObjectMetadataJsExpression();
162158

163159
final result = await _inspector.jsCallFunctionOn(
164160
remoteObject,

dwds/lib/src/debugging/metadata/function.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ class FunctionMetaData {
1717
RemoteDebugger remoteDebugger,
1818
RemoteObject remoteObject,
1919
) async {
20-
final evalExpression = '''
21-
function() {
22-
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk');
23-
const dart = sdk.dart;
24-
return dart.getFunctionMetadata(this);
25-
}
26-
''';
20+
final evalExpression = globalToolConfiguration
21+
.loadStrategy.dartRuntimeDebugger
22+
.getFunctionMetadataJsExpression();
2723

2824
final response = await remoteDebugger.sendCommand(
2925
'Runtime.callFunctionOn',

dwds/lib/src/loaders/ddc.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'dart:convert';
66

7+
import 'package:dwds/src/debugging/dart_runtime_debugger.dart';
78
import 'package:dwds/src/debugging/metadata/provider.dart';
89
import 'package:dwds/src/loaders/strategy.dart';
910
import 'package:dwds/src/readers/asset_reader.dart';
@@ -163,6 +164,12 @@ class DdcStrategy extends LoadStrategy {
163164
@override
164165
String get loadModuleSnippet => 'dart_library.import';
165166

167+
@override
168+
late final DartRuntimeDebugger dartRuntimeDebugger = DartRuntimeDebugger(
169+
loadStrategy: this,
170+
useLibraryBundleExpression: false,
171+
);
172+
166173
@override
167174
BuildSettings get buildSettings => _buildSettings;
168175

0 commit comments

Comments
 (0)