source: frontend/node_modules/es-abstract/2020/GetIterator.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

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