5d4e75295020fdda7837617939b34018bb0c937bcd1d8f209f95252b138ae7688d55570a4667468a6a215865f0539d678521ee148d187d0c07a8abe5a07408 1.2 KB

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