source: imaps-frontend/node_modules/es-abstract/2024/GetIterator.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.8 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $TypeError = require('es-errors/type');
6var $asyncIterator = GetIntrinsic('%Symbol.asyncIterator%', true);
7
8var inspect = require('object-inspect');
9var hasSymbols = require('has-symbols')();
10
11var AdvanceStringIndex = require('./AdvanceStringIndex');
12var CreateAsyncFromSyncIterator = require('./CreateAsyncFromSyncIterator');
13var GetIteratorFromMethod = require('./GetIteratorFromMethod');
14var GetMethod = require('./GetMethod');
15var IsArray = require('./IsArray');
16
17var ES = {
18 AdvanceStringIndex: AdvanceStringIndex,
19 GetMethod: GetMethod,
20 IsArray: IsArray
21};
22
23var getIteratorMethod = require('../helpers/getIteratorMethod');
24
25// https://262.ecma-international.org/14.0/#sec-getiterator
26
27module.exports = function GetIterator(obj, kind) {
28 if (kind !== 'SYNC' && kind !== 'ASYNC') {
29 throw new $TypeError("Assertion failed: `kind` must be one of 'sync' or 'async', got " + inspect(kind));
30 }
31
32 var method;
33 if (kind === 'ASYNC') { // step 1
34 if (hasSymbols && $asyncIterator) {
35 method = GetMethod(obj, $asyncIterator); // step 1.a
36 }
37 }
38 if (typeof method === 'undefined') { // step 1.b
39 // var syncMethod = GetMethod(obj, $iterator); // step 1.b.i
40 var syncMethod = getIteratorMethod(ES, obj);
41 if (kind === 'ASYNC') {
42 if (typeof syncMethod === 'undefined') {
43 throw new $TypeError('iterator method is `undefined`'); // step 1.b.ii
44 }
45 var syncIteratorRecord = GetIteratorFromMethod(obj, syncMethod); // step 1.b.iii
46 return CreateAsyncFromSyncIterator(syncIteratorRecord); // step 1.b.iv
47 }
48 method = syncMethod; // step 2, kind of
49 }
50
51 if (typeof method === 'undefined') {
52 throw new $TypeError('iterator method is `undefined`'); // step 3
53 }
54 return GetIteratorFromMethod(obj, method); // step 4
55};
Note: See TracBrowser for help on using the repository browser.