From 13978f85fd34761c6b6e0bc315e265c59a52ed4f Mon Sep 17 00:00:00 2001 From: Vyacheslav Egorov Date: Mon, 19 Dec 2022 16:03:46 +0000 Subject: [PATCH] [lib] Update SendPort.send documentation Try to make it more clear that you can only send default implementations of List, Map, Set, etc. Add CHANGELOG.md entry that documents a8fe399c79eedd1e0bce072719bd142f25138f70 Related to https://github.com/dart-lang/sdk/issues/50594 Change-Id: Ib0cf9d389b91cc5ab72b8bab5461ee91037baf25 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273185 Commit-Queue: Slava Egorov Reviewed-by: Lasse Nielsen --- CHANGELOG.md | 10 ++++++++++ sdk/lib/isolate/isolate.dart | 30 ++++++++++++++++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7e44692fb8..954b4bb1921 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -256,6 +256,16 @@ Updates the Linter to `1.32.0`, which includes changes that #### `dart:isolate` - Add `Isolate.run` to run a function in a new isolate. +- **Breaking change**: `SendPort.send` is again applying strict checks to the + contents of the message when sending messages between isolates that are not + known to share the same code (e.g. an isolate spawned via `Isolate.spawnUri`). + These checks were accidentally relaxed in an earlier Dart version allowing + all classes from `dart:core` and `dart:collection` through. This for + example means that you can't send an instance of a `HashMap` to an isolate + spawned via `Isolate.spawnUri`. See [`SendPort.send`] documentation for + the full list of restrictions. + +[`SendPort.send`]: https://api.dart.dev/stable/dart-isolate/SendPort/send.html #### `dart:mirrors` diff --git a/sdk/lib/isolate/isolate.dart b/sdk/lib/isolate/isolate.dart index ddde17458ed..083dab98c54 100644 --- a/sdk/lib/isolate/isolate.dart +++ b/sdk/lib/isolate/isolate.dart @@ -707,18 +707,24 @@ abstract class SendPort implements Capability { /// Sends an asynchronous [message] through this send port, to its /// corresponding [ReceivePort]. /// - /// The transitive object graph of [message] can contain the following - /// objects: - /// - [Null] - /// - [bool] - /// - [int] - /// - [double] - /// - [String] - /// - [List], [Map] or [Set] (whose elements are any of these) - /// - [TransferableTypedData] - /// - [SendPort] - /// - [Capability] - /// - [Type] representing one of these types, Object, dynamic, void or Never + /// If the sending and receiving isolates do not share the same code + /// (an isolate created using [Isolate.spawnUri] does not share the code + /// of the isolate that spawned it), the transitive object graph of [message] + /// can **only** contain the following kinds of objects: + /// + /// - `null` + /// - `true` and `false` + /// - Instances of [int], [double], [String] + /// - Instances created through list, map and set literals + /// - Instances created by constructors of: + /// - [List], [Map], [LinkedHashMap], [Set] and [LinkedHashSet] + /// - [TransferableTypedData] + /// - [Capability] + /// - [SendPort] instances returned by [ReceivePort]'s `sendPort` getter + /// - Instances of [Type] representing one of the types mentioned above, + /// `Object`, `dynamic`, `void` and `Never` as well as nullable variants + /// of all these types. For generic types type arguments must be sendable + /// types for the whole type to be sendable. /// /// If the sender and receiver isolate share the same code (e.g. isolates /// created via [Isolate.spawn]), the transitive object graph of [message] can