1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 'use strict';
- var GetIntrinsic = require('get-intrinsic');
- var $TypeError = require('es-errors/type');
- var $asyncIterator = GetIntrinsic('%Symbol.asyncIterator%', true);
- var inspect = require('object-inspect');
- var hasSymbols = require('has-symbols')();
- var AdvanceStringIndex = require('./AdvanceStringIndex');
- var CreateAsyncFromSyncIterator = require('./CreateAsyncFromSyncIterator');
- var GetIteratorFromMethod = require('./GetIteratorFromMethod');
- var GetMethod = require('./GetMethod');
- var IsArray = require('./IsArray');
- var getIteratorMethod = require('../helpers/getIteratorMethod');
- module.exports = function GetIterator(obj, kind) {
- if (kind !== 'sync' && kind !== 'async') {
- throw new $TypeError("Assertion failed: `kind` must be one of 'sync' or 'async', got " + inspect(kind));
- }
- var method;
- if (kind === 'async') {
- if (hasSymbols && $asyncIterator) {
- method = GetMethod(obj, $asyncIterator);
- }
- }
- if (typeof method === 'undefined') {
-
- var syncMethod = getIteratorMethod(
- {
- AdvanceStringIndex: AdvanceStringIndex,
- GetMethod: GetMethod,
- IsArray: IsArray
- },
- obj
- );
- if (kind === 'async') {
- if (typeof syncMethod === 'undefined') {
- throw new $TypeError('iterator method is `undefined`');
- }
- var syncIteratorRecord = GetIteratorFromMethod(obj, syncMethod);
- return CreateAsyncFromSyncIterator(syncIteratorRecord);
- }
- method = syncMethod;
- }
- if (typeof method === 'undefined') {
- throw new $TypeError('iterator method is `undefined`');
- }
- return GetIteratorFromMethod(obj, method);
- };
|