From 4b98ed114e5f13e514647ed5299b9201ab8c3eec Mon Sep 17 00:00:00 2001 From: Marc Laval Date: Fri, 22 May 2015 12:43:48 +0200 Subject: [PATCH] fix(collection): iterator on Map keys is not supported (Safari) Closes #2096 --- modules/angular2/src/facade/collection.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/modules/angular2/src/facade/collection.ts b/modules/angular2/src/facade/collection.ts index a12feec44d..5f4f5dfd36 100644 --- a/modules/angular2/src/facade/collection.ts +++ b/modules/angular2/src/facade/collection.ts @@ -38,6 +38,21 @@ var createMapFromMap: {(m: Map): Map} = (function() { return map; } })(); +var _clearValues: {(m: Map)} = (function() { + if (((new Map()).keys()).next) { + return function _clearValues(m: Map) { + var keyIterator = m.keys(); + var k; + while (!((k = (keyIterator).next()).done)) { + m.set(k.value, null); + } + }; + } else { + return function _clearValuesWithForeEach(m: Map) { + m.forEach((v, k) => { m.set(k, null); }); + } + } +})(); export class MapWrapper { static create(): Map { return new Map(); } @@ -57,13 +72,7 @@ export class MapWrapper { static size(m: Map) { return m.size; } static delete(m: Map, k: K) { m.delete(k); } static clear(m: Map) { m.clear(); } - static clearValues(m: Map) { - var keyIterator = m.keys(); - var k; - while (!((k = (keyIterator).next()).done)) { - m.set(k.value, null); - } - } + static clearValues(m: Map) { _clearValues(m); } static iterable(m) { return m; } static keys(m: Map): List { return m.keys(); } static values(m: Map): List { return m.values(); }