-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
363 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/core-js-pure/override/modules/esnext.typed-array.from-async.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require('../../modules/es.array.iterator'); | ||
require('../../modules/es.object.to-string'); | ||
require('../../modules/es.promise'); | ||
require('../../modules/es.string.iterator'); | ||
require('../../modules/esnext.array.from-async'); | ||
var path = require('../../internals/path'); | ||
|
||
module.exports = path.Array.fromAsync; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('../../modules/esnext.typed-array.from-async'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
var bind = require('../internals/function-bind-context'); | ||
var toObject = require('../internals/to-object'); | ||
var isConstructor = require('../internals/is-constructor'); | ||
var getAsyncIterator = require('../internals/get-async-iterator'); | ||
var getIterator = require('../internals/get-iterator'); | ||
var getIteratorMethod = require('../internals/get-iterator-method'); | ||
var getMethod = require('../internals/get-method'); | ||
var getVirtual = require('../internals/entry-virtual'); | ||
var wellKnownSymbol = require('../internals/well-known-symbol'); | ||
var AsyncFromSyncIterator = require('../internals/async-from-sync-iterator'); | ||
var toArray = require('../internals/async-iterator-iteration').toArray; | ||
|
||
var ASYNC_ITERATOR = wellKnownSymbol('asyncIterator'); | ||
var arrayIterator = getVirtual('Array').values; | ||
|
||
// `Array.fromAsync` method implementation | ||
// https://github.com/tc39/proposal-array-from-async | ||
module.exports = function fromAsync(asyncItems /* , mapfn = undefined, thisArg = undefined */) { | ||
var O = toObject(asyncItems); | ||
var argumentsLength = arguments.length; | ||
var mapfn = argumentsLength > 1 ? arguments[1] : undefined; | ||
if (mapfn !== undefined) mapfn = bind(mapfn, argumentsLength > 2 ? arguments[2] : undefined, 2); | ||
var usingAsyncIterator = getMethod(O, ASYNC_ITERATOR); | ||
var usingIterator; | ||
if (!usingAsyncIterator) usingIterator = getIteratorMethod(O); | ||
var A = isConstructor(this) ? new this() : []; | ||
var iterator = usingAsyncIterator | ||
? getAsyncIterator(O, usingAsyncIterator) | ||
: new AsyncFromSyncIterator(getIterator(O, usingIterator || arrayIterator)); | ||
return toArray(iterator, mapfn, A); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var $ = require('../internals/export'); | ||
var fromAsync = require('../internals/array-from-async'); | ||
|
||
// `Array.fromAsync` method | ||
// https://github.com/tc39/proposal-array-from-async | ||
$({ target: 'Array', stat: true }, { | ||
fromAsync: fromAsync | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
var aConstructor = require('../internals/a-constructor'); | ||
var arrayFromAsync = require('../internals/array-from-async'); | ||
var TYPED_ARRAYS_CONSTRUCTORS_REQUIRES_WRAPPERS = require('../internals/typed-array-constructors-require-wrappers'); | ||
var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); | ||
var arrayFromConstructorAndList = require('../internals/array-from-constructor-and-list'); | ||
|
||
var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor; | ||
var exportTypedArrayStaticMethod = ArrayBufferViewCore.exportTypedArrayStaticMethod; | ||
|
||
// `%TypedArray%.fromAsync` method | ||
// https://github.com/tc39/proposal-array-from-async | ||
// eslint-disable-next-line -- required for .length | ||
exportTypedArrayStaticMethod('fromAsync', function fromAsync(asyncItems /* , mapfn = undefined, thisArg = undefined */) { | ||
var C = aConstructor(this); | ||
return arrayFromAsync.apply(Array, arguments).then(function (list) { | ||
return arrayFromConstructorAndList(aTypedArrayConstructor(C), list); | ||
}); | ||
}, TYPED_ARRAYS_CONSTRUCTORS_REQUIRES_WRAPPERS); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// https://github.com/tc39/proposal-array-from-async | ||
require('../modules/esnext.array.from-async'); | ||
require('../modules/esnext.typed-array.from-async'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { createAsyncIterable, createIterable } from '../helpers/helpers'; | ||
import { STRICT_THIS } from '../helpers/constants'; | ||
import Promise from 'core-js-pure/es/promise'; | ||
import fromAsync from 'core-js-pure/features/array/from-async'; | ||
|
||
QUnit.test('Array.fromAsync', assert => { | ||
assert.expect(25); | ||
const async = assert.async(); | ||
|
||
assert.isFunction(fromAsync); | ||
assert.arity(fromAsync, 1); | ||
assert.name(fromAsync, 'fromAsync'); | ||
|
||
function C() { /* empty */ } | ||
|
||
fromAsync(createAsyncIterable([1, 2, 3]), it => it ** 2).then(it => { | ||
assert.arrayEqual(it, [1, 4, 9], 'async iterable and mapfn'); | ||
return fromAsync(createAsyncIterable([1]), function (arg, index) { | ||
assert.same(this, STRICT_THIS, 'this'); | ||
assert.same(arguments.length, 2, 'arguments length'); | ||
assert.same(arg, 1, 'argument'); | ||
assert.same(index, 0, 'index'); | ||
}); | ||
}).then(() => { | ||
return fromAsync(createAsyncIterable([1, 2, 3])); | ||
}).then(it => { | ||
assert.arrayEqual(it, [1, 2, 3], 'async iterable without mapfn'); | ||
return fromAsync(createIterable([1, 2, 3]), arg => arg ** 2); | ||
}).then(it => { | ||
assert.arrayEqual(it, [1, 4, 9], 'iterable and mapfn'); | ||
return fromAsync(createIterable([1, 2, 3]), arg => Promise.resolve(arg ** 2)); | ||
}).then(it => { | ||
assert.arrayEqual(it, [1, 4, 9], 'iterable and async mapfn'); | ||
return fromAsync(createIterable([1]), function (arg, index) { | ||
assert.same(this, STRICT_THIS, 'this'); | ||
assert.same(arguments.length, 2, 'arguments length'); | ||
assert.same(arg, 1, 'argument'); | ||
assert.same(index, 0, 'index'); | ||
}); | ||
}).then(() => { | ||
return fromAsync(createIterable([1, 2, 3])); | ||
}).then(it => { | ||
assert.arrayEqual(it, [1, 2, 3], 'iterable and without mapfn'); | ||
return fromAsync([1, Promise.resolve(2), 3]); | ||
}).then(it => { | ||
assert.arrayEqual(it, [1, 2, 3], 'array'); | ||
return fromAsync('123'); | ||
}).then(it => { | ||
assert.arrayEqual(it, ['1', '2', '3'], 'string'); | ||
return fromAsync.call(C, [1]); | ||
}).then(it => { | ||
assert.ok(it instanceof C, 'subclassable'); | ||
return fromAsync({ length: 1, 0: 1 }); | ||
}).then(it => { | ||
assert.arrayEqual(it, [1], 'non-iterable'); | ||
return fromAsync(createIterable([1]), () => { throw 42; }); | ||
}).catch(error => { | ||
assert.same(error, 42, 'rejection on a callback error'); | ||
}).then(() => async()); | ||
|
||
assert.throws(() => fromAsync(undefined, () => { /* empty */ }), TypeError); | ||
assert.throws(() => fromAsync(null, () => { /* empty */ }), TypeError); | ||
assert.throws(() => fromAsync([1], null), TypeError); | ||
assert.throws(() => fromAsync([1], {}), TypeError); | ||
}); |
Oops, something went wrong.