| 1 | 'use strict';
|
|---|
| 2 | var $ = require('../internals/export');
|
|---|
| 3 | var call = require('../internals/function-call');
|
|---|
| 4 | var iterate = require('../internals/iterate');
|
|---|
| 5 | var aCallable = require('../internals/a-callable');
|
|---|
| 6 | var anObject = require('../internals/an-object');
|
|---|
| 7 | var getIteratorDirect = require('../internals/get-iterator-direct');
|
|---|
| 8 | var iteratorClose = require('../internals/iterator-close');
|
|---|
| 9 | var iteratorHelperWithoutClosingOnEarlyError = require('../internals/iterator-helper-without-closing-on-early-error');
|
|---|
| 10 |
|
|---|
| 11 | var someWithoutClosingOnEarlyError = iteratorHelperWithoutClosingOnEarlyError('some', TypeError);
|
|---|
| 12 |
|
|---|
| 13 | // `Iterator.prototype.some` method
|
|---|
| 14 | // https://tc39.es/ecma262/#sec-iterator.prototype.some
|
|---|
| 15 | $({ target: 'Iterator', proto: true, real: true, forced: someWithoutClosingOnEarlyError }, {
|
|---|
| 16 | some: function some(predicate) {
|
|---|
| 17 | anObject(this);
|
|---|
| 18 | try {
|
|---|
| 19 | aCallable(predicate);
|
|---|
| 20 | } catch (error) {
|
|---|
| 21 | iteratorClose(this, 'throw', error);
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | if (someWithoutClosingOnEarlyError) return call(someWithoutClosingOnEarlyError, this, predicate);
|
|---|
| 25 |
|
|---|
| 26 | var record = getIteratorDirect(this);
|
|---|
| 27 | var counter = 0;
|
|---|
| 28 | return iterate(record, function (value, stop) {
|
|---|
| 29 | if (predicate(value, counter++)) return stop();
|
|---|
| 30 | }, { IS_RECORD: true, INTERRUPTED: true }).stopped;
|
|---|
| 31 | }
|
|---|
| 32 | });
|
|---|