2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- // @dart = 2.9
6
-
7
5
import 'package:dwds/src/utilities/domain.dart' ;
8
6
import 'package:logging/logging.dart' ;
9
7
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart' ;
@@ -78,19 +76,18 @@ class ExpressionEvaluator {
78
76
String isolateId,
79
77
String libraryUri,
80
78
String expression,
81
- Map <String , String > scope,
79
+ Map <String , String >? scope,
82
80
) async {
83
81
scope ?? = {};
84
- if (_compiler == null ) {
85
- return _createError (ErrorKind .internal,
86
- 'ExpressionEvaluator needs an ExpressionCompiler' );
87
- }
88
82
89
- if (expression == null || expression .isEmpty) {
83
+ if (expression.isEmpty) {
90
84
return _createError (ErrorKind .invalidInput, expression);
91
85
}
92
86
93
87
final module = await _modules.moduleForlibrary (libraryUri);
88
+ if (module == null ) {
89
+ return _createError (ErrorKind .internal, 'no module for $libraryUri ' );
90
+ }
94
91
95
92
// Wrap the expression in a lambda so we can call it as a function.
96
93
expression = _createDartLambda (expression, scope.keys);
@@ -132,13 +129,17 @@ class ExpressionEvaluator {
132
129
/// [frameIndex] JavaScript frame to evaluate the expression in.
133
130
/// [expression] dart expression to evaluate.
134
131
Future <RemoteObject > evaluateExpressionInFrame (String isolateId,
135
- int frameIndex, String expression, Map <String , String > scope) async {
136
- if (_compiler == null ) {
137
- return _createError (ErrorKind .internal,
138
- 'ExpressionEvaluator needs an ExpressionCompiler' );
132
+ int frameIndex, String expression, Map <String , String >? scope) async {
133
+ if (scope != null ) {
134
+ // TODO(annagrin): Implement scope support.
135
+ // Issue: https://github.com/dart-lang/webdev/issues/1344
136
+ return _createError (
137
+ ErrorKind .internal,
138
+ 'Using scope for expression evaluation in frame '
139
+ 'is not supported.' );
139
140
}
140
141
141
- if (expression == null || expression .isEmpty) {
142
+ if (expression.isEmpty) {
142
143
return _createError (ErrorKind .invalidInput, expression);
143
144
}
144
145
@@ -158,7 +159,11 @@ class ExpressionEvaluator {
158
159
final jsScope = await _collectLocalJsScope (jsFrame);
159
160
160
161
// Find corresponding dart location and scope.
161
- final url = _urlForScriptId (jsScriptId);
162
+ final url = _debugger.urlForScriptId (jsScriptId);
163
+ if (url == null ) {
164
+ return _createError (
165
+ ErrorKind .internal, 'Cannot find url for JS script: $jsScriptId ' );
166
+ }
162
167
final locationMap = await _locations.locationForJs (url, jsLine, jsColumn);
163
168
if (locationMap == null ) {
164
169
return _createError (
@@ -171,13 +176,20 @@ class ExpressionEvaluator {
171
176
}
172
177
173
178
final dartLocation = locationMap.dartLocation;
174
- final libraryUri =
175
- await _modules.libraryForSource (dartLocation.uri.serverPath);
179
+ final dartSourcePath = dartLocation.uri.serverPath;
180
+ final libraryUri = await _modules.libraryForSource (dartSourcePath);
181
+ if (libraryUri == null ) {
182
+ return _createError (
183
+ ErrorKind .internal, 'no libraryUri for $dartSourcePath ' );
184
+ }
176
185
177
- final currentModule =
178
- await _modules.moduleForSource (dartLocation.uri.serverPath);
186
+ final module = await _modules.moduleForlibrary (libraryUri.toString ());
187
+ if (module == null ) {
188
+ return _createError (
189
+ ErrorKind .internal, 'no module for $libraryUri ($dartSourcePath )' );
190
+ }
179
191
180
- _logger.finest ('Evaluating "$expression " at $currentModule , '
192
+ _logger.finest ('Evaluating "$expression " at $module , '
181
193
'$libraryUri :${dartLocation .line }:${dartLocation .column }' );
182
194
183
195
// Compile expression using an expression compiler, such as
@@ -189,7 +201,7 @@ class ExpressionEvaluator {
189
201
dartLocation.column,
190
202
{},
191
203
jsScope,
192
- currentModule ,
204
+ module ,
193
205
expression);
194
206
195
207
final isError = compilationResult.isError;
@@ -267,7 +279,9 @@ class ExpressionEvaluator {
267
279
for (var p in variables) {
268
280
final name = p.name;
269
281
final value = p.value;
270
- if (! _isUndefined (value)) {
282
+ // TODO: null values represent variables optimized by v8.
283
+ // Show that to the user.
284
+ if (name != null && value != null && ! _isUndefined (value)) {
271
285
jsScope[name] = name;
272
286
}
273
287
}
@@ -276,17 +290,17 @@ class ExpressionEvaluator {
276
290
// skip library and main scope
277
291
final scopeChain = filterScopes (frame).reversed;
278
292
for (var scope in scopeChain) {
279
- final scopeProperties =
280
- await _debugger.getProperties (scope.object.objectId);
281
-
282
- collectVariables (scope.scope, scopeProperties);
293
+ final objectId = scope.object.objectId;
294
+ if (objectId != null ) {
295
+ final scopeProperties = await _debugger.getProperties (objectId);
296
+ collectVariables (scope.scope, scopeProperties);
297
+ }
283
298
}
284
299
285
300
return jsScope;
286
301
}
287
302
288
- bool _isUndefined (RemoteObject value) =>
289
- value == null || value.type == 'undefined' ;
303
+ bool _isUndefined (RemoteObject value) => value.type == 'undefined' ;
290
304
291
305
/// Strip try/catch incorrectly added by the expression compiler.
292
306
/// TODO: remove adding try/catch block in expression compiler.
@@ -346,8 +360,4 @@ class ExpressionEvaluator {
346
360
347
361
String _createDartLambda (String expression, Iterable <String > params) =>
348
362
'(${params .join (', ' )}) => $expression ' ;
349
-
350
- /// Returns Chrome script uri for Chrome script ID.
351
- String _urlForScriptId (String scriptId) =>
352
- _inspector.remoteDebugger.scripts[scriptId]? .url;
353
363
}
0 commit comments