es.iterator.every.js 738 B

1234567891011121314151617181920
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var iterate = require('../internals/iterate');
  4. var aCallable = require('../internals/a-callable');
  5. var anObject = require('../internals/an-object');
  6. var getIteratorDirect = require('../internals/get-iterator-direct');
  7. // `Iterator.prototype.every` method
  8. // https://tc39.es/ecma262/#sec-iterator.prototype.every
  9. $({ target: 'Iterator', proto: true, real: true }, {
  10. every: function every(predicate) {
  11. anObject(this);
  12. aCallable(predicate);
  13. var record = getIteratorDirect(this);
  14. var counter = 0;
  15. return !iterate(record, function (value, stop) {
  16. if (!predicate(value, counter++)) return stop();
  17. }, { IS_RECORD: true, INTERRUPTED: true }).stopped;
  18. }
  19. });