1 | 'use strict';
|
---|
2 |
|
---|
3 | var $TypeError = require('es-errors/type');
|
---|
4 |
|
---|
5 | var AdvanceStringIndex = require('es-abstract/2024/AdvanceStringIndex');
|
---|
6 | var Call = require('es-abstract/2024/Call');
|
---|
7 | var GetIteratorDirect = require('./GetIteratorDirect');
|
---|
8 | var GetMethod = require('es-abstract/2024/GetMethod');
|
---|
9 | var IsArray = require('es-abstract/2024/IsArray');
|
---|
10 | var Type = require('es-abstract/2024/Type');
|
---|
11 |
|
---|
12 | var getIteratorMethod = require('es-abstract/helpers/getIteratorMethod');
|
---|
13 |
|
---|
14 | // https://tc39.es/proposal-iterator-helpers/#sec-getiteratorflattenable
|
---|
15 |
|
---|
16 | module.exports = function GetIteratorFlattenable(obj, stringHandling) {
|
---|
17 | if (stringHandling !== 'REJECT-STRINGS' && stringHandling !== 'ITERATE-STRINGS') {
|
---|
18 | throw new $TypeError('Assertion failed: `stringHandling` must be "REJECT-STRINGS" or "ITERATE-STRINGS"');
|
---|
19 | }
|
---|
20 |
|
---|
21 | if (Type(obj) !== 'Object') {
|
---|
22 | if (stringHandling === 'REJECT-STRINGS' || typeof obj !== 'string') {
|
---|
23 | throw new $TypeError('obj must be an Object'); // step 1.a
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | var method = void undefined; // step 2
|
---|
28 |
|
---|
29 | // method = GetMethod(obj, Symbol.iterator); // step 5.a
|
---|
30 | method = getIteratorMethod(
|
---|
31 | {
|
---|
32 | AdvanceStringIndex: AdvanceStringIndex,
|
---|
33 | GetMethod: GetMethod,
|
---|
34 | IsArray: IsArray
|
---|
35 | },
|
---|
36 | obj
|
---|
37 | );
|
---|
38 |
|
---|
39 | var iterator;
|
---|
40 | if (typeof method === 'undefined') { // step 3
|
---|
41 | iterator = obj; // step 3.a
|
---|
42 | } else { // step 4
|
---|
43 | iterator = Call(method, obj); // step 4.a
|
---|
44 | }
|
---|
45 |
|
---|
46 | if (Type(iterator) !== 'Object') {
|
---|
47 | throw new $TypeError('iterator must be an Object'); // step 5
|
---|
48 | }
|
---|
49 | return GetIteratorDirect(iterator); // step 6
|
---|
50 | };
|
---|