fix(collection): new Map(iterable) is not supported (Safari)

This commit is contained in:
Marc Laval 2015-05-22 12:42:24 +02:00
parent 10bc7e948c
commit d308e55e12
1 changed files with 14 additions and 1 deletions

View File

@ -25,10 +25,23 @@ var createMapFromPairs: {(pairs: List<any>): Map<any, any>} = (function() {
return map;
}
})();
var createMapFromMap: {(m: Map<any, any>): Map<any, any>} = (function() {
try {
if (new Map(new Map())) {
return function createMapFromMap(m: Map<any, any>): Map<any, any> { return new Map(m); };
}
} catch (e) {
}
return function createMapAndPopulateFromMap(m: Map<any, any>): Map<any, any> {
var map = new Map();
m.forEach((v, k) => { map.set(k, v); });
return map;
}
})();
export class MapWrapper {
static create(): Map<any, any> { return new Map(); }
static clone<K, V>(m: Map<K, V>): Map<K, V> { return new Map(m); }
static clone<K, V>(m: Map<K, V>): Map<K, V> { return createMapFromMap(m); }
static createFromStringMap(stringMap): Map<string, any> {
var result = MapWrapper.create();
for (var prop in stringMap) {