main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
727 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
| 4 |
|
---|
| 5 | var Call = require('./Call');
|
---|
| 6 | var GetV = require('./GetV');
|
---|
| 7 | var IsCallable = require('./IsCallable');
|
---|
| 8 | var Type = require('./Type');
|
---|
| 9 |
|
---|
| 10 | // https://262.ecma-international.org/14.0/#sec-getiteratorfrommethod
|
---|
| 11 |
|
---|
| 12 | module.exports = function GetIteratorFromMethod(obj, method) {
|
---|
| 13 | if (!IsCallable(method)) {
|
---|
| 14 | throw new $TypeError('method must be a function');
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | var iterator = Call(method, obj); // step 1
|
---|
| 18 | if (Type(iterator) !== 'Object') {
|
---|
| 19 | throw new $TypeError('iterator must return an object'); // step 2
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | var nextMethod = GetV(iterator, 'next'); // step 3
|
---|
| 23 | return { // steps 4-5
|
---|
| 24 | '[[Iterator]]': iterator,
|
---|
| 25 | '[[NextMethod]]': nextMethod,
|
---|
| 26 | '[[Done]]': false
|
---|
| 27 | };
|
---|
| 28 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.