source: imaps-frontend/node_modules/es-abstract/2021/GetIterator.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $TypeError = require('es-errors/type');
6var $SyntaxError = require('es-errors/syntax');
7var $asyncIterator = GetIntrinsic('%Symbol.asyncIterator%', true);
8
9var inspect = require('object-inspect');
10var hasSymbols = require('has-symbols')();
11
12var getIteratorMethod = require('../helpers/getIteratorMethod');
13var AdvanceStringIndex = require('./AdvanceStringIndex');
14var Call = require('./Call');
15var GetMethod = require('./GetMethod');
16var IsArray = require('./IsArray');
17var Type = require('./Type');
18
19// https://262.ecma-international.org/11.0/#sec-getiterator
20
21module.exports = function GetIterator(obj, hint, method) {
22 var actualHint = hint;
23 if (arguments.length < 2) {
24 actualHint = 'sync';
25 }
26 if (actualHint !== 'sync' && actualHint !== 'async') {
27 throw new $TypeError("Assertion failed: `hint` must be one of 'sync' or 'async', got " + inspect(hint));
28 }
29
30 var actualMethod = method;
31 if (arguments.length < 3) {
32 if (actualHint === 'async') {
33 if (hasSymbols && $asyncIterator) {
34 actualMethod = GetMethod(obj, $asyncIterator);
35 }
36 if (actualMethod === undefined) {
37 throw new $SyntaxError("async from sync iterators aren't currently supported");
38 }
39 } else {
40 actualMethod = getIteratorMethod(
41 {
42 AdvanceStringIndex: AdvanceStringIndex,
43 GetMethod: GetMethod,
44 IsArray: IsArray
45 },
46 obj
47 );
48 }
49 }
50 var iterator = Call(actualMethod, obj);
51 if (Type(iterator) !== 'Object') {
52 throw new $TypeError('iterator must return an object');
53 }
54
55 return iterator;
56
57 // TODO: This should return an IteratorRecord
58 /*
59 var nextMethod = GetV(iterator, 'next');
60 return {
61 '[[Iterator]]': iterator,
62 '[[NextMethod]]': nextMethod,
63 '[[Done]]': false
64 };
65 */
66};
Note: See TracBrowser for help on using the repository browser.