Skip to content

Commit 167b263

Browse files
committed
Merge remote-tracking branch 'upstream/main' into removereassemble
2 parents 9fff37e + 3e17660 commit 167b263

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

dwds/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
- The registered extension `reassemble` is now no longer called when calling
44
`reloadSources`. Users should call `reassemble` using `callServiceExtension`.
55

6+
- `callServiceExtension` now checks the runtime for the list of registered
7+
service extensions. It also now throws a `RPCError` with
8+
`RPCErrorKind.kMethodNotFound` when a service extension is not found instead
9+
of throwing a JS evaluation error.
10+
611
## 24.3.6
712

813
- Bump minimum sdk version to 3.7.0

dwds/lib/src/debugging/inspector.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ class AppInspector implements AppInspectorInterface {
115115
await DartUri.initialize();
116116
DartUri.recordAbsoluteUris(libraries.map((lib) => lib.uri).nonNulls);
117117
DartUri.recordAbsoluteUris(scripts.map((script) => script.uri).nonNulls);
118-
119-
isolate.extensionRPCs?.addAll(await _getExtensionRpcs());
118+
await getExtensionRpcs();
120119
}
121120

122121
static IsolateRef _toIsolateRef(Isolate isolate) => IsolateRef(
@@ -760,11 +759,16 @@ class AppInspector implements AppInspectorInterface {
760759
scriptId == null ? null : _scriptRefsById[scriptId];
761760

762761
/// Runs an eval on the page to compute all existing registered extensions.
763-
Future<List<String>> _getExtensionRpcs() async {
762+
///
763+
/// Combines this with the RPCs registered in the [isolate]. Use this over
764+
/// [Isolate.extensionRPCs] as this computes a live set.
765+
///
766+
/// Updates [Isolate.extensionRPCs] to this set.
767+
Future<Set<String>> getExtensionRpcs() async {
764768
final expression =
765769
globalToolConfiguration.loadStrategy.dartRuntimeDebugger
766770
.getDartDeveloperExtensionNamesJsExpression();
767-
final extensionRpcs = <String>[];
771+
final extensionRpcs = <String>{};
768772
final params = {
769773
'expression': expression,
770774
'returnByValue': true,
@@ -784,6 +788,7 @@ class AppInspector implements AppInspectorInterface {
784788
s,
785789
);
786790
}
791+
isolate.extensionRPCs = List<String>.of(extensionRpcs);
787792
return extensionRpcs;
788793
}
789794

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ class ChromeProxyService implements VmServiceInterface {
343343
// TODO: We shouldn't need to fire these events since they exist on the
344344
// isolate, but devtools doesn't recognize extensions after a page refresh
345345
// otherwise.
346-
for (final extensionRpc in inspector.isolate.extensionRPCs ?? []) {
346+
for (final extensionRpc in await inspector.getExtensionRpcs()) {
347347
_streamNotify(
348348
'Isolate',
349349
Event(
@@ -509,6 +509,13 @@ class ChromeProxyService implements VmServiceInterface {
509509
v is String ? v : jsonEncode(v),
510510
),
511511
);
512+
if (!(await inspector.getExtensionRpcs()).contains(method)) {
513+
throw RPCError(
514+
method,
515+
RPCErrorKind.kMethodNotFound.code,
516+
'Unknown service method: $method',
517+
);
518+
}
512519
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
513520
.invokeExtensionJsExpression(method, jsonEncode(stringArgs));
514521
final result = await inspector.jsEvaluate(expression, awaitPromise: true);

dwds/test/common/chrome_proxy_service_common.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,20 @@ void runTests({
298298
),
299299
},
300300
);
301+
302+
test('not found', () async {
303+
final serviceMethod = 'ext.test.missingServiceExtension';
304+
expect(
305+
service.callServiceExtension(serviceMethod),
306+
throwsA(
307+
predicate(
308+
(dynamic error) =>
309+
error is RPCError &&
310+
error.code == RPCErrorKind.kMethodNotFound.code,
311+
),
312+
),
313+
);
314+
});
301315
});
302316

303317
group('VMTimeline', () {

0 commit comments

Comments
 (0)