-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Symbol.iterator): no longer polyfilled
BREAKING CHANGE: We are no longer polyfilling `Symbol.iterator`. That would be done by a proper polyfilling library
- Loading branch information
Showing
2 changed files
with
9 additions
and
131 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,16 @@ | ||
import { root } from '../util/root'; | ||
|
||
export function symbolIteratorPonyfill(root: any) { | ||
const Symbol: any = root.Symbol; | ||
|
||
if (typeof Symbol === 'function') { | ||
if (!Symbol.iterator) { | ||
Symbol.iterator = Symbol('iterator polyfill'); | ||
} | ||
return Symbol.iterator; | ||
} else { | ||
// [for Mozilla Gecko 27-35:](https://mzl.la/2ewE1zC) | ||
const { Set } = root; | ||
if (Set && typeof new Set()['@@iterator'] === 'function') { | ||
return '@@iterator'; | ||
} | ||
const { Map } = root; | ||
// required for compatability with es6-shim | ||
if (Map) { | ||
let keys = Object.getOwnPropertyNames(Map.prototype); | ||
for (let i = 0; i < keys.length; ++i) { | ||
let key = keys[i]; | ||
// according to spec, Map.prototype[@@iterator] and Map.orototype.entries must be equal. | ||
if (key !== 'entries' && key !== 'size' && Map.prototype[key] === Map.prototype['entries']) { | ||
return key; | ||
} | ||
} | ||
} | ||
return '@@iterator'; | ||
} | ||
/* NOTE: Warning users that they don't have a Symbol.iterator | ||
polyfill. We don't want to throw on this, because it's not required | ||
by the library. However it will provide clues to users on older | ||
browsers why things like `from(iterable)` doesn't work. */ | ||
if (!Symbol.iterator) { | ||
console.warn('RxJS: Symbol.observable does not exist'); | ||
} | ||
|
||
export const iterator = symbolIteratorPonyfill(root); | ||
/** The native Symbol.iterator instance or a string */ | ||
export const iterator = Symbol.iterator || '@@iterator'; | ||
|
||
/** | ||
* @deprecated use iterator instead | ||
* @deprecated use {@link iterator} instead | ||
*/ | ||
export const $$iterator = iterator; |