Skip to content

Commit 6319f3c

Browse files
authored
feat(Symbol.iterator): no longer polyfilled (#3389)
BREAKING CHANGE: We are no longer polyfilling `Symbol.iterator`. That would be done by a proper polyfilling library
1 parent c3d9e1b commit 6319f3c

File tree

2 files changed

+9
-131
lines changed

2 files changed

+9
-131
lines changed

spec/symbol/iterator-spec.ts

-100
This file was deleted.

src/internal/symbol/iterator.ts

+9-31
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,16 @@
1-
import { root } from '../util/root';
21

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');
318
}
329

33-
export const iterator = symbolIteratorPonyfill(root);
10+
/** The native Symbol.iterator instance or a string */
11+
export const iterator = Symbol && Symbol.iterator || '@@iterator';
3412

3513
/**
36-
* @deprecated use iterator instead
14+
* @deprecated use {@link iterator} instead
3715
*/
3816
export const $$iterator = iterator;

0 commit comments

Comments
 (0)