michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: 'use strict'; michael@0: michael@0: module.metadata = { michael@0: "stability": "experimental" michael@0: }; michael@0: michael@0: // This is known as @@iterator in the ES6 spec. Until it is bound to michael@0: // some well-known name, find the @@iterator object by expecting it as michael@0: // the first property accessed on a for-of iterable. michael@0: const iteratorSymbol = (function() { michael@0: try { michael@0: for (var _ of Proxy.create({get: function(_, name) { throw name; } })) michael@0: break; michael@0: } catch (name) { michael@0: return name; michael@0: } michael@0: throw new TypeError; michael@0: })(); michael@0: michael@0: exports.iteratorSymbol = iteratorSymbol; michael@0: michael@0: // An adaptor that, given an object that is iterable with for-of, is michael@0: // suitable for being bound to __iterator__ in order to make the object michael@0: // iterable in the same way via for-in. michael@0: function forInIterator() { michael@0: for (let item of this) michael@0: yield item; michael@0: } michael@0: michael@0: exports.forInIterator = forInIterator;