mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:19:49 +00:00
[vm,corelib] Restrict Expando/WeakReference usage for records
From records specification: ``` Like numbers, records do not have a well-defined persistent identity. That means Expandos can not be attached to them. ``` This change updates Expando and WeakReference API documentation and adds a check to disallow attaching Expando or WeakReference to a record. TEST=co19/LanguageFeatures/Records/expandos_A01_t01 Issue: https://github.com/dart-lang/sdk/issues/49719 Change-Id: I6459f43a2deac697e201673589d73abedc8d413e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263420 Reviewed-by: Lasse Nielsen <lrn@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
parent
174f3d3be2
commit
cf111fdcfb
|
@ -225,11 +225,12 @@ void checkValidWeakTarget(object, name) {
|
||||||
(object is bool) ||
|
(object is bool) ||
|
||||||
(object is num) ||
|
(object is num) ||
|
||||||
(object is String) ||
|
(object is String) ||
|
||||||
|
(object is Record) ||
|
||||||
(object is Pointer) ||
|
(object is Pointer) ||
|
||||||
(object is Struct) ||
|
(object is Struct) ||
|
||||||
(object is Union)) {
|
(object is Union)) {
|
||||||
throw new ArgumentError.value(object, name,
|
throw new ArgumentError.value(object, name,
|
||||||
"Cannot be a string, number, boolean, null, Pointer, Struct or Union");
|
"Cannot be a string, number, boolean, record, null, Pointer, Struct or Union");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ part of dart.core;
|
||||||
|
|
||||||
/// An [Expando] allows adding new properties to objects.
|
/// An [Expando] allows adding new properties to objects.
|
||||||
///
|
///
|
||||||
/// Does not work on numbers, strings, booleans, `null`, `dart:ffi` pointers,
|
/// Does not work on numbers, strings, booleans, records, `null`,
|
||||||
/// `dart:ffi` structs, or `dart:ffi` unions.
|
/// `dart:ffi` pointers, `dart:ffi` structs, or `dart:ffi` unions.
|
||||||
///
|
///
|
||||||
/// An `Expando` does not hold on to the added property value after an object
|
/// An `Expando` does not hold on to the added property value after an object
|
||||||
/// becomes inaccessible.
|
/// becomes inaccessible.
|
||||||
|
@ -24,6 +24,8 @@ part of dart.core;
|
||||||
/// released. To avoid this, expando properties cannot be added to numbers.
|
/// released. To avoid this, expando properties cannot be added to numbers.
|
||||||
/// The same argument applies to strings, booleans and `null`, which also have
|
/// The same argument applies to strings, booleans and `null`, which also have
|
||||||
/// literals that evaluate to identical values when they occur more than once.
|
/// literals that evaluate to identical values when they occur more than once.
|
||||||
|
/// In addition, expando properties can not be added to records because
|
||||||
|
/// records do not have a well-defined persistent identity.
|
||||||
///
|
///
|
||||||
/// There is no restriction on other classes, even for compile time constant
|
/// There is no restriction on other classes, even for compile time constant
|
||||||
/// objects. Be careful if adding expando properties to compile time constants,
|
/// objects. Be careful if adding expando properties to compile time constants,
|
||||||
|
@ -47,8 +49,8 @@ class Expando<T extends Object> {
|
||||||
///
|
///
|
||||||
/// If the object hasn't been expanded, the result is the `null` value.
|
/// If the object hasn't been expanded, the result is the `null` value.
|
||||||
///
|
///
|
||||||
/// The object must not be a number, a string, a boolean, `null`, a
|
/// The object must not be a number, a string, a boolean, a record, `null`,
|
||||||
/// `dart:ffi` pointer, a `dart:ffi` struct, or a `dart:ffi` union.
|
/// a `dart:ffi` pointer, a `dart:ffi` struct, or a `dart:ffi` union.
|
||||||
external T? operator [](Object object);
|
external T? operator [](Object object);
|
||||||
|
|
||||||
/// Sets this [Expando]'s property value on the given object to [value].
|
/// Sets this [Expando]'s property value on the given object to [value].
|
||||||
|
@ -56,8 +58,8 @@ class Expando<T extends Object> {
|
||||||
/// Properties can effectively be removed again
|
/// Properties can effectively be removed again
|
||||||
/// by setting their value to `null`.
|
/// by setting their value to `null`.
|
||||||
///
|
///
|
||||||
/// The object must not be a number, a string, a boolean, `null`, a
|
/// The object must not be a number, a string, a boolean, a record, `null`,
|
||||||
/// `dart:ffi` pointer, a `dart:ffi` struct, or a `dart:ffi` union.
|
/// a `dart:ffi` pointer, a `dart:ffi` struct, or a `dart:ffi` union.
|
||||||
external void operator []=(Object object, T? value);
|
external void operator []=(Object object, T? value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +127,7 @@ abstract class WeakReference<T extends Object> {
|
||||||
/// Creates a [WeakReference] pointing to the given [target].
|
/// Creates a [WeakReference] pointing to the given [target].
|
||||||
///
|
///
|
||||||
/// The [target] must be an object supported as an [Expando] key,
|
/// The [target] must be an object supported as an [Expando] key,
|
||||||
/// which means [target] cannot be a number, a string, a boolean,
|
/// which means [target] cannot be a number, a string, a boolean, a record,
|
||||||
/// the `null` value, or certain other types of special objects.
|
/// the `null` value, or certain other types of special objects.
|
||||||
external factory WeakReference(T target);
|
external factory WeakReference(T target);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue