UNPKG

1.2 kBJavaScriptView Raw
1'use strict';
2// TODO: Remove from `core-js@4`
3var getBuiltIn = require('../internals/get-built-in');
4var aConstructor = require('../internals/a-constructor');
5var arrayFromAsync = require('../internals/array-from-async');
6var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
7var arrayFromConstructorAndList = require('../internals/array-from-constructor-and-list');
8
9var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor;
10var exportTypedArrayStaticMethod = ArrayBufferViewCore.exportTypedArrayStaticMethod;
11
12// `%TypedArray%.fromAsync` method
13// https://github.com/tc39/proposal-array-from-async
14exportTypedArrayStaticMethod('fromAsync', function fromAsync(asyncItems /* , mapfn = undefined, thisArg = undefined */) {
15 var C = this;
16 var argumentsLength = arguments.length;
17 var mapfn = argumentsLength > 1 ? arguments[1] : undefined;
18 var thisArg = argumentsLength > 2 ? arguments[2] : undefined;
19 return new (getBuiltIn('Promise'))(function (resolve) {
20 aConstructor(C);
21 resolve(arrayFromAsync(asyncItems, mapfn, thisArg));
22 }).then(function (list) {
23 return arrayFromConstructorAndList(aTypedArrayConstructor(C), list);
24 });
25}, true);