mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:39:48 +00:00
[dart2wasm] Implement leaking Expando.
Change-Id: I14b92315c32eb9930fa852a424646fc2d0f0c0a5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274820 Reviewed-by: Aske Simon Christensen <askesc@google.com> Commit-Queue: Joshua Litt <joshualitt@google.com>
This commit is contained in:
parent
750b684cf9
commit
220bb44c55
|
@ -3,11 +3,40 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "dart:_internal" show patch;
|
||||
import "dart:ffi" show Pointer, Struct, Union;
|
||||
|
||||
// Stub Expando implementation to make the Expando class compile.
|
||||
|
||||
@patch
|
||||
class Expando<T> {
|
||||
final Map<Object, T?> _expando = Map.identity();
|
||||
|
||||
@patch
|
||||
Expando([String? name]) : name = name;
|
||||
|
||||
void _checkValidWeakTarget(Object? object) {
|
||||
if ((object == null) ||
|
||||
(object is bool) ||
|
||||
(object is num) ||
|
||||
(object is String) ||
|
||||
(object is Record) ||
|
||||
(object is Pointer) ||
|
||||
(object is Struct) ||
|
||||
(object is Union)) {
|
||||
throw new ArgumentError.value(object,
|
||||
"Cannot be a string, number, boolean, record, null, Pointer, Struct or Union");
|
||||
}
|
||||
}
|
||||
|
||||
@patch
|
||||
T? operator [](Object object) {
|
||||
_checkValidWeakTarget(object);
|
||||
return _expando[object];
|
||||
}
|
||||
|
||||
@patch
|
||||
void operator []=(Object object, T? value) {
|
||||
_checkValidWeakTarget(object);
|
||||
_expando[object] = value;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue