diff --git a/packages/regenerator-runtime/runtime.js b/packages/regenerator-runtime/runtime.js index 02d2bea88..9e0c50d58 100644 --- a/packages/regenerator-runtime/runtime.js +++ b/packages/regenerator-runtime/runtime.js @@ -82,14 +82,21 @@ var runtime = (function (exports) { IteratorPrototype = NativeIteratorPrototype; } + function ensureDefaultToStringTag(object, defaultValue) { + // https://bugzilla.mozilla.org/show_bug.cgi?id=1644581#c6 + return toStringTagSymbol in object + ? object[toStringTagSymbol] + : object[toStringTagSymbol] = defaultValue; + } + var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype; GeneratorFunctionPrototype.constructor = GeneratorFunction; - if (!(toStringTagSymbol in GeneratorFunctionPrototype)) { - GeneratorFunctionPrototype[toStringTagSymbol] = "GeneratorFunction"; - } - GeneratorFunction.displayName = GeneratorFunctionPrototype[toStringTagSymbol]; + GeneratorFunction.displayName = ensureDefaultToStringTag( + GeneratorFunctionPrototype, + "GeneratorFunction" + ); // Helper for defining the .next, .throw, and .return methods of the // Iterator interface in terms of a single ._invoke method. @@ -116,9 +123,7 @@ var runtime = (function (exports) { Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); } else { genFun.__proto__ = GeneratorFunctionPrototype; - if (!(toStringTagSymbol in genFun)) { - genFun[toStringTagSymbol] = "GeneratorFunction"; - } + ensureDefaultToStringTag(genFun, "GeneratorFunction"); } genFun.prototype = Object.create(Gp); return genFun; @@ -388,9 +393,7 @@ var runtime = (function (exports) { // unified ._invoke helper method. defineIteratorMethods(Gp); - if (!(toStringTagSymbol in Gp)) { - Gp[toStringTagSymbol] = "Generator"; - } + ensureDefaultToStringTag(Gp, "Generator"); // A Generator should always return itself as the iterator object when the // @@iterator function is called on it. Some browsers' implementations of the