mirror of
https://github.com/dart-lang/sdk
synced 2024-10-02 23:39:19 +00:00
Make json-maps implement Map<String, dynamic>.
Fixes #26407. http://dartbug.com/26407 R=lrn@google.com Review-Url: https://codereview.chromium.org/1980663002 .
This commit is contained in:
parent
0367d955fb
commit
f6020b6d7e
|
@ -14,6 +14,9 @@
|
|||
* Added 'RawSynchronousSocket', a basic synchronous socket implementation.
|
||||
* `dart:convert`
|
||||
* Removed deprecated `ChunkedConverter` class.
|
||||
* JSON maps are now typed as `Map<String, dynamic>` instead of
|
||||
`Map<dynamic, dynamic>`. A JSON-map is not a `HashMap` or `LinkedHashMap`
|
||||
anymore (but just a `Map`).
|
||||
|
||||
### Dart VM
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ class _BuildJsonListener extends _JsonListener {
|
|||
|
||||
void beginObject() {
|
||||
pushContainer();
|
||||
currentContainer = {};
|
||||
currentContainer = <String, dynamic>{};
|
||||
}
|
||||
|
||||
void propertyName() {
|
||||
|
|
|
@ -123,7 +123,7 @@ _convertJsonToDartLazy(object) {
|
|||
return object;
|
||||
}
|
||||
|
||||
class _JsonMap implements LinkedHashMap {
|
||||
class _JsonMap implements Map<String, dynamic> {
|
||||
// The original JavaScript object remains unchanged until
|
||||
// the map is eventually upgraded, in which case we null it
|
||||
// out to reclaim the memory used by it.
|
||||
|
@ -156,7 +156,7 @@ class _JsonMap implements LinkedHashMap {
|
|||
bool get isEmpty => length == 0;
|
||||
bool get isNotEmpty => length > 0;
|
||||
|
||||
Iterable get keys {
|
||||
Iterable<String> get keys {
|
||||
if (_isUpgraded) return _upgradedMap.keys;
|
||||
return new _JsonMapKeyIterable(this);
|
||||
}
|
||||
|
@ -280,12 +280,12 @@ class _JsonMap implements LinkedHashMap {
|
|||
return JS('JSExtendableArray', '#', keys);
|
||||
}
|
||||
|
||||
Map _upgrade() {
|
||||
Map<String, dynamic> _upgrade() {
|
||||
if (_isUpgraded) return _upgradedMap;
|
||||
|
||||
// Copy all the (key, value) pairs to a freshly allocated
|
||||
// linked hash map thus preserving the ordering.
|
||||
Map result = {};
|
||||
Map result = <String, dynamic>{};
|
||||
List<String> keys = _computeKeys();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
String key = keys[i];
|
||||
|
@ -331,7 +331,7 @@ class _JsonMap implements LinkedHashMap {
|
|||
static _newJavaScriptObject() => JS('=Object', 'Object.create(null)');
|
||||
}
|
||||
|
||||
class _JsonMapKeyIterable extends ListIterable {
|
||||
class _JsonMapKeyIterable extends ListIterable<String> {
|
||||
final _JsonMap _parent;
|
||||
|
||||
_JsonMapKeyIterable(this._parent);
|
||||
|
@ -347,7 +347,7 @@ class _JsonMapKeyIterable extends ListIterable {
|
|||
/// Although [ListIterable] defines its own iterator, we return the iterator
|
||||
/// of the underlying list [_keys] in order to propagate
|
||||
/// [ConcurrentModificationError]s.
|
||||
Iterator get iterator {
|
||||
Iterator<String> get iterator {
|
||||
return _parent._isUpgraded
|
||||
? _parent.keys.iterator
|
||||
: _parent._computeKeys().iterator;
|
||||
|
|
|
@ -53,7 +53,6 @@ void test(bool revive) {
|
|||
testToString();
|
||||
testConcurrentModifications();
|
||||
testType();
|
||||
testNonStringKeys();
|
||||
testClear();
|
||||
|
||||
testListEntry();
|
||||
|
@ -300,23 +299,8 @@ void testConcurrentModifications() {
|
|||
|
||||
void testType() {
|
||||
Expect.isTrue(jsonify({}) is Map);
|
||||
Expect.isTrue(jsonify({}) is HashMap);
|
||||
Expect.isTrue(jsonify({}) is LinkedHashMap);
|
||||
|
||||
Expect.isTrue(jsonify({}) is Map<String, dynamic>);
|
||||
Expect.isTrue(jsonify({}) is HashMap<String, dynamic>);
|
||||
Expect.isTrue(jsonify({}) is LinkedHashMap<String, dynamic>);
|
||||
|
||||
Expect.isTrue(jsonify({}) is Map<int, dynamic>);
|
||||
Expect.isTrue(jsonify({}) is HashMap<int, dynamic>);
|
||||
Expect.isTrue(jsonify({}) is LinkedHashMap<int, dynamic>);
|
||||
}
|
||||
|
||||
void testNonStringKeys() {
|
||||
Map map = jsonify({});
|
||||
map[1] = 2;
|
||||
Expect.equals(1, map.length);
|
||||
Expect.equals(2, map[1]);
|
||||
Expect.isFalse(jsonify({}) is Map<int, dynamic>);
|
||||
}
|
||||
|
||||
void testClear() {
|
||||
|
|
|
@ -21,8 +21,6 @@ void main() {
|
|||
test(new MapView(new SplayTreeMap()));
|
||||
test(new MapBaseMap());
|
||||
test(new MapMixinMap());
|
||||
test(newJsonMap());
|
||||
test(newJsonMapCustomReviver());
|
||||
testLinkedHashMap();
|
||||
testMapLiteral();
|
||||
testNullValue();
|
||||
|
@ -53,8 +51,6 @@ void main() {
|
|||
testNumericKeys(new LinkedHashMap<num, String>.identity());
|
||||
testNumericKeys(new MapBaseMap<num, String>());
|
||||
testNumericKeys(new MapMixinMap<num, String>());
|
||||
testNumericKeys(newJsonMap());
|
||||
testNumericKeys(newJsonMapCustomReviver());
|
||||
|
||||
testNaNKeys(new Map());
|
||||
testNaNKeys(new Map<num, String>());
|
||||
|
@ -64,8 +60,6 @@ void main() {
|
|||
testNaNKeys(new LinkedHashMap<num, String>());
|
||||
testNaNKeys(new MapBaseMap<num, String>());
|
||||
testNaNKeys(new MapMixinMap<num, String>());
|
||||
testNaNKeys(newJsonMap());
|
||||
testNaNKeys(newJsonMapCustomReviver());
|
||||
// Identity maps fail the NaN-keys tests because the test assumes that
|
||||
// NaN is not equal to NaN.
|
||||
|
||||
|
@ -96,8 +90,6 @@ void main() {
|
|||
|
||||
testIterationOrder(new LinkedHashMap());
|
||||
testIterationOrder(new LinkedHashMap.identity());
|
||||
testIterationOrder(newJsonMap());
|
||||
testIterationOrder(newJsonMapCustomReviver());
|
||||
|
||||
testOtherKeys(new SplayTreeMap<int, int>());
|
||||
testOtherKeys(
|
||||
|
@ -121,8 +113,6 @@ void main() {
|
|||
isValidKey: (v) => v is int));
|
||||
testOtherKeys(new MapBaseMap<int, int>());
|
||||
testOtherKeys(new MapMixinMap<int, int>());
|
||||
testOtherKeys(newJsonMap());
|
||||
testOtherKeys(newJsonMapCustomReviver());
|
||||
|
||||
testUnmodifiableMap(const {1: 37});
|
||||
testUnmodifiableMap(new UnmodifiableMapView({1: 37}));
|
||||
|
|
Loading…
Reference in a new issue