source: frontend/node_modules/es-abstract/helpers/getIteratorMethod.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[9af201e]1'use strict';
2
3var hasSymbols = require('has-symbols')();
4var GetIntrinsic = require('get-intrinsic');
5var callBound = require('call-bound');
6var isString = require('is-string');
7
8var $iterator = GetIntrinsic('%Symbol.iterator%', true);
9var $stringSlice = callBound('String.prototype.slice');
10var $String = GetIntrinsic('%String%');
11
12var IsArray = require('./IsArray');
13
14module.exports = function getIteratorMethod(ES, iterable) {
15 var usingIterator;
16 if (hasSymbols) {
17 usingIterator = ES.GetMethod(iterable, $iterator);
18 } else if (IsArray(iterable)) {
19 usingIterator = function () {
20 var i = -1;
21 var arr = this;
22 return {
23 next: function () {
24 i += 1;
25 return {
26 done: i >= arr.length,
27 value: arr[i]
28 };
29 }
30 };
31 };
32 } else if (isString(iterable)) {
33 usingIterator = function () {
34 var i = 0;
35 return {
36 next: function () {
37 var nextIndex = ES.AdvanceStringIndex($String(iterable), i, true);
38 var value = $stringSlice(iterable, i, nextIndex);
39 i = nextIndex;
40 var done = nextIndex > iterable.length;
41 return {
42 done: done,
43 value: done ? void undefined : value
44 };
45 }
46 };
47 };
48 }
49 return usingIterator;
50};
Note: See TracBrowser for help on using the repository browser.