Skip to content

Commit d1355bf

Browse files
committed
fix(collection): new Set(iterable) is not supported (IE11, Safari)
1 parent 863eb3c commit d1355bf

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

modules/angular2/src/facade/collection.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,16 @@ export function iterateListLike(obj, fn: Function) {
234234
}
235235

236236
export class SetWrapper {
237-
static createFromList<T>(lst: List<T>): Set<T> { return new Set(lst); }
237+
// Safari and Internet Explorer do not support the iterable parameter to the
238+
// Set constructor. We work around that by manually adding the items.
239+
static createFromList<T>(lst: List<T>): Set<T> {
240+
var res = new Set(lst);
241+
if (res.size !== lst.length) {
242+
for (var i = 0; i < lst.length; i++) {
243+
res.add(lst[i]);
244+
}
245+
}
246+
return res;
247+
}
238248
static has<T>(s: Set<T>, key: T): boolean { return s.has(key); }
239249
}

0 commit comments

Comments
 (0)