diff --git a/modules/angular2/src/facade/collection.ts b/modules/angular2/src/facade/collection.ts index 47659c5755..b76358af5e 100644 --- a/modules/angular2/src/facade/collection.ts +++ b/modules/angular2/src/facade/collection.ts @@ -233,7 +233,26 @@ export function iterateListLike(obj, fn: Function) { } } + +// Safari and Internet Explorer do not support the iterable parameter to the +// Set constructor. We work around that by manually adding the items. +var createSetFromList: {(lst: List): Set} = (function() { + var test = new Set([1, 2, 3]); + if (test.size === 3) { + return function createSetFromList(lst: List): Set { return new Set(lst); }; + } else { + return function createSetAndPopulateFromList(lst: List): Set { + var res = new Set(lst); + if (res.size !== lst.length) { + for (var i = 0; i < lst.length; i++) { + res.add(lst[i]); + } + } + return res; + }; + } +})(); export class SetWrapper { - static createFromList(lst: List): Set { return new Set(lst); } + static createFromList(lst: List): Set { return createSetFromList(lst); } static has(s: Set, key: T): boolean { return s.has(key); } }