fix(collection): iterator on Map keys is not supported (Safari)

Closes #2096
This commit is contained in:
Marc Laval 2015-05-22 12:43:48 +02:00
parent d308e55e12
commit 4b98ed114e
1 changed files with 16 additions and 7 deletions

View File

@ -38,6 +38,21 @@ var createMapFromMap: {(m: Map<any, any>): Map<any, any>} = (function() {
return map; return map;
} }
})(); })();
var _clearValues: {(m: Map<any, any>)} = (function() {
if ((<any>(new Map()).keys()).next) {
return function _clearValues(m: Map<any, any>) {
var keyIterator = m.keys();
var k;
while (!((k = (<any>keyIterator).next()).done)) {
m.set(k.value, null);
}
};
} else {
return function _clearValuesWithForeEach(m: Map<any, any>) {
m.forEach((v, k) => { m.set(k, null); });
}
}
})();
export class MapWrapper { export class MapWrapper {
static create(): Map<any, any> { return new Map(); } static create(): Map<any, any> { return new Map(); }
@ -57,13 +72,7 @@ export class MapWrapper {
static size(m: Map<any, any>) { return m.size; } static size(m: Map<any, any>) { return m.size; }
static delete<K>(m: Map<K, any>, k: K) { m.delete(k); } static delete<K>(m: Map<K, any>, k: K) { m.delete(k); }
static clear(m: Map<any, any>) { m.clear(); } static clear(m: Map<any, any>) { m.clear(); }
static clearValues(m: Map<any, any>) { static clearValues(m: Map<any, any>) { _clearValues(m); }
var keyIterator = m.keys();
var k;
while (!((k = (<any>keyIterator).next()).done)) {
m.set(k.value, null);
}
}
static iterable(m) { return m; } static iterable(m) { return m; }
static keys<K>(m: Map<K, any>): List<K> { return m.keys(); } static keys<K>(m: Map<K, any>): List<K> { return m.keys(); }
static values<V>(m: Map<any, V>): List<V> { return m.values(); } static values<V>(m: Map<any, V>): List<V> { return m.values(); }