Cast errors to HttpExceptions and add lint to convert to tidy up dynamic calls in core libraries. Change-Id: I7ea73b232d13baf84e834d742ebc16f2a081e727 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262626 Commit-Queue: Kallen Tu <kallentu@google.com> Reviewed-by: Lasse Nielsen <lrn@google.com> Reviewed-by: Leaf Petersen <leafp@google.com>
diff --git a/pkg/compiler/test/analyses/api_allowed.json b/pkg/compiler/test/analyses/api_allowed.json index 2af663c..3718f64 100644 --- a/pkg/compiler/test/analyses/api_allowed.json +++ b/pkg/compiler/test/analyses/api_allowed.json
@@ -1,6 +1,5 @@ { "org-dartlang-sdk:///lib/_http/http_impl.dart": { - "Dynamic access of 'message'.": 3, "Dynamic access of 'address'.": 1, "Dynamic access of 'port'.": 1, "Dynamic invocation of 'listen'.": 1,
diff --git a/sdk/lib/_http/http_impl.dart b/sdk/lib/_http/http_impl.dart index dc6e3cb..6ea4c2d 100644 --- a/sdk/lib/_http/http_impl.dart +++ b/sdk/lib/_http/http_impl.dart
@@ -438,8 +438,8 @@ {Function? onError, void Function()? onDone, bool? cancelOnError}) { hasSubscriber = true; return _stream.handleError((error) { - throw HttpException(error.message, uri: uri); - }).listen(onData, + throw HttpException((error as HttpException).message, uri: uri); + }, test: (error) => error is HttpException).listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError); } @@ -2062,16 +2062,18 @@ _subscription!.resume(); }).catchError((dynamic error, StackTrace stackTrace) { _nextResponseCompleter!.completeError( - HttpException(error.message, uri: _currentUri), stackTrace); + HttpException((error as HttpException).message, uri: _currentUri), + stackTrace); _nextResponseCompleter = null; - }); + }, test: (error) => error is HttpException); } else { _nextResponseCompleter!.complete(incoming); _nextResponseCompleter = null; } }, onError: (dynamic error, StackTrace stackTrace) { _nextResponseCompleter?.completeError( - HttpException(error.message, uri: _currentUri), stackTrace); + HttpException((error as HttpException).message, uri: _currentUri), + stackTrace); _nextResponseCompleter = null; }, onDone: () { _nextResponseCompleter?.completeError(HttpException(
diff --git a/sdk/lib/convert/json.dart b/sdk/lib/convert/json.dart index c3a6793..e39ff28 100644 --- a/sdk/lib/convert/json.dart +++ b/sdk/lib/convert/json.dart
@@ -622,7 +622,7 @@ external dynamic _parseJson(String source, reviver(key, value)?); // Implementation of encoder/stringifier. - +// ignore: avoid_dynamic_calls dynamic _defaultToEncodable(dynamic object) => object.toJson(); /// JSON encoder that traverses an object structure and writes JSON source.