@@ -251,18 +251,28 @@ require("dart_sdk").developer.invokeExtension(
251251 throw UnsupportedError (
252252 'Evaluate is only supported when `targetId` is a library.' );
253253 }
254- var result = await tabConnection.runtime. evaluate ( '''
254+ var evalExpression = '''
255255(function() {
256256 ${_getLibrarySnippet (library .uri )};
257257 return library.$expression ;
258258})();
259- ''' );
259+ ''' ;
260+ var result = await tabConnection.runtime.sendCommand ('Runtime.evaluate' ,
261+ params: {'expression' : evalExpression, 'returnByValue' : true });
262+ _handleErrorIfPresent (result,
263+ evalContents: evalExpression,
264+ additionalDetails: {
265+ 'Dart expression' : expression,
266+ 'scope' : scope,
267+ });
268+ var remoteObject =
269+ RemoteObject (result.result['result' ] as Map <String , dynamic >);
260270
261271 String kind;
262272 var classRef = ClassRef ()
263- ..id = 'dart:core:${result .type }'
264- ..name = result .type;
265- switch (result .type) {
273+ ..id = 'dart:core:${remoteObject .type }'
274+ ..name = remoteObject .type;
275+ switch (remoteObject .type) {
266276 case 'string' :
267277 kind = InstanceKind .kString;
268278 break ;
@@ -273,11 +283,12 @@ require("dart_sdk").developer.invokeExtension(
273283 kind = InstanceKind .kBool;
274284 break ;
275285 default :
276- throw UnsupportedError ('Unsupported response type ${result .type }' );
286+ throw UnsupportedError (
287+ 'Unsupported response type ${remoteObject .type }' );
277288 }
278289
279290 return InstanceRef ()
280- ..valueAsString = '${result .value }'
291+ ..valueAsString = '${remoteObject .value }'
281292 ..classRef = classRef
282293 ..kind = kind;
283294 }
@@ -788,11 +799,13 @@ const _stdoutTypes = ['log', 'info', 'warning'];
788799
789800/// Throws an [ExceptionDetails] object if `exceptionDetails` is present on the
790801/// result.
791- void _handleErrorIfPresent (WipResponse response, {String evalContents}) {
802+ void _handleErrorIfPresent (WipResponse response,
803+ {String evalContents, Object additionalDetails}) {
792804 if (response.result.containsKey ('exceptionDetails' )) {
793805 throw ChromeDebugException (
794806 response.result['exceptionDetails' ] as Map <String , dynamic >,
795- evalContents: evalContents);
807+ evalContents: evalContents,
808+ additionalDetails: additionalDetails);
796809 }
797810}
798811
@@ -818,11 +831,14 @@ String _getLibrarySnippet(String libraryUri) => '''
818831''' ;
819832
820833class ChromeDebugException extends ExceptionDetails implements Exception {
834+ /// Optional, additional information about the exception.
835+ final Object additionalDetails;
836+
821837 /// Optional, the exact contents of the eval that was attempted.
822838 final String evalContents;
823839
824840 ChromeDebugException (Map <String , dynamic > exceptionDetails,
825- {this .evalContents})
841+ {this .additionalDetails, this . evalContents})
826842 : super (exceptionDetails);
827843
828844 @override
@@ -839,7 +855,10 @@ class ChromeDebugException extends ExceptionDetails implements Exception {
839855 description.writeln (' value: ${exception .value }' );
840856 }
841857 if (evalContents != null ) {
842- description.writeln ('attempted eval: `$evalContents `' );
858+ description.writeln ('attempted JS eval: `$evalContents `' );
859+ }
860+ if (additionalDetails != null ) {
861+ description.writeln ('additional details:\n $additionalDetails ' );
843862 }
844863 return description.toString ();
845864 }
0 commit comments