Skip to content

Commit 81624f9

Browse files
committed
Added support for some debugging APIs with the DDC library bundle format - getModuleLibraries
1 parent 81b9915 commit 81624f9

File tree

7 files changed

+506
-354
lines changed

7 files changed

+506
-354
lines changed

dwds/lib/src/debugging/dart_runtime_debugger.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,14 @@ class DartRuntimeDebugger {
231231
),
232232
);
233233
}
234+
235+
/// Generates a JS expression to retrieve a library variable.
236+
/// This method is only available for the `RequireStrategy`.
237+
String getLibraryVariableJsExpression(
238+
String libraryName,
239+
String libraryUri,
240+
String variable,
241+
) {
242+
return '${_loadStrategy.loadModuleSnippet}("dart_sdk").dart.getModuleLibraries("$libraryName")["$libraryUri"]["$variable"]';
243+
}
234244
}

dwds/lib/src/debugging/inspector.dart

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,18 @@ class AppInspector implements AppInspectorInterface {
302302
String selector,
303303
List<RemoteObject> arguments,
304304
) {
305+
final libraryUri = library.uri;
306+
if (libraryUri == null) {
307+
throwInvalidParam('invoke', 'library uri is null');
308+
}
305309
return globalToolConfiguration.loadStrategy is DdcLibraryBundleStrategy
306310
? _evaluateLibraryMethodWithDdcLibraryBundle(
307-
library,
311+
libraryUri,
308312
selector,
309313
arguments,
310314
)
311315
: _evaluateInLibrary(
312-
library,
316+
libraryUri,
313317
'function () { return this.$selector.apply(this, arguments); }',
314318
arguments,
315319
);
@@ -337,16 +341,12 @@ class AppInspector implements AppInspectorInterface {
337341
}
338342

339343
/// Evaluate the JS function with source [jsFunction] in the context of
340-
/// [library] with [arguments].
344+
/// the library identified by [libraryUri] with [arguments].
341345
Future<RemoteObject> _evaluateInLibrary(
342-
Library library,
346+
String libraryUri,
343347
String jsFunction,
344348
List<RemoteObject> arguments,
345349
) async {
346-
final libraryUri = library.uri;
347-
if (libraryUri == null) {
348-
throwInvalidParam('invoke', 'library uri is null');
349-
}
350350
final findLibraryJsExpression = globalToolConfiguration
351351
.loadStrategy.dartRuntimeDebugger
352352
.callLibraryMethodJsExpression(libraryUri, jsFunction);
@@ -355,23 +355,63 @@ class AppInspector implements AppInspectorInterface {
355355
return jsCallFunctionOn(remoteLibrary, jsFunction, arguments);
356356
}
357357

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].
358+
/// Evaluates the specified top-level method [methodName] within the library
359+
/// identified by [libraryUri] using the Dart Development Compiler (DDC)
360+
/// library bundle strategy with the given [arguments].
361361
Future<RemoteObject> _evaluateLibraryMethodWithDdcLibraryBundle(
362-
Library library,
362+
String libraryUri,
363363
String methodName,
364364
List<RemoteObject> arguments,
365365
) {
366-
final libraryUri = library.uri;
367-
if (libraryUri == null) {
368-
throwInvalidParam('invoke', 'library uri is null');
369-
}
370366
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
371367
.callLibraryMethodJsExpression(libraryUri, methodName);
372368
return _jsCallFunction(expression, arguments);
373369
}
374370

371+
/// Evaluates the specified top-level variable [variableName] within the
372+
/// library identified by [libraryName] and [libraryUri] using the
373+
/// RequireStrategy.
374+
Future<RemoteObject> _evaluateLibraryVariable(
375+
String libraryUri,
376+
String libraryName,
377+
String variableName,
378+
) {
379+
return jsEvaluate(
380+
globalToolConfiguration.loadStrategy.dartRuntimeDebugger
381+
.getLibraryVariableJsExpression(
382+
libraryName,
383+
libraryUri,
384+
variableName,
385+
),
386+
);
387+
}
388+
389+
/// Retrieves a reference to a library variable or method by evaluating
390+
/// the specified [variableName] or invoking the provided [methodName].
391+
/// The evaluation method is determined based on the current load strategy.
392+
///
393+
/// If the load strategy uses `DdcLibraryBundleStrategy`, it evaluates the
394+
/// method with the given [libraryUri] and [methodName]. Otherwise, it
395+
/// evaluates the variable using [libraryUri], [libraryName], and [variableName].
396+
Future<RemoteObject> getLibraryReference(
397+
String libraryUri,
398+
String libraryName,
399+
String variableName,
400+
String methodName,
401+
) {
402+
return globalToolConfiguration.loadStrategy is DdcLibraryBundleStrategy
403+
? _evaluateLibraryMethodWithDdcLibraryBundle(
404+
libraryUri,
405+
methodName,
406+
[],
407+
)
408+
: _evaluateLibraryVariable(
409+
libraryUri,
410+
libraryName,
411+
variableName,
412+
);
413+
}
414+
375415
/// Call [function] with objects referred by [argumentIds] as arguments.
376416
@override
377417
Future<RemoteObject> callFunction(

0 commit comments

Comments
 (0)