Skip to content

Commit 383556b

Browse files
committed
move array type checking from enumerator to .all
1 parent 10a6859 commit 383556b

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

lib/es6-promise/enumerator.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,23 @@ function Enumerator(Constructor, input) {
3030
makePromise(this.promise);
3131
}
3232

33-
if (isArray(input)) {
34-
this._input = input;
35-
this.length = input.length;
36-
this._remaining = input.length;
33+
this._input = input;
34+
this.length = input.length;
35+
this._remaining = input.length;
3736

38-
this._result = new Array(this.length);
37+
this._result = new Array(this.length);
3938

40-
if (this.length === 0) {
39+
if (this.length === 0) {
40+
fulfill(this.promise, this._result);
41+
} else {
42+
this.length = this.length || 0;
43+
this._enumerate();
44+
if (this._remaining === 0) {
4145
fulfill(this.promise, this._result);
42-
} else {
43-
this.length = this.length || 0;
44-
this._enumerate();
45-
if (this._remaining === 0) {
46-
fulfill(this.promise, this._result);
47-
}
4846
}
49-
} else {
50-
reject(this.promise, validationError());
5147
}
5248
}
5349

54-
function validationError() {
55-
return new Error('Array Methods must be provided an Array');
56-
};
57-
5850
Enumerator.prototype._enumerate = function() {
5951
let { length, _input } = this;
6052

lib/es6-promise/promise/all.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Enumerator from '../enumerator';
2-
2+
import {
3+
isArray,
4+
isMaybeThenable
5+
} from '../utils';
36
/**
47
`Promise.all` accepts an array of promises, and returns a new promise which
58
is fulfilled with an array of fulfillment values for the passed promises, or
@@ -48,5 +51,9 @@ import Enumerator from '../enumerator';
4851
@static
4952
*/
5053
export default function all(entries) {
54+
if (!isArray(entries)){
55+
return this.reject(new TypeError('You must pass an array to all.'));
56+
}
57+
5158
return new Enumerator(this, entries).promise;
5259
}

0 commit comments

Comments
 (0)