source: imaps-frontend/node_modules/es-abstract/2021/AddEntriesFromIterable.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.4 KB
Line 
1'use strict';
2
3var inspect = require('object-inspect');
4
5var $TypeError = require('es-errors/type');
6
7var Call = require('./Call');
8var Get = require('./Get');
9var GetIterator = require('./GetIterator');
10var IsCallable = require('./IsCallable');
11var IteratorClose = require('./IteratorClose');
12var IteratorStep = require('./IteratorStep');
13var IteratorValue = require('./IteratorValue');
14var ThrowCompletion = require('./ThrowCompletion');
15
16var isObject = require('../helpers/isObject');
17
18// https://262.ecma-international.org/10.0/#sec-add-entries-from-iterable
19
20module.exports = function AddEntriesFromIterable(target, iterable, adder) {
21 if (!IsCallable(adder)) {
22 throw new $TypeError('Assertion failed: `adder` is not callable');
23 }
24 if (iterable == null) {
25 throw new $TypeError('Assertion failed: `iterable` is present, and not nullish');
26 }
27 var iteratorRecord = GetIterator(iterable);
28 while (true) { // eslint-disable-line no-constant-condition
29 var next = IteratorStep(iteratorRecord);
30 if (!next) {
31 return target;
32 }
33 var nextItem = IteratorValue(next);
34 if (!isObject(nextItem)) {
35 var error = ThrowCompletion(new $TypeError('iterator next must return an Object, got ' + inspect(nextItem)));
36 return IteratorClose(iteratorRecord, error);
37 }
38 try {
39 var k = Get(nextItem, '0');
40 var v = Get(nextItem, '1');
41 Call(adder, target, [k, v]);
42 } catch (e) {
43 return IteratorClose(iteratorRecord, ThrowCompletion(e));
44 }
45 }
46};
Note: See TracBrowser for help on using the repository browser.