From f171f9d1e3992526245947ae033bcc4ada06f989 Mon Sep 17 00:00:00 2001 From: Jay Phelps Date: Wed, 7 Mar 2018 01:17:08 -0500 Subject: [PATCH] fix(Symbol.iterator): correctly handle case where Symbol constructor itself is not defined --- src/internal/symbol/iterator.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/internal/symbol/iterator.ts b/src/internal/symbol/iterator.ts index 2475131f06..2ca0f21ae4 100644 --- a/src/internal/symbol/iterator.ts +++ b/src/internal/symbol/iterator.ts @@ -1,14 +1,17 @@ +export function getSymbolIterator(): symbol { + /* 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 (typeof Symbol !== 'function' || !Symbol.iterator) { + console.warn('RxJS: Symbol.iterator does not exist, so things like from(iterable) won\'t work'); + return '@@iterator' as any; + } -/* 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 || !Symbol.iterator) { - console.warn('RxJS: Symbol.observable does not exist'); + return Symbol.iterator; } -/** The native Symbol.iterator instance or a string */ -export const iterator = Symbol && Symbol.iterator || '@@iterator'; +export const iterator = getSymbolIterator(); /** * @deprecated use {@link iterator} instead