Files
react-native-devtools-frontend/node_modules/core-js-pure/modules/esnext.iterator.flat-map.js
T
Tim van der Lippe 1fe7f95b0e Add eslint-plugin-lit-a11y to manage_node_deps
This also adds the MPL-2.0 license as valid license to our allowed
licenses list.

R=jacktfranklin@chromium.org
DISABLE_THIRD_PARTY_CHECK=NPM update

Change-Id: I2a3bee2ffc0b328a0579ab62ab27f938bdc876c8
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2593130
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
2021-01-05 13:13:19 +00:00

53 lines
1.6 KiB
JavaScript

'use strict';
// https://github.com/tc39/proposal-iterator-helpers
var $ = require('../internals/export');
var aFunction = require('../internals/a-function');
var anObject = require('../internals/an-object');
var getIteratorMethod = require('../internals/get-iterator-method');
var createIteratorProxy = require('../internals/iterator-create-proxy');
var iteratorClose = require('../internals/iterator-close');
var IteratorProxy = createIteratorProxy(function (arg) {
var iterator = this.iterator;
var mapper = this.mapper;
var result, mapped, iteratorMethod, innerIterator;
while (true) {
try {
if (innerIterator = this.innerIterator) {
result = anObject(this.innerNext.call(innerIterator));
if (!result.done) return result.value;
this.innerIterator = this.innerNext = null;
}
result = anObject(this.next.call(iterator, arg));
if (this.done = !!result.done) return;
mapped = mapper(result.value);
iteratorMethod = getIteratorMethod(mapped);
if (iteratorMethod === undefined) {
throw TypeError('.flatMap callback should return an iterable object');
}
this.innerIterator = innerIterator = anObject(iteratorMethod.call(mapped));
this.innerNext = aFunction(innerIterator.next);
} catch (error) {
iteratorClose(iterator);
throw error;
}
}
});
$({ target: 'Iterator', proto: true, real: true }, {
flatMap: function flatMap(mapper) {
return new IteratorProxy({
iterator: anObject(this),
mapper: aFunction(mapper),
innerIterator: null,
innerNext: null
});
}
});