Version 1
[yaffs-website] / node_modules / core-js / modules / es6.array.iterator.js
1 'use strict';
2 var addToUnscopables = require('./_add-to-unscopables')
3   , step             = require('./_iter-step')
4   , Iterators        = require('./_iterators')
5   , toIObject        = require('./_to-iobject');
6
7 // 22.1.3.4 Array.prototype.entries()
8 // 22.1.3.13 Array.prototype.keys()
9 // 22.1.3.29 Array.prototype.values()
10 // 22.1.3.30 Array.prototype[@@iterator]()
11 module.exports = require('./_iter-define')(Array, 'Array', function(iterated, kind){
12   this._t = toIObject(iterated); // target
13   this._i = 0;                   // next index
14   this._k = kind;                // kind
15 // 22.1.5.2.1 %ArrayIteratorPrototype%.next()
16 }, function(){
17   var O     = this._t
18     , kind  = this._k
19     , index = this._i++;
20   if(!O || index >= O.length){
21     this._t = undefined;
22     return step(1);
23   }
24   if(kind == 'keys'  )return step(0, index);
25   if(kind == 'values')return step(0, O[index]);
26   return step(0, [index, O[index]]);
27 }, 'values');
28
29 // argumentsList[@@iterator] is %ArrayProto_values% (9.4.4.6, 9.4.4.7)
30 Iterators.Arguments = Iterators.Array;
31
32 addToUnscopables('keys');
33 addToUnscopables('values');
34 addToUnscopables('entries');