diff --git a/CHANGELOG.md b/CHANGELOG.md index b0d08774093..a0982c4fa0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,14 @@ opted out of null safety by adding `// @dart=2.9` to the beginning of the file. * `LinkedList` made it explicit that elements are compared by identity, and updated `contains` to take advantage of this. +#### `dart:html` + +* `EventStreamSubscription.cancel` has been updated to retain its synchronous + timing when running in both sound and unsound null safety modes. See issue + [#44157][] for more details. + +[#44157]: https://github.com/dart-lang/sdk/issues/44157 + ### Dart VM * **Breaking Change** [#42312][]: `Dart_WeakPersistentHandle`s will no longer diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart index 8800d4c562e..87fed8fc870 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart @@ -5530,27 +5530,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor js_ast.Expression visitAsExpression(AsExpression node) { var fromExpr = node.operand; var jsFrom = _visitExpression(fromExpr); - - // The `_EventStreamSubscription.cancel()` method dart:html returns null in - // weak mode. This causes unwanted warnings/failures when you turn on the - // weak mode warnings/errors so we remove these specific runtime casts. - // TODO(44157) Remove this workaround once it returns a consistent type. - if (_isWebLibrary(currentLibraryUri) && node.parent is ReturnStatement) { - var parent = node.parent; - while (parent != null && parent is! FunctionNode) { - parent = parent?.parent; - } - parent = parent?.parent; - if (parent is Procedure) { - if (parent.enclosingClass != null && - parent.enclosingClass.name == '_EventStreamSubscription' && - parent.name.name == 'cancel') { - // Ignore these casts and just emit the expression. - return jsFrom; - } - } - } - var to = node.type; var from = fromExpr.getStaticType(_staticTypeContext); diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart index a79aff6f7a6..bc7bdfbc053 100644 --- a/sdk/lib/html/dart2js/html_dart2js.dart +++ b/sdk/lib/html/dart2js/html_dart2js.dart @@ -37285,18 +37285,13 @@ class _EventStreamSubscription extends StreamSubscription { } Future cancel() { - // Check for strong mode. This function can no longer return null in strong - // mode, so only return null in weak mode to preserve synchronous timing. - // See issue 41653 for more details. - dynamic emptyFuture = - typeAcceptsNull() ? null : Future.value(); - if (_canceled) return emptyFuture as Future; + if (_canceled) return nullFuture; _unlisten(); // Clear out the target to indicate this is complete. _target = null; _onData = null; - return emptyFuture as Future; + return nullFuture; } bool get _canceled => _target == null; diff --git a/tools/dom/src/EventStreamProvider.dart b/tools/dom/src/EventStreamProvider.dart index fe01be9be79..feadc26d26f 100644 --- a/tools/dom/src/EventStreamProvider.dart +++ b/tools/dom/src/EventStreamProvider.dart @@ -248,18 +248,13 @@ class _EventStreamSubscription extends StreamSubscription { } Future cancel() { - // Check for strong mode. This function can no longer return null in strong - // mode, so only return null in weak mode to preserve synchronous timing. - // See issue 41653 for more details. - dynamic emptyFuture = - typeAcceptsNull() ? null : Future.value(); - if (_canceled) return emptyFuture as Future; + if (_canceled) return nullFuture; _unlisten(); // Clear out the target to indicate this is complete. _target = null; _onData = null; - return emptyFuture as Future; + return nullFuture; } bool get _canceled => _target == null;