@@ -8,7 +8,7 @@ import 'package:logging/logging.dart';
88import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart' ;
99
1010import '../debugging/dart_scope.dart' ;
11- import '../debugging/debugger .dart' ;
11+ import '../debugging/inspector .dart' ;
1212import '../debugging/location.dart' ;
1313import '../debugging/modules.dart' ;
1414import '../utilities/objects.dart' as chrome;
@@ -33,7 +33,7 @@ class ErrorKind {
3333/// collect context for evaluation (scope, types, modules), and using
3434/// ExpressionCompilerInterface to compile dart expressions to JavaScript.
3535class ExpressionEvaluator {
36- final Future < Debugger > _debugger ;
36+ final AppInspector _inspector ;
3737 final Locations _locations;
3838 final Modules _modules;
3939 final ExpressionCompiler _compiler;
@@ -43,7 +43,7 @@ class ExpressionEvaluator {
4343 RegExp ('org-dartlang-debug:synthetic_debug_expression:.*:.*Error: ' );
4444
4545 ExpressionEvaluator (
46- this ._debugger , this ._locations, this ._modules, this ._compiler);
46+ this ._inspector , this ._locations, this ._modules, this ._compiler);
4747
4848 RemoteObject _createError (ErrorKind severity, String message) {
4949 return RemoteObject (
@@ -62,7 +62,11 @@ class ExpressionEvaluator {
6262 /// [libraryUri] dart library to evaluate the expression in.
6363 /// [expression] dart expression to evaluate.
6464 Future <RemoteObject > evaluateExpression (
65- String isolateId, String libraryUri, String expression) async {
65+ String isolateId,
66+ String libraryUri,
67+ String expression,
68+ Map <String , String > scope,
69+ ) async {
6670 if (_compiler == null ) {
6771 return _createError (ErrorKind .internal,
6872 'ExpressionEvaluator needs an ExpressionCompiler' );
@@ -74,6 +78,10 @@ class ExpressionEvaluator {
7478
7579 var module = await _modules.moduleForlibrary (libraryUri);
7680
81+ if (scope != null && scope.isNotEmpty) {
82+ var params = scope.keys.join (', ' );
83+ expression = '($params ) => $expression ' ;
84+ }
7785 _logger.finest ('Evaluating "$expression " at $module ' );
7886
7987 // Compile expression using an expression compiler, such as
@@ -88,8 +96,22 @@ class ExpressionEvaluator {
8896 }
8997
9098 // Send JS expression to chrome to evaluate.
91- var result = await (await _debugger).evaluate (jsResult);
92- result = _formatEvaluationError (result);
99+ RemoteObject result;
100+ if (scope != null && scope.isNotEmpty) {
101+ // Strip try/catch.
102+ // TODO: remove adding try/catch block in expression compiler.
103+ // https://github.com/dart-lang/webdev/issues/1341
104+ var lines = jsResult.split ('\n ' );
105+ var inner = lines.getRange (2 , lines.length - 3 ).join ('\n ' );
106+ var function = 'function(t) {'
107+ ' return $inner (t);'
108+ '}' ;
109+ result = await _inspector.callFunction (function, scope.values);
110+ result = _formatEvaluationError (result);
111+ } else {
112+ result = await _inspector.debugger.evaluate (jsResult);
113+ result = _formatEvaluationError (result);
114+ }
93115
94116 _logger.finest ('Evaluated "$expression " to "$result "' );
95117 return result;
@@ -107,8 +129,8 @@ class ExpressionEvaluator {
107129 /// [isolateId] current isolate ID.
108130 /// [frameIndex] JavaScript frame to evaluate the expression in.
109131 /// [expression] dart expression to evaluate.
110- Future <RemoteObject > evaluateExpressionInFrame (
111- String isolateId, int frameIndex, String expression) async {
132+ Future <RemoteObject > evaluateExpressionInFrame (String isolateId,
133+ int frameIndex, String expression, Map < String , String > scope ) async {
112134 if (_compiler == null ) {
113135 return _createError (ErrorKind .internal,
114136 'ExpressionEvaluator needs an ExpressionCompiler' );
@@ -119,7 +141,7 @@ class ExpressionEvaluator {
119141 }
120142
121143 // Get JS scope and current JS location.
122- var jsFrame = ( await _debugger) .jsFrameForIndex (frameIndex);
144+ var jsFrame = _inspector.debugger .jsFrameForIndex (frameIndex);
123145 if (jsFrame == null ) {
124146 return _createError (
125147 ErrorKind .internal, 'No frame with index $frameIndex ' );
@@ -175,7 +197,7 @@ class ExpressionEvaluator {
175197 }
176198
177199 // Send JS expression to chrome to evaluate.
178- var result = await ( await _debugger)
200+ var result = await _inspector.debugger
179201 .evaluateJsOnCallFrameIndex (frameIndex, jsResult);
180202 result = _formatEvaluationError (result);
181203
@@ -271,7 +293,7 @@ class ExpressionEvaluator {
271293 var scopeChain = filterScopes (frame).reversed;
272294 for (var scope in scopeChain) {
273295 var scopeProperties =
274- await ( await _debugger) .getProperties (scope.object.objectId);
296+ await _inspector.debugger .getProperties (scope.object.objectId);
275297
276298 collectVariables (scope.scope, scopeProperties);
277299 }
0 commit comments