From 7e7ff873e449f55db3d14a9cc7c5775c726e6ca5 Mon Sep 17 00:00:00 2001 From: Ray Di Ciaccio Date: Tue, 14 Feb 2017 19:58:38 -0500 Subject: [PATCH 1/2] Detect when Firefox is trying to use the broken, alternative Iterator form and don't use it. Polyfill instead. --- packages/regenerator-runtime/runtime.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/regenerator-runtime/runtime.js b/packages/regenerator-runtime/runtime.js index 15fdacce8..1a0e47c6b 100644 --- a/packages/regenerator-runtime/runtime.js +++ b/packages/regenerator-runtime/runtime.js @@ -96,9 +96,13 @@ if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { - // This environment has a native %IteratorPrototype%; use it instead - // of the polyfill. - IteratorPrototype = NativeIteratorPrototype; + // This environment has a native %IteratorPrototype%; use it instead of the + // polyfill unless it's the broken Firefox IteratorPrototype. See + // https://github.com/facebook/regenerator/issues/274 for more details. + var _n = NativeIteratorPrototype[iteratorSymbol].call(NativeIteratorPrototype); + if (!_n || !_n.next || _n.next.name !== 'LegacyIteratorNext') { + IteratorPrototype = NativeIteratorPrototype; + } } var Gp = GeneratorFunctionPrototype.prototype = From 6480f91c2d2dba786e51c19019c113e618d5b262 Mon Sep 17 00:00:00 2001 From: Ray Di Ciaccio Date: Wed, 22 Feb 2017 01:46:42 -0500 Subject: [PATCH 2/2] Fix @@iterator function call for generators, so that the generator itself is returned. --- packages/regenerator-runtime/runtime.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/regenerator-runtime/runtime.js b/packages/regenerator-runtime/runtime.js index 1a0e47c6b..5cd995ff5 100644 --- a/packages/regenerator-runtime/runtime.js +++ b/packages/regenerator-runtime/runtime.js @@ -96,13 +96,9 @@ if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { - // This environment has a native %IteratorPrototype%; use it instead of the - // polyfill unless it's the broken Firefox IteratorPrototype. See - // https://github.com/facebook/regenerator/issues/274 for more details. - var _n = NativeIteratorPrototype[iteratorSymbol].call(NativeIteratorPrototype); - if (!_n || !_n.next || _n.next.name !== 'LegacyIteratorNext') { - IteratorPrototype = NativeIteratorPrototype; - } + // This environment has a native %IteratorPrototype%; use it instead + // of the polyfill. + IteratorPrototype = NativeIteratorPrototype; } var Gp = GeneratorFunctionPrototype.prototype = @@ -396,6 +392,15 @@ Gp[toStringTagSymbol] = "Generator"; + // A Generator should always return itself as the iterator object when the + // @@iterator function is called on it. Some browsers' implementations of the + // iterator prototype chain incorrectly implement this, causing the Generator + // object to not be returned from this call. This ensures that doesn't happen. + // See https://github.com/facebook/regenerator/issues/274 for more details. + Gp[iteratorSymbol] = function() { + return this; + }; + Gp.toString = function() { return "[object Generator]"; };