|
1 | | -import { root } from '../util/root'; |
2 | 1 |
|
3 | | -export function symbolIteratorPonyfill(root: any) { |
4 | | - const Symbol: any = root.Symbol; |
5 | | - |
6 | | - if (typeof Symbol === 'function') { |
7 | | - if (!Symbol.iterator) { |
8 | | - Symbol.iterator = Symbol('iterator polyfill'); |
9 | | - } |
10 | | - return Symbol.iterator; |
11 | | - } else { |
12 | | - // [for Mozilla Gecko 27-35:](https://mzl.la/2ewE1zC) |
13 | | - const { Set } = root; |
14 | | - if (Set && typeof new Set()['@@iterator'] === 'function') { |
15 | | - return '@@iterator'; |
16 | | - } |
17 | | - const { Map } = root; |
18 | | - // required for compatability with es6-shim |
19 | | - if (Map) { |
20 | | - let keys = Object.getOwnPropertyNames(Map.prototype); |
21 | | - for (let i = 0; i < keys.length; ++i) { |
22 | | - let key = keys[i]; |
23 | | - // according to spec, Map.prototype[@@iterator] and Map.orototype.entries must be equal. |
24 | | - if (key !== 'entries' && key !== 'size' && Map.prototype[key] === Map.prototype['entries']) { |
25 | | - return key; |
26 | | - } |
27 | | - } |
28 | | - } |
29 | | - return '@@iterator'; |
30 | | - } |
| 2 | +/* NOTE: Warning users that they don't have a Symbol.iterator |
| 3 | + polyfill. We don't want to throw on this, because it's not required |
| 4 | + by the library. However it will provide clues to users on older |
| 5 | + browsers why things like `from(iterable)` doesn't work. */ |
| 6 | +if (!Symbol || !Symbol.iterator) { |
| 7 | + console.warn('RxJS: Symbol.observable does not exist'); |
31 | 8 | } |
32 | 9 |
|
33 | | -export const iterator = symbolIteratorPonyfill(root); |
| 10 | +/** The native Symbol.iterator instance or a string */ |
| 11 | +export const iterator = Symbol && Symbol.iterator || '@@iterator'; |
34 | 12 |
|
35 | 13 | /** |
36 | | - * @deprecated use iterator instead |
| 14 | + * @deprecated use {@link iterator} instead |
37 | 15 | */ |
38 | 16 | export const $$iterator = iterator; |
0 commit comments