Skip to content

Commit 57b88ec

Browse files
committed
fix(collection): new Set(iterable) is not supported (IE11, Safari)
Closes #2063
1 parent b1c9bf1 commit 57b88ec

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

modules/angular2/src/facade/collection.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,26 @@ export function iterateListLike(obj, fn: Function) {
233233
}
234234
}
235235

236+
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+
var createSetFromList: {(lst: List<any>): Set<any>} = (function() {
240+
var test = new Set([1, 2, 3]);
241+
if (test.size === 3) {
242+
return function createSetFromList(lst: List<any>): Set<any> { return new Set(lst); };
243+
} else {
244+
return function createSetAndPopulateFromList(lst: List<any>): Set<any> {
245+
var res = new Set(lst);
246+
if (res.size !== lst.length) {
247+
for (var i = 0; i < lst.length; i++) {
248+
res.add(lst[i]);
249+
}
250+
}
251+
return res;
252+
};
253+
}
254+
})();
236255
export class SetWrapper {
237-
static createFromList<T>(lst: List<T>): Set<T> { return new Set(lst); }
256+
static createFromList<T>(lst: List<T>): Set<T> { return createSetFromList(lst); }
238257
static has<T>(s: Set<T>, key: T): boolean { return s.has(key); }
239258
}

0 commit comments

Comments
 (0)