diff --git a/modules/angular2/src/facade/collection.ts b/modules/angular2/src/facade/collection.ts index 448bab07b8..feea9a14a1 100644 --- a/modules/angular2/src/facade/collection.ts +++ b/modules/angular2/src/facade/collection.ts @@ -52,6 +52,26 @@ var _clearValues: {(m: Map)} = (function() { }; } })(); +// Safari doesn't implement MapIterator.next(), which is used is Traceur's polyfill of Array.from +// TODO(mlaval): remove the work around once we have a working polyfill of Array.from +var _arrayFromMap: {(m: Map, getValues: boolean): List} = (function() { + try { + if (((new Map()).values()).next) { + return function createArrayFromMap(m: Map, getValues: boolean): List { + return getValues ? (Array).from(m.values()) : (Array).from(m.keys()); + }; + } + } catch (e) { + } + return function createArrayFromMapWithForeach(m: Map, getValues: boolean): List { + var res = ListWrapper.createFixedSize(m.size), i = 0; + m.forEach((v, k) => { + ListWrapper.set(res, i, getValues ? v : k); + i++; + }); + return res; + }; +})(); export class MapWrapper { static clone(m: Map): Map { return createMapFromMap(m); } @@ -74,8 +94,8 @@ export class MapWrapper { static delete(m: Map, k: K) { m.delete(k); } static clearValues(m: Map) { _clearValues(m); } static iterable(m: T): T { return m; } - static keys(m: Map): List { return (Array).from(m.keys()); } - static values(m: Map): List { return (Array).from(m.values()); } + static keys(m: Map): List { return _arrayFromMap(m, false); } + static values(m: Map): List { return _arrayFromMap(m, true); } } /**