Skip to content

Commit e81fa22

Browse files
committed
Added support for callLibraryMethod with the DDC library bundle format.
1 parent a551cb5 commit e81fa22

File tree

7 files changed

+2376
-2431
lines changed

7 files changed

+2376
-2431
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## 24.3.3-wip
2-
- Added support for some debugging APIs with the DDC library bundle format. - [#2563](https://github.com/dart-lang/webdev/issues/2563)
2+
- 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)
33

44
## 24.3.2
55

dwds/lib/src/debugging/dart_runtime_debugger.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,15 @@ 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
}
206207

208+
/// Generates a JS expression for calling a library method.
207209
String callLibraryMethodJsExpression(
208210
String libraryUri,
209211
String methodName,
@@ -220,7 +222,10 @@ class DartRuntimeDebugger {
220222

221223
return _generateJsExpression(
222224
findLibraryExpression(),
223-
'dartDevEmbedder.debugger.callLibraryMethod("$libraryUri", "$methodName", argumentz)',
225+
_wrapWithBundleLoader(
226+
'',
227+
'callLibraryMethod("$libraryUri", "$methodName", Array.from(arguments))',
228+
),
224229
);
225230
}
226231
}

dwds/lib/src/debugging/inspector.dart

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,7 @@ class AppInspector implements AppInspectorInterface {
213213
// We use the JS pseudo-variable 'arguments' to get the list of all arguments.
214214
final send = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
215215
.callInstanceMethodJsExpression(methodName);
216-
print(
217-
'***YJ_TEST: _invokeMethod: receiver: $receiver, methodName: $methodName, positionalArgs: $positionalArgs, send: $send');
218216
final remote = await jsCallFunctionOn(receiver, send, positionalArgs);
219-
print('***YJ_TEST: _invokeMethod: remote: $remote');
220217
return remote;
221218
}
222219

@@ -255,8 +252,6 @@ class AppInspector implements AppInspectorInterface {
255252
List<Object> arguments, {
256253
bool returnByValue = false,
257254
}) async {
258-
print(
259-
'**YJ_TEST: _jsCallFunction: evalExpression: $evalExpression, arguments: $arguments');
260255
final jsArguments = arguments.map(callArgumentFor).toList();
261256
final response = await remoteDebugger.sendCommand(
262257
'Runtime.callFunctionOn',
@@ -285,8 +280,6 @@ class AppInspector implements AppInspectorInterface {
285280
String selector,
286281
List<dynamic> arguments,
287282
) async {
288-
print(
289-
'YJ_TEST: invoke: targetId: $targetId, selector: $selector, arguments: $arguments');
290283
final remoteArguments =
291284
arguments.cast<String>().map(remoteObjectFor).toList();
292285
// We special case the Dart library, where invokeMethod won't work because
@@ -308,16 +301,14 @@ class AppInspector implements AppInspectorInterface {
308301
Library library,
309302
String selector,
310303
List<RemoteObject> arguments,
311-
) async {
312-
print(
313-
'YJ_TEST: _invokeLibraryFunction: library: ${library.uri}, selector: $selector, arguments: $arguments',
314-
);
315-
final result = await _evaluateInLibrary(
316-
library,
317-
'function () { return this.$selector.apply(this, arguments);}',
318-
arguments,
319-
);
320-
return result;
304+
) {
305+
return globalToolConfiguration.loadStrategy is DdcLibraryBundleStrategy
306+
? _evaluateWithDdcLibraryBundle(library, selector, arguments)
307+
: _evaluateInLibrary(
308+
library,
309+
'function () { return this.$selector.apply(this, arguments); }',
310+
arguments,
311+
);
321312
}
322313

323314
/// Evaluate [expression] by calling Chrome's Runtime.evaluate.
@@ -352,28 +343,29 @@ class AppInspector implements AppInspectorInterface {
352343
if (libraryUri == null) {
353344
throwInvalidParam('invoke', 'library uri is null');
354345
}
355-
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
346+
final findLibraryJsExpression = globalToolConfiguration
347+
.loadStrategy.dartRuntimeDebugger
356348
.callLibraryMethodJsExpression(libraryUri, jsFunction);
357349

358-
print('YJ_TEST: Evaluating in library: $expression');
359-
if (globalToolConfiguration.loadStrategy is DdcLibraryBundleStrategy) {
360-
print('YJ_TEST-A-1: DdcLibraryBundleStrategy');
361-
final result = await _jsCallFunction(jsFunction, arguments);
362-
print(
363-
'YJ_TEST-A-2: result: $result',
364-
);
365-
return result;
366-
} else {
367-
print('YJ_TEST-B-1: ${globalToolConfiguration.loadStrategy}');
368-
final remoteLibrary = await jsEvaluate(expression);
369-
print(
370-
'YJ_TEST-B-2: remoteLibrary: ${remoteLibrary.objectId}, jsFunction: $jsFunction, arguments: $arguments',
371-
);
372-
final result =
373-
await jsCallFunctionOn(remoteLibrary, jsFunction, arguments);
374-
print('YJ_TEST-B-3: result: ${result.objectId}');
375-
return result;
350+
final remoteLibrary = await jsEvaluate(findLibraryJsExpression);
351+
return jsCallFunctionOn(remoteLibrary, jsFunction, arguments);
352+
}
353+
354+
/// Evaluates the specified method [methodName] in the context of [library]
355+
/// using the Dart Development Compiler (DDC) library bundle strategy with
356+
/// the given [arguments].
357+
Future<RemoteObject> _evaluateWithDdcLibraryBundle(
358+
Library library,
359+
String methodName,
360+
List<RemoteObject> arguments,
361+
) {
362+
final libraryUri = library.uri;
363+
if (libraryUri == null) {
364+
throwInvalidParam('invoke', 'library uri is null');
376365
}
366+
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
367+
.callLibraryMethodJsExpression(libraryUri, methodName);
368+
return _jsCallFunction(expression, arguments);
377369
}
378370

379371
/// Call [function] with objects referred by [argumentIds] as arguments.
@@ -382,11 +374,7 @@ class AppInspector implements AppInspectorInterface {
382374
String function,
383375
Iterable<String> argumentIds,
384376
) async {
385-
print(
386-
'YJ_TEST-1: callFunction - function: $function, argumentIDs: $argumentIds',
387-
);
388377
final arguments = argumentIds.map(remoteObjectFor).toList();
389-
print('YJ_TEST-2: callFunction - arguments: $arguments');
390378
final result = await _jsCallFunction(function, arguments);
391379
return result;
392380
}

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,9 @@ class ChromeProxyService implements VmServiceInterface {
636636
String targetId,
637637
String expression, {
638638
Map<String, String>? scope,
639-
}) async {
639+
}) {
640640
// TODO(798) - respect disableBreakpoints.
641-
print('YJ-TEST _evaluate - 1: calling _evaluate');
642-
final result = await captureElapsedTime(
641+
return captureElapsedTime(
643642
() async {
644643
await isInitialized;
645644
final evaluator = _expressionEvaluator;
@@ -675,7 +674,7 @@ class ChromeProxyService implements VmServiceInterface {
675674
expression = '$target.$expression';
676675
scope = (scope ?? {})..addAll({target: targetId});
677676
}
678-
print('YJ-TEST _evaluate - 2: calling _getEvaluationResult');
677+
679678
return await _getEvaluationResult(
680679
isolateId,
681680
() => evaluator.evaluateExpression(
@@ -695,8 +694,6 @@ class ChromeProxyService implements VmServiceInterface {
695694
},
696695
(result) => DwdsEvent.evaluate(expression, result),
697696
);
698-
print('YJ-TEST _evaluate - 3: result: $result');
699-
return result;
700697
}
701698

702699
String _newVariableForScope(Map<String, String>? scope) {

dwds/lib/src/services/expression_evaluator.dart

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ class ExpressionEvaluator {
9191
String expression,
9292
Map<String, String>? scope,
9393
) async {
94-
print(
95-
'YJ-TEST-A: evaluateExpression - isolateId: $isolateId, libraryUri: $libraryUri, expression: $expression, scope: $scope',
96-
);
9794
if (_closed) {
9895
return createError(
9996
EvaluationErrorKind.internal,
@@ -116,11 +113,8 @@ class ExpressionEvaluator {
116113
'no library uri',
117114
);
118115
}
119-
print(
120-
'YJ-TEST-B: evaluateExpression - retieving module for libraryUri: $libraryUri',
121-
);
116+
122117
final module = await _modules.moduleForLibrary(libraryUri);
123-
print('YJ-TEST-C: evaluateExpression - module: $module');
124118
if (module == null) {
125119
return createError(
126120
EvaluationErrorKind.internal,
@@ -130,7 +124,6 @@ class ExpressionEvaluator {
130124

131125
// Wrap the expression in a lambda so we can call it as a function.
132126
expression = _createDartLambda(expression, scope.keys);
133-
print('YJ-TEST-D: evaluateExpression - NEW expression: $expression');
134127
_logger.finest('Evaluating "$expression" at $module');
135128

136129
// Compile expression using an expression compiler, such as
@@ -145,27 +138,20 @@ class ExpressionEvaluator {
145138
module,
146139
expression,
147140
);
148-
print(
149-
'YJ-TEST-E: evaluateExpression - compilationResult: $compilationResult');
150141

151142
final isError = compilationResult.isError;
152143
final jsResult = compilationResult.result;
153144
if (isError) {
154145
return _formatCompilationError(jsResult);
155146
}
156-
print('YJ-TEST-F: evaluateExpression - jsResult: $jsResult');
157147

158148
// Strip try/catch incorrectly added by the expression compiler.
159149
final jsCode = _maybeStripTryCatch(jsResult);
160150

161151
// Send JS expression to chrome to evaluate.
162-
print('**YJ-TEST-G: evaluateExpression - calling _callJsFunction');
163152
var result = await _callJsFunction(jsCode, scope);
164-
print(
165-
'**YJ-TEST-H: evaluateExpression - result of _callJsFunction: $result');
166153
result = await _formatEvaluationError(result);
167-
print(
168-
'**YJ-TEST-I: evaluateExpression - result of _formatEvaluationError: $result');
154+
169155
_logger.finest('Evaluated "$expression" to "${result.json}"');
170156
return result;
171157
}
@@ -400,17 +386,11 @@ class ExpressionEvaluator {
400386
Future<RemoteObject> _callJsFunction(
401387
String function,
402388
Map<String, String> scope,
403-
) async {
404-
print(
405-
'YJ-TEST-1: _callJsFunction - function: $function, scope: $scope, scope.keys: ${scope.keys}, scope.values: ${scope.values}',
406-
);
389+
) {
407390
final jsCode = _createEvalFunction(function, scope.keys);
408-
print('YJ-TEST-2: _callJsFunction - jsCode: $jsCode');
409391

410392
_logger.finest('Evaluating JS: "$jsCode" with scope: $scope');
411-
final result = await _inspector.callFunction(jsCode, scope.values);
412-
print('YJ-TEST-3: _callJsFunction - result: $result');
413-
return result;
393+
return _inspector.callFunction(jsCode, scope.values);
414394
}
415395

416396
/// Evaluate JavaScript [expression] on frame [frameIndex].

0 commit comments

Comments
 (0)