Skip to content
Permalink
Newer
Older
100644 35 lines (29 sloc) 874 Bytes
September 14, 2020 10:42
1
'use strict';
2
3
var GetIntrinsic = require('../GetIntrinsic');
4
5
var $TypeError = GetIntrinsic('%TypeError%');
6
7
var getIteratorMethod = require('../helpers/getIteratorMethod');
8
var AdvanceStringIndex = require('./AdvanceStringIndex');
9
var Call = require('./Call');
10
var GetMethod = require('./GetMethod');
11
var IsArray = require('./IsArray');
12
var Type = require('./Type');
13
14
// https://ecma-international.org/ecma-262/6.0/#sec-getiterator
15
16
module.exports = function GetIterator(obj, method) {
17
var actualMethod = method;
18
if (arguments.length < 2) {
19
actualMethod = getIteratorMethod(
20
{
21
AdvanceStringIndex: AdvanceStringIndex,
22
GetMethod: GetMethod,
23
IsArray: IsArray,
24
Type: Type
25
},
26
obj
27
);
28
}
29
var iterator = Call(actualMethod, obj);
30
if (Type(iterator) !== 'Object') {
31
throw new $TypeError('iterator must return an object');
32
}
33
34
return iterator;
35
};