source: imaps-frontend/node_modules/es-abstract/2019/AddEntriesFromIterable.js

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