[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:
Joshua Litt 2022-12-13 00:27:59 +00:00 committed by Commit Queue
parent 750b684cf9
commit 220bb44c55

View file

@ -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;
}
}