Skip to content

Commit a551cb5

Browse files
committed
WIP
1 parent aa38d3a commit a551cb5

File tree

5 files changed

+2439
-2365
lines changed

5 files changed

+2439
-2365
lines changed

dwds/lib/src/debugging/dart_runtime_debugger.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,24 @@ class DartRuntimeDebugger {
203203
"dartDevEmbedder.debugger.invokeExtension('$methodName', JSON.stringify($encodedJson));",
204204
);
205205
}
206+
207+
String callLibraryMethodJsExpression(
208+
String libraryUri,
209+
String methodName,
210+
) {
211+
String findLibraryExpression() => '''
212+
(function() {
213+
const sdk = ${_loadStrategy.loadModuleSnippet}('dart_sdk');
214+
const dart = sdk.dart;
215+
const library = dart.getLibrary('$libraryUri');
216+
if (!library) throw 'cannot find library for $libraryUri';
217+
return library;
218+
})();
219+
''';
220+
221+
return _generateJsExpression(
222+
findLibraryExpression(),
223+
'dartDevEmbedder.debugger.callLibraryMethod("$libraryUri", "$methodName", argumentz)',
224+
);
225+
}
206226
}

dwds/lib/src/debugging/inspector.dart

Lines changed: 43 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';
@@ -212,7 +213,10 @@ class AppInspector implements AppInspectorInterface {
212213
// We use the JS pseudo-variable 'arguments' to get the list of all arguments.
213214
final send = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
214215
.callInstanceMethodJsExpression(methodName);
216+
print(
217+
'***YJ_TEST: _invokeMethod: receiver: $receiver, methodName: $methodName, positionalArgs: $positionalArgs, send: $send');
215218
final remote = await jsCallFunctionOn(receiver, send, positionalArgs);
219+
print('***YJ_TEST: _invokeMethod: remote: $remote');
216220
return remote;
217221
}
218222

@@ -251,6 +255,8 @@ class AppInspector implements AppInspectorInterface {
251255
List<Object> arguments, {
252256
bool returnByValue = false,
253257
}) async {
258+
print(
259+
'**YJ_TEST: _jsCallFunction: evalExpression: $evalExpression, arguments: $arguments');
254260
final jsArguments = arguments.map(callArgumentFor).toList();
255261
final response = await remoteDebugger.sendCommand(
256262
'Runtime.callFunctionOn',
@@ -279,6 +285,8 @@ class AppInspector implements AppInspectorInterface {
279285
String selector,
280286
List<dynamic> arguments,
281287
) async {
288+
print(
289+
'YJ_TEST: invoke: targetId: $targetId, selector: $selector, arguments: $arguments');
282290
final remoteArguments =
283291
arguments.cast<String>().map(remoteObjectFor).toList();
284292
// We special case the Dart library, where invokeMethod won't work because
@@ -300,12 +308,16 @@ class AppInspector implements AppInspectorInterface {
300308
Library library,
301309
String selector,
302310
List<RemoteObject> arguments,
303-
) {
304-
return _evaluateInLibrary(
311+
) async {
312+
print(
313+
'YJ_TEST: _invokeLibraryFunction: library: ${library.uri}, selector: $selector, arguments: $arguments',
314+
);
315+
final result = await _evaluateInLibrary(
305316
library,
306317
'function () { return this.$selector.apply(this, arguments);}',
307318
arguments,
308319
);
320+
return result;
309321
}
310322

311323
/// Evaluate [expression] by calling Chrome's Runtime.evaluate.
@@ -340,27 +352,43 @@ class AppInspector implements AppInspectorInterface {
340352
if (libraryUri == null) {
341353
throwInvalidParam('invoke', 'library uri is null');
342354
}
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);
353-
return jsCallFunctionOn(remoteLibrary, jsFunction, arguments);
355+
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
356+
.callLibraryMethodJsExpression(libraryUri, jsFunction);
357+
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;
376+
}
354377
}
355378

356379
/// Call [function] with objects referred by [argumentIds] as arguments.
357380
@override
358381
Future<RemoteObject> callFunction(
359382
String function,
360383
Iterable<String> argumentIds,
361-
) {
384+
) async {
385+
print(
386+
'YJ_TEST-1: callFunction - function: $function, argumentIDs: $argumentIds',
387+
);
362388
final arguments = argumentIds.map(remoteObjectFor).toList();
363-
return _jsCallFunction(function, arguments);
389+
print('YJ_TEST-2: callFunction - arguments: $arguments');
390+
final result = await _jsCallFunction(function, arguments);
391+
return result;
364392
}
365393

366394
@override

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,10 @@ class ChromeProxyService implements VmServiceInterface {
636636
String targetId,
637637
String expression, {
638638
Map<String, String>? scope,
639-
}) {
639+
}) async {
640640
// TODO(798) - respect disableBreakpoints.
641-
return captureElapsedTime(
641+
print('YJ-TEST _evaluate - 1: calling _evaluate');
642+
final result = await captureElapsedTime(
642643
() async {
643644
await isInitialized;
644645
final evaluator = _expressionEvaluator;
@@ -674,7 +675,7 @@ class ChromeProxyService implements VmServiceInterface {
674675
expression = '$target.$expression';
675676
scope = (scope ?? {})..addAll({target: targetId});
676677
}
677-
678+
print('YJ-TEST _evaluate - 2: calling _getEvaluationResult');
678679
return await _getEvaluationResult(
679680
isolateId,
680681
() => evaluator.evaluateExpression(
@@ -694,6 +695,8 @@ class ChromeProxyService implements VmServiceInterface {
694695
},
695696
(result) => DwdsEvent.evaluate(expression, result),
696697
);
698+
print('YJ-TEST _evaluate - 3: result: $result');
699+
return result;
697700
}
698701

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

dwds/lib/src/services/expression_evaluator.dart

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ 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+
);
9497
if (_closed) {
9598
return createError(
9699
EvaluationErrorKind.internal,
@@ -113,8 +116,11 @@ class ExpressionEvaluator {
113116
'no library uri',
114117
);
115118
}
116-
119+
print(
120+
'YJ-TEST-B: evaluateExpression - retieving module for libraryUri: $libraryUri',
121+
);
117122
final module = await _modules.moduleForLibrary(libraryUri);
123+
print('YJ-TEST-C: evaluateExpression - module: $module');
118124
if (module == null) {
119125
return createError(
120126
EvaluationErrorKind.internal,
@@ -124,6 +130,7 @@ class ExpressionEvaluator {
124130

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

129136
// Compile expression using an expression compiler, such as
@@ -138,20 +145,27 @@ class ExpressionEvaluator {
138145
module,
139146
expression,
140147
);
148+
print(
149+
'YJ-TEST-E: evaluateExpression - compilationResult: $compilationResult');
141150

142151
final isError = compilationResult.isError;
143152
final jsResult = compilationResult.result;
144153
if (isError) {
145154
return _formatCompilationError(jsResult);
146155
}
156+
print('YJ-TEST-F: evaluateExpression - jsResult: $jsResult');
147157

148158
// Strip try/catch incorrectly added by the expression compiler.
149159
final jsCode = _maybeStripTryCatch(jsResult);
150160

151161
// Send JS expression to chrome to evaluate.
162+
print('**YJ-TEST-G: evaluateExpression - calling _callJsFunction');
152163
var result = await _callJsFunction(jsCode, scope);
164+
print(
165+
'**YJ-TEST-H: evaluateExpression - result of _callJsFunction: $result');
153166
result = await _formatEvaluationError(result);
154-
167+
print(
168+
'**YJ-TEST-I: evaluateExpression - result of _formatEvaluationError: $result');
155169
_logger.finest('Evaluated "$expression" to "${result.json}"');
156170
return result;
157171
}
@@ -386,11 +400,17 @@ class ExpressionEvaluator {
386400
Future<RemoteObject> _callJsFunction(
387401
String function,
388402
Map<String, String> scope,
389-
) {
403+
) async {
404+
print(
405+
'YJ-TEST-1: _callJsFunction - function: $function, scope: $scope, scope.keys: ${scope.keys}, scope.values: ${scope.values}',
406+
);
390407
final jsCode = _createEvalFunction(function, scope.keys);
408+
print('YJ-TEST-2: _callJsFunction - jsCode: $jsCode');
391409

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

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

0 commit comments

Comments
 (0)