mirror of https://github.com/jkjoy/sunpeiwen.git
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
'use strict';
|
|
var addToUnscopables = require('./_add-to-unscopables');
|
|
var step = require('./_iter-step');
|
|
var Iterators = require('./_iterators');
|
|
var toIObject = require('./_to-iobject');
|
|
|
|
// 22.1.3.4 Array.prototype.entries()
|
|
// 22.1.3.13 Array.prototype.keys()
|
|
// 22.1.3.29 Array.prototype.values()
|
|
// 22.1.3.30 Array.prototype[@@iterator]()
|
|
module.exports = require('./_iter-define')(Array, 'Array', function (iterated, kind) {
|
|
this._t = toIObject(iterated); // target
|
|
this._i = 0; // next index
|
|
this._k = kind; // kind
|
|
// 22.1.5.2.1 %ArrayIteratorPrototype%.next()
|
|
}, function () {
|
|
var O = this._t;
|
|
var kind = this._k;
|
|
var index = this._i++;
|
|
if (!O || index >= O.length) {
|
|
this._t = undefined;
|
|
return step(1);
|
|
}
|
|
if (kind == 'keys') return step(0, index);
|
|
if (kind == 'values') return step(0, O[index]);
|
|
return step(0, [index, O[index]]);
|
|
}, 'values');
|
|
|
|
// argumentsList[@@iterator] is %ArrayProto_values% (9.4.4.6, 9.4.4.7)
|
|
Iterators.Arguments = Iterators.Array;
|
|
|
|
addToUnscopables('keys');
|
|
addToUnscopables('values');
|
|
addToUnscopables('entries');
|