diff --git a/dwds/lib/src/debugging/debugger.dart b/dwds/lib/src/debugging/debugger.dart index a8f226e3f..9744a98c3 100644 --- a/dwds/lib/src/debugging/debugger.dart +++ b/dwds/lib/src/debugging/debugger.dart @@ -12,7 +12,6 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart' hide StackTrace; import '../loaders/strategy.dart'; -import '../services/chrome_debug_exception.dart'; import '../utilities/conversions.dart'; import '../utilities/dart_uri.dart'; import '../utilities/domain.dart'; @@ -476,7 +475,7 @@ class Debugger extends Domain { final range = await _subrange(objectId, offset ?? 0, count ?? 0, length); rangeId = range.objectId ?? rangeId; } - final jsProperties = await sendCommandAndvalidateResult( + final jsProperties = await sendCommandAndValidateResult( _remoteDebugger, method: 'Runtime.getProperties', resultField: 'result', @@ -722,18 +721,15 @@ class Debugger extends Domain { try { return await _remoteDebugger.evaluateOnCallFrame(callFrameId, expression); } on ExceptionDetails catch (e) { - throw ChromeDebugException( + throwChromeDebugException( e.json, evalContents: expression, - additionalDetails: { - 'Dart expression': expression, - }, ); } } } -Future sendCommandAndvalidateResult( +Future sendCommandAndValidateResult( RemoteDebugger remoteDebugger, { required String method, required String resultField, @@ -868,7 +864,7 @@ class _Breakpoints extends Domain { // Prevent `Aww, snap!` errors when setting multiple breakpoints // simultaneously by serializing the requests. return _pool.withResource(() async { - final breakPointId = await sendCommandAndvalidateResult( + final breakPointId = await sendCommandAndValidateResult( remoteDebugger, method: 'Debugger.setBreakpointByUrl', resultField: 'breakpointId', diff --git a/dwds/lib/src/debugging/inspector.dart b/dwds/lib/src/debugging/inspector.dart index dc4d50228..a0c543756 100644 --- a/dwds/lib/src/debugging/inspector.dart +++ b/dwds/lib/src/debugging/inspector.dart @@ -2,9 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file.import 'dart:async'; -// @dart = 2.9 - import 'package:async/async.dart'; +import 'package:collection/collection.dart'; import 'package:logging/logging.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; @@ -67,9 +66,9 @@ class AppInspector implements AppInspectorInterface { final ExecutionContext _executionContext; - LibraryHelper _libraryHelper; - ClassHelper _classHelper; - InstanceHelper _instanceHelper; + late final LibraryHelper _libraryHelper; + late final ClassHelper _classHelper; + late final InstanceHelper _instanceHelper; final AssetReader _assetReader; final Locations _locations; @@ -106,15 +105,17 @@ class AppInspector implements AppInspectorInterface { final libraries = await _libraryHelper.libraryRefs; isolate.rootLib = await _libraryHelper.rootLib; - isolate.libraries.addAll(libraries); + isolate.libraries?.addAll(libraries); final scripts = await scriptRefs; await DartUri.initialize(_sdkConfiguration); - await DartUri.recordAbsoluteUris(libraries.map((lib) => lib.uri)); - await DartUri.recordAbsoluteUris(scripts.map((script) => script.uri)); + await DartUri.recordAbsoluteUris( + libraries.map((lib) => lib.uri).whereNotNull()); + await DartUri.recordAbsoluteUris( + scripts.map((script) => script.uri).whereNotNull()); - isolate.extensionRPCs.addAll(await _getExtensionRpcs()); + isolate.extensionRPCs?.addAll(await _getExtensionRpcs()); } static IsolateRef _toIsolateRef(Isolate isolate) => IsolateRef( @@ -187,7 +188,7 @@ class AppInspector implements AppInspectorInterface { /// Returns the ID for the execution context or null if not found. @override - Future get contextId async { + Future get contextId async { try { return await _executionContext.id; } catch (e, s) { @@ -236,15 +237,16 @@ class AppInspector implements AppInspectorInterface { String evalExpression, List arguments, {bool returnByValue = false}) async { final jsArguments = arguments.map(callArgumentFor).toList(); - final result = + final response = await remoteDebugger.sendCommand('Runtime.callFunctionOn', params: { 'functionDeclaration': evalExpression, 'arguments': jsArguments, 'objectId': receiver.objectId, 'returnByValue': returnByValue, }); - handleErrorIfPresent(result, evalContents: evalExpression); - return RemoteObject(result.result['result'] as Map); + final result = + getResultOrHandleError(response, evalContents: evalExpression); + return RemoteObject(result); } /// Calls Chrome's Runtime.callFunctionOn method with a global function. @@ -255,15 +257,16 @@ class AppInspector implements AppInspectorInterface { String evalExpression, List arguments, {bool returnByValue = false}) async { final jsArguments = arguments.map(callArgumentFor).toList(); - final result = + final response = await remoteDebugger.sendCommand('Runtime.callFunctionOn', params: { 'functionDeclaration': evalExpression, 'arguments': jsArguments, 'executionContextId': await contextId, 'returnByValue': returnByValue, }); - handleErrorIfPresent(result, evalContents: evalExpression); - return RemoteObject(result.result['result'] as Map); + final result = + getResultOrHandleError(response, evalContents: evalExpression); + return RemoteObject(result); } /// Invoke the function named [selector] on the object identified by @@ -303,26 +306,28 @@ class AppInspector implements AppInspectorInterface { Future jsEvaluate(String expression, {bool returnByValue = false, bool awaitPromise = false}) async { // TODO(alanknight): Support a version with arguments if needed. - WipResponse result; - result = await remoteDebugger.sendCommand('Runtime.evaluate', params: { + final response = + await remoteDebugger.sendCommand('Runtime.evaluate', params: { 'expression': expression, 'returnByValue': returnByValue, 'awaitPromise': awaitPromise, 'contextId': await contextId, }); - handleErrorIfPresent(result, evalContents: expression, additionalDetails: { - 'Dart expression': expression, - }); - return RemoteObject(result.result['result'] as Map); + final result = getResultOrHandleError(response, evalContents: expression); + return RemoteObject(result); } /// Evaluate the JS function with source [jsFunction] in the context of /// [library] with [arguments]. Future _evaluateInLibrary( Library library, String jsFunction, List arguments) async { + final libraryUri = library.uri; + if (libraryUri == null) { + throwInvalidParam('invoke', 'library uri is null'); + } final findLibrary = ''' (function() { - ${globalLoadStrategy.loadLibrarySnippet(library.uri)}; + ${globalLoadStrategy.loadLibrarySnippet(libraryUri)}; return library; })(); '''; @@ -339,25 +344,25 @@ class AppInspector implements AppInspectorInterface { } @override - Future instanceRefFor(Object value) => + Future instanceRefFor(Object value) => _instanceHelper.instanceRefFor(value); - Future instanceFor(Object value) => + Future instanceFor(RemoteObject value) => _instanceHelper.instanceFor(value); @override - Future libraryRefFor(String objectId) => + Future libraryRefFor(String objectId) => _libraryHelper.libraryRefFor(objectId); @override - Future getLibrary(String objectId) async { + Future getLibrary(String objectId) async { final libraryRef = await libraryRefFor(objectId); if (libraryRef == null) return null; return _libraryHelper.libraryFor(libraryRef); } @override - Future getObject(String objectId, {int offset, int count}) async { + Future getObject(String objectId, {int? offset, int? count}) async { try { final library = await getLibrary(objectId); if (library != null) { @@ -384,9 +389,13 @@ class AppInspector implements AppInspectorInterface { 'are supported for getObject'); } - Future